BEGIN; BEGIN EXPLAIN (ANALYZE, BUFFERS) select l_shipmode, sum(case when o_orderpriority = '1-URGENT' or o_orderpriority = '2-HIGH' then 1 else 0 end) as high_line_count, sum(case when o_orderpriority <> '1-URGENT' and o_orderpriority <> '2-HIGH' then 1 else 0 end) as low_line_count from orders, lineitem where o_orderkey = l_orderkey and l_shipmode in ('REG AIR', 'SHIP') and l_commitdate < l_receiptdate and l_shipdate < l_commitdate and l_receiptdate >= date '1995-01-01' and l_receiptdate < date '1995-01-01' + interval '1 year' group by l_shipmode order by l_shipmode; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Sort (cost=989175.77..989175.77 rows=1 width=27) (actual time=46247.899..46247.900 rows=2 loops=1) Sort Key: lineitem.l_shipmode Sort Method: quicksort Memory: 25kB Buffers: shared hit=919691 read=445816 dirtied=1189 written=5777 -> HashAggregate (cost=989175.75..989175.76 rows=1 width=27) (actual time=46247.754..46247.755 rows=2 loops=1) Buffers: shared hit=919686 read=445816 dirtied=1189 written=5777 -> Hash Join (cost=596675.08..984064.64 rows=292063 width=27) (actual time=19419.291..45607.497 rows=311791 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=919686 read=445816 dirtied=1189 written=5777 -> Index Scan using lineitem_l_orderkey_idx_part2 on lineitem (cost=0.00..378262.60 rows=292063 width=15) (actual time=0.297..24746.508 rows=311791 loops=1) Filter: ((l_shipmode = ANY ('{"REG AIR",SHIP}'::bpchar[])) AND (l_receiptdate >= '1995-01-01'::date) AND (l_receiptdate < '1996-01-01 00:00:00'::timestamp without time zone)) Rows Removed by Filter: 6877579 Buffers: shared hit=741326 read=368372 dirtied=1074 written=256 -> Hash (cost=407300.59..407300.59 rows=15149959 width=20) (actual time=19406.140..19406.140 rows=15000000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 761719kB Buffers: shared hit=178357 read=77444 dirtied=115 written=5521 -> Seq Scan on orders (cost=0.00..407300.59 rows=15149959 width=20) (actual time=0.019..10209.751 rows=15000000 loops=1) Buffers: shared hit=178357 read=77444 dirtied=115 written=5521 Total runtime: 46451.725 ms (19 rows) COMMIT; COMMIT