本文整理汇总了C++中DrgPexpr::Release方法的典型用法代码示例。如果您正苦于以下问题:C++ DrgPexpr::Release方法的具体用法?C++ DrgPexpr::Release怎么用?C++ DrgPexpr::Release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DrgPexpr
的用法示例。
在下文中一共展示了DrgPexpr::Release方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
//---------------------------------------------------------------------------
// @function:
// CStatsPredUtils::PdrgpstatsjoinExtract
//
// @doc:
// Helper function to extract array of statistics join filter
// from an array of join predicates
//
//---------------------------------------------------------------------------
DrgPstatsjoin *
CStatsPredUtils::PdrgpstatsjoinExtract
(
IMemoryPool *pmp,
CExpression *pexprScalar,
DrgPcrs *pdrgpcrsOutput, // array of output columns of join's relational inputs
CColRefSet *pcrsOuterRefs,
CStatsPred **ppstatspredUnsupported
)
{
GPOS_ASSERT(NULL != pexprScalar);
GPOS_ASSERT(NULL != pdrgpcrsOutput);
DrgPstatsjoin *pdrgpstatsjoin = GPOS_NEW(pmp) DrgPstatsjoin(pmp);
DrgPexpr *pdrgpexprUnsupported = GPOS_NEW(pmp) DrgPexpr(pmp);
// extract all the conjuncts
DrgPexpr *pdrgpexprConjuncts = CPredicateUtils::PdrgpexprConjuncts(pmp, pexprScalar);
const ULONG ulSize = pdrgpexprConjuncts->UlLength();
for (ULONG ul = 0; ul < ulSize; ul++)
{
CExpression *pexprPred = (*pdrgpexprConjuncts) [ul];
CStatisticsJoin *pstatsjoin = PstatsjoinExtract
(
pmp,
pexprPred,
pdrgpcrsOutput,
pcrsOuterRefs,
pdrgpexprUnsupported
);
if (NULL != pstatsjoin)
{
pdrgpstatsjoin->Append(pstatsjoin);
}
}
const ULONG ulUnsupported = pdrgpexprUnsupported->UlLength();
if (1 == ulUnsupported)
{
*ppstatspredUnsupported = CStatsPredUtils::PstatspredExtract(pmp, (*pdrgpexprUnsupported)[0], pcrsOuterRefs);
}
else if (1 < ulUnsupported)
{
pdrgpexprUnsupported->AddRef();
CExpression *pexprConj = CPredicateUtils::PexprConjDisj(pmp, pdrgpexprUnsupported, true /* fConjunction */);
*ppstatspredUnsupported = CStatsPredUtils::PstatspredExtract(pmp, pexprConj, pcrsOuterRefs);
pexprConj->Release();
}
// clean up
pdrgpexprUnsupported->Release();
pdrgpexprConjuncts->Release();
return pdrgpstatsjoin;
}
示例2:
//---------------------------------------------------------------------------
// @function:
// CNormalizer::SplitConjunctForSeqPrj
//
// @doc:
// Split the given conjunct into pushable and unpushable predicates
// for a sequence project expression
//
//---------------------------------------------------------------------------
void
CNormalizer::SplitConjunctForSeqPrj
(
IMemoryPool *pmp,
CExpression *pexprSeqPrj,
CExpression *pexprConj,
DrgPexpr **ppdrgpexprPushable,
DrgPexpr **ppdrgpexprUnpushable
)
{
GPOS_ASSERT(NULL != pexprSeqPrj);
GPOS_ASSERT(NULL != pexprConj);
GPOS_ASSERT(NULL != ppdrgpexprPushable);
GPOS_ASSERT(NULL != ppdrgpexprUnpushable);
*ppdrgpexprPushable = GPOS_NEW(pmp) DrgPexpr(pmp);
*ppdrgpexprUnpushable = GPOS_NEW(pmp) DrgPexpr(pmp);
DrgPexpr *pdrgpexprPreds = CPredicateUtils::PdrgpexprConjuncts(pmp, pexprConj);
const ULONG ulPreds = pdrgpexprPreds->UlLength();
for (ULONG ul = 0; ul < ulPreds; ul++)
{
CExpression *pexprPred = (*pdrgpexprPreds)[ul];
pexprPred->AddRef();
if (FPushableThruSeqPrjChild(pexprSeqPrj, pexprPred))
{
(*ppdrgpexprPushable)->Append(pexprPred);
}
else
{
(*ppdrgpexprUnpushable)->Append(pexprPred);
}
}
pdrgpexprPreds->Release();
}
示例3: CExpression
//---------------------------------------------------------------------------
// @function:
// CNormalizer::PushThruUnaryWithScalarChild
//
// @doc:
// Push a conjunct through a unary operator with scalar child
//
//---------------------------------------------------------------------------
void
CNormalizer::PushThruUnaryWithScalarChild
(
IMemoryPool *pmp,
CExpression *pexprLogical,
CExpression *pexprConj,
CExpression **ppexprResult
)
{
GPOS_ASSERT(NULL != pexprLogical);
GPOS_ASSERT(2 == pexprLogical->UlArity());
GPOS_ASSERT(NULL != pexprConj);
GPOS_ASSERT(NULL != ppexprResult);
// get logical and scalar children
CExpression *pexprLogicalChild = (*pexprLogical)[0];
CExpression *pexprScalarChild = (*pexprLogical)[1];
// push conjuncts through the logical child
CExpression *pexprNewLogicalChild = NULL;
DrgPexpr *pdrgpexprUnpushable = NULL;
// break scalar expression to conjuncts
DrgPexpr *pdrgpexprConjuncts = CPredicateUtils::PdrgpexprConjuncts(pmp, pexprConj);
PushThru(pmp, pexprLogicalChild, pdrgpexprConjuncts, &pexprNewLogicalChild, &pdrgpexprUnpushable);
pdrgpexprConjuncts->Release();
// create a new logical expression based on recursion results
COperator *pop = pexprLogical->Pop();
pop->AddRef();
pexprScalarChild->AddRef();
CExpression *pexprNewLogical = GPOS_NEW(pmp) CExpression(pmp, pop, pexprNewLogicalChild, pexprScalarChild);
*ppexprResult = PexprSelect(pmp, pexprNewLogical, pdrgpexprUnpushable);
}
示例4: at
//---------------------------------------------------------------------------
// @function:
// COptimizer::PrintQuery
//
// @doc:
// Helper function to print query expression
//
//---------------------------------------------------------------------------
void
COptimizer::PrintQuery
(
IMemoryPool *pmp,
CExpression *pexprTranslated,
CQueryContext *pqc
)
{
CAutoTrace at(pmp);
at.Os() << std::endl << "Algebrized query: " << std::endl << *pexprTranslated;
DrgPexpr *pdrgpexpr = COptCtxt::PoctxtFromTLS()->Pcteinfo()->PdrgPexpr(pmp);
const ULONG ulCTEs = pdrgpexpr->UlLength();
if (0 < ulCTEs)
{
at.Os() << std::endl << "Common Table Expressions: ";
for (ULONG ul = 0; ul < ulCTEs; ul++)
{
at.Os() << std::endl << *(*pdrgpexpr)[ul];
}
}
pdrgpexpr->Release();
CExpression *pexprPreprocessed = pqc->Pexpr();
(void) pexprPreprocessed->PdpDerive();
at.Os() << std::endl << "Algebrized preprocessed query: " << std::endl << *pexprPreprocessed;
}
示例5: GPOS_NEW
//---------------------------------------------------------------------------
// @function:
// CPhysicalUnionAll::PdshashedPassThru
//
// @doc:
// Compute required hashed distribution of the n-th child
//
//---------------------------------------------------------------------------
CDistributionSpecHashed *
CPhysicalUnionAll::PdshashedPassThru
(
IMemoryPool *pmp,
CDistributionSpecHashed *pdshashedRequired,
ULONG ulChildIndex
)
const
{
DrgPexpr *pdrgpexprRequired = pdshashedRequired->Pdrgpexpr();
DrgPcr *pdrgpcrChild = (*m_pdrgpdrgpcrInput)[ulChildIndex];
const ULONG ulExprs = pdrgpexprRequired->UlLength();
const ULONG ulOutputCols = m_pdrgpcrOutput->UlLength();
DrgPexpr *pdrgpexprChildRequired = GPOS_NEW(pmp) DrgPexpr(pmp);
for (ULONG ulExpr = 0; ulExpr < ulExprs; ulExpr++)
{
CExpression *pexpr = (*pdrgpexprRequired)[ulExpr];
if (COperator::EopScalarIdent != pexpr->Pop()->Eopid())
{
// skip expressions that are not in form of scalar identifiers
continue;
}
const CColRef *pcrHashed = CScalarIdent::PopConvert(pexpr->Pop())->Pcr();
const IMDType *pmdtype = pcrHashed->Pmdtype();
if (!pmdtype->FHashable())
{
// skip non-hashable columns
continue;
}
for (ULONG ulCol = 0; ulCol < ulOutputCols; ulCol++)
{
const CColRef *pcrOutput = (*m_pdrgpcrOutput)[ulCol];
if (pcrOutput == pcrHashed)
{
const CColRef *pcrInput = (*pdrgpcrChild)[ulCol];
pdrgpexprChildRequired->Append(CUtils::PexprScalarIdent(pmp, pcrInput));
}
}
}
if (0 < pdrgpexprChildRequired->UlLength())
{
return GPOS_NEW(pmp) CDistributionSpecHashed(pdrgpexprChildRequired, true /* fNullsCollocated */);
}
// failed to create a matching hashed distribution
pdrgpexprChildRequired->Release();
if (NULL != pdshashedRequired->PdshashedEquiv())
{
// try again with equivalent distribution
return PdshashedPassThru(pmp, pdshashedRequired->PdshashedEquiv(), ulChildIndex);
}
// failed to create hashed distribution
return NULL;
}
示例6: GPOS_NEW
//---------------------------------------------------------------------------
// @function:
// CBinding::PexprExtract
//
// @doc:
// Extract a binding according to a given pattern;
// Keep root node fixed;
//
//---------------------------------------------------------------------------
CExpression *
CBinding::PexprExtract
(
IMemoryPool *pmp,
CGroupExpression *pgexpr,
CExpression *pexprPattern,
CExpression *pexprLast
)
{
GPOS_CHECK_ABORT;
if (!pexprPattern->FMatchPattern(pgexpr))
{
// shallow matching fails
return NULL;
}
// the previously extracted pattern must have the same root
GPOS_ASSERT_IMP(NULL != pexprLast, pexprLast->Pgexpr() == pgexpr);
COperator *popPattern = pexprPattern->Pop();
if (popPattern->FPattern() && CPattern::PopConvert(popPattern)->FLeaf())
{
// return immediately; no deep extraction for leaf patterns
pgexpr->Pop()->AddRef();
return GPOS_NEW(pmp) CExpression(pmp, pgexpr->Pop(), pgexpr);
}
DrgPexpr *pdrgpexpr = NULL;
ULONG ulArity = pgexpr->UlArity();
if (0 == ulArity && NULL != pexprLast)
{
// no more bindings
return NULL;
}
else
{
// attempt binding to children
pdrgpexpr = GPOS_NEW(pmp) DrgPexpr(pmp);
if (!FExtractChildren(pmp, pgexpr, pexprPattern, pexprLast, pdrgpexpr))
{
pdrgpexpr->Release();
return NULL;
}
}
CExpression *pexpr = PexprFinalize(pmp, pgexpr, pdrgpexpr);
GPOS_ASSERT(NULL != pexpr);
return pexpr;
}
示例7:
//---------------------------------------------------------------------------
// @function:
// CStatsPredUtils::FConjunction
//
// @doc:
// Is the condition a conjunctive predicate
//---------------------------------------------------------------------------
BOOL
CStatsPredUtils::FConjunction
(
IMemoryPool *pmp,
CExpression *pexprPred
)
{
GPOS_ASSERT(NULL != pexprPred);
DrgPexpr *pdrgpexprConjuncts = CPredicateUtils::PdrgpexprConjuncts(pmp, pexprPred);
const ULONG ulLen = pdrgpexprConjuncts->UlLength();
pdrgpexprConjuncts->Release();
return (1 < ulLen);
}
示例8:
//---------------------------------------------------------------------------
// @function:
// CLogicalInnerJoin::FFewerConj
//
// @doc:
// Compare two innerJoin group expressions, test whether the first one
// has less join predicates than the second one. This is used to
// prioritize innerJoin with less predicates for stats derivation
//
//---------------------------------------------------------------------------
BOOL
CLogicalInnerJoin::FFewerConj
(
IMemoryPool *pmp,
CGroupExpression *pgexprFst,
CGroupExpression *pgexprSnd
)
{
if (NULL == pgexprFst || NULL == pgexprSnd)
{
return false;
}
if (COperator::EopLogicalInnerJoin != pgexprFst->Pop()->Eopid() ||
COperator::EopLogicalInnerJoin != pgexprSnd->Pop()->Eopid())
{
return false;
}
// third child must be the group for join conditions
CGroup *pgroupScalarFst = (*pgexprFst)[2];
CGroup *pgroupScalarSnd = (*pgexprSnd)[2];
GPOS_ASSERT(pgroupScalarFst->FScalar());
GPOS_ASSERT(pgroupScalarSnd->FScalar());
DrgPexpr *pdrgpexprConjFst = CPredicateUtils::PdrgpexprConjuncts(pmp, pgroupScalarFst->PexprScalar());
DrgPexpr *pdrgpexprConjSnd = CPredicateUtils::PdrgpexprConjuncts(pmp, pgroupScalarSnd->PexprScalar());
ULONG ulConjFst = pdrgpexprConjFst->UlLength();
ULONG ulConjSnd = pdrgpexprConjSnd->UlLength();
pdrgpexprConjFst->Release();
pdrgpexprConjSnd->Release();
return ulConjFst < ulConjSnd;
}
示例9: GPOS_NEW
//---------------------------------------------------------------------------
// @function:
// CStatsPredUtils::PstatspredConj
//
// @doc:
// Create conjunctive statistics filter composed of the extracted
// components of the conjunction
//---------------------------------------------------------------------------
CStatsPred *
CStatsPredUtils::PstatspredConj
(
IMemoryPool *pmp,
CExpression *pexprScalar,
CColRefSet *pcrsOuterRefs
)
{
GPOS_ASSERT(NULL != pexprScalar);
DrgPexpr *pdrgpexprConjuncts = CPredicateUtils::PdrgpexprConjuncts(pmp, pexprScalar);
const ULONG ulLen = pdrgpexprConjuncts->UlLength();
DrgPstatspred *pdrgpstatspred = GPOS_NEW(pmp) DrgPstatspred(pmp);
for (ULONG ul = 0; ul < ulLen; ul++)
{
CExpression *pexprPred = (*pdrgpexprConjuncts)[ul];
CColRefSet *pcrsUsed = CDrvdPropScalar::Pdpscalar(pexprPred->PdpDerive())->PcrsUsed();
if (NULL != pcrsOuterRefs && pcrsOuterRefs->FSubset(pcrsUsed))
{
// skip predicate with outer references
continue;
}
if (CPredicateUtils::FOr(pexprPred))
{
CStatsPred *pstatspredDisj = PstatspredDisj(pmp, pexprPred, pcrsOuterRefs);
if (NULL != pstatspredDisj)
{
pdrgpstatspred->Append(pstatspredDisj);
}
}
else
{
AddSupportedStatsFilters(pmp, pdrgpstatspred, pexprPred, pcrsOuterRefs);
}
}
pdrgpexprConjuncts->Release();
if (0 < pdrgpstatspred->UlLength())
{
return GPOS_NEW(pmp) CStatsPredConj(pdrgpstatspred);
}
pdrgpstatspred->Release();
return NULL;
}
示例10: PexprNormalize
//---------------------------------------------------------------------------
// @function:
// CNormalizer::PushThruSeqPrj
//
// @doc:
// Push a conjunct through a sequence project expression
//
//---------------------------------------------------------------------------
void
CNormalizer::PushThruSeqPrj
(
IMemoryPool *pmp,
CExpression *pexprSeqPrj,
CExpression *pexprConj,
CExpression **ppexprResult
)
{
GPOS_ASSERT(NULL != pexprSeqPrj);
GPOS_ASSERT(CLogical::EopLogicalSequenceProject == pexprSeqPrj->Pop()->Eopid());
GPOS_ASSERT(NULL != pexprConj);
GPOS_ASSERT(NULL != ppexprResult);
// get logical and scalar children
CExpression *pexprLogicalChild = (*pexprSeqPrj)[0];
CExpression *pexprScalarChild = (*pexprSeqPrj)[1];
// break scalar expression to pushable and unpushable conjuncts
DrgPexpr *pdrgpexprPushable = NULL;
DrgPexpr *pdrgpexprUnpushable = NULL;
SplitConjunctForSeqPrj(pmp, pexprSeqPrj, pexprConj, &pdrgpexprPushable, &pdrgpexprUnpushable);
CExpression *pexprNewLogicalChild = NULL;
if (0 < pdrgpexprPushable->UlLength())
{
CExpression *pexprPushableConj = CPredicateUtils::PexprConjunction(pmp, pdrgpexprPushable);
PushThru(pmp, pexprLogicalChild, pexprPushableConj, &pexprNewLogicalChild);
pexprPushableConj->Release();
}
else
{
// no pushable predicates on top of sequence project,
// we still need to process child recursively to push-down child's own predicates
pdrgpexprPushable->Release();
pexprNewLogicalChild = PexprNormalize(pmp, pexprLogicalChild);
}
// create a new logical expression based on recursion results
COperator *pop = pexprSeqPrj->Pop();
pop->AddRef();
pexprScalarChild->AddRef();
CExpression *pexprNewLogical = GPOS_NEW(pmp) CExpression(pmp, pop, pexprNewLogicalChild, pexprScalarChild);
// create a select node for remaining predicates, if any
*ppexprResult = PexprSelect(pmp, pexprNewLogical, pdrgpexprUnpushable);
}
示例11: GPOS_NEW
//---------------------------------------------------------------------------
// @function:
// CDistributionSpecHashed::PdshashedExcludeColumns
//
// @doc:
// Return a copy of the distribution spec after excluding the given
// columns, return NULL if all distribution expressions are excluded
//
//---------------------------------------------------------------------------
CDistributionSpecHashed *
CDistributionSpecHashed::PdshashedExcludeColumns
(
IMemoryPool *pmp,
CColRefSet *pcrs
)
{
GPOS_ASSERT(NULL != pcrs);
DrgPexpr *pdrgpexprNew = GPOS_NEW(pmp) DrgPexpr(pmp);
const ULONG ulExprs = m_pdrgpexpr->UlLength();
for (ULONG ul = 0; ul < ulExprs; ul++)
{
CExpression *pexpr = (*m_pdrgpexpr)[ul];
COperator *pop = pexpr->Pop();
if (COperator::EopScalarIdent == pop->Eopid())
{
// we only care here about column identifiers,
// any more complicated expressions are copied to output
const CColRef *pcr = CScalarIdent::PopConvert(pop)->Pcr();
if (pcrs->FMember(pcr))
{
continue;
}
}
pexpr->AddRef();
pdrgpexprNew->Append(pexpr);
}
if (0 == pdrgpexprNew->UlLength())
{
pdrgpexprNew->Release();
return NULL;
}
return GPOS_NEW(pmp) CDistributionSpecHashed(pdrgpexprNew, m_fNullsColocated);
}
示例12: PexprConjunction
//---------------------------------------------------------------------------
// @function:
// CCNFConverter::PexprOr2CNF
//
// @doc:
// Convert an OR tree into CNF
//
//---------------------------------------------------------------------------
CExpression *
CCNFConverter::PexprOr2CNF
(
IMemoryPool *pmp,
CExpression *pexpr
)
{
GPOS_ASSERT(NULL != pmp);
GPOS_ASSERT(NULL != pexpr);
DrgPexpr *pdrgpexpr = PdrgpexprConvertChildren(pmp, pexpr);
// build array of arrays each representing terms in a disjunct
DrgPdrgPexpr *pdrgpdrgpexprDisjuncts = Pdrgpdrgpexpr(pmp, pdrgpexpr);
pdrgpexpr->Release();
// compute conjuncts by distributing AND over OR
DrgPexpr *pdrgpexprChildren = GPOS_NEW(pmp) DrgPexpr(pmp);
Expand(pmp, pdrgpdrgpexprDisjuncts, pdrgpexprChildren, GPOS_NEW(pmp) DrgPexpr(pmp), 0 /*ulCurrent*/);
pdrgpdrgpexprDisjuncts->Release();
return CPredicateUtils::PexprConjunction(pmp, pdrgpexprChildren);
}
示例13: mda
//---------------------------------------------------------------------------
// @function:
// CPredicateUtilsTest::EresUnittest_Conjunctions
//
// @doc:
// Test extraction and construction of conjuncts
//
//---------------------------------------------------------------------------
GPOS_RESULT
CPredicateUtilsTest::EresUnittest_Conjunctions()
{
CAutoMemoryPool amp;
IMemoryPool *pmp = amp.Pmp();
// setup a file-based provider
CMDProviderMemory *pmdp = CTestUtils::m_pmdpf;
pmdp->AddRef();
CMDAccessor mda(pmp, CMDCache::Pcache(), CTestUtils::m_sysidDefault, pmdp);
// install opt context in TLS
CAutoOptCtxt aoc
(
pmp,
&mda,
NULL, /* pceeval */
CTestUtils::Pcm(pmp)
);
// build conjunction
DrgPexpr *pdrgpexpr = GPOS_NEW(pmp) DrgPexpr(pmp);
const ULONG ulConjs = 3;
for (ULONG ul = 0; ul < ulConjs; ul++)
{
pdrgpexpr->Append(CUtils::PexprScalarConstBool(pmp, true /*fValue*/));
}
CExpression *pexprConjunction = CUtils::PexprScalarBoolOp(pmp, CScalarBoolOp::EboolopAnd, pdrgpexpr);
// break into conjuncts
DrgPexpr *pdrgpexprExtract = CPredicateUtils::PdrgpexprConjuncts(pmp, pexprConjunction);
GPOS_ASSERT(pdrgpexprExtract->UlLength() == ulConjs);
// collapse into single conjunct
CExpression *pexpr = CPredicateUtils::PexprConjunction(pmp, pdrgpexprExtract);
GPOS_ASSERT(NULL != pexpr);
GPOS_ASSERT(CUtils::FScalarConstTrue(pexpr));
pexpr->Release();
// collapse empty input array to conjunct
CExpression *pexprSingleton = CPredicateUtils::PexprConjunction(pmp, NULL /*pdrgpexpr*/);
GPOS_ASSERT(NULL != pexprSingleton);
pexprSingleton->Release();
pexprConjunction->Release();
// conjunction on scalar comparisons
CExpression *pexprGet = CTestUtils::PexprLogicalGet(pmp);
CColRefSet *pcrs = CDrvdPropRelational::Pdprel(pexprGet->PdpDerive())->PcrsOutput();
CColRef *pcr1 = pcrs->PcrAny();
CColRef *pcr2 = pcrs->PcrFirst();
CExpression *pexprCmp1 = CUtils::PexprScalarCmp(pmp, pcr1, pcr2, IMDType::EcmptEq);
CExpression *pexprCmp2 = CUtils::PexprScalarCmp(pmp, pcr1, CUtils::PexprScalarConstInt4(pmp, 1 /*iVal*/), IMDType::EcmptEq);
CExpression *pexprConj = CPredicateUtils::PexprConjunction(pmp, pexprCmp1, pexprCmp2);
pdrgpexprExtract = CPredicateUtils::PdrgpexprConjuncts(pmp, pexprConj);
GPOS_ASSERT(2 == pdrgpexprExtract->UlLength());
pdrgpexprExtract->Release();
pexprCmp1->Release();
pexprCmp2->Release();
pexprConj->Release();
pexprGet->Release();
return GPOS_OK;
}
示例14: DrgPexpr
void
CXformJoinAssociativity::Transform
(
CXformContext *pxfctxt,
CXformResult *pxfres,
CExpression *pexpr
)
const
{
GPOS_ASSERT(NULL != pxfctxt);
GPOS_ASSERT(FPromising(pxfctxt->Pmp(), this, pexpr));
GPOS_ASSERT(FCheckPattern(pexpr));
IMemoryPool *pmp = pxfctxt->Pmp();
// create new predicates
DrgPexpr *pdrgpexprLower = GPOS_NEW(pmp) DrgPexpr(pmp);
DrgPexpr *pdrgpexprUpper = GPOS_NEW(pmp) DrgPexpr(pmp);
CreatePredicates(pmp, pexpr, pdrgpexprLower, pdrgpexprUpper);
GPOS_ASSERT(pdrgpexprLower->UlLength() > 0);
// cross join contains CScalarConst(1) as the join condition. if the
// input expression is as below with cross join at top level between
// CLogicalInnerJoin and CLogicalGet "t3"
// +--CLogicalInnerJoin
// |--CLogicalInnerJoin
// | |--CLogicalGet "t1"
// | |--CLogicalGet "t2"
// | +--CScalarCmp (=)
// | |--CScalarIdent "a" (0)
// | +--CScalarIdent "b" (9)
// |--CLogicalGet "t3"
// +--CScalarConst (1)
// for the above expression (lower) predicate generated for the cross join
// between t1 and t3 will be: CScalarConst (1) In *only* such cases, donot
// generate such alternative with the lower join as cross join example:
// +--CLogicalInnerJoin
// |--CLogicalInnerJoin
// | |--CLogicalGet "t1"
// | |--CLogicalGet "t3"
// | +--CScalarConst (1)
// |--CLogicalGet "t2"
// +--CScalarCmp (=)
// |--CScalarIdent "a" (0)
// +--CScalarIdent "b" (9)
// NOTE that we want to be careful to check that input lower join wasn't a
// cross join to begin with, because we want to build a join in this case even
// though a new cross join will be created.
// check if the input lower join expression is a cross join
BOOL fInputLeftIsCrossJoin = CUtils::FCrossJoin((*pexpr)[0]);
// check if the output lower join would result in a cross join
BOOL fOutputLeftIsCrossJoin = (1 == pdrgpexprLower->UlLength() &&
CUtils::FScalarConstTrue((*pdrgpexprLower)[0]));
// build a join only if it does not result in a cross join
// unless the input itself was a cross join (see earlier comments)
if (!fOutputLeftIsCrossJoin || fInputLeftIsCrossJoin)
{
// bind operators
CExpression *pexprLeft = (*pexpr)[0];
CExpression *pexprLeftLeft = (*pexprLeft)[0];
CExpression *pexprLeftRight = (*pexprLeft)[1];
CExpression *pexprRight = (*pexpr)[1];
// add-ref all components for re-use
pexprLeftLeft->AddRef();
pexprRight->AddRef();
pexprLeftRight->AddRef();
// build new joins
CExpression *pexprBottomJoin = CUtils::PexprLogicalJoin<CLogicalInnerJoin>
(
pmp,
pexprLeftLeft,
pexprRight,
CPredicateUtils::PexprConjunction(pmp, pdrgpexprLower)
);
CExpression *pexprResult = CUtils::PexprLogicalJoin<CLogicalInnerJoin>
(
pmp,
pexprBottomJoin,
pexprLeftRight,
CPredicateUtils::PexprConjunction(pmp, pdrgpexprUpper)
);
// add alternative to transformation result
pxfres->Add(pexprResult);
}
else
{
pdrgpexprLower->Release();
pdrgpexprUpper->Release();
}
}
示例15: DrgPexpr
//---------------------------------------------------------------------------
// @function:
// CDecorrelator::FProcessJoin
//
// @doc:
// Decorrelate a join expression;
//
//---------------------------------------------------------------------------
BOOL
CDecorrelator::FProcessJoin
(
IMemoryPool *pmp,
CExpression *pexpr,
BOOL fEqualityOnly,
CExpression **ppexprDecorrelated,
DrgPexpr *pdrgpexprCorrelations
)
{
GPOS_ASSERT(CUtils::FLogicalJoin(pexpr->Pop()) || CUtils::FApply(pexpr->Pop()));
ULONG ulArity = pexpr->UlArity();
DrgPexpr *pdrgpexpr = GPOS_NEW(pmp) DrgPexpr(pmp, ulArity);
CColRefSet *pcrsOutput = GPOS_NEW(pmp) CColRefSet(pmp);
// decorrelate all relational children
for (ULONG ul = 0; ul < ulArity - 1; ul++)
{
CExpression *pexprInput = NULL;
if (FProcess(pmp, (*pexpr)[ul], fEqualityOnly, &pexprInput, pdrgpexprCorrelations))
{
pdrgpexpr->Append(pexprInput);
pcrsOutput->Union(CDrvdPropRelational::Pdprel(pexprInput->PdpDerive())->PcrsOutput());
}
else
{
pdrgpexpr->Release();
pcrsOutput->Release();
return false;
}
}
// check for valid semi join correlations
if (!FPullableCorrelations(pmp, pexpr, pdrgpexpr, pdrgpexprCorrelations))
{
pdrgpexpr->Release();
pcrsOutput->Release();
return false;
}
// decorrelate predicate and build new join operator
CExpression *pexprPredicate = NULL;
BOOL fSuccess = FProcessPredicate(pmp, pexpr, (*pexpr)[ulArity - 1], fEqualityOnly, pcrsOutput, &pexprPredicate, pdrgpexprCorrelations);
pcrsOutput->Release();
if (fSuccess)
{
// in case entire predicate is being deferred, plug in a 'true'
if (NULL == pexprPredicate)
{
pexprPredicate = CUtils::PexprScalarConstBool(pmp, true /*fVal*/);
}
pdrgpexpr->Append(pexprPredicate);
COperator *pop = pexpr->Pop();
pop->AddRef();
*ppexprDecorrelated = GPOS_NEW(pmp) CExpression(pmp, pop, pdrgpexpr);
}
else
{
pdrgpexpr->Release();
CRefCount::SafeRelease(pexprPredicate);
}
return fSuccess;
}