//--------------------------------------------------------------------------- // @function: // CPhysicalScan::ComputeTableStats // // @doc: // Compute stats of underlying table // //--------------------------------------------------------------------------- void CPhysicalScan::ComputeTableStats ( IMemoryPool *pmp ) { GPOS_ASSERT(NULL == m_pstatsBaseTable); CColRefSet *pcrsHist = GPOS_NEW(pmp) CColRefSet(pmp, m_pdrgpcrOutput); CColRefSet *pcrsWidth = GPOS_NEW(pmp) CColRefSet(pmp); CMDAccessor *pmda = COptCtxt::PoctxtFromTLS()->Pmda(); m_pstatsBaseTable = pmda->Pstats(pmp, m_ptabdesc->Pmdid(), pcrsHist, pcrsWidth); GPOS_ASSERT(NULL != m_pstatsBaseTable); pcrsHist->Release(); pcrsWidth->Release(); }
//--------------------------------------------------------------------------- // @function: // CLogical::PstatsBaseTable // // @doc: // Helper for deriving statistics on a base table // //--------------------------------------------------------------------------- IStatistics * CLogical::PstatsBaseTable ( IMemoryPool *pmp, CExpressionHandle &exprhdl, CTableDescriptor *ptabdesc, CColRefSet *pcrsHistExtra // additional columns required for stats, not required by parent ) { CReqdPropRelational *prprel = CReqdPropRelational::Prprel(exprhdl.Prp()); CColRefSet *pcrsHist = GPOS_NEW(pmp) CColRefSet(pmp); pcrsHist->Include(prprel->PcrsStat()); if (NULL != pcrsHistExtra) { pcrsHist->Include(pcrsHistExtra); } CDrvdPropRelational *pdprel = exprhdl.Pdprel(); CColRefSet *pcrsOutput = pdprel->PcrsOutput(); CColRefSet *pcrsWidth = GPOS_NEW(pmp) CColRefSet(pmp); pcrsWidth->Include(pcrsOutput); pcrsWidth->Exclude(pcrsHist); const COptCtxt *poctxt = COptCtxt::PoctxtFromTLS(); CMDAccessor *pmda = poctxt->Pmda(); CStatisticsConfig *pstatsconf = poctxt->Poconf()->Pstatsconf(); IStatistics *pstats = pmda->Pstats ( pmp, ptabdesc->Pmdid(), pcrsHist, pcrsWidth, pstatsconf ); // clean up pcrsWidth->Release(); pcrsHist->Release(); return pstats; }
//--------------------------------------------------------------------------- // @function: // CLogical::PstatsBaseTable // // @doc: // Helper for deriving statistics on a base table // //--------------------------------------------------------------------------- IStatistics * CLogical::PstatsBaseTable ( IMemoryPool *pmp, CExpressionHandle &exprhdl, CTableDescriptor *ptabdesc, CColRefSet *pcrsStatExtra // additional columns required for stats, not required by parent ) { // extract colids and attribute for which detailed stats are necessary CReqdPropRelational *prprel = CReqdPropRelational::Prprel(exprhdl.Prp()); CColRefSet *pcrsStat = GPOS_NEW(pmp) CColRefSet(pmp); pcrsStat->Include(prprel->PcrsStat()); if (NULL != pcrsStatExtra) { pcrsStat->Include(pcrsStatExtra); } DrgPul *pdrgpulHistColIds = GPOS_NEW(pmp) DrgPul(pmp); DrgPul *pdrgpulHistPos = GPOS_NEW(pmp) DrgPul(pmp); CUtils::ExtractColIdsAttno(pmp, ptabdesc, pcrsStat, pdrgpulHistColIds, pdrgpulHistPos); // extract colids and attribute for which widths are necessary CDrvdPropRelational *pdprel = exprhdl.Pdprel(); CColRefSet *pcrsWidth = pdprel->PcrsOutput(); DrgPul *pdrgpulWidthColIds = GPOS_NEW(pmp) DrgPul(pmp); DrgPul *pdrgpulWidthPos = GPOS_NEW(pmp) DrgPul(pmp); CUtils::ExtractColIdsAttno(pmp, ptabdesc, pcrsWidth, pdrgpulWidthColIds, pdrgpulWidthPos); CMDAccessor *pmda = COptCtxt::PoctxtFromTLS()->Pmda(); IStatistics *pstats = pmda->Pstats(pmp, ptabdesc->Pmdid(), pdrgpulHistPos, pdrgpulHistColIds, pdrgpulWidthPos, pdrgpulWidthColIds); if (!GPOS_FTRACE(EopttraceDonotCollectMissingStatsCols) && !pstats->FEmpty()) { CStatisticsUtils::RecordMissingStatisticsColumns(pmp, ptabdesc, pcrsStat, pstats); } pcrsStat->Release(); return pstats; }