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) > 313 ) 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=10174948.58..10174951.33 rows=100 width=39) (actual time=86848.381..86848.711 rows=99 loops=1) Buffers: shared hit=1515120 read=911414 dirtied=649 written=590 -> GroupAggregate (cost=10174948.58..11002225.34 rows=30082791 width=39) (actual time=86848.378..86848.700 rows=99 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1515120 read=911414 dirtied=649 written=590 -> Sort (cost=10174948.58..10250155.56 rows=30082791 width=39) (actual time=86848.366..86848.408 rows=693 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 79kB Buffers: shared hit=1515120 read=911414 dirtied=649 written=590 -> Hash Join (cost=2892561.17..5615722.67 rows=30082791 width=39) (actual time=65082.001..86847.078 rows=693 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1515108 read=911414 dirtied=649 written=590 -> Seq Scan on lineitem (cost=0.00..1670263.82 rows=60165582 width=8) (actual time=0.030..12461.896 rows=59985653 loops=1) Buffers: shared hit=571635 read=496973 dirtied=649 written=585 -> Hash (cost=2798530.21..2798530.21 rows=7522476 width=39) (actual time=64516.631..64516.631 rows=99 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65543kB Buffers: shared hit=943473 read=414441 written=5 -> Hash Join (cost=2183757.59..2798530.21 rows=7522476 width=39) (actual time=57346.833..64516.293 rows=99 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=943473 read=414441 written=5 -> Hash Join (cost=2114729.59..2616665.07 rows=7522476 width=20) (actual time=56167.306..63332.682 rows=99 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=912003 read=410633 written=4 -> Seq Scan on orders (cost=0.00..404477.52 rows=15044952 width=16) (actual time=0.013..3716.568 rows=15000000 loops=1) Buffers: shared hit=239571 read=14457 -> Hash (cost=2063430.36..2063430.36 rows=4103939 width=4) (actual time=55987.671..55987.671 rows=99 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32772kB Buffers: shared hit=672432 read=396176 written=4 -> HashAggregate (cost=1971091.73..2022390.97 rows=4103939 width=8) (actual time=50016.687..55987.220 rows=99 loops=1) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > 313::double precision) Rows Removed by Filter: 14999901 Buffers: shared hit=672432 read=396176 written=4 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1670263.82 rows=60165582 width=8) (actual time=0.016..14318.569 rows=59985653 loops=1) Buffers: shared hit=672432 read=396176 written=4 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1163.940..1163.940 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=31470 read=3808 written=1 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.024..659.867 rows=1500000 loops=1) Buffers: shared hit=31470 read=3808 written=1 Planning time: 4.638 ms Execution time: 87014.392 ms (42 rows) COMMIT; COMMIT