//---------------------------------------------------------------------------
//	@function:
//		CLogicalConstTableGet::PstatsDerive
//
//	@doc:
//		Derive statistics
//
//---------------------------------------------------------------------------
IStatistics *
CLogicalConstTableGet::PstatsDerive
	(
	IMemoryPool *pmp,
	CExpressionHandle &exprhdl,
	DrgPstat * // not used
	)
	const
{
	GPOS_ASSERT(Esp(exprhdl) > EspNone);
	CReqdPropRelational *prprel = CReqdPropRelational::Prprel(exprhdl.Prp());
	CColRefSet *pcrs = prprel->PcrsStat();
	DrgPul *pdrgpulColIds = GPOS_NEW(pmp) DrgPul(pmp);
	pcrs->ExtractColIds(pmp, pdrgpulColIds);
	DrgPul *pdrgpulColWidth = CUtils::Pdrgpul(pmp, m_pdrgpcrOutput);

	IStatistics *pstats = CStatistics::PstatsDummy
										(
										pmp,
										pdrgpulColIds,
										pdrgpulColWidth,
										m_pdrgpdrgpdatum->UlLength()
										);

	// clean up
	pdrgpulColIds->Release();
	pdrgpulColWidth->Release();

	return pstats;
}
Exemple #2
0
//---------------------------------------------------------------------------
//	@function:
//		CLogical::PstatsDeriveDummy
//
//	@doc:
//		Derive dummy statistics
//
//---------------------------------------------------------------------------
IStatistics *
CLogical::PstatsDeriveDummy
	(
	IMemoryPool *pmp,
	CExpressionHandle &exprhdl,
	CDouble dRows
	)
	const
{
	GPOS_CHECK_ABORT;

	// return a dummy stats object that has a histogram for every
	// required-stats column
	GPOS_ASSERT(Esp(exprhdl) > EspNone);
	CReqdPropRelational *prprel = CReqdPropRelational::Prprel(exprhdl.Prp());
	CColRefSet *pcrs = prprel->PcrsStat();
	DrgPul *pdrgpulColIds = GPOS_NEW(pmp) DrgPul(pmp);
	pcrs->ExtractColIds(pmp, pdrgpulColIds);

	IStatistics *pstats = CStatistics::PstatsDummy(pmp, pdrgpulColIds, dRows);

	// clean up
	pdrgpulColIds->Release();

	return pstats;
}
Exemple #3
0
//---------------------------------------------------------------------------
//	@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;
}
Exemple #4
0
//---------------------------------------------------------------------------
//	@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;
}