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=10252774.00..10252776.75 rows=100 width=39) (actual time=81678.151..81678.461 rows=100 loops=1) Buffers: shared hit=1432970 read=1012614 written=32 -> GroupAggregate (cost=10252774.00..11086637.42 rows=30322306 width=39) (actual time=81678.148..81678.444 rows=100 loops=1) Group Key: orders.o_totalprice, orders.o_orderdate, customer.c_name, customer.c_custkey, orders.o_orderkey Buffers: shared hit=1432970 read=1012614 written=32 -> Sort (cost=10252774.00..10328579.77 rows=30322306 width=39) (actual time=81678.129..81678.165 rows=700 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=1432970 read=1012614 written=32 -> Hash Join (cost=2910663.94..5655510.81 rows=30322306 width=39) (actual time=59390.896..81676.573 rows=700 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1432958 read=1012614 written=32 -> Seq Scan on lineitem (cost=0.00..1683566.13 rows=60644613 width=8) (actual time=0.031..11595.802 rows=60044872 loops=1) Buffers: shared hit=586356 read=490764 written=2 -> Hash (cost=2815883.04..2815883.04 rows=7582472 width=39) (actual time=58711.002..58711.002 rows=100 loops=1) Buckets: 8388608 Batches: 1 Memory Usage: 65544kB Buffers: shared hit=846602 read=521850 written=30 -> Hash Join (cost=2197183.59..2815883.04 rows=7582472 width=39) (actual time=51709.178..58710.606 rows=100 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=846602 read=521850 written=30 -> Hash Join (cost=2128155.59..2633117.96 rows=7582472 width=20) (actual time=50366.115..57366.774 rows=100 loops=1) Hash Cond: (orders.o_orderkey = lineitem_1.l_orderkey) Buffers: shared hit=811324 read=521850 written=30 -> Seq Scan on orders (cost=0.00..407703.43 rows=15164943 width=16) (actual time=0.008..3763.764 rows=15015000 loops=1) Buffers: shared hit=149421 read=106633 written=23 -> Hash (cost=2077667.59..2077667.59 rows=4039040 width=4) (actual time=50248.742..50248.742 rows=100 loops=1) Buckets: 4194304 Batches: 1 Memory Usage: 32772kB Buffers: shared hit=661903 read=415217 written=7 -> HashAggregate (cost=1986789.19..2037277.19 rows=4039040 width=8) (actual time=44564.243..50248.116 rows=100 loops=1) Group Key: lineitem_1.l_orderkey Filter: (sum(lineitem_1.l_quantity) > 313::double precision) Rows Removed by Filter: 15014900 Buffers: shared hit=661903 read=415217 written=7 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1683566.13 rows=60644613 width=8) (actual time=0.021..13447.737 rows=60044872 loops=1) Buffers: shared hit=661903 read=415217 written=7 -> Hash (cost=50278.00..50278.00 rows=1500000 width=23) (actual time=1036.383..1036.383 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 98416kB Buffers: shared hit=35278 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=23) (actual time=0.011..527.207 rows=1500000 loops=1) Buffers: shared hit=35278 Planning time: 4.385 ms Execution time: 81904.987 ms (42 rows) COMMIT; COMMIT