¿Cómo almacena MySQL los índices?

Just a question. On of my websites became significant slower. Loadtimes taking over 30 seconds on 30k rows. I must say queries aren't optimized so 10k queries can be fired but still, I find this taking too long... So I figured, let's check the indexes. After viewing some of the 'problem' tables I saw I made index over multiple columns but the cardinality is only shown on 1 column and the other indexes have 0 cardinality.

Did I made wrong indexes? In other words, should I make an index for each column instead of combining them?

preguntado el 08 de noviembre de 11 a las 19:11

Do those fields have all the same values? -

You should enable slow logging to find the queries you're having problems with, the run them through EXPLAIN and post the results here or in a new question. -

No, only 1 field. See this screenshot as example: imageshack.us/f/812/schermafbeelding2011110kj.png This is a booking-table containing 35.721 rows at this moment. -

Have a look at my SQL indexing tutorial: use-the-index-luke.com - Not a short answer. Sorry. -

1 Respuestas

It's almost certainly the case that you created the wrong indexes. Most people do! :-)

There's no rule to create indexes on multiple columns vs. individual columns. The best indexes to create depends on the queries you run, not your database schema.

Analyzing the queries and deciding on indexes is a meticulous process. You can use EXPLICAR to see how a given query is using existing indexes. Be sure to read the docs:

respondido 08 nov., 11:23

Thanks for the reply. I know I should make indexes on columns most used to filter data from the tables. The columns in the screenshot (see comment in startpost) are the most used. Thanks for the links as well though I'm familiar using the EXPLAIN syntax. :) - Ben Fransen

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.