zhangyue-hashdata commented on code in PR #1022: URL: https://github.com/apache/cloudberry/pull/1022#discussion_r2156197767
########## src/backend/gporca/libgpopt/src/translate/CTranslatorExprToDXL.cpp: ########## @@ -1429,6 +1434,425 @@ CTranslatorExprToDXL::PdxlnDynamicTableScan( return pdxlnDTS; } +//--------------------------------------------------------------------------- +// @function: +// CTranslatorExprToDXL::PdxlnDynamicScanToAppend +// +// @doc: +// Create a DXL Append node from an optimizer +// dynamic scan or foreign scan node. +// +//--------------------------------------------------------------------------- +template <class PhysicalScanType> +CDXLNode * +CTranslatorExprToDXL::PdxlnDynamicScanToAppend(CExpression *pexprDTS, + CColRefArray *colref_array, + CDistributionSpecArray *pdrgpdsBaseTables, + CExpression *pexprScalarCond, + CDXLPhysicalProperties *dxl_properties) { + + PhysicalScanType *popDTS = + PhysicalScanType::PopConvert(pexprDTS->Pop()); + + ULongPtrArray *selector_ids = GPOS_NEW(m_mp) ULongPtrArray(m_mp); + CPartitionPropagationSpec *pps_reqd = + pexprDTS->Prpp()->Pepp()->PppsRequired(); + if (pps_reqd->Contains(popDTS->ScanId())) + { + const CBitSet *bs = pps_reqd->SelectorIds(popDTS->ScanId()); + CBitSetIter bsi(*bs); + for (ULONG ul = 0; bsi.Advance(); ul++) + { + selector_ids->Append(GPOS_NEW(m_mp) ULONG(bsi.Bit())); + } + } + + // construct plan costs + CDXLPhysicalProperties *pdxlpropDTS = GetProperties(pexprDTS); + + if (nullptr != dxl_properties) + { + CWStringDynamic *rows_out_str = GPOS_NEW(m_mp) CWStringDynamic( + m_mp, + dxl_properties->GetDXLOperatorCost()->GetRowsOutStr()->GetBuffer()); + CWStringDynamic *pstrCost = GPOS_NEW(m_mp) + CWStringDynamic(m_mp, dxl_properties->GetDXLOperatorCost() + ->GetTotalCostStr() + ->GetBuffer()); + + pdxlpropDTS->GetDXLOperatorCost()->SetRows(rows_out_str); + pdxlpropDTS->GetDXLOperatorCost()->SetCost(pstrCost); + dxl_properties->Release(); + } + GPOS_ASSERT(nullptr != pexprDTS->Prpp()); + + // construct projection list for top-level Append node + CColRefSet *pcrsOutput = pexprDTS->Prpp()->PcrsRequired(); + CDXLNode *pdxlnPrLAppend = PdxlnProjList(pcrsOutput, colref_array); + CDXLTableDescr *root_dxl_table_descr = MakeDXLTableDescr( + popDTS->Ptabdesc(), popDTS->PdrgpcrOutput(), pexprDTS->Prpp()); + + // Construct the Append node - even when there is only one child partition. + // This is done for two reasons: + // * Dynamic partition pruning + // Even if one partition is present in the statically pruned plan, we could + // still dynamically prune it away. This needs an Append node. + // * Col mappings issues + // When the first selected child partition's cols have different types/order + // than the root partition, we can no longer re-use the colrefs of the root + // partition, since colrefs are immutable. Thus, we create new colrefs for + // this partition. But, if there is no Append (in case of just one selected + // partition), then we also go through update all references above the DTS + // with the new colrefs. For simplicity, we decided to keep the Append + // around to maintain this projection (mapping) from the old root colrefs + // to the first selected partition colrefs. + // + // GPDB_12_MERGE_FIXME: An Append on a single TableScan can be removed in + // CTranslatorDXLToPlstmt since these points do not apply there. + CDXLNode *pdxlnAppend = GPOS_NEW(m_mp) CDXLNode( + m_mp, + GPOS_NEW(m_mp) CDXLPhysicalAppend(m_mp, false, false, popDTS->ScanId(), + root_dxl_table_descr, selector_ids)); + pdxlnAppend->SetProperties(pdxlpropDTS); + pdxlnAppend->AddChild(pdxlnPrLAppend); + pdxlnAppend->AddChild(PdxlnFilter(nullptr)); + + IMdIdArray *part_mdids = popDTS->GetPartitionMdids(); + for (ULONG ul = 0; ul < part_mdids->Size(); ++ul) + { + IMDId *part_mdid = (*part_mdids)[ul]; + const IMDRelation *part = m_pmda->RetrieveRel(part_mdid); + + CTableDescriptor *part_tabdesc = Review Comment: Is it better `CAutoP<CTableDescriptor> auto_part_tabdesc(part_tabdesc);`? ########## src/backend/gporca/libnaucrates/src/operators/CDXLPhysicalAppend.cpp: ########## @@ -113,9 +132,28 @@ CDXLPhysicalAppend::SerializeToDXL(CXMLSerializer *xml_serializer, xml_serializer->AddAttribute( CDXLTokens::GetDXLTokenStr(EdxltokenAppendIsZapped), m_is_zapped); + if (m_scan_id != gpos::ulong_max) + { + xml_serializer->AddAttribute( + CDXLTokens::GetDXLTokenStr(EdxltokenPartIndexId), m_scan_id); + + CWStringDynamic *serialized_selector_ids = Review Comment: Is it better `CAutoP<CWStringDynamic> serialized_selector_ids(xxx);`? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@cloudberry.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cloudberry.apache.org For additional commands, e-mail: commits-h...@cloudberry.apache.org