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) > 314 ) 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=10184991.27..10184994.02 rows=100 width=39) (actual time=107580.455..107580.733 rows=84 loops=1) Buffers: shared hit=1392283 read=1036620 dirtied=1 written=1663 -> GroupAggregate (cost=10184991.27..11013087.08 rows=30112575 width=39) (actual time=107580.450..107580.717 rows=84 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1392283 read=1036620 dirtied=1 written=1663 -> Sort (cost=10184991.27..10260272.71 rows=30112575 width=39) (actual time=107580.423..107580.459 rows=588 loops=1) Sort Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Sort Method: quicksort Memory: 70kB Buffers: shared hit=1392283 read=1036620 dirtied=1 written=1663 -> Hash Join (cost=2895177.75..5621035.37 rows=30112575 width=39) (actual time=81909.335..107578.979 rows=588 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1392271 read=1036620 dirtied=1 written=1663 -> Seq Scan on lineitem (cost=0.00..1671917.50 rows=60225150 width=8) (actual time=0.031..14255.045 rows=60045303 loops=1) Buffers: shared hit=579106 read=490560 -> Hash (cost=2801053.15..2801053.15 rows=7529968 width=39) (actual time=81594.732..81594.732 rows=84 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65542kB Buffers: shared hit=813165 read=546060 dirtied=1 written=1663 -> Hash Join (cost=2185709.11..2801053.15 rows=7529968 width=39) (actual time=71245.763..81590.349 rows=84 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=813165 read=546060 dirtied=1 written=1663 -> Hash Join (cost=2116681.11..2619075.62 rows=7529968 width=20) (actual time=69592.844..79929.459 rows=84 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=813163 read=510784 dirtied=1 written=1663 -> Seq Scan on orders (cost=0.00..404880.36 rows=15059936 width=16) (actual time=0.013..4227.409 rows=15015000 loops=1) Buffers: shared hit=155948 read=98333 written=1658 -> Hash (cost=2065381.88..2065381.88 rows=4103939 width=4) (actual time=65989.076..65989.076 rows=84 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32771kB Buffers: shared hit=657215 read=412451 dirtied=1 written=5 -> HashAggregate (cost=1973043.25..2024342.49 rows=4103939 width=8) (actual time=52400.491..65987.589 rows=84 loops=1) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > 314::double precision) Rows Removed by Filter: 15014916 Buffers: shared hit=657215 read=412451 dirtied=1 written=5 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1671917.50 rows=60225150 width=8) (actual time=0.198..15092.383 rows=60045303 loops=1) Buffers: shared hit=657215 read=412451 dirtied=1 written=5 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1635.497..1635.497 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=2 read=35276 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.016..1023.232 rows=1500000 loops=1) Buffers: shared hit=2 read=35276 Planning time: 7.276 ms Execution time: 107871.720 ms (42 rows) COMMIT; COMMIT