//--------------------------------------------------------------------------- // @function: // CLogicalSetOp::PdrgpcrsInputMapped // // @doc: // Get equivalence classes from one input child, mapped to output columns // //--------------------------------------------------------------------------- DrgPcrs * CLogicalSetOp::PdrgpcrsInputMapped ( IMemoryPool *pmp, CExpressionHandle &exprhdl, ULONG ulChild ) const { DrgPcrs *pdrgpcrsInput = exprhdl.Pdprel(ulChild)->Ppc()->PdrgpcrsEquivClasses(); const ULONG ulLen = pdrgpcrsInput->UlLength(); CColRefSet* pcrsChildInput = (*m_pdrgpcrsInput)[ulChild]; DrgPcrs *pdrgpcrs = GPOS_NEW(pmp) DrgPcrs(pmp); for (ULONG ul = 0; ul < ulLen; ul++) { CColRefSet *pcrs = GPOS_NEW(pmp) CColRefSet(pmp); pcrs->Include((*pdrgpcrsInput)[ul]); pcrs->Intersection(pcrsChildInput); if (0 == pcrs->CElements()) { pcrs->Release(); continue; } // replace each input column with its corresponding output column pcrs->Replace((*m_pdrgpdrgpcrInput)[ulChild], m_pdrgpcrOutput); pdrgpcrs->Append(pcrs); } return pdrgpcrs; }
//--------------------------------------------------------------------------- // @function: // CLogical::PpcDeriveConstraintRestrict // // @doc: // Derive constraint property only on the given columns // //--------------------------------------------------------------------------- CPropConstraint * CLogical::PpcDeriveConstraintRestrict ( IMemoryPool *pmp, CExpressionHandle &exprhdl, CColRefSet *pcrsOutput ) { // constraint property from relational child CPropConstraint *ppc = exprhdl.Pdprel(0)->Ppc(); DrgPcrs *pdrgpcrs = ppc->PdrgpcrsEquivClasses(); // construct new array of equivalence classes DrgPcrs *pdrgpcrsNew = GPOS_NEW(pmp) DrgPcrs(pmp); const ULONG ulLen = pdrgpcrs->UlLength(); for (ULONG ul = 0; ul < ulLen; ul++) { CColRefSet *pcrsEquiv = GPOS_NEW(pmp) CColRefSet(pmp); pcrsEquiv->Include((*pdrgpcrs)[ul]); pcrsEquiv->Intersection(pcrsOutput); if (0 < pcrsEquiv->CElements()) { pdrgpcrsNew->Append(pcrsEquiv); } else { pcrsEquiv->Release(); } } CConstraint *pcnstrChild = ppc->Pcnstr(); if (NULL == pcnstrChild) { return GPOS_NEW(pmp) CPropConstraint(pmp, pdrgpcrsNew, NULL); } DrgPcnstr *pdrgpcnstr = GPOS_NEW(pmp) DrgPcnstr(pmp); // include only constraints on given columns CColRefSetIter crsi(*pcrsOutput); while (crsi.FAdvance()) { CColRef *pcr = crsi.Pcr(); CConstraint *pcnstrCol = pcnstrChild->Pcnstr(pmp, pcr); if (NULL == pcnstrCol) { continue; } if (pcnstrCol->FUnbounded()) { pcnstrCol->Release(); continue; } pdrgpcnstr->Append(pcnstrCol); } CConstraint *pcnstr = CConstraint::PcnstrConjunction(pmp, pdrgpcnstr); return GPOS_NEW(pmp) CPropConstraint(pmp, pdrgpcrsNew, pcnstr); }