select * from (
select t_tmp_a.*, rownum t_tmp_id from (
select t.*, i.counts
from table1 t, (select id, count(id) counts from table2 group by id) i
where t.id=i.id and t.kindid in (0,1,3) order by t.id desc
) t_tmp_a where rownum <= 20) t_tmp_b where t_tmp_id >= 11;
table1 と table2 には、テーブルごとに 200 万を超えるデータがあります。このクエリを実行するには 18 秒が必要です。このクエリを実行する前に、合計カウントを計算する必要があるため、約 7 秒かかるため、25 秒以上かかります。最適化するアイデアはありますか?