This is an automated email from the ASF dual-hosted git repository.

avamingli pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git

commit 108422daf82cdfb10f871db89e35d8bcdc158fc7
Author: Zhang Mingli <[email protected]>
AuthorDate: Tue Oct 28 11:23:13 2025 +0800

    fix unstable cte_prune
---
 src/test/regress/expected/cte_prune.out           | 91 +++++++++++----------
 src/test/regress/expected/cte_prune_optimizer.out | 99 ++++++++++++-----------
 src/test/regress/sql/cte_prune.sql                |  2 +
 3 files changed, 99 insertions(+), 93 deletions(-)

diff --git a/src/test/regress/expected/cte_prune.out 
b/src/test/regress/expected/cte_prune.out
index f3b0260628a..bdda6b89c9c 100644
--- a/src/test/regress/expected/cte_prune.out
+++ b/src/test/regress/expected/cte_prune.out
@@ -1192,6 +1192,8 @@ HINT:  The 'DISTRIBUTED BY' clause determines the 
distribution of data. Make sur
 CREATE TABLE t4 AS SELECT i as c, i+1 as d from generate_series(1,10)i;
 NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 
'c' as the Apache Cloudberry data distribution key for this table.
 HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make 
sure column(s) chosen are the optimal data distribution key to minimize skew.
+analyze t3;
+analyze t4;
 -- Additional filtering conditions are added to the consumer.
 -- This is caused by `PexprInferPredicates` in the ORCA preprocessor.
 explain verbose WITH t(a,b,d) AS
@@ -1206,91 +1208,88 @@ t WHERE cup.e < 10
 GROUP BY cup.c,cup.d, cup.e ,t.d, t.b
 ORDER BY 1,2,3,4
 LIMIT 10;
-                                                                               
              QUERY PLAN                                                        
                                     
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- Limit  (cost=102679372549802016.00..102679372549802016.00 rows=10 width=56)
+                                                                               
        QUERY PLAN                                                              
                         
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Limit  (cost=20000000031.26..20000000031.40 rows=10 width=56)
    Output: cup.c, cup.d, cup.e, (sum(t.d) OVER (?)), t.d, t.b
-   ->  Gather Motion 3:1  (slice1; segments: 3)  
(cost=102679372549802016.00..102679372549802016.00 rows=30 width=56)
+   ->  Gather Motion 3:1  (slice1; segments: 3)  
(cost=20000000031.26..20000000031.68 rows=30 width=56)
          Output: cup.c, cup.d, cup.e, (sum(t.d) OVER (?)), t.d, t.b
          Merge Key: cup.c, cup.d, cup.e, (sum(t.d) OVER (?))
-         ->  Limit  (cost=102679372549802016.00..102679372549802016.00 rows=10 
width=56)
+         ->  Limit  (cost=20000000031.26..20000000031.28 rows=10 width=56)
                Output: cup.c, cup.d, cup.e, (sum(t.d) OVER (?)), t.d, t.b
-               ->  Sort  (cost=102679372549802016.00..102679990317302016.00 
rows=247107000000000 width=56)
+               ->  Sort  (cost=20000000031.26..20000000031.54 rows=111 
width=56)
                      Output: cup.c, cup.d, cup.e, (sum(t.d) OVER (?)), t.d, t.b
                      Sort Key: cup.c, cup.d, cup.e, (sum(t.d) OVER (?))
-                     ->  WindowAgg  
(cost=102669708283873296.00..102674032656373296.00 rows=247107000000000 
width=56)
+                     ->  WindowAgg  (cost=20000000026.91..20000000028.86 
rows=111 width=56)
                            Output: cup.c, cup.d, cup.e, sum(t.d) OVER (?), 
t.d, t.b
                            Partition By: t.b
-                           ->  Sort  
(cost=102669708283873296.00..102670326051373296.00 rows=247107000000000 
width=48)
+                           ->  Sort  (cost=20000000026.91..20000000027.19 
rows=111 width=48)
                                  Output: cup.c, cup.d, cup.e, t.d, t.b
                                  Sort Key: t.b
-                                 ->  Redistribute Motion 3:3  (slice2; 
segments: 3)  (cost=102580688686565152.00..102601132929768272.00 
rows=247107000000000 width=48)
+                                 ->  Redistribute Motion 3:3  (slice2; 
segments: 3)  (cost=20000000018.14..20000000023.14 rows=111 width=48)
                                        Output: cup.c, cup.d, cup.e, t.d, t.b
                                        Hash Key: t.b
-                                       ->  HashAggregate  
(cost=102580688686565152.00..102596190789768272.00 rows=247107000000000 
width=48)
+                                       ->  GroupAggregate  
(cost=20000000018.14..20000000020.92 rows=111 width=48)
                                              Output: cup.c, cup.d, cup.e, t.d, 
t.b
                                              Group Key: cup.c, cup.d, cup.e, 
t.d, t.b
-                                             Planned Partitions: 512
-                                             ->  Redistribute Motion 3:3  
(slice3; segments: 3)  (cost=93196181903903024.00..102459992361252656.00 
rows=741321000000000 width=48)
+                                             ->  Sort  
(cost=20000000018.14..20000000018.42 rows=111 width=48)
                                                    Output: cup.c, cup.d, 
cup.e, t.d, t.b
-                                                   Hash Key: cup.c, cup.d, 
cup.e, t.d, t.b
-                                                   ->  Streaming HashAggregate 
 (cost=93196181903903024.00..102445165941252656.00 rows=741321000000000 
width=48)
+                                                   Sort Key: cup.c, cup.d, 
cup.e, t.d, t.b
+                                                   ->  Redistribute Motion 3:3 
 (slice3; segments: 3)  (cost=20000000008.36..20000000014.36 rows=111 width=48)
                                                          Output: cup.c, cup.d, 
cup.e, t.d, t.b
-                                                         Group Key: cup.c, 
cup.d, cup.e, t.d, t.b
-                                                         Planned Partitions: 
512
-                                                         ->  Nested Loop  
(cost=67221234716.02..7598699218584692.00 rows=525742695955889984 width=48)
+                                                         Hash Key: cup.c, 
cup.d, cup.e, t.d, t.b
+                                                         ->  Nested Loop  
(cost=20000000008.36..20000000012.14 rows=111 width=48)
                                                                Output: cup.c, 
cup.d, cup.e, t.d, t.b
-                                                               ->  Broadcast 
Motion 3:3  (slice4; segments: 3)  (cost=679.75..228161.25 rows=7413210 width=8)
+                                                               ->  Broadcast 
Motion 3:3  (slice4; segments: 3)  (cost=1.08..2.35 rows=10 width=8)
                                                                      Output: 
t.d, t.b
-                                                                     ->  
Subquery Scan on t  (cost=679.75..129318.45 rows=2471070 width=8)
+                                                                     ->  
Subquery Scan on t  (cost=1.08..2.22 rows=3 width=8)
                                                                            
Output: t.d, t.b
-                                                                           ->  
Hash Join  (cost=679.75..129318.45 rows=2471070 width=12)
+                                                                           ->  
Hash Join  (cost=1.08..2.22 rows=3 width=12)
                                                                                
  Output: t3.a, t3.b, t4.d
                                                                                
  Hash Cond: (t4.d = t3.a)
-                                                                               
  ->  Redistribute Motion 3:3  (slice5; segments: 3)  (cost=0.00..895.00 
rows=28700 width=4)
+                                                                               
  ->  Redistribute Motion 3:3  (slice5; segments: 3)  (cost=0.00..1.10 rows=3 
width=4)
                                                                                
        Output: t4.d
                                                                                
        Hash Key: t4.d
-                                                                               
        ->  Seq Scan on cte_prune.t4  (cost=0.00..321.00 rows=28700 width=4)
+                                                                               
        ->  Seq Scan on cte_prune.t4  (cost=0.00..1.03 rows=3 width=4)
                                                                                
              Output: t4.d
-                                                                               
  ->  Hash  (cost=321.00..321.00 rows=28700 width=8)
+                                                                               
  ->  Hash  (cost=1.03..1.03 rows=3 width=8)
                                                                                
        Output: t3.a, t3.b
-                                                                               
        ->  Seq Scan on cte_prune.t3  (cost=0.00..321.00 rows=28700 width=8)
+                                                                               
        ->  Seq Scan on cte_prune.t3  (cost=0.00..1.03 rows=3 width=8)
                                                                                
              Output: t3.a, t3.b
-                                                               ->  Materialize 
 (cost=57221234036.27..64629019265.77 rows=70919709000 width=40)
+                                                               ->  Materialize 
 (cost=10000000007.29..10000000008.43 rows=11 width=40)
                                                                      Output: 
cup.c, cup.d, cup.e
-                                                                     ->  
Subquery Scan on cup  (cost=57221234036.27..64135905663.77 rows=70919709000 
width=40)
+                                                                     ->  
Subquery Scan on cup  (cost=10000000007.29..10000000008.37 rows=11 width=40)
                                                                            
Output: cup.c, cup.d, cup.e
                                                                            
Filter: (cup.e < '10'::numeric)
-                                                                           ->  
WindowAgg  (cost=57221234036.27..61476416576.27 rows=212759127000 width=48)
+                                                                           ->  
WindowAgg  (cost=10000000007.29..10000000007.95 rows=33 width=48)
                                                                                
  Output: t4_1.c, t4_1.d, avg(t3_1.b) OVER (?), t3_1.b, t3_1.a
                                                                                
  Partition By: t3_1.a
                                                                                
  Order By: t3_1.b
-                                                                               
  ->  Sort  (cost=57221234036.27..57753131853.77 rows=212759127000 width=16)
+                                                                               
  ->  Sort  (cost=10000000007.29..10000000007.37 rows=33 width=16)
                                                                                
        Output: t3_1.b, t3_1.a, t4_1.c, t4_1.d
                                                                                
        Sort Key: t3_1.a, t3_1.b DESC
-                                                                               
        ->  Nested Loop  (cost=10000000679.75..14463131602.75 rows=212759127000 
width=16)
+                                                                               
        ->  Nested Loop  (cost=10000000001.08..10000000006.44 rows=33 width=16)
                                                                                
              Output: t3_1.b, t3_1.a, t4_1.c, t4_1.d
-                                                                               
              ->  Broadcast Motion 3:3  (slice6; segments: 3)  
(cost=0.00..1469.00 rows=86100 width=8)
-                                                                               
                    Output: t4_1.c, t4_1.d
-                                                                               
                    ->  Seq Scan on cte_prune.t4 t4_1  (cost=0.00..321.00 
rows=28700 width=8)
-                                                                               
                          Output: t4_1.c, t4_1.d
-                                                                               
              ->  Materialize  (cost=679.75..141673.80 rows=2471070 width=8)
+                                                                               
              ->  Hash Join  (cost=1.08..2.22 rows=3 width=12)
                                                                                
                    Output: t3_1.a, t3_1.b, t4_2.d
-                                                                               
                    ->  Hash Join  (cost=679.75..129318.45 rows=2471070 
width=12)
-                                                                               
                          Output: t3_1.a, t3_1.b, t4_2.d
-                                                                               
                          Hash Cond: (t4_2.d = t3_1.a)
-                                                                               
                          ->  Redistribute Motion 3:3  (slice7; segments: 3)  
(cost=0.00..895.00 rows=28700 width=4)
+                                                                               
                    Hash Cond: (t4_2.d = t3_1.a)
+                                                                               
                    ->  Redistribute Motion 3:3  (slice6; segments: 3)  
(cost=0.00..1.10 rows=3 width=4)
+                                                                               
                          Output: t4_2.d
+                                                                               
                          Hash Key: t4_2.d
+                                                                               
                          ->  Seq Scan on cte_prune.t4 t4_2  (cost=0.00..1.03 
rows=3 width=4)
                                                                                
                                Output: t4_2.d
-                                                                               
                                Hash Key: t4_2.d
-                                                                               
                                ->  Seq Scan on cte_prune.t4 t4_2  
(cost=0.00..321.00 rows=28700 width=4)
-                                                                               
                                      Output: t4_2.d
-                                                                               
                          ->  Hash  (cost=321.00..321.00 rows=28700 width=8)
+                                                                               
                    ->  Hash  (cost=1.03..1.03 rows=3 width=8)
+                                                                               
                          Output: t3_1.a, t3_1.b
+                                                                               
                          ->  Seq Scan on cte_prune.t3 t3_1  (cost=0.00..1.03 
rows=3 width=8)
                                                                                
                                Output: t3_1.a, t3_1.b
-                                                                               
                                ->  Seq Scan on cte_prune.t3 t3_1  
(cost=0.00..321.00 rows=28700 width=8)
-                                                                               
                                      Output: t3_1.a, t3_1.b
- Settings: enable_parallel = 'off', optimizer = 'off'
+                                                                               
              ->  Materialize  (cost=0.00..1.22 rows=10 width=8)
+                                                                               
                    Output: t4_1.c, t4_1.d
+                                                                               
                    ->  Broadcast Motion 3:3  (slice7; segments: 3)  
(cost=0.00..1.17 rows=10 width=8)
+                                                                               
                          Output: t4_1.c, t4_1.d
+                                                                               
                          ->  Seq Scan on cte_prune.t4 t4_1  (cost=0.00..1.03 
rows=3 width=8)
+                                                                               
                                Output: t4_1.c, t4_1.d
  Optimizer: Postgres query optimizer
-(82 rows)
+(80 rows)
 
 WITH t(a,b,d) AS
 (
diff --git a/src/test/regress/expected/cte_prune_optimizer.out 
b/src/test/regress/expected/cte_prune_optimizer.out
index ed3516845b2..d0573b3f2d4 100644
--- a/src/test/regress/expected/cte_prune_optimizer.out
+++ b/src/test/regress/expected/cte_prune_optimizer.out
@@ -1260,6 +1260,8 @@ drop table t2;
 -- comm cases
 CREATE TABLE t3 AS SELECT i as a, i+1 as b from generate_series(1,10)i;
 CREATE TABLE t4 AS SELECT i as c, i+1 as d from generate_series(1,10)i;
+analyze t3;
+analyze t4;
 -- Additional filtering conditions are added to the consumer.
 -- This is caused by `PexprInferPredicates` in the ORCA preprocessor.
 explain verbose WITH t(a,b,d) AS
@@ -1274,99 +1276,102 @@ t WHERE cup.e < 10
 GROUP BY cup.c,cup.d, cup.e ,t.d, t.b
 ORDER BY 1,2,3,4
 LIMIT 10;
-                                                                               
                 QUERY PLAN                                                     
                                            
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- Gather Motion 3:1  (slice1; segments: 3)  (cost=0.00..1356692546.41 rows=1 
width=24)
+                                                                               
                  QUERY PLAN                                                    
                                             
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Gather Motion 3:1  (slice1; segments: 3)  (cost=0.00..1356697001.21 rows=10 
width=24)
    Output: t4_1.c, t4_1.d, (avg(share0_ref3.b) OVER (?)), (sum(share0_ref2.d) 
OVER (?))
    Merge Key: t4_1.c, t4_1.d, (avg(share0_ref3.b) OVER (?)), 
(sum(share0_ref2.d) OVER (?))
-   ->  Sort  (cost=0.00..1356692546.41 rows=1 width=24)
+   ->  Sort  (cost=0.00..1356697001.21 rows=4 width=24)
          Output: t4_1.c, t4_1.d, (avg(share0_ref3.b) OVER (?)), 
(sum(share0_ref2.d) OVER (?))
          Sort Key: t4_1.c, t4_1.d, (avg(share0_ref3.b) OVER (?)), 
(sum(share0_ref2.d) OVER (?))
-         ->  Sequence  (cost=0.00..1356692546.41 rows=1 width=24)
+         ->  Sequence  (cost=0.00..1356697001.21 rows=4 width=24)
                Output: t4_1.c, t4_1.d, (avg(share0_ref3.b) OVER (?)), 
(sum(share0_ref2.d) OVER (?))
-               ->  Shared Scan (share slice:id 1:0)  (cost=0.00..862.00 rows=1 
width=1)
+               ->  Shared Scan (share slice:id 1:0)  (cost=0.00..862.00 rows=4 
width=1)
                      Output: share0_ref1.a, share0_ref1.b, share0_ref1.d
-                     ->  Hash Join  (cost=0.00..862.00 rows=1 width=12)
+                     ->  Hash Join  (cost=0.00..862.00 rows=4 width=12)
                            Output: t3.a, t3.b, t4.d
                            Hash Cond: (t3.a = t4.d)
-                           ->  Seq Scan on cte_prune.t3  (cost=0.00..431.00 
rows=1 width=8)
+                           ->  Redistribute Motion 3:3  (slice2; segments: 3)  
(cost=0.00..431.00 rows=4 width=8)
                                  Output: t3.a, t3.b
-                           ->  Hash  (cost=431.00..431.00 rows=1 width=4)
+                                 Hash Key: t3.a
+                                 ->  Seq Scan on cte_prune.t3  
(cost=0.00..431.00 rows=4 width=8)
+                                       Output: t3.a, t3.b
+                           ->  Hash  (cost=431.00..431.00 rows=4 width=4)
                                  Output: t4.d
-                                 ->  Broadcast Motion 3:3  (slice2; segments: 
3)  (cost=0.00..431.00 rows=1 width=4)
+                                 ->  Redistribute Motion 3:3  (slice3; 
segments: 3)  (cost=0.00..431.00 rows=4 width=4)
                                        Output: t4.d
-                                       ->  Seq Scan on cte_prune.t4  
(cost=0.00..431.00 rows=1 width=4)
+                                       Hash Key: t4.d
+                                       ->  Seq Scan on cte_prune.t4  
(cost=0.00..431.00 rows=4 width=4)
                                              Output: t4.d
-               ->  Redistribute Motion 1:3  (slice3)  
(cost=0.00..1356691684.41 rows=1 width=24)
+               ->  Redistribute Motion 1:3  (slice4)  
(cost=0.00..1356696139.21 rows=4 width=24)
                      Output: t4_1.c, t4_1.d, (avg(share0_ref3.b) OVER (?)), 
(sum(share0_ref2.d) OVER (?))
-                     ->  Limit  (cost=0.00..1356691684.41 rows=1 width=24)
+                     ->  Limit  (cost=0.00..1356696139.20 rows=10 width=24)
                            Output: t4_1.c, t4_1.d, (avg(share0_ref3.b) OVER 
(?)), (sum(share0_ref2.d) OVER (?))
-                           ->  Gather Motion 3:1  (slice4; segments: 3)  
(cost=0.00..1356691684.41 rows=1 width=24)
+                           ->  Gather Motion 3:1  (slice5; segments: 3)  
(cost=0.00..1356696139.20 rows=10 width=24)
                                  Output: t4_1.c, t4_1.d, (avg(share0_ref3.b) 
OVER (?)), (sum(share0_ref2.d) OVER (?))
                                  Merge Key: t4_1.c, t4_1.d, 
(avg(share0_ref3.b) OVER (?)), (sum(share0_ref2.d) OVER (?))
-                                 ->  Result  (cost=0.00..1356691684.41 rows=1 
width=24)
+                                 ->  Limit  (cost=0.00..1356696139.20 rows=4 
width=24)
                                        Output: t4_1.c, t4_1.d, 
(avg(share0_ref3.b) OVER (?)), (sum(share0_ref2.d) OVER (?))
-                                       ->  Sort  (cost=0.00..1356691684.41 
rows=1 width=24)
-                                             Output: t4_1.c, t4_1.d, 
(avg(share0_ref3.b) OVER (?)), (sum(share0_ref2.d) OVER (?)), share0_ref2.b
-                                             Sort Key: t4_1.c, t4_1.d, 
(avg(share0_ref3.b) OVER (?)), (sum(share0_ref2.d) OVER (?))
-                                             ->  WindowAgg  
(cost=0.00..1356691684.40 rows=1 width=24)
-                                                   Output: t4_1.c, t4_1.d, 
(avg(share0_ref3.b) OVER (?)), sum(share0_ref2.d) OVER (?), share0_ref2.b
-                                                   Partition By: share0_ref2.b
-                                                   ->  Sort  
(cost=0.00..1356691684.40 rows=1 width=24)
-                                                         Output: t4_1.c, 
t4_1.d, (avg(share0_ref3.b) OVER (?)), share0_ref2.b, share0_ref2.d
-                                                         Sort Key: 
share0_ref2.b
-                                                         ->  Redistribute 
Motion 3:3  (slice5; segments: 3)  (cost=0.00..1356691684.40 rows=1 width=24)
+                                       ->  Result  (cost=0.00..1356696139.20 
rows=134 width=24)
+                                             Output: t4_1.c, t4_1.d, 
(avg(share0_ref3.b) OVER (?)), (sum(share0_ref2.d) OVER (?))
+                                             ->  Sort  
(cost=0.00..1356696139.20 rows=134 width=24)
+                                                   Output: t4_1.c, t4_1.d, 
(avg(share0_ref3.b) OVER (?)), (sum(share0_ref2.d) OVER (?)), share0_ref2.b
+                                                   Sort Key: t4_1.c, t4_1.d, 
(avg(share0_ref3.b) OVER (?)), (sum(share0_ref2.d) OVER (?))
+                                                   ->  WindowAgg  
(cost=0.00..1356696139.08 rows=134 width=24)
+                                                         Output: t4_1.c, 
t4_1.d, (avg(share0_ref3.b) OVER (?)), sum(share0_ref2.d) OVER (?), 
share0_ref2.b
+                                                         Partition By: 
share0_ref2.b
+                                                         ->  Sort  
(cost=0.00..1356696139.08 rows=134 width=24)
                                                                Output: t4_1.c, 
t4_1.d, (avg(share0_ref3.b) OVER (?)), share0_ref2.b, share0_ref2.d
-                                                               Hash Key: 
share0_ref2.b
-                                                               ->  
GroupAggregate  (cost=0.00..1356691684.40 rows=1 width=24)
+                                                               Sort Key: 
share0_ref2.b
+                                                               ->  
Redistribute Motion 3:3  (slice6; segments: 3)  (cost=0.00..1356696138.95 
rows=134 width=24)
                                                                      Output: 
t4_1.c, t4_1.d, (avg(share0_ref3.b) OVER (?)), share0_ref2.b, share0_ref2.d
-                                                                     Group 
Key: t4_1.c, t4_1.d, (avg(share0_ref3.b) OVER (?)), share0_ref2.d, share0_ref2.b
-                                                                     ->  Sort  
(cost=0.00..1356691684.40 rows=1 width=24)
+                                                                     Hash Key: 
share0_ref2.b
+                                                                     ->  
HashAggregate  (cost=0.00..1356696138.94 rows=134 width=24)
                                                                            
Output: t4_1.c, t4_1.d, (avg(share0_ref3.b) OVER (?)), share0_ref2.b, 
share0_ref2.d
-                                                                           
Sort Key: t4_1.c, t4_1.d, (avg(share0_ref3.b) OVER (?)), share0_ref2.d, 
share0_ref2.b
-                                                                           ->  
Redistribute Motion 3:3  (slice6; segments: 3)  (cost=0.00..1356691684.40 
rows=1 width=24)
+                                                                           
Group Key: t4_1.c, t4_1.d, (avg(share0_ref3.b) OVER (?)), share0_ref2.d, 
share0_ref2.b
+                                                                           ->  
Redistribute Motion 3:3  (slice7; segments: 3)  (cost=0.00..1356696138.85 
rows=134 width=24)
                                                                                
  Output: t4_1.c, t4_1.d, (avg(share0_ref3.b) OVER (?)), share0_ref2.b, 
share0_ref2.d
                                                                                
  Hash Key: t4_1.c, t4_1.d, (avg(share0_ref3.b) OVER (?)), share0_ref2.d, 
share0_ref2.b
-                                                                               
  ->  Nested Loop  (cost=0.00..1356691684.40 rows=1 width=24)
+                                                                               
  ->  Nested Loop  (cost=0.00..1356696138.84 rows=134 width=24)
                                                                                
        Output: t4_1.c, t4_1.d, (avg(share0_ref3.b) OVER (?)), share0_ref2.b, 
share0_ref2.d
                                                                                
        Join Filter: true
-                                                                               
        ->  Result  (cost=0.00..1324032.22 rows=1 width=16)
+                                                                               
        ->  Result  (cost=0.00..1324036.56 rows=14 width=16)
                                                                                
              Output: t4_1.c, t4_1.d, (avg(share0_ref3.b) OVER (?))
                                                                                
              Filter: ((avg(share0_ref3.b) OVER (?)) < '10'::numeric)
-                                                                               
              ->  WindowAgg  (cost=0.00..1324032.22 rows=1 width=16)
+                                                                               
              ->  WindowAgg  (cost=0.00..1324036.56 rows=34 width=16)
                                                                                
                    Output: avg(share0_ref3.b) OVER (?), share0_ref3.a, 
share0_ref3.b, t4_1.c, t4_1.d
                                                                                
                    Partition By: share0_ref3.a
                                                                                
                    Order By: share0_ref3.b
-                                                                               
                    ->  Sort  (cost=0.00..1324032.22 rows=1 width=16)
+                                                                               
                    ->  Sort  (cost=0.00..1324036.56 rows=34 width=16)
                                                                                
                          Output: share0_ref3.a, share0_ref3.b, t4_1.c, t4_1.d
                                                                                
                          Sort Key: share0_ref3.a, share0_ref3.b DESC
-                                                                               
                          ->  Redistribute Motion 3:3  (slice8; segments: 3)  
(cost=0.00..1324032.22 rows=1 width=16)
+                                                                               
                          ->  Redistribute Motion 3:3  (slice9; segments: 3)  
(cost=0.00..1324036.54 rows=34 width=16)
                                                                                
                                Output: share0_ref3.a, share0_ref3.b, t4_1.c, 
t4_1.d
                                                                                
                                Hash Key: share0_ref3.a
-                                                                               
                                ->  Nested Loop  (cost=0.00..1324032.22 rows=1 
width=16)
+                                                                               
                                ->  Nested Loop  (cost=0.00..1324036.54 rows=34 
width=16)
                                                                                
                                      Output: share0_ref3.a, share0_ref3.b, 
t4_1.c, t4_1.d
                                                                                
                                      Join Filter: true
-                                                                               
                                      ->  Broadcast Motion 3:3  (slice9; 
segments: 3)  (cost=0.00..431.00 rows=1 width=8)
+                                                                               
                                      ->  Broadcast Motion 3:3  (slice10; 
segments: 3)  (cost=0.00..431.00 rows=10 width=8)
                                                                                
                                            Output: share0_ref3.a, share0_ref3.b
-                                                                               
                                            ->  Result  (cost=0.00..431.00 
rows=1 width=8)
+                                                                               
                                            ->  Result  (cost=0.00..431.00 
rows=4 width=8)
                                                                                
                                                  Output: share0_ref3.a, 
share0_ref3.b
                                                                                
                                                  Filter: (share0_ref3.a = 
share0_ref3.d)
-                                                                               
                                                  ->  Shared Scan (share 
slice:id 9:0)  (cost=0.00..431.00 rows=1 width=12)
+                                                                               
                                                  ->  Shared Scan (share 
slice:id 10:0)  (cost=0.00..431.00 rows=4 width=12)
                                                                                
                                                        Output: share0_ref3.a, 
share0_ref3.b, share0_ref3.d
-                                                                               
                                      ->  Seq Scan on cte_prune.t4 t4_1  
(cost=0.00..431.00 rows=1 width=8)
+                                                                               
                                      ->  Seq Scan on cte_prune.t4 t4_1  
(cost=0.00..431.00 rows=4 width=8)
                                                                                
                                            Output: t4_1.c, t4_1.d
-                                                                               
        ->  Materialize  (cost=0.00..431.00 rows=1 width=8)
+                                                                               
        ->  Materialize  (cost=0.00..431.00 rows=10 width=8)
                                                                                
              Output: share0_ref2.b, share0_ref2.d
-                                                                               
              ->  Broadcast Motion 3:3  (slice7; segments: 3)  
(cost=0.00..431.00 rows=1 width=8)
+                                                                               
              ->  Broadcast Motion 3:3  (slice8; segments: 3)  
(cost=0.00..431.00 rows=10 width=8)
                                                                                
                    Output: share0_ref2.b, share0_ref2.d
-                                                                               
                    ->  Result  (cost=0.00..431.00 rows=1 width=8)
+                                                                               
                    ->  Result  (cost=0.00..431.00 rows=4 width=8)
                                                                                
                          Output: share0_ref2.b, share0_ref2.d
                                                                                
                          Filter: (share0_ref2.a = share0_ref2.d)
-                                                                               
                          ->  Shared Scan (share slice:id 7:0)  
(cost=0.00..431.00 rows=1 width=12)
+                                                                               
                          ->  Shared Scan (share slice:id 8:0)  
(cost=0.00..431.00 rows=4 width=12)
                                                                                
                                Output: share0_ref2.a, share0_ref2.b, 
share0_ref2.d
- Settings: enable_parallel = 'off', optimizer = 'on'
+ Settings: optimizer = 'on'
  Optimizer: GPORCA
-(90 rows)
+(93 rows)
 
 WITH t(a,b,d) AS
 (
diff --git a/src/test/regress/sql/cte_prune.sql 
b/src/test/regress/sql/cte_prune.sql
index db2351b134e..ae3c7671f11 100644
--- a/src/test/regress/sql/cte_prune.sql
+++ b/src/test/regress/sql/cte_prune.sql
@@ -255,6 +255,8 @@ drop table t2;
 
 CREATE TABLE t3 AS SELECT i as a, i+1 as b from generate_series(1,10)i;
 CREATE TABLE t4 AS SELECT i as c, i+1 as d from generate_series(1,10)i;
+analyze t3;
+analyze t4;
 
 -- Additional filtering conditions are added to the consumer.
 -- This is caused by `PexprInferPredicates` in the ORCA preprocessor.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


Reply via email to