//--------------------------------------------------------------------------- // @function: // CLogicalUnion::PstatsDerive // // @doc: // Derive statistics // //--------------------------------------------------------------------------- IStatistics * CLogicalUnion::PstatsDerive ( IMemoryPool *pmp, CExpressionHandle &exprhdl, DrgPstat * // not used ) const { GPOS_ASSERT(Esp(exprhdl) > EspNone); // union is transformed into a group by over an union all // we follow the same route to compute statistics IStatistics *pstatsUnionAll = CLogicalUnionAll::PstatsDeriveUnionAll(pmp, exprhdl); // computed columns DrgPul *pdrgpulComputedCols = GPOS_NEW(pmp) DrgPul(pmp); IStatistics *pstats = CLogicalGbAgg::PstatsDerive ( pmp, pstatsUnionAll, m_pdrgpcrOutput, // we group by the output columns pdrgpulComputedCols, // no computed columns for set ops NULL // no keys, use all grouping cols ); // clean up pdrgpulComputedCols->Release(); pstatsUnionAll->Release(); return pstats; }
//--------------------------------------------------------------------------- // @function: // CLogicalDifference::PstatsDerive // // @doc: // Derive statistics // //--------------------------------------------------------------------------- IStatistics * CLogicalDifference::PstatsDerive ( IMemoryPool *pmp, CExpressionHandle &exprhdl, DrgPstat * // not used ) const { GPOS_ASSERT(Esp(exprhdl) > EspNone); // difference is transformed into an aggregate over a LASJ, // we follow the same route to compute statistics DrgPcrs *pdrgpcrsOutput = GPOS_NEW(pmp) DrgPcrs(pmp); const ULONG ulSize = m_pdrgpdrgpcrInput->UlLength(); for (ULONG ul = 0; ul < ulSize; ul++) { CColRefSet *pcrs = GPOS_NEW(pmp) CColRefSet(pmp, (*m_pdrgpdrgpcrInput)[ul]); pdrgpcrsOutput->Append(pcrs); } IStatistics *pstatsOuter = exprhdl.Pstats(0); IStatistics *pstatsInner = exprhdl.Pstats(1); // construct the scalar condition for the LASJ CExpression *pexprScCond = CUtils::PexprConjINDFCond(pmp, m_pdrgpdrgpcrInput); // compute the statistics for LASJ CColRefSet *pcrsOuterRefs = exprhdl.Pdprel()->PcrsOuter(); DrgPstatsjoin *pdrgpstatsjoin = CStatsPredUtils::Pdrgpstatsjoin ( pmp, exprhdl, pexprScCond, pdrgpcrsOutput, pcrsOuterRefs ); IStatistics *pstatsLASJ = pstatsOuter->PstatsLASJoin ( pmp, pstatsInner, pdrgpstatsjoin, true /* fIgnoreLasjHistComputation */ ); // clean up pexprScCond->Release(); pdrgpstatsjoin->Release(); // computed columns DrgPul *pdrgpulComputedCols = GPOS_NEW(pmp) DrgPul(pmp); IStatistics *pstats = CLogicalGbAgg::PstatsDerive ( pmp, pstatsLASJ, (*m_pdrgpdrgpcrInput)[0], // we group by the columns of the first child pdrgpulComputedCols, // no computed columns for set ops NULL // no keys, use all grouping cols ); // clean up pdrgpulComputedCols->Release(); pstatsLASJ->Release(); pdrgpcrsOutput->Release(); return pstats; }
//--------------------------------------------------------------------------- // @function: // CLogicalDynamicGetBase::PstatsDeriveFilter // // @doc: // Derive stats from base table using filters on partition and/or index columns // //--------------------------------------------------------------------------- IStatistics * CLogicalDynamicGetBase::PstatsDeriveFilter ( IMemoryPool *pmp, CExpressionHandle &exprhdl, CExpression *pexprFilter ) const { CExpression *pexprFilterNew = NULL; CConstraint *pcnstr = m_ppartcnstr->PcnstrCombined(); if (m_fPartial && NULL != pcnstr && !pcnstr->FUnbounded()) { if (NULL == pexprFilter) { pexprFilterNew = pcnstr->PexprScalar(pmp); pexprFilterNew->AddRef(); } else { pexprFilterNew = CPredicateUtils::PexprConjunction(pmp, pexprFilter, pcnstr->PexprScalar(pmp)); } } else if (NULL != pexprFilter) { pexprFilterNew = pexprFilter; pexprFilterNew->AddRef(); } CColRefSet *pcrsStat = GPOS_NEW(pmp) CColRefSet(pmp); CDrvdPropScalar *pdpscalar = NULL; if (NULL != pexprFilterNew) { pdpscalar = CDrvdPropScalar::Pdpscalar(pexprFilterNew->PdpDerive()); pcrsStat->Include(pdpscalar->PcrsUsed()); } // requesting statistics on distribution columns to estimate data skew if (NULL != m_pcrsDist) { pcrsStat->Include(m_pcrsDist); } IStatistics *pstatsFullTable = PstatsBaseTable(pmp, exprhdl, m_ptabdesc, pcrsStat); pcrsStat->Release(); if (NULL == pexprFilterNew || pdpscalar->FHasSubquery()) { return pstatsFullTable; } CStatsPred *pstatspred = CStatsPredUtils::PstatspredExtract ( pmp, pexprFilterNew, NULL /*pcrsOuterRefs*/ ); pexprFilterNew->Release(); IStatistics *pstatsResult = pstatsFullTable->PstatsFilter ( pmp, pstatspred, true /* fCapNdvs */ ); pstatspred->Release(); pstatsFullTable->Release(); return pstatsResult; }