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

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


The following commit(s) were added to refs/heads/main by this push:
     new c2e818629ff ORCA: Fix detection of mixed storage in partitioned tables 
with foreign partitions (#1524)
c2e818629ff is described below

commit c2e818629ffa48000b2bd24b697aa1a743f9d1aa
Author: Jianghua.yjh <[email protected]>
AuthorDate: Thu Mar 5 10:09:02 2026 -0800

    ORCA: Fix detection of mixed storage in partitioned tables with foreign 
partitions (#1524)
    
    The storage type detection logic failed to properly identify mixed storage 
when
    foreign and non-foreign partitions coexisted, leading to incorrect metadata 
that
    could cause issues with scan type selection and query planning.
---
 .../gpopt/translate/CTranslatorRelcacheToDXL.cpp   | 22 ++++++++++++++++++++--
 .../minidump/MixedPartitioned-ForeignHeap-Test.mdp | 17 +++++++++++++++++
 src/backend/gporca/server/CMakeLists.txt           |  2 +-
 3 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/src/backend/gpopt/translate/CTranslatorRelcacheToDXL.cpp 
b/src/backend/gpopt/translate/CTranslatorRelcacheToDXL.cpp
index 6a5d679a11f..ee4b8888b19 100644
--- a/src/backend/gpopt/translate/CTranslatorRelcacheToDXL.cpp
+++ b/src/backend/gpopt/translate/CTranslatorRelcacheToDXL.cpp
@@ -3147,6 +3147,20 @@ 
CTranslatorRelcacheToDXL::RetrieveStorageTypeForPartitionedTable(Relation rel)
                                                "Queries with partitions of 
greenplum_fdw are not supported"));
                        }
                        GPOS_DELETE(fdw_name_str);
+
+                       // Check for mixed storage before continuing
+                       // If we already encountered non-foreign partitions, 
mark as mixed
+                       if (rel_storage_type != 
IMDRelation::ErelstorageSentinel &&
+                               rel_storage_type != 
IMDRelation::ErelstorageForeign)
+                       {
+                               // Already have non-foreign partition(s), now 
found foreign → mixed
+                               rel_storage_type = 
IMDRelation::ErelstorageMixedPartitioned;
+                       }
+                       else if (rel_storage_type == 
IMDRelation::ErelstorageSentinel)
+                       {
+                               // First partition is foreign
+                               rel_storage_type = 
IMDRelation::ErelstorageForeign;
+                       }
                        continue;
                }
                all_foreign = false;
@@ -3154,11 +3168,15 @@ 
CTranslatorRelcacheToDXL::RetrieveStorageTypeForPartitionedTable(Relation rel)
                {
                        rel_storage_type = child_storage;
                }
-
+               else if (rel_storage_type == IMDRelation::ErelstorageForeign)
+               {
+                       // Previously had foreign partition(s), now found 
non-foreign → mixed
+                       rel_storage_type = 
IMDRelation::ErelstorageMixedPartitioned;
+               }
                // mark any partitioned table with supported partitions of 
mixed storage types,
                // this is more conservative for certain skans (eg: we can't do 
an index scan if any
                // partition is ao, we must only do a sequential or bitmap scan)
-               if (rel_storage_type != child_storage)
+               else if (rel_storage_type != child_storage)
                {
                        rel_storage_type = 
IMDRelation::ErelstorageMixedPartitioned;
                }
diff --git 
a/src/backend/gporca/data/dxl/minidump/MixedPartitioned-ForeignHeap-Test.mdp 
b/src/backend/gporca/data/dxl/minidump/MixedPartitioned-ForeignHeap-Test.mdp
new file mode 100644
index 00000000000..181df7b0262
--- /dev/null
+++ b/src/backend/gporca/data/dxl/minidump/MixedPartitioned-ForeignHeap-Test.mdp
@@ -0,0 +1,17 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<dxl:DXLMessage xmlns:dxl="http://greenplum.com/dxl/2010/12/";><dxl:Comment>
+Objective: Test RetrieveStorageTypeForPartitionedTable with Foreign + Heap 
partitions
+Expected: StorageType="MixedPartitioned"
+
+Original query:
+create table part (a int, b int) partition by range (b);
+create external table p1_e (a int, b int) location ('file://...') format 'csv';
+create external table p2_e (a int, b int) location ('file://...') format 'csv';
+alter table part attach partition p1_e for values from (0) to (10);
+alter table part attach partition p2_e for values from (10) to (19);
+create table p3 (a int, b int) distributed by (a);
+create table p4 (a int, b int) distributed by (a);
+alter table part attach partition p3 for values from (20) to (30);
+alter table part attach partition p4 for values from (30) to (40);
+SELECT * FROM part;
+    </dxl:Comment><dxl:Thread 
Id="0"><dxl:OptimizerConfig><dxl:EnumeratorConfig Id="0" PlanSamples="0" 
CostThreshold="0" /><dxl:StatisticsConfig DampingFactorFilter="0.750000" 
DampingFactorJoin="0.000000" DampingFactorGroupBy="0.750000" 
MaxStatsBuckets="100" /><dxl:CTEConfig CTEInliningCutoff="0" /><dxl:WindowOids 
RowNumber="3100" Rank="3101" DenseRank="3102" /><dxl:CostModelConfig 
CostModelType="1" SegmentsForCosting="3"><dxl:CostParams><dxl:CostParam 
Name="NLJFactor" Value="1024.000000 [...]
\ No newline at end of file
diff --git a/src/backend/gporca/server/CMakeLists.txt 
b/src/backend/gporca/server/CMakeLists.txt
index 3c7b52cda91..7e6a4980479 100644
--- a/src/backend/gporca/server/CMakeLists.txt
+++ b/src/backend/gporca/server/CMakeLists.txt
@@ -420,7 +420,7 @@ Hint-Leading-Multiple Hint-Leading-Directed 
Hint-Leading-NonDirected
 Hint-FullHashJoin-JoinType Hint-FullMergeJoin-JoinType 
Hint-IndexHashJoin-JoinType Hint-IndexNestLoop-JoinType;
 
 CForeignPartTest:
-ForeignPartUniform PartForeignMixed PartForeignDifferentServer 
PartForeignDifferentExecLocation PartForeignMixedDPE PartForeignMixedSPE 
PartForeignUniformSPE ForeignScanExecLocAnySimpleScan ForeignScanExecLocAnyJoin 
ForeignPartOneTimeFilterDPE;
+ForeignPartUniform PartForeignMixed PartForeignDifferentServer 
PartForeignDifferentExecLocation PartForeignMixedDPE PartForeignMixedSPE 
PartForeignUniformSPE ForeignScanExecLocAnySimpleScan ForeignScanExecLocAnyJoin 
ForeignPartOneTimeFilterDPE MixedPartitioned-ForeignHeap-Test;
 
 CCardinalityTest:
 SystemColCtidStats SystemColSegIdStats


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

Reply via email to