devo un esempio di query come ad esempio:Quale tipo di indice è ideale per questa query?
SELECT
rest.name, rest.shortname
FROM
restaurant AS rest
INNER JOIN specials ON rest.id=specials.restaurantid
WHERE
specials.dateend >= CURDATE()
AND
rest.state='VIC'
AND
rest.status = 1
AND
specials.status = 1
ORDER BY
rest.name ASC;
Chiedo solo di sotto dei due indici, che sarebbe meglio sul tavolo del ristorante?
id,state,status,name
state,status,name
Non è sicuro che la colonna utilizzata nel join debba essere inclusa?
abbastanzaDivertente però, mi hanno creato entrambi i tipi per i test ed entrambe le volte MySQL sceglie l'indice primario, che è solo id
. Perché?
Spiegate in uscita:
1,'SIMPLE','specials','index','NewIndex1\,NewIndex2\,NewIndex3\,NewIndex4','NewIndex4','11',\N,82,'Using where; Using index; Using temporary; Using filesort',
1,'SIMPLE','rest','eq_ref','PRIMARY\,search\,status\,state\,NewIndex1\,NewIndex2\,id-suburb\,NewIndex3\,id-status-name','PRIMARY','4','db_name.specials.restaurantid',1,'Using where'
Non molte righe in questo momento così forse è per questo che è la scelta PRIMARIO !?
È sempre possibile utilizzare 'EXPLAIN' per ottenere alcune informazioni su come verrà eseguita la query di selezione. http://dev.mysql.com/doc/refman/5.0/en/using-explain.html –
Cyclonecode
L'ho fatto, è così che ho scoperto che stava usando l'indice 'PRIMARY', che conteneva la colonna' id'. – Brett
Potresti postare il tuo output completo di spiegazioni e la versione di MySQL? –