Skip to content

Commit 450e873

Browse files
committed
ORCA: Fix detection of mixed storage in partitioned tables with foreign partitions
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.
1 parent 176e5c4 commit 450e873

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/backend/gpopt/translate/CTranslatorRelcacheToDXL.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3147,18 +3147,36 @@ CTranslatorRelcacheToDXL::RetrieveStorageTypeForPartitionedTable(Relation rel)
31473147
"Queries with partitions of greenplum_fdw are not supported"));
31483148
}
31493149
GPOS_DELETE(fdw_name_str);
3150+
3151+
// Check for mixed storage before continuing
3152+
// If we already encountered non-foreign partitions, mark as mixed
3153+
if (rel_storage_type != IMDRelation::ErelstorageSentinel &&
3154+
rel_storage_type != IMDRelation::ErelstorageForeign)
3155+
{
3156+
// Already have non-foreign partition(s), now found foreign → mixed
3157+
rel_storage_type = IMDRelation::ErelstorageMixedPartitioned;
3158+
}
3159+
else if (rel_storage_type == IMDRelation::ErelstorageSentinel)
3160+
{
3161+
// First partition is foreign
3162+
rel_storage_type = IMDRelation::ErelstorageForeign;
3163+
}
31503164
continue;
31513165
}
31523166
all_foreign = false;
31533167
if (rel_storage_type == IMDRelation::ErelstorageSentinel)
31543168
{
31553169
rel_storage_type = child_storage;
31563170
}
3157-
3171+
else if (rel_storage_type == IMDRelation::ErelstorageForeign)
3172+
{
3173+
// Previously had foreign partition(s), now found non-foreign → mixed
3174+
rel_storage_type = IMDRelation::ErelstorageMixedPartitioned;
3175+
}
31583176
// mark any partitioned table with supported partitions of mixed storage types,
31593177
// this is more conservative for certain skans (eg: we can't do an index scan if any
31603178
// partition is ao, we must only do a sequential or bitmap scan)
3161-
if (rel_storage_type != child_storage)
3179+
else if (rel_storage_type != child_storage)
31623180
{
31633181
rel_storage_type = IMDRelation::ErelstorageMixedPartitioned;
31643182
}

0 commit comments

Comments
 (0)