Qualified Subquery Rewrite
Copyright © 2024 PawSQL
explain analyze
select * from orders where o_orderdate < all(select o_orderdate from orders where o_custkey > 100)
;
-> Filter: <not>((orders.O_ORDERDATE >= (select #2))) (cost=13846.04 rows=133181) (actual time=672.536..672.536 rows=0 loops=1)
-> Table scan on orders (cost=13846.04 rows=199762) (actual time=2.460..408.819 rows=201800 loops=1)
-> Select #2 (subquery in condition; run only once)
-> Aggregate: min(orders.O_ORDERDATE) (cost=30281.45 rows=1) (actual time=214.765..214.765 rows=1 loops=1)
-> Filter: (orders.O_CUSTKEY > 100) (cost=20293.35 rows=99881) (actual time=0.237..202.460 rows=199252 loops=1)
-> Covering index range scan on orders using comp_idx over (100 < O_CUSTKEY) (cost=20293.35 rows=99881) (actual time=0.138..189.628 rows=199252 loops=1)