@@ -1351,6 +1351,11 @@ CTranslatorExprToDXL::PdxlnDynamicTableScan(
1351
1351
GPOS_ASSERT (nullptr != pexprDTS);
1352
1352
GPOS_ASSERT_IFF (nullptr != pexprScalarCond, nullptr != dxl_properties);
1353
1353
1354
+ if (GPOS_FTRACE (EopttraceDisableDynamicTableScan)) {
1355
+ return PdxlnDynamicScanToAppend<CPhysicalDynamicTableScan>(pexprDTS, colref_array,
1356
+ pdrgpdsBaseTables, pexprScalarCond, dxl_properties);
1357
+ }
1358
+
1354
1359
CPhysicalDynamicTableScan *popDTS =
1355
1360
CPhysicalDynamicTableScan::PopConvert (pexprDTS->Pop ());
1356
1361
CColRefArray *pdrgpcrOutput = popDTS->PdrgpcrOutput ();
@@ -1429,6 +1434,143 @@ CTranslatorExprToDXL::PdxlnDynamicTableScan(
1429
1434
return pdxlnDTS;
1430
1435
}
1431
1436
1437
+
1438
+ template <class PhysicalScanType >
1439
+ CDXLNode *
1440
+ CTranslatorExprToDXL::PdxlnDynamicScanToAppend (CExpression *pexprDTS,
1441
+ CColRefArray *colref_array,
1442
+ CDistributionSpecArray *pdrgpdsBaseTables,
1443
+ CExpression *pexprScalarCond,
1444
+ CDXLPhysicalProperties *dxl_properties) {
1445
+
1446
+ PhysicalScanType *popDTS =
1447
+ PhysicalScanType::PopConvert (pexprDTS->Pop ());
1448
+
1449
+ ULongPtrArray *selector_ids = GPOS_NEW (m_mp) ULongPtrArray (m_mp);
1450
+ CPartitionPropagationSpec *pps_reqd =
1451
+ pexprDTS->Prpp ()->Pepp ()->PppsRequired ();
1452
+ if (pps_reqd->Contains (popDTS->ScanId ()))
1453
+ {
1454
+ const CBitSet *bs = pps_reqd->SelectorIds (popDTS->ScanId ());
1455
+ CBitSetIter bsi (*bs);
1456
+ for (ULONG ul = 0 ; bsi.Advance (); ul++)
1457
+ {
1458
+ selector_ids->Append (GPOS_NEW (m_mp) ULONG (bsi.Bit ()));
1459
+ }
1460
+ }
1461
+
1462
+ // construct plan costs
1463
+ CDXLPhysicalProperties *pdxlpropDTS = GetProperties (pexprDTS);
1464
+
1465
+ if (nullptr != dxl_properties)
1466
+ {
1467
+ CWStringDynamic *rows_out_str = GPOS_NEW (m_mp) CWStringDynamic (
1468
+ m_mp,
1469
+ dxl_properties->GetDXLOperatorCost ()->GetRowsOutStr ()->GetBuffer ());
1470
+ CWStringDynamic *pstrCost = GPOS_NEW (m_mp)
1471
+ CWStringDynamic (m_mp, dxl_properties->GetDXLOperatorCost ()
1472
+ ->GetTotalCostStr ()
1473
+ ->GetBuffer ());
1474
+
1475
+ pdxlpropDTS->GetDXLOperatorCost ()->SetRows (rows_out_str);
1476
+ pdxlpropDTS->GetDXLOperatorCost ()->SetCost (pstrCost);
1477
+ dxl_properties->Release ();
1478
+ }
1479
+ GPOS_ASSERT (nullptr != pexprDTS->Prpp ());
1480
+
1481
+ // construct projection list for top-level Append node
1482
+ CColRefSet *pcrsOutput = pexprDTS->Prpp ()->PcrsRequired ();
1483
+ CDXLNode *pdxlnPrLAppend = PdxlnProjList (pcrsOutput, colref_array);
1484
+ CDXLTableDescr *root_dxl_table_descr = MakeDXLTableDescr (
1485
+ popDTS->Ptabdesc (), popDTS->PdrgpcrOutput (), pexprDTS->Prpp ());
1486
+
1487
+ // Construct the Append node - even when there is only one child partition.
1488
+ // This is done for two reasons:
1489
+ // * Dynamic partition pruning
1490
+ // Even if one partition is present in the statically pruned plan, we could
1491
+ // still dynamically prune it away. This needs an Append node.
1492
+ // * Col mappings issues
1493
+ // When the first selected child partition's cols have different types/order
1494
+ // than the root partition, we can no longer re-use the colrefs of the root
1495
+ // partition, since colrefs are immutable. Thus, we create new colrefs for
1496
+ // this partition. But, if there is no Append (in case of just one selected
1497
+ // partition), then we also go through update all references above the DTS
1498
+ // with the new colrefs. For simplicity, we decided to keep the Append
1499
+ // around to maintain this projection (mapping) from the old root colrefs
1500
+ // to the first selected partition colrefs.
1501
+ //
1502
+ // GPDB_12_MERGE_FIXME: An Append on a single TableScan can be removed in
1503
+ // CTranslatorDXLToPlstmt since these points do not apply there.
1504
+ CDXLNode *pdxlnAppend = GPOS_NEW (m_mp) CDXLNode (
1505
+ m_mp,
1506
+ GPOS_NEW (m_mp) CDXLPhysicalAppend (m_mp, false , false , popDTS->ScanId (),
1507
+ root_dxl_table_descr, selector_ids));
1508
+ pdxlnAppend->SetProperties (pdxlpropDTS);
1509
+ pdxlnAppend->AddChild (pdxlnPrLAppend);
1510
+ pdxlnAppend->AddChild (PdxlnFilter (nullptr ));
1511
+
1512
+ IMdIdArray *part_mdids = popDTS->GetPartitionMdids ();
1513
+ for (ULONG ul = 0 ; ul < part_mdids->Size (); ++ul)
1514
+ {
1515
+ IMDId *part_mdid = (*part_mdids)[ul];
1516
+ const IMDRelation *part = m_pmda->RetrieveRel (part_mdid);
1517
+
1518
+ CTableDescriptor *part_tabdesc =
1519
+ MakeTableDescForPart (part, popDTS->Ptabdesc ());
1520
+
1521
+ // Create new colrefs for the child partition. The ColRefs from root
1522
+ // DTS, which may be used in any parent node, can no longer be exported
1523
+ // by a child of the Append node. Thus it is exported by the Append
1524
+ // node itself, and new colrefs are created here.
1525
+ CColRefArray *part_colrefs = GPOS_NEW (m_mp) CColRefArray (m_mp);
1526
+ for (ULONG ul_col = 0 ; ul_col < part_tabdesc->ColumnCount (); ++ul_col)
1527
+ {
1528
+ const CColumnDescriptor *cd = part_tabdesc->Pcoldesc (ul_col);
1529
+ CColRef *cr = m_pcf->PcrCreate (cd->RetrieveType (),
1530
+ cd->TypeModifier (), cd->Name ());
1531
+ part_colrefs->Append (cr);
1532
+ }
1533
+
1534
+ CDXLTableDescr *dxl_table_descr =
1535
+ MakeDXLTableDescr (part_tabdesc, part_colrefs, pexprDTS->Prpp ());
1536
+ part_tabdesc->Release ();
1537
+
1538
+ CDXLNode *dxlnode = GPOS_NEW (m_mp) CDXLNode (
1539
+ m_mp, GPOS_NEW (m_mp) CDXLPhysicalTableScan (m_mp, dxl_table_descr));
1540
+
1541
+ // GPDB_12_MERGE_FIXME: Compute stats & properties per scan
1542
+ pdxlpropDTS->AddRef ();
1543
+ dxlnode->SetProperties (pdxlpropDTS);
1544
+
1545
+ // ColRef -> index in child table desc (per partition)
1546
+ auto root_col_mapping = (*popDTS->GetRootColMappingPerPart ())[ul];
1547
+
1548
+ // construct projection list, re-ordered to match root DTS
1549
+ CDXLNode *pdxlnPrL = PdxlnProjListForChildPart (
1550
+ root_col_mapping, part_colrefs, pcrsOutput, colref_array);
1551
+ dxlnode->AddChild (pdxlnPrL); // project list
1552
+
1553
+ // construct the filter
1554
+ CDXLNode *filter_dxlnode = PdxlnFilter (
1555
+ PdxlnCondForChildPart (root_col_mapping, part_colrefs,
1556
+ popDTS->PdrgpcrOutput (), pexprScalarCond));
1557
+ dxlnode->AddChild (filter_dxlnode); // filter
1558
+
1559
+ // add to the other scans under the created Append node
1560
+ pdxlnAppend->AddChild (dxlnode);
1561
+
1562
+ // cleanup
1563
+ part_colrefs->Release ();
1564
+ }
1565
+
1566
+ CDistributionSpec *pds = pexprDTS->GetDrvdPropPlan ()->Pds ();
1567
+ pds->AddRef ();
1568
+ pdrgpdsBaseTables->Append (pds);
1569
+
1570
+ GPOS_ASSERT (pdxlnAppend);
1571
+ return pdxlnAppend;
1572
+ }
1573
+
1432
1574
// ---------------------------------------------------------------------------
1433
1575
// @function:
1434
1576
// CTranslatorExprToDXL::PdxlnDynamicBitmapTableScan
@@ -1763,6 +1905,11 @@ CTranslatorExprToDXL::PdxlnDynamicForeignScan(
1763
1905
GPOS_ASSERT (nullptr != pexprDFS);
1764
1906
GPOS_ASSERT_IFF (nullptr != pexprScalarCond, nullptr != dxl_properties);
1765
1907
1908
+ if (GPOS_FTRACE (EopttraceDisableDynamicTableScan)) {
1909
+ return PdxlnDynamicScanToAppend<CPhysicalDynamicForeignScan>(pexprDFS, colref_array,
1910
+ pdrgpdsBaseTables, pexprScalarCond, dxl_properties);
1911
+ }
1912
+
1766
1913
CPhysicalDynamicForeignScan *popDFS =
1767
1914
CPhysicalDynamicForeignScan::PopConvert (pexprDFS->Pop ());
1768
1915
CColRefArray *pdrgpcrOutput = popDFS->PdrgpcrOutput ();
@@ -1841,6 +1988,7 @@ CTranslatorExprToDXL::PdxlnDynamicForeignScan(
1841
1988
1842
1989
return pdxlnDFS;
1843
1990
}
1991
+
1844
1992
// ---------------------------------------------------------------------------
1845
1993
// @function:
1846
1994
// CTranslatorExprToDXL::PdxlnResult
0 commit comments