will a mysql query run slower if one of the tables involved has no index defined??
Posted
by lock
on Stack Overflow
See other posts from Stack Overflow
or by lock
Published on 2010-03-23T02:25:43Z
Indexed on
2010/03/23
2:31 UTC
Read the original article
Hit count: 361
mysql
|query-optimization
there's this already populated database which came from another dev
im not sure what went on that dev's mind when he created the tables, but on one of our scripts there is this query involving 4 tables and it runs super slow
SELECT
a.col_1, a.col_2, a.col_3, a.col_4, a.col_5, a.col_6, a.col_7
FROM
a, b, c, d
WHERE
a.id = b.id
AND b.c_id = c.id
AND c.id = d.c_id
AND a.col_8 = '$col_8'
AND d.g_id = '$g_id'
AND c.private = '1'
NOTE: $col_8 and $g_id are variables from a form
its only my theory that it's due to tables b and c not having an index, although im guessing that the dev didnt think that it was necessary since those tables only tell relations between a and d, where b tells that the data in a belongs to a certain user, and c tells that the user belongs to a group in d
as you can see, there's not even a join or other extensive query functions used but this query which returns only around 100 rows takes 2 minutes to execute.
anyway my question is simply this post's title. will a mysql query run slower if one of the tables involved has no index defined??
© Stack Overflow or respective owner