jomsfx Posted July 18, 2011 Share Posted July 18, 2011 I have a really simple query but can't figure out how to make it faster. It's just something like: SELECT field1 FROM table1 WHERE field2 = 'value'; Because of 300,000 rows in the table it takes around 50 seconds to execute. I have been researching about indexes and tried to create an index for field2(varchar 80) with an Index Type of Normal and Index Method of BTREE, but the process is still slow. The storage engine is InnoDB. Once I solve this I will be adding other criteria in the WHERE clause using other columns within the said table. If you could suggest another way to speed this up or could point me to the right direction I would really appreciate it. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/242247-simple-query-optimization-by-indexing/ Share on other sites More sharing options...
fenway Posted July 18, 2011 Share Posted July 18, 2011 Show us the EXPLAIN output. Quote Link to comment https://forums.phpfreaks.com/topic/242247-simple-query-optimization-by-indexing/#findComment-1244038 Share on other sites More sharing options...
jomsfx Posted July 18, 2011 Author Share Posted July 18, 2011 id:1 Select Type: Simple table: table1 type: ref possible keys: field2 key: field2 key len: 43 ref: const rows: 40950 Extra: Using Where This is how I created the index: CREATE INDEX field2 ON table1(field2(40)); Thanks Quote Link to comment https://forums.phpfreaks.com/topic/242247-simple-query-optimization-by-indexing/#findComment-1244050 Share on other sites More sharing options...
fenway Posted July 18, 2011 Share Posted July 18, 2011 That's not EXPLAIN output -- I mean post mysql's query plan using EXPLAIN. Quote Link to comment https://forums.phpfreaks.com/topic/242247-simple-query-optimization-by-indexing/#findComment-1244107 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.