BEGIN; BEGIN EXPLAIN (ANALYZE, BUFFERS) select c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, sum(l_quantity) from customer, orders, lineitem where o_orderkey in ( select l_orderkey from lineitem group by l_orderkey having sum(l_quantity) > 312 ) and c_custkey = o_custkey and o_orderkey = l_orderkey group by c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice order by o_totalprice desc, o_orderdate LIMIT 100; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=10164873.69..10164876.44 rows=100 width=39) (actual time=105849.128..105849.461 rows=100 loops=1) Buffers: shared hit=1353674 read=1070483 written=4 -> GroupAggregate (cost=10164873.69..10991328.28 rows=30052894 width=39) (actual time=105849.126..105849.445 rows=100 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1353674 read=1070483 written=4 -> Sort (cost=10164873.69..10240005.93 rows=30052894 width=39) (actual time=105849.104..105849.150 rows=701 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 85kB Buffers: shared hit=1353674 read=1070483 written=4 -> Hash Join (cost=2889937.21..5610392.40 rows=30052894 width=39) (actual time=81459.314..105847.367 rows=777 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1353662 read=1070483 written=4 -> Seq Scan on lineitem (cost=0.00..1668603.89 rows=60105789 width=8) (actual time=0.029..13069.387 rows=60045603 loops=1) Buffers: shared hit=591315 read=476231 -> Hash (cost=2795999.91..2795999.91 rows=7514984 width=39) (actual time=81383.870..81383.870 rows=111 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65544kB Buffers: shared hit=762347 read=594252 written=4 -> Hash Join (cost=2181798.70..2795999.91 rows=7514984 width=39) (actual time=71515.587..81383.142 rows=111 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=762347 read=594252 written=4 -> Hash Join (cost=2112770.70..2614247.15 rows=7514984 width=20) (actual time=70465.165..80329.092 rows=111 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=732384 read=588937 written=4 -> Seq Scan on orders (cost=0.00..404074.68 rows=15029968 width=16) (actual time=0.012..3876.324 rows=15015000 loops=1) Buffers: shared hit=217996 read=35779 written=1 -> Hash (cost=2061471.46..2061471.46 rows=4103939 width=4) (actual time=70257.587..70257.587 rows=111 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32772kB Buffers: shared hit=514388 read=553158 written=3 -> HashAggregate (cost=1969132.83..2020432.07 rows=4103939 width=8) (actual time=56299.356..70256.440 rows=111 loops=1) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > 312::double precision) Rows Removed by Filter: 15014889 Buffers: shared hit=514388 read=553158 written=3 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1668603.89 rows=60105789 width=8) (actual time=0.015..15428.031 rows=60045603 loops=1) Buffers: shared hit=514388 read=553158 written=3 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1041.936..1041.936 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=29963 read=5315 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.014..578.809 rows=1500000 loops=1) Buffers: shared hit=29963 read=5315 Planning time: 4.376 ms Execution time: 106144.626 ms (42 rows) COMMIT; COMMIT