New answers tagged

0

EXPLAIN may be saying 2, but the real number could be 1 or 10000. Don't trust EXPLAIN. Here's how to get a more accurate count of rows touched by a query: FLUSH STATUS; SELECT ...; SHOW SESSION STATUS LIKE 'Handler_%';


2

This composite index may help: INDEX(account_id, lastname) When adding it, you may as well remove INDEX(account_id), since it will then be redundant. This may be even better, but I am not sure: INDEX(deleted, account_id, lastname) However it does not supersede INDEX(account_id).


0

Try using exists operator which should perform a search and stop when the first record that matches the condition is found: select 1 from dual where exists ( select * from someTable where owner_id = 0 and reviewed = 0 );


0

LIMIT provides a window into the result set. LIMIT 1 is equivalent to LIMIT 0, 1; return 1 row starting at offset 0. Explain plan reports the estimated number of rows the LIMIT is running against. However, only one match should be examined. Testing on your SQL Fiddle shows the query runs against the INDEX (KEY) which should be the fastest access method. ...



Top 50 recent answers are included