MockY Posted September 23, 2011 Share Posted September 23, 2011 I have a table with almost 800,000 rows. Without any indexes (just an auto incremented Id), a simple SELECT statement takes almost 2 seconds. SELECT Id, Number FROM clients WHERE Number=8596; Creating an index on Number makes no difference. The query takes just as long. Why on earth is that? I figured that if you create an index on the field you have in the WHERE clause, that the query should become so much faster. The Number field is a VARCHAR(11) by the way. EDIT: For some reason I tried to enclode the number in the where clause in single quotes, and then the query took 0.00 seconds. I've been trying to figure this out all day as I am creating a report file with just 17,000 records, but it has been taken hours and it's not even half done. I made this single quote change and the file was created in a few seconds. Now begs the question, why this enormous change? EDIT2: I did an explain on the last query and ended up with this +----+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+ | 1 | SIMPLE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | Impossible WHERE noticed after reading const tables | +----+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+ Without the quotes, I get this +----+-------------+----------+------+---------------+------+---------+------+--------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+----------+------+---------------+------+---------+------+--------+-------------+ | 1 | SIMPLE | clients | ALL | number_index | NULL | NULL | NULL | 725713 | Using where | +----+-------------+----------+------+---------------+------+---------+------+--------+-------------+ Even though the quoted query is efficient as heck and creates the results I want, the explain command sure came back with some odd data that makes me kind of confused. Any help with shedding some light on my problem would be much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/247691-creating-indes-makes-no-difference-in-select-statement/ Share on other sites More sharing options...
fenway Posted September 23, 2011 Share Posted September 23, 2011 Post the table structure, and the query. Quote Link to comment https://forums.phpfreaks.com/topic/247691-creating-indes-makes-no-difference-in-select-statement/#findComment-1272016 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.