select * from fd_peal where fid in (select fid from bert where sid is null) ;
takes 0.7 seconds to execute.
select * from fd_peal where fid in (select fid from bert where sid is null) order by rung;
(i.e. adding order by rung) takes between 70 and 90 seconds to execute.
The query returns 94 rows, the table fd_peal has 335154 rows, and the table bert has 335137 rows.
The execution plans for the queries are:
The tables are defined as follows:
I would have expected to order by clause to sort the rows returned by the query, whereas, given the amount of time the query is taking it is presumably doing the order by before the query.