//--------------------------------------------------------------------------- // @function: // CPhysicalJoin::FProvidesReqdCols // // @doc: // Helper for checking if required columns are included in output columns // //--------------------------------------------------------------------------- BOOL CPhysicalJoin::FProvidesReqdCols ( CExpressionHandle &exprhdl, CColRefSet *pcrsRequired, ULONG // ulOptReq ) const { GPOS_ASSERT(NULL != pcrsRequired); GPOS_ASSERT(3 == exprhdl.UlArity()); // union columns from relational children CColRefSet *pcrs = GPOS_NEW(m_pmp) CColRefSet(m_pmp); ULONG ulArity = exprhdl.UlArity(); for (ULONG i = 0; i < ulArity - 1; i++) { CColRefSet *pcrsChild = exprhdl.Pdprel(i)->PcrsOutput(); pcrs->Union(pcrsChild); } BOOL fProvidesCols = pcrs->FSubset(pcrsRequired); pcrs->Release(); return fProvidesCols; }
//--------------------------------------------------------------------------- // @function: // CPhysicalUnionAll::AssertValidChildDistributions // // @doc: // Helper to validate child distributions // //--------------------------------------------------------------------------- void CPhysicalUnionAll::AssertValidChildDistributions ( IMemoryPool *pmp, CExpressionHandle &exprhdl, CDistributionSpec::EDistributionType *pedt, // array of distribution types to check ULONG ulDistrs, // number of distribution types to check const CHAR *szAssertMsg ) { const ULONG ulArity = exprhdl.UlArity(); for (ULONG ulChild = 0; ulChild < ulArity; ulChild++) { CDistributionSpec *pdsChild = exprhdl.Pdpplan(ulChild)->Pds(); CDistributionSpec::EDistributionType edtChild = pdsChild->Edt(); BOOL fMatch = false; for (ULONG ulDistr = 0; !fMatch && ulDistr < ulDistrs; ulDistr++) { fMatch = (pedt[ulDistr] == edtChild); } if (!fMatch) { CAutoTrace at(pmp); at.Os() << szAssertMsg; } GPOS_ASSERT(fMatch); } }
//--------------------------------------------------------------------------- // @function: // CPhysicalUnionAll::FProvidesReqdCols // // @doc: // Check if required columns are included in output columns // //--------------------------------------------------------------------------- BOOL CPhysicalUnionAll::FProvidesReqdCols ( CExpressionHandle & #ifdef GPOS_DEBUG exprhdl #endif // GPOS_DEBUG , CColRefSet *pcrsRequired, ULONG // ulOptReq ) const { GPOS_ASSERT(NULL != pcrsRequired); GPOS_ASSERT(m_pdrgpdrgpcrInput->UlLength() == exprhdl.UlArity()); CColRefSet *pcrs = GPOS_NEW(m_pmp) CColRefSet(m_pmp); // include output columns pcrs->Include(m_pdrgpcrOutput); BOOL fProvidesCols = pcrs->FSubset(pcrsRequired); pcrs->Release(); return fProvidesCols; }
//--------------------------------------------------------------------------- // @function: // CPhysicalJoin::FOuterProvidesReqdCols // // @doc: // Helper for checking if the outer input of a binary join operator // includes the required columns // //--------------------------------------------------------------------------- BOOL CPhysicalJoin::FOuterProvidesReqdCols ( CExpressionHandle &exprhdl, CColRefSet *pcrsRequired ) { GPOS_ASSERT(NULL != pcrsRequired); GPOS_ASSERT(3 == exprhdl.UlArity() && "expected binary join"); CColRefSet *pcrsOutput = exprhdl.Pdprel(0 /*ulChildIndex*/)->PcrsOutput(); return pcrsOutput->FSubset(pcrsRequired); }
//--------------------------------------------------------------------------- // @function: // CLogicalUnion::Maxcard // // @doc: // Derive max card // //--------------------------------------------------------------------------- CMaxCard CLogicalUnion::Maxcard ( IMemoryPool *, // pmp CExpressionHandle &exprhdl ) const { const ULONG ulArity = exprhdl.UlArity(); CMaxCard maxcard = exprhdl.Pdprel(0)->Maxcard(); for (ULONG ul = 1; ul < ulArity; ul++) { maxcard += exprhdl.Pdprel(ul)->Maxcard(); } return maxcard; }
//--------------------------------------------------------------------------- // @function: // CLogical::MaxcardDef // // @doc: // Default max card for join and apply operators // //--------------------------------------------------------------------------- CMaxCard CLogical::MaxcardDef ( CExpressionHandle &exprhdl ) { const ULONG ulArity = exprhdl.UlArity(); CMaxCard maxcard = exprhdl.Pdprel(0)->Maxcard(); for (ULONG ul = 1; ul < ulArity - 1; ul++) { if (!exprhdl.FScalarChild(ul)) { maxcard *= exprhdl.Pdprel(ul)->Maxcard(); } } return maxcard; }
//--------------------------------------------------------------------------- // @function: // CPhysicalSequence::FProvidesReqdCols // // @doc: // Helper for checking if required columns are included in output columns // //--------------------------------------------------------------------------- BOOL CPhysicalSequence::FProvidesReqdCols ( CExpressionHandle &exprhdl, CColRefSet *pcrsRequired, ULONG // ulOptReq ) const { GPOS_ASSERT(NULL != pcrsRequired); // last child must provide required columns ULONG ulArity = exprhdl.UlArity(); GPOS_ASSERT(0 < ulArity); CColRefSet *pcrsChild = exprhdl.Pdprel(ulArity - 1)->PcrsOutput(); return pcrsChild->FSubset(pcrsRequired); }
//--------------------------------------------------------------------------- // @function: // CXformExpandNAryJoin::Exfp // // @doc: // Compute xform promise for a given expression handle // //--------------------------------------------------------------------------- CXform::EXformPromise CXformExpandNAryJoin::Exfp ( CExpressionHandle &exprhdl ) const { if (exprhdl.Pdpscalar(exprhdl.UlArity() - 1)->FHasSubquery()) { // subqueries must be unnested before applying xform return CXform::ExfpNone; } #ifdef GPOS_DEBUG CAutoMemoryPool amp; GPOS_ASSERT(!CXformUtils::FJoinPredOnSingleChild(amp.Pmp(), exprhdl) && "join predicates are not pushed down"); #endif // GPOS_DEBUG return CXform::ExfpHigh; }
//--------------------------------------------------------------------------- // @function: // COperator::EfdaDeriveFromChildren // // @doc: // Derive data access function property from child expressions // //--------------------------------------------------------------------------- IMDFunction::EFuncDataAcc COperator::EfdaDeriveFromChildren ( CExpressionHandle &exprhdl, IMDFunction::EFuncDataAcc efdaDefault ) { IMDFunction::EFuncDataAcc efda = efdaDefault; const ULONG ulArity = exprhdl.UlArity(); for (ULONG ul = 0; ul < ulArity; ul++) { IMDFunction::EFuncDataAcc efdaChild = exprhdl.PfpChild(ul)->Efda(); if (efdaChild > efda) { efda = efdaChild; } } return efda; }
//--------------------------------------------------------------------------- // @function: // COperator::EfsDeriveFromChildren // // @doc: // Derive stability function property from child expressions // //--------------------------------------------------------------------------- IMDFunction::EFuncStbl COperator::EfsDeriveFromChildren ( CExpressionHandle &exprhdl, IMDFunction::EFuncStbl efsDefault ) { IMDFunction::EFuncStbl efs = efsDefault; const ULONG ulArity = exprhdl.UlArity(); for (ULONG ul = 0; ul < ulArity; ul++) { IMDFunction::EFuncStbl efsChild = exprhdl.PfpChild(ul)->Efs(); if (efsChild > efs) { efs = efsChild; } } return efs; }
//--------------------------------------------------------------------------- // @function: // CLogical::UlJoinDepth // // @doc: // Derive join depth // //--------------------------------------------------------------------------- ULONG CLogical::UlJoinDepth ( IMemoryPool *, // pmp CExpressionHandle &exprhdl ) const { const ULONG ulArity = exprhdl.UlArity(); // sum-up join depth of all relational children ULONG ulDepth = 0; for (ULONG ul = 0; ul < ulArity; ul++) { if (!exprhdl.FScalarChild(ul)) { ulDepth = ulDepth + exprhdl.Pdprel(ul)->UlJoinDepth(); } } return ulDepth; }
//--------------------------------------------------------------------------- // @function: // CPhysicalComputeScalar::FProvidesReqdCols // // @doc: // Check if required columns are included in output columns // //--------------------------------------------------------------------------- BOOL CPhysicalComputeScalar::FProvidesReqdCols ( CExpressionHandle &exprhdl, CColRefSet *pcrsRequired, ULONG // ulOptReq ) const { GPOS_ASSERT(NULL != pcrsRequired); GPOS_ASSERT(2 == exprhdl.UlArity()); CColRefSet *pcrs = GPOS_NEW(m_pmp) CColRefSet(m_pmp); // include defined columns by scalar project list pcrs->Union(exprhdl.Pdpscalar(1 /*ulChildIndex*/)->PcrsDefined()); // include output columns of the relational child pcrs->Union(exprhdl.Pdprel(0 /*ulChildIndex*/)->PcrsOutput()); BOOL fProvidesCols = pcrs->FSubset(pcrsRequired); pcrs->Release(); return fProvidesCols; }
//--------------------------------------------------------------------------- // @function: // CPhysicalAgg::FProvidesReqdCols // // @doc: // Check if required columns are included in output columns // //--------------------------------------------------------------------------- BOOL CPhysicalAgg::FProvidesReqdCols ( CExpressionHandle &exprhdl, CColRefSet *pcrsRequired, ULONG // ulOptReq ) const { GPOS_ASSERT(NULL != pcrsRequired); GPOS_ASSERT(2 == exprhdl.UlArity()); CColRefSet *pcrs = GPOS_NEW(m_pmp) CColRefSet(m_pmp); // include grouping columns pcrs->Include(PdrgpcrGroupingCols()); // include defined columns by scalar child pcrs->Union(exprhdl.Pdpscalar(1 /*ulChildIndex*/)->PcrsDefined()); BOOL fProvidesCols = pcrs->FSubset(pcrsRequired); pcrs->Release(); return fProvidesCols; }
//--------------------------------------------------------------------------- // @function: // CDrvdPropScalar::Derive // // @doc: // Derive scalar props // //--------------------------------------------------------------------------- void CDrvdPropScalar::Derive ( IMemoryPool *pmp, CExpressionHandle &exprhdl, CDrvdPropCtxt * // pdpctxt ) { CScalar *popScalar = CScalar::PopConvert(exprhdl.Pop()); // call derivation functions on the operator GPOS_ASSERT(NULL == m_pcrsDefined); m_pcrsDefined = popScalar->PcrsDefined(pmp, exprhdl); GPOS_ASSERT(NULL == m_pcrsSetReturningFunction); m_pcrsSetReturningFunction = popScalar->PcrsSetReturningFunction(pmp, exprhdl); GPOS_ASSERT(NULL == m_pcrsUsed); m_pcrsUsed = popScalar->PcrsUsed(pmp, exprhdl); // derive function properties m_pfp = popScalar->PfpDerive(pmp, exprhdl); // add defined and used columns of children const ULONG ulArity = exprhdl.UlArity(); for (ULONG i = 0; i < ulArity; i++) { // only propagate properties from scalar children if (exprhdl.FScalarChild(i)) { m_pcrsDefined->Union(exprhdl.Pdpscalar(i)->PcrsDefined()); m_pcrsUsed->Union(exprhdl.Pdpscalar(i)->PcrsUsed()); m_pcrsSetReturningFunction->Union(exprhdl.Pdpscalar(i)->PcrsSetReturningFunction()); } else { GPOS_ASSERT(CUtils::FSubquery(popScalar)); // parent operator is a subquery, add outer references // from its relational child as used columns m_pcrsUsed->Union(exprhdl.Pdprel(0)->PcrsOuter()); } } // derive existence of subqueries GPOS_ASSERT(!m_fHasSubquery); m_fHasSubquery = popScalar->FHasSubquery(exprhdl); if (m_fHasSubquery) { m_ppartinfo = popScalar->PpartinfoDerive(pmp, exprhdl); } else { m_ppartinfo = GPOS_NEW(pmp) CPartInfo(pmp); } m_fHasNonScalarFunction = popScalar->FHasNonScalarFunction(exprhdl); if (COperator::EopScalarProjectList == exprhdl.Pop()->Eopid()) { m_ulDistinctAggs = CScalarProjectList::UlDistinctAggs(exprhdl); m_fHasMultipleDistinctAggs = CScalarProjectList::FHasMultipleDistinctAggs(exprhdl); } if (COperator::EopScalarProjectElement == exprhdl.Pop()->Eopid()) { if (m_fHasNonScalarFunction) { CScalarProjectElement *pspeProject = (CScalarProjectElement *)(exprhdl.Pop()); m_pcrsSetReturningFunction->Include(pspeProject->Pcr()); } } }