There may be some business requirements that need to retrieve the first N number of rows from a join tables. Some people may encounter unexpected performance problem.
Here is an example SQL that retrieves first 1000 row from a join tables of Employee and Department in the order of dpt_id. Where emp_dept and dpt_id columns are both indexed.
select *
from employee ,department
where emp_dept=dpt_id
order by dpt_id
limit 1000;
Here the following are the query plans...
How to tune “Order by Limit N” SQL statement?
Here is an example SQL that retrieves first 1000 row from a join tables of Employee and Department in the order of dpt_id. Where emp_dept and dpt_id columns are both indexed.
select *
from employee ,department
where emp_dept=dpt_id
order by dpt_id
limit 1000;
Here the following are the query plans...
How to tune “Order by Limit N” SQL statement?