Skip to content

ORCA: allow partition table use the append node #1022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/backend/gpopt/config/CConfigParamMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,18 @@ CConfigParamMapping::SConfigMappingElem CConfigParamMapping::m_elements[] = {
{EopttraceEnableUseDistributionInDQA,
&optimizer_enable_use_distribution_in_dqa,
false, // m_negate_param
GPOS_WSZ_LIT(
"Enable use the distribution key in DQA")},
GPOS_WSZ_LIT("Enable use the distribution key in DQA")},
{EopttraceDisableInnerHashJoin, &optimizer_enable_hashjoin,
true, // m_negate_param
GPOS_WSZ_LIT("Explore hash join alternatives")},
{EopttraceDisableInnerNLJ, &optimizer_enable_nljoin,
true, // m_negate_param
GPOS_WSZ_LIT("Enable nested loop join alternatives")},

{EopttraceDisableDynamicTableScan, &optimizer_disable_dynamic_table_scan,
false, // m_negate_param
GPOS_WSZ_LIT(
"Disable the dynamic seq/bitmap/index scan in partition table")},
};

//---------------------------------------------------------------------------
Expand Down
25 changes: 25 additions & 0 deletions src/backend/gpopt/translate/CTranslatorDXLToPlStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3917,6 +3917,31 @@ CTranslatorDXLToPlStmt::TranslateDXLAppend(
GPOS_ASSERT(EdxlappendIndexFirstChild < arity);
append->appendplans = NIL;

// translate table descriptor into a range table entry
CDXLPhysicalAppend *phy_append_dxlop =
CDXLPhysicalAppend::Cast(append_dxlnode->GetOperator());

// If this append was create from a DynamicTableScan node in ORCA, it will
// contain the table descriptor of the root partitioned table. Add that to
// the range table in the PlStmt.
if (phy_append_dxlop->GetScanId() != gpos::ulong_max)
{
GPOS_ASSERT(nullptr != phy_append_dxlop->GetDXLTableDesc());

// translation context for column mappings in the base relation
CDXLTranslateContextBaseTable base_table_context(m_mp);

(void) ProcessDXLTblDescr(phy_append_dxlop->GetDXLTableDesc(),
&base_table_context);

OID oid_type =
CMDIdGPDB::CastMdid(m_md_accessor->PtMDType<IMDTypeInt4>()->MDId())
->Oid();
append->join_prune_paramids =
TranslateJoinPruneParamids(phy_append_dxlop->GetSelectorIds(),
oid_type, m_dxl_to_plstmt_context);
}

// translate children
CDXLTranslateContext child_context(m_mp, false,
output_context->GetColIdToParamIdMap());
Expand Down
5 changes: 5 additions & 0 deletions src/backend/gpopt/translate/CTranslatorQueryToDXL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,11 @@ CTranslatorQueryToDXL::CheckRangeTable(Query *query)
GPOS_RAISE(gpdxl::ExmaDXL, gpdxl::ExmiQuery2DXLUnsupportedFeature,
GPOS_WSZ_LIT("TABLESAMPLE in the FROM clause"));
}

if (rte->relkind == 'p' && query->hasRowSecurity && GPOS_FTRACE(EopttraceDisableDynamicTableScan)) {
GPOS_RAISE(gpdxl::ExmaDXL, gpdxl::ExmiQuery2DXLUnsupportedFeature,
GPOS_WSZ_LIT("ORCA not support row-level security if dynamic table scan is disabled."));
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/backend/gpopt/translate/CTranslatorRelcacheToDXL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3038,7 +3038,7 @@ CTranslatorRelcacheToDXL::RetrieveIndexPartitions(CMemoryPool *mp, OID rel_oid)
{
OID oid = lfirst_oid(lc);
partition_oids->Append(GPOS_NEW(mp)
CMDIdGPDB(IMDId::EmdidGeneral, oid));
CMDIdGPDB(IMDId::EmdidInd, oid));
}

return partition_oids;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ class CLogicalDynamicGetBase : public CLogical
static ColRefToUlongMapArray *ConstructRootColMappingPerPart(
CMemoryPool *mp, CColRefArray *root_cols, IMdIdArray *partition_mdids);

using ColNameToIndexMap =
CHashMap<const CWStringConst, ULONG, CWStringConst::HashValue,
CWStringConst::Equals, CleanupNULL<const CWStringConst>,
CleanupDelete<ULONG>>;

public:
// ctors
explicit CLogicalDynamicGetBase(CMemoryPool *mp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ class CLogicalDynamicIndexOnlyGet : public CLogicalDynamicIndexGet
{
CXformSet *xform_set = GPOS_NEW(mp) CXformSet(mp);

(void) xform_set->ExchangeSet(
CXform::ExfDynamicIndexOnlyGet2DynamicIndexOnlyScan);

// Append node have not implements the index only scan
if (!GPOS_FTRACE(EopttraceDisableDynamicTableScan)) {
(void) xform_set->ExchangeSet(
CXform::ExfDynamicIndexOnlyGet2DynamicIndexOnlyScan);
}
return xform_set;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,26 @@ class CTranslatorExprToDXL
CDistributionSpecArray *pdrgpdsBaseTables,
ULONG *pulNonGatherMotions, BOOL *pfDML);

// translate a dynamic seq/foreign scan to append
template <class PhysicalScanType>
CDXLNode *PdxlnDynamicScanToAppend(
CExpression *pexprDTS, CColRefArray *colref_array,
CDistributionSpecArray *pdrgpdsBaseTables, CExpression *pexprScalarCond,
CDXLPhysicalProperties *dxl_properties);

// translate a dynamic index/index only scan to append
template <class PhysicalScanType>
CDXLNode *PdxlnDynamicIndexScanToAppend(CExpression *pexprDIS,
CColRefArray *colref_array,
CDXLPhysicalProperties *dxl_properties,
CReqdPropPlan *prpp);

// translate a dynamic bitmap scan to append
CDXLNode *PdxlnDynamicBitmapScanToAppend(
CExpression *pexprDTS, CColRefArray *colref_array,
CDistributionSpecArray *pdrgpdsBaseTables, CExpression *pexprScalarCond,
CDXLPhysicalProperties *dxl_properties);

// translate a dynamic table scan
CDXLNode *PdxlnDynamicTableScan(CExpression *pexprDTS,
CColRefArray *colref_array,
Expand Down Expand Up @@ -562,6 +582,16 @@ class CTranslatorExprToDXL
const CColRefArray *root_colrefs,
CExpression *pred);

CDXLNode *PdxlnBitmapIndexProbeForChildPart(
const ColRefToUlongMap *root_col_mapping,
const CColRefArray *part_colrefs, const CColRefArray *root_colrefs,
const IMDRelation *part, CExpression *pexprBitmapIndexProbe);

CDXLNode *PdxlnBitmapIndexPathForChildPart(
const ColRefToUlongMap *root_col_mapping,
const CColRefArray *part_colrefs, const CColRefArray *root_colrefs,
const IMDRelation *part, CExpression *pexprBitmapIndexPath);

// translate a project list expression into a DXL proj list node
// according to the order specified in the dynamic array
CDXLNode *PdxlnProjList(const CExpression *pexprProjList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,6 @@ CLogicalDynamicGetBase::ConstructRootColMappingPerPart(
CMDAccessor *mda = COptCtxt::PoctxtFromTLS()->Pmda();

ColRefToUlongMapArray *part_maps = GPOS_NEW(mp) ColRefToUlongMapArray(mp);

// Build hashmap of colname to the index
ColNameToIndexMap *root_mapping = GPOS_NEW(mp) ColNameToIndexMap(mp);
for (ULONG i = 0; i < root_cols->Size(); ++i)
{
CColRef *root_colref = (*root_cols)[i];
root_mapping->Insert(root_colref->Name().Pstr(), GPOS_NEW(mp) ULONG(i));
}

for (ULONG ul = 0; ul < partition_mdids->Size(); ++ul)
{
IMDId *part_mdid = (*partition_mdids)[ul];
Expand All @@ -253,28 +244,35 @@ CLogicalDynamicGetBase::ConstructRootColMappingPerPart(
GPOS_ASSERT(nullptr != partrel);

ColRefToUlongMap *mapping = GPOS_NEW(mp) ColRefToUlongMap(mp);
// The root mapping cannot contain dropped columns, but may be
// in a different order than the child cols.Iterate through each of the child
// cols, and retrieve the corresponding index in the parent table
for (ULONG j = 0; j < partrel->ColumnCount(); ++j)

for (ULONG i = 0; i < root_cols->Size(); ++i)
{
const IMDColumn *coldesc = partrel->GetMdCol(j);
const CWStringConst *colname = coldesc->Mdname().GetMDName();
CColRef *root_colref = (*root_cols)[i];

if (coldesc->IsDropped())
BOOL found_mapping = false;
for (ULONG j = 0, idx = 0; j < partrel->ColumnCount(); ++j, ++idx)
{
continue;
const IMDColumn *coldesc = partrel->GetMdCol(j);
const CWStringConst *colname = coldesc->Mdname().GetMDName();

if (coldesc->IsDropped())
{
--idx;
continue;
}

if (colname->Equals(root_colref->Name().Pstr()))
{
// Found the corresponding column in the child partition
// Save the index in the mapping
mapping->Insert(root_colref, GPOS_NEW(mp) ULONG(idx));
found_mapping = true;
break;
}
}

ULONG *root_idx = root_mapping->Find(colname);
if (nullptr != root_idx)
{
mapping->Insert((*root_cols)[*root_idx],
GPOS_NEW(mp) ULONG(*root_idx));
}
else
if (!found_mapping)
{
root_mapping->Release();
GPOS_RAISE(
CException::ExmaInvalid, CException::ExmiInvalid,
GPOS_WSZ_LIT(
Expand All @@ -283,6 +281,5 @@ CLogicalDynamicGetBase::ConstructRootColMappingPerPart(
}
part_maps->Append(mapping);
}
root_mapping->Release();
return part_maps;
}
Loading
Loading