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 ('31', '11', '22', '10', '30', '15', '25') and c_acctbal > ( select avg(c_acctbal) from customer where c_acctbal > 0.00 and substring(c_phone from 1 for 2) in ('31', '11', '22', '10', '30', '15', '25') ) and not exists ( select * from orders where o_custkey = c_custkey ) ) as vip group by cntrycode order by cntrycode; NOTICE: duration: 1239.962 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 ('31', '11', '22', '10', '30', '15', '25') and c_acctbal > ( select avg(c_acctbal) from customer where c_acctbal > 0.00 and substring(c_phone from 1 for 2) in ('31', '11', '22', '10', '30', '15', '25') ) and not exists ( select * from orders where o_custkey = c_custkey ) ) as vip group by cntrycode order by cntrycode; Finalize GroupAggregate (cost=122015.65..122022.43 rows=25 width=72) (actual time=1229.598..1239.942 rows=7 loops=1) Group Key: (SUBSTRING(customer.c_phone FROM 1 FOR 2)) InitPlan 1 (returns $1) -> Finalize Aggregate (cost=50111.54..50111.55 rows=1 width=32) (actual time=466.389..468.434 rows=1 loops=1) -> Gather (cost=50111.32..50111.53 rows=2 width=32) (actual time=458.865..468.409 rows=3 loops=1) Workers Planned: 2 Workers Launched: 2 -> Partial Aggregate (cost=49111.32..49111.33 rows=1 width=32) (actual time=451.333..451.334 rows=1 loops=3) -> Parallel Bitmap Heap Scan on customer customer_1 (cost=8665.62..48713.08 rows=159294 width=6) (actual time=106.925..392.696 rows=127114 loops=3) Recheck Cond: ((SUBSTRING(c_phone FROM 1 FOR 2) = ANY ('{31,11,22,10,30,15,25}'::text[])) AND (c_acctbal > 0.00)) Heap Blocks: exact=15700 -> Bitmap Index Scan on customer_c_phone_c_acctbal_c_custkey_idx (cost=0.00..8570.04 rows=382305 width=0) (actual time=103.403..103.404 rows=381341 loops=1) Index Cond: ((SUBSTRING(c_phone FROM 1 FOR 2) = ANY ('{31,11,22,10,30,15,25}'::text[])) AND (c_acctbal > 0.00)) -> Gather Merge (cost=71904.10..71909.94 rows=50 width=72) (actual time=1229.576..1237.853 rows=21 loops=1) Workers Planned: 2 Params Evaluated: $1 Workers Launched: 2 -> Sort (cost=70904.08..70904.14 rows=25 width=72) (actual time=740.776..740.779 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=70903.06..70903.50 rows=25 width=72) (actual time=740.695..740.703 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=3321.46..70715.82 rows=24966 width=38) (actual time=65.654..726.324 rows=21202 loops=3) -> Parallel Bitmap Heap Scan on customer (cost=3321.02..40725.80 rows=58620 width=26) (actual time=64.015..206.134 rows=63554 loops=3) Recheck Cond: ((SUBSTRING(c_phone FROM 1 FOR 2) = ANY ('{31,11,22,10,30,15,25}'::text[])) AND (c_acctbal > $1)) Heap Blocks: exact=12860 -> Bitmap Index Scan on customer_c_phone_c_acctbal_c_custkey_idx (cost=0.00..3285.85 rows=140688 width=0) (actual time=67.383..67.383 rows=190661 loops=1) Index Cond: ((SUBSTRING(c_phone FROM 1 FOR 2) = ANY ('{31,11,22,10,30,15,25}'::text[])) AND (c_acctbal > $1)) -> Index Only Scan using orders_o_custkey_idx on orders (cost=0.43..1.17 rows=17 width=4) (actual time=0.007..0.007 rows=1 loops=190661) Index Cond: (o_custkey = customer.c_custkey) Heap Fetches: 7099 cntrycode | numcust | totacctbal -----------+---------+------------- 10 | 9053 | 67752399.56 11 | 9007 | 67899527.62 15 | 9036 | 67837467.01 22 | 8991 | 67276842.61 25 | 9106 | 68335809.72 30 | 9336 | 70083836.84 31 | 9076 | 68094522.06 (7 rows) COMMIT; COMMIT