Skip to content

Commit 108422d

Browse files
committed
fix unstable cte_prune
1 parent e520e30 commit 108422d

3 files changed

Lines changed: 99 additions & 93 deletions

File tree

src/test/regress/expected/cte_prune.out

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,8 @@ HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sur
11921192
CREATE TABLE t4 AS SELECT i as c, i+1 as d from generate_series(1,10)i;
11931193
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'c' as the Apache Cloudberry data distribution key for this table.
11941194
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
1195+
analyze t3;
1196+
analyze t4;
11951197
-- Additional filtering conditions are added to the consumer.
11961198
-- This is caused by `PexprInferPredicates` in the ORCA preprocessor.
11971199
explain verbose WITH t(a,b,d) AS
@@ -1206,91 +1208,88 @@ t WHERE cup.e < 10
12061208
GROUP BY cup.c,cup.d, cup.e ,t.d, t.b
12071209
ORDER BY 1,2,3,4
12081210
LIMIT 10;
1209-
QUERY PLAN
1210-
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1211-
Limit (cost=102679372549802016.00..102679372549802016.00 rows=10 width=56)
1211+
QUERY PLAN
1212+
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1213+
Limit (cost=20000000031.26..20000000031.40 rows=10 width=56)
12121214
Output: cup.c, cup.d, cup.e, (sum(t.d) OVER (?)), t.d, t.b
1213-
-> Gather Motion 3:1 (slice1; segments: 3) (cost=102679372549802016.00..102679372549802016.00 rows=30 width=56)
1215+
-> Gather Motion 3:1 (slice1; segments: 3) (cost=20000000031.26..20000000031.68 rows=30 width=56)
12141216
Output: cup.c, cup.d, cup.e, (sum(t.d) OVER (?)), t.d, t.b
12151217
Merge Key: cup.c, cup.d, cup.e, (sum(t.d) OVER (?))
1216-
-> Limit (cost=102679372549802016.00..102679372549802016.00 rows=10 width=56)
1218+
-> Limit (cost=20000000031.26..20000000031.28 rows=10 width=56)
12171219
Output: cup.c, cup.d, cup.e, (sum(t.d) OVER (?)), t.d, t.b
1218-
-> Sort (cost=102679372549802016.00..102679990317302016.00 rows=247107000000000 width=56)
1220+
-> Sort (cost=20000000031.26..20000000031.54 rows=111 width=56)
12191221
Output: cup.c, cup.d, cup.e, (sum(t.d) OVER (?)), t.d, t.b
12201222
Sort Key: cup.c, cup.d, cup.e, (sum(t.d) OVER (?))
1221-
-> WindowAgg (cost=102669708283873296.00..102674032656373296.00 rows=247107000000000 width=56)
1223+
-> WindowAgg (cost=20000000026.91..20000000028.86 rows=111 width=56)
12221224
Output: cup.c, cup.d, cup.e, sum(t.d) OVER (?), t.d, t.b
12231225
Partition By: t.b
1224-
-> Sort (cost=102669708283873296.00..102670326051373296.00 rows=247107000000000 width=48)
1226+
-> Sort (cost=20000000026.91..20000000027.19 rows=111 width=48)
12251227
Output: cup.c, cup.d, cup.e, t.d, t.b
12261228
Sort Key: t.b
1227-
-> Redistribute Motion 3:3 (slice2; segments: 3) (cost=102580688686565152.00..102601132929768272.00 rows=247107000000000 width=48)
1229+
-> Redistribute Motion 3:3 (slice2; segments: 3) (cost=20000000018.14..20000000023.14 rows=111 width=48)
12281230
Output: cup.c, cup.d, cup.e, t.d, t.b
12291231
Hash Key: t.b
1230-
-> HashAggregate (cost=102580688686565152.00..102596190789768272.00 rows=247107000000000 width=48)
1232+
-> GroupAggregate (cost=20000000018.14..20000000020.92 rows=111 width=48)
12311233
Output: cup.c, cup.d, cup.e, t.d, t.b
12321234
Group Key: cup.c, cup.d, cup.e, t.d, t.b
1233-
Planned Partitions: 512
1234-
-> Redistribute Motion 3:3 (slice3; segments: 3) (cost=93196181903903024.00..102459992361252656.00 rows=741321000000000 width=48)
1235+
-> Sort (cost=20000000018.14..20000000018.42 rows=111 width=48)
12351236
Output: cup.c, cup.d, cup.e, t.d, t.b
1236-
Hash Key: cup.c, cup.d, cup.e, t.d, t.b
1237-
-> Streaming HashAggregate (cost=93196181903903024.00..102445165941252656.00 rows=741321000000000 width=48)
1237+
Sort Key: cup.c, cup.d, cup.e, t.d, t.b
1238+
-> Redistribute Motion 3:3 (slice3; segments: 3) (cost=20000000008.36..20000000014.36 rows=111 width=48)
12381239
Output: cup.c, cup.d, cup.e, t.d, t.b
1239-
Group Key: cup.c, cup.d, cup.e, t.d, t.b
1240-
Planned Partitions: 512
1241-
-> Nested Loop (cost=67221234716.02..7598699218584692.00 rows=525742695955889984 width=48)
1240+
Hash Key: cup.c, cup.d, cup.e, t.d, t.b
1241+
-> Nested Loop (cost=20000000008.36..20000000012.14 rows=111 width=48)
12421242
Output: cup.c, cup.d, cup.e, t.d, t.b
1243-
-> Broadcast Motion 3:3 (slice4; segments: 3) (cost=679.75..228161.25 rows=7413210 width=8)
1243+
-> Broadcast Motion 3:3 (slice4; segments: 3) (cost=1.08..2.35 rows=10 width=8)
12441244
Output: t.d, t.b
1245-
-> Subquery Scan on t (cost=679.75..129318.45 rows=2471070 width=8)
1245+
-> Subquery Scan on t (cost=1.08..2.22 rows=3 width=8)
12461246
Output: t.d, t.b
1247-
-> Hash Join (cost=679.75..129318.45 rows=2471070 width=12)
1247+
-> Hash Join (cost=1.08..2.22 rows=3 width=12)
12481248
Output: t3.a, t3.b, t4.d
12491249
Hash Cond: (t4.d = t3.a)
1250-
-> Redistribute Motion 3:3 (slice5; segments: 3) (cost=0.00..895.00 rows=28700 width=4)
1250+
-> Redistribute Motion 3:3 (slice5; segments: 3) (cost=0.00..1.10 rows=3 width=4)
12511251
Output: t4.d
12521252
Hash Key: t4.d
1253-
-> Seq Scan on cte_prune.t4 (cost=0.00..321.00 rows=28700 width=4)
1253+
-> Seq Scan on cte_prune.t4 (cost=0.00..1.03 rows=3 width=4)
12541254
Output: t4.d
1255-
-> Hash (cost=321.00..321.00 rows=28700 width=8)
1255+
-> Hash (cost=1.03..1.03 rows=3 width=8)
12561256
Output: t3.a, t3.b
1257-
-> Seq Scan on cte_prune.t3 (cost=0.00..321.00 rows=28700 width=8)
1257+
-> Seq Scan on cte_prune.t3 (cost=0.00..1.03 rows=3 width=8)
12581258
Output: t3.a, t3.b
1259-
-> Materialize (cost=57221234036.27..64629019265.77 rows=70919709000 width=40)
1259+
-> Materialize (cost=10000000007.29..10000000008.43 rows=11 width=40)
12601260
Output: cup.c, cup.d, cup.e
1261-
-> Subquery Scan on cup (cost=57221234036.27..64135905663.77 rows=70919709000 width=40)
1261+
-> Subquery Scan on cup (cost=10000000007.29..10000000008.37 rows=11 width=40)
12621262
Output: cup.c, cup.d, cup.e
12631263
Filter: (cup.e < '10'::numeric)
1264-
-> WindowAgg (cost=57221234036.27..61476416576.27 rows=212759127000 width=48)
1264+
-> WindowAgg (cost=10000000007.29..10000000007.95 rows=33 width=48)
12651265
Output: t4_1.c, t4_1.d, avg(t3_1.b) OVER (?), t3_1.b, t3_1.a
12661266
Partition By: t3_1.a
12671267
Order By: t3_1.b
1268-
-> Sort (cost=57221234036.27..57753131853.77 rows=212759127000 width=16)
1268+
-> Sort (cost=10000000007.29..10000000007.37 rows=33 width=16)
12691269
Output: t3_1.b, t3_1.a, t4_1.c, t4_1.d
12701270
Sort Key: t3_1.a, t3_1.b DESC
1271-
-> Nested Loop (cost=10000000679.75..14463131602.75 rows=212759127000 width=16)
1271+
-> Nested Loop (cost=10000000001.08..10000000006.44 rows=33 width=16)
12721272
Output: t3_1.b, t3_1.a, t4_1.c, t4_1.d
1273-
-> Broadcast Motion 3:3 (slice6; segments: 3) (cost=0.00..1469.00 rows=86100 width=8)
1274-
Output: t4_1.c, t4_1.d
1275-
-> Seq Scan on cte_prune.t4 t4_1 (cost=0.00..321.00 rows=28700 width=8)
1276-
Output: t4_1.c, t4_1.d
1277-
-> Materialize (cost=679.75..141673.80 rows=2471070 width=8)
1273+
-> Hash Join (cost=1.08..2.22 rows=3 width=12)
12781274
Output: t3_1.a, t3_1.b, t4_2.d
1279-
-> Hash Join (cost=679.75..129318.45 rows=2471070 width=12)
1280-
Output: t3_1.a, t3_1.b, t4_2.d
1281-
Hash Cond: (t4_2.d = t3_1.a)
1282-
-> Redistribute Motion 3:3 (slice7; segments: 3) (cost=0.00..895.00 rows=28700 width=4)
1275+
Hash Cond: (t4_2.d = t3_1.a)
1276+
-> Redistribute Motion 3:3 (slice6; segments: 3) (cost=0.00..1.10 rows=3 width=4)
1277+
Output: t4_2.d
1278+
Hash Key: t4_2.d
1279+
-> Seq Scan on cte_prune.t4 t4_2 (cost=0.00..1.03 rows=3 width=4)
12831280
Output: t4_2.d
1284-
Hash Key: t4_2.d
1285-
-> Seq Scan on cte_prune.t4 t4_2 (cost=0.00..321.00 rows=28700 width=4)
1286-
Output: t4_2.d
1287-
-> Hash (cost=321.00..321.00 rows=28700 width=8)
1281+
-> Hash (cost=1.03..1.03 rows=3 width=8)
1282+
Output: t3_1.a, t3_1.b
1283+
-> Seq Scan on cte_prune.t3 t3_1 (cost=0.00..1.03 rows=3 width=8)
12881284
Output: t3_1.a, t3_1.b
1289-
-> Seq Scan on cte_prune.t3 t3_1 (cost=0.00..321.00 rows=28700 width=8)
1290-
Output: t3_1.a, t3_1.b
1291-
Settings: enable_parallel = 'off', optimizer = 'off'
1285+
-> Materialize (cost=0.00..1.22 rows=10 width=8)
1286+
Output: t4_1.c, t4_1.d
1287+
-> Broadcast Motion 3:3 (slice7; segments: 3) (cost=0.00..1.17 rows=10 width=8)
1288+
Output: t4_1.c, t4_1.d
1289+
-> Seq Scan on cte_prune.t4 t4_1 (cost=0.00..1.03 rows=3 width=8)
1290+
Output: t4_1.c, t4_1.d
12921291
Optimizer: Postgres query optimizer
1293-
(82 rows)
1292+
(80 rows)
12941293

12951294
WITH t(a,b,d) AS
12961295
(

0 commit comments

Comments
 (0)