我有这个查询:
SELECT adressid, adressname FROM kino_adressen WHERE city ='Seattle'
我想创建一个这样的索引
ALTER TABLE <tablename> ADD KEY index_abc(adressid, adressname(40))
但是当我使用以下方法检查它时:
EXPLAIN SELECT adressid, adressname FROM kino_adressen WHERE city ='Seattle'
它说
type = ALL
possible keys = NULL
key = NULL
...rows = 106
谁能给一些建议如何正确地做到这一点?
// 编辑:另一个我不明白的问题:
SELECT DISTINCT
titel,
regie,
darsteller,
filmbild,
kino_filme.filmid,
kino_filme.beschreibung,
fsk,
filmlaenge,
verleih,
sprachfassung
FROM
kino_filme
LEFT JOIN kino_terminefilme ON (
kino_terminefilme.filmid = kino_filme.filmid
)
LEFT JOIN kino_termine ON (
kino_terminefilme.terminid = kino_termine.terminid
)
LEFT JOIN kino_kinos ON (
kino_kinos.kinoid = kino_termine.kinoid
)
LEFT JOIN kino_adressen ON (
kino_adressen.adressid = kino_kinos.adressid
)
WHERE
kino_adressen.adressid = 32038
为什么 kino_termine 不使用任何索引?我在创建时将其设置为 PK,甚至在之后添加了一个索引,但这些都没有帮助。