load 'auto_explain'; LOAD set auto_explain.log_min_duration to 0; SET set auto_explain.log_analyze to on; SET set auto_explain.log_wal to on; SET set auto_explain.log_timing to on; SET set auto_explain.log_level to notice; SET BEGIN; BEGIN select cntrycode, count(*) as numcust, sum(c_acctbal) as totacctbal from ( select substring(c_phone from 1 for 2) as cntrycode, c_acctbal from customer where substring(c_phone from 1 for 2) in ('27', '14', '29', '30', '26', '12', '28') and c_acctbal > ( select avg(c_acctbal) from customer where c_acctbal > 0.00 and substring(c_phone from 1 for 2) in ('27', '14', '29', '30', '26', '12', '28') ) and not exists ( select * from orders where o_custkey = c_custkey ) ) as vip group by cntrycode order by cntrycode; NOTICE: duration: 437.040 ms plan: Query Text: select cntrycode, count(*) as numcust, sum(c_acctbal) as totacctbal from ( select substring(c_phone from 1 for 2) as cntrycode, c_acctbal from customer where substring(c_phone from 1 for 2) in ('27', '14', '29', '30', '26', '12', '28') and c_acctbal > ( select avg(c_acctbal) from customer where c_acctbal > 0.00 and substring(c_phone from 1 for 2) in ('27', '14', '29', '30', '26', '12', '28') ) and not exists ( select * from orders where o_custkey = c_custkey ) ) as vip group by cntrycode order by cntrycode; Finalize GroupAggregate (cost=122531.68..122538.45 rows=25 width=72) (actual time=430.274..437.028 rows=7 loops=1) Group Key: (SUBSTRING(customer.c_phone FROM 1 FOR 2)) InitPlan 1 (returns $1) -> Finalize Aggregate (cost=50276.32..50276.33 rows=1 width=32) (actual time=150.595..151.939 rows=1 loops=1) -> Gather (cost=50276.10..50276.31 rows=2 width=32) (actual time=150.324..151.928 rows=3 loops=1) Workers Planned: 2 Workers Launched: 2 -> Partial Aggregate (cost=49276.10..49276.11 rows=1 width=32) (actual time=147.551..147.552 rows=1 loops=3) -> Parallel Bitmap Heap Scan on customer customer_1 (cost=8765.30..48872.20 rows=161558 width=6) (actual time=50.477..132.310 rows=127038 loops=3) Recheck Cond: ((SUBSTRING(c_phone FROM 1 FOR 2) = ANY ('{27,14,29,30,26,12,28}'::text[])) AND (c_acctbal > 0.00)) Heap Blocks: exact=12175 -> Bitmap Index Scan on customer_c_phone_c_acctbal_c_custkey_idx (cost=0.00..8668.36 rows=387740 width=0) (actual time=46.951..46.952 rows=381115 loops=1) Index Cond: ((SUBSTRING(c_phone FROM 1 FOR 2) = ANY ('{27,14,29,30,26,12,28}'::text[])) AND (c_acctbal > 0.00)) -> Gather Merge (cost=72255.35..72261.18 rows=50 width=72) (actual time=430.263..435.661 rows=21 loops=1) Workers Planned: 2 Params Evaluated: $1 Workers Launched: 2 -> Sort (cost=71255.32..71255.39 rows=25 width=72) (actual time=276.129..276.131 rows=7 loops=3) Sort Key: (SUBSTRING(customer.c_phone FROM 1 FOR 2)) Sort Method: quicksort Memory: 25kB Worker 0: Sort Method: quicksort Memory: 25kB Worker 1: Sort Method: quicksort Memory: 25kB -> Partial HashAggregate (cost=71254.31..71254.74 rows=25 width=72) (actual time=276.089..276.093 rows=7 loops=3) Group Key: SUBSTRING(customer.c_phone FROM 1 FOR 2) Batches: 1 Memory Usage: 24kB Worker 0: Batches: 1 Memory Usage: 24kB Worker 1: Batches: 1 Memory Usage: 24kB -> Nested Loop Anti Join (cost=3365.98..71064.40 rows=25321 width=38) (actual time=32.275..269.386 rows=21224 loops=3) -> Parallel Bitmap Heap Scan on customer (cost=3365.54..40792.19 rows=59453 width=26) (actual time=32.220..105.064 rows=63525 loops=3) Recheck Cond: ((SUBSTRING(c_phone FROM 1 FOR 2) = ANY ('{27,14,29,30,26,12,28}'::text[])) AND (c_acctbal > $1)) Heap Blocks: exact=12368 -> Bitmap Index Scan on customer_c_phone_c_acctbal_c_custkey_idx (cost=0.00..3329.87 rows=142688 width=0) (actual time=28.724..28.724 rows=190576 loops=1) Index Cond: ((SUBSTRING(c_phone FROM 1 FOR 2) = ANY ('{27,14,29,30,26,12,28}'::text[])) AND (c_acctbal > $1)) -> Index Only Scan using orders_o_custkey_idx on orders (cost=0.43..1.14 rows=17 width=4) (actual time=0.002..0.002 rows=1 loops=190576) Index Cond: (o_custkey = customer.c_custkey) Heap Fetches: 7 cntrycode | numcust | totacctbal -----------+---------+------------- 12 | 9050 | 67863719.22 14 | 9014 | 67806653.74 26 | 9019 | 67735004.20 27 | 9016 | 67650907.79 28 | 9027 | 67660096.94 29 | 9202 | 69030431.09 30 | 9344 | 70123835.79 (7 rows) COMMIT; COMMIT