How to index the following?

I have the following table ( file_category_tbl) for representing the connections between files and categories.

fileId - bigint(20)         
categoryId - bigint(20)
order - int(10)

So that the files in the category can be sorted, I have an order field ... Therefore, my question is what indexes I will need for optimal performance according to the following:

SELECT * FROM file_category_tbl WHERE categoryId="3" ORDER BY order ASC

I have a unique index a UNIQUE ( fileId, categoryId); Because it cannot be the same fileIdwith the same categoryId. I also have an index on categoryId, since this is what is being executed. I also have an index on order? ... but is this necessary? since it only performs orderByon this ...

Respectfully to any defendant ... J

+5
source share
2 answers

ORDER BY :

MySQL ORDER BY, - , WHERE. :

[ deletia ]

  • , , , ORDER BY:

    SELECT * FROM t1 WHERE key2=constant ORDER BY key1;

. :

, ORDER BY , ORDER BY - WHERE. ORDER BY:

[ deletia ]

SELECT * FROM t1
  WHERE key_part1=constant
  ORDER BY key_part2;

(categoryId,order) , , .

+2

, . Primary Key , Unique Index

, , , , , , . , , , 4 . , .

, : -)

+1

All Articles