//--------------------------------------------------------------------------- // @function: // CParseHandlerSearchStrategy::EndElement // // @doc: // Invoked by Xerces to process a closing tag // //--------------------------------------------------------------------------- void CParseHandlerSearchStrategy::EndElement ( const XMLCh* const, // xmlstrUri, const XMLCh* const xmlstrLocalname, const XMLCh* const // xmlstrQname ) { if (0 != XMLString::compareString(CDXLTokens::XmlstrToken(EdxltokenSearchStrategy), xmlstrLocalname)) { CWStringDynamic *pstr = CDXLUtils::PstrFromXMLCh(m_pphm->Pmm(), xmlstrLocalname); GPOS_RAISE(gpdxl::ExmaDXL, gpdxl::ExmiDXLUnexpectedTag, pstr->Wsz()); } const ULONG ulSize = this->UlLength(); for (ULONG ul = 0; ul < ulSize; ul++) { CParseHandlerSearchStage *pphSearchStage = dynamic_cast<CParseHandlerSearchStage*>((*this)[ul]); CXformSet *pxfs = pphSearchStage->Pxfs(); pxfs->AddRef(); CSearchStage *pss = GPOS_NEW(m_pmp) CSearchStage(pxfs, pphSearchStage->UlTimeThreshold(), pphSearchStage->CostThreshold()); m_pdrgpss->Append(pss); } // deactivate handler m_pphm->DeactivateHandler(); }
//--------------------------------------------------------------------------- // @function: // CLogicalConstTableGet::PxfsCandidates // // @doc: // Get candidate xforms // //--------------------------------------------------------------------------- CXformSet * CLogicalConstTableGet::PxfsCandidates ( IMemoryPool *pmp ) const { CXformSet *pxfs = GPOS_NEW(pmp) CXformSet(pmp); (void) pxfs->FExchangeSet(CXform::ExfImplementConstTableGet); return pxfs; }
//--------------------------------------------------------------------------- // @function: // CLogicalUnion::PxfsCandidates // // @doc: // Get candidate xforms // //--------------------------------------------------------------------------- CXformSet * CLogicalUnion::PxfsCandidates ( IMemoryPool *pmp ) const { CXformSet *pxfs = GPOS_NEW(pmp) CXformSet(pmp); (void) pxfs->FExchangeSet(CXform::ExfUnion2UnionAll); return pxfs; }
//--------------------------------------------------------------------------- // @function: // CLogicalDifferenceAll::PxfsCandidates // // @doc: // Get candidate xforms // //--------------------------------------------------------------------------- CXformSet * CLogicalDifferenceAll::PxfsCandidates ( IMemoryPool *pmp ) const { CXformSet *pxfs = GPOS_NEW(pmp) CXformSet(pmp); (void) pxfs->FExchangeSet(CXform::ExfDifferenceAll2LeftAntiSemiJoin); return pxfs; }
//--------------------------------------------------------------------------- // @function: // CLogicalFullOuterJoin::PxfsCandidates // // @doc: // Get candidate xforms // //--------------------------------------------------------------------------- CXformSet * CLogicalFullOuterJoin::PxfsCandidates ( IMemoryPool *pmp ) const { CXformSet *pxfs = GPOS_NEW(pmp) CXformSet(pmp); (void) pxfs->FExchangeSet(CXform::ExfExpandFullOuterJoin); return pxfs; }
//--------------------------------------------------------------------------- // @function: // CLogicalInnerCorrelatedApply::PxfsCandidates // // @doc: // Get candidate xforms // //--------------------------------------------------------------------------- CXformSet * CLogicalInnerCorrelatedApply::PxfsCandidates ( IMemoryPool *pmp ) const { CXformSet *pxfs = GPOS_NEW(pmp) CXformSet(pmp); (void) pxfs->FExchangeSet(CXform::ExfImplementInnerCorrelatedApply); return pxfs; }
//--------------------------------------------------------------------------- // @function: // CLogicalCTEAnchor::PxfsCandidates // // @doc: // Get candidate xforms // //--------------------------------------------------------------------------- CXformSet * CLogicalCTEAnchor::PxfsCandidates ( IMemoryPool *pmp ) const { CXformSet *pxfs = GPOS_NEW(pmp) CXformSet(pmp); (void) pxfs->FExchangeSet(CXform::ExfCTEAnchor2Sequence); (void) pxfs->FExchangeSet(CXform::ExfCTEAnchor2TrivialSelect); return pxfs; }
//--------------------------------------------------------------------------- // @function: // CLogicalGet::PxfsCandidates // // @doc: // Get candidate xforms // //--------------------------------------------------------------------------- CXformSet * CLogicalGet::PxfsCandidates ( IMemoryPool *pmp ) const { CXformSet *pxfs = GPOS_NEW(pmp) CXformSet(pmp); (void) pxfs->FExchangeSet(CXform::ExfGet2TableScan); return pxfs; }
//--------------------------------------------------------------------------- // @function: // CLogicalTVF::PxfsCandidates // // @doc: // Get candidate xforms // //--------------------------------------------------------------------------- CXformSet * CLogicalTVF::PxfsCandidates ( IMemoryPool *pmp ) const { CXformSet *pxfs = GPOS_NEW(pmp) CXformSet(pmp); (void) pxfs->FExchangeSet(CXform::ExfUnnestTVF); (void) pxfs->FExchangeSet(CXform::ExfImplementTVF); (void) pxfs->FExchangeSet(CXform::ExfImplementTVFNoArgs); return pxfs; }
//--------------------------------------------------------------------------- // @function: // CLogicalGbAggDeduplicate::PxfsCandidates // // @doc: // Get candidate xforms // //--------------------------------------------------------------------------- CXformSet * CLogicalGbAggDeduplicate::PxfsCandidates ( IMemoryPool *pmp ) const { CXformSet *pxfs = GPOS_NEW(pmp) CXformSet(pmp); (void) pxfs->FExchangeSet(CXform::ExfPushGbDedupBelowJoin); (void) pxfs->FExchangeSet(CXform::ExfSplitGbAggDedup); (void) pxfs->FExchangeSet(CXform::ExfGbAggDedup2HashAggDedup); (void) pxfs->FExchangeSet(CXform::ExfGbAggDedup2StreamAggDedup); return pxfs; }
//--------------------------------------------------------------------------- // @function: // CLogicalLeftSemiApply::PxfsCandidates // // @doc: // Get candidate xforms // //--------------------------------------------------------------------------- CXformSet * CLogicalLeftSemiApply::PxfsCandidates ( IMemoryPool *pmp ) const { CXformSet *pxfs = GPOS_NEW(pmp) CXformSet(pmp); (void) pxfs->FExchangeSet(CXform::ExfLeftSemiApply2LeftSemiJoin); (void) pxfs->FExchangeSet(CXform::ExfLeftSemiApplyWithExternalCorrs2InnerJoin); (void) pxfs->FExchangeSet(CXform::ExfLeftSemiApply2LeftSemiJoinNoCorrelations); return pxfs; }
//--------------------------------------------------------------------------- // @function: // CLogicalInnerApply::PxfsCandidates // // @doc: // Get candidate xforms // //--------------------------------------------------------------------------- CXformSet * CLogicalInnerApply::PxfsCandidates ( IMemoryPool *pmp ) const { CXformSet *pxfs = GPOS_NEW(pmp) CXformSet(pmp); (void) pxfs->FExchangeSet(CXform::ExfInnerApply2InnerJoin); (void) pxfs->FExchangeSet(CXform::ExfInnerApply2InnerJoinNoCorrelations); (void) pxfs->FExchangeSet(CXform::ExfInnerApplyWithOuterKey2InnerJoin); return pxfs; }
//--------------------------------------------------------------------------- // @function: // CJobGroupExpressionImplementation::ScheduleApplicableTransformations // // @doc: // Schedule transformation jobs for all applicable xforms // //--------------------------------------------------------------------------- void CJobGroupExpressionImplementation::ScheduleApplicableTransformations ( CSchedulerContext *psc ) { GPOS_ASSERT(!FXformsScheduled()); // get all applicable xforms COperator *pop = m_pgexpr->Pop(); CXformSet *pxfs = CLogical::PopConvert(pop)->PxfsCandidates(psc->PmpGlobal()); // intersect them with required xforms and schedule jobs pxfs->Intersection(CXformFactory::Pxff()->PxfsImplementation()); pxfs->Intersection(psc->Peng()->PxfsCurrentStage()); ScheduleTransformations(psc, pxfs); pxfs->Release(); SetXformsScheduled(); }
//--------------------------------------------------------------------------- // @function: // CLogicalLeftSemiJoin::PxfsCandidates // // @doc: // Get candidate xforms // //--------------------------------------------------------------------------- CXformSet * CLogicalLeftSemiJoin::PxfsCandidates ( IMemoryPool *pmp ) const { CXformSet *pxfs = GPOS_NEW(pmp) CXformSet(pmp); (void) pxfs->FExchangeSet(CXform::ExfSemiJoinSemiJoinSwap); (void) pxfs->FExchangeSet(CXform::ExfSemiJoinAntiSemiJoinSwap); (void) pxfs->FExchangeSet(CXform::ExfSemiJoinAntiSemiJoinNotInSwap); (void) pxfs->FExchangeSet(CXform::ExfSemiJoinInnerJoinSwap); (void) pxfs->FExchangeSet(CXform::ExfLeftSemiJoin2InnerJoin); (void) pxfs->FExchangeSet(CXform::ExfLeftSemiJoin2InnerJoinUnderGb); (void) pxfs->FExchangeSet(CXform::ExfLeftSemiJoin2CrossProduct); (void) pxfs->FExchangeSet(CXform::ExfLeftSemiJoin2NLJoin); (void) pxfs->FExchangeSet(CXform::ExfLeftSemiJoin2HashJoin); return pxfs; }
//--------------------------------------------------------------------------- // @function: // CLogicalSelect::PxfsCandidates // // @doc: // Get candidate xforms // //--------------------------------------------------------------------------- CXformSet * CLogicalSelect::PxfsCandidates ( IMemoryPool *pmp ) const { CXformSet *pxfs = GPOS_NEW(pmp) CXformSet(pmp); (void) pxfs->FExchangeSet(CXform::ExfSelect2Apply); (void) pxfs->FExchangeSet(CXform::ExfInlineCTEConsumerUnderSelect); (void) pxfs->FExchangeSet(CXform::ExfPushGbWithHavingBelowJoin); (void) pxfs->FExchangeSet(CXform::ExfSelect2IndexGet); (void) pxfs->FExchangeSet(CXform::ExfSelect2DynamicIndexGet); (void) pxfs->FExchangeSet(CXform::ExfSelect2PartialDynamicIndexGet); (void) pxfs->FExchangeSet(CXform::ExfSelect2BitmapBoolOp); (void) pxfs->FExchangeSet(CXform::ExfSelect2DynamicBitmapBoolOp); (void) pxfs->FExchangeSet(CXform::ExfSimplifySelectWithSubquery); (void) pxfs->FExchangeSet(CXform::ExfSelect2Filter); return pxfs; }
//--------------------------------------------------------------------------- // @function: // CLogicalInnerJoin::PxfsCandidates // // @doc: // Get candidate xforms // //--------------------------------------------------------------------------- CXformSet * CLogicalInnerJoin::PxfsCandidates ( IMemoryPool *pmp ) const { CXformSet *pxfs = GPOS_NEW(pmp) CXformSet(pmp); (void) pxfs->FExchangeSet(CXform::ExfInnerJoin2NLJoin); (void) pxfs->FExchangeSet(CXform::ExfInnerJoin2HashJoin); (void) pxfs->FExchangeSet(CXform::ExfSubqJoin2Apply); (void) pxfs->FExchangeSet(CXform::ExfInnerJoin2IndexGetApply); (void) pxfs->FExchangeSet(CXform::ExfInnerJoin2DynamicIndexGetApply); (void) pxfs->FExchangeSet(CXform::ExfInnerJoin2PartialDynamicIndexGetApply); (void) pxfs->FExchangeSet(CXform::ExfInnerJoin2BitmapIndexGetApply); (void) pxfs->FExchangeSet(CXform::ExfInnerJoinWithInnerSelect2IndexGetApply); (void) pxfs->FExchangeSet(CXform::ExfInnerJoinWithInnerSelect2DynamicIndexGetApply); (void) pxfs->FExchangeSet(CXform::ExfInnerJoinWithInnerSelect2PartialDynamicIndexGetApply); (void) pxfs->FExchangeSet(CXform::ExfInnerJoin2DynamicBitmapIndexGetApply); (void) pxfs->FExchangeSet(CXform::ExfInnerJoinWithInnerSelect2BitmapIndexGetApply); (void) pxfs->FExchangeSet(CXform::ExfInnerJoinWithInnerSelect2DynamicBitmapIndexGetApply); (void) pxfs->FExchangeSet(CXform::ExfJoinCommutativity); (void) pxfs->FExchangeSet(CXform::ExfJoinAssociativity); (void) pxfs->FExchangeSet(CXform::ExfInnerJoinSemiJoinSwap); (void) pxfs->FExchangeSet(CXform::ExfInnerJoinAntiSemiJoinSwap); (void) pxfs->FExchangeSet(CXform::ExfInnerJoinAntiSemiJoinNotInSwap); return pxfs; }
//--------------------------------------------------------------------------- // @function: // CSubqueryHandlerTest::EresUnittest_Subquery2Apply // // @doc: // Test of subquery handler // //--------------------------------------------------------------------------- GPOS_RESULT CSubqueryHandlerTest::EresUnittest_Subquery2Apply() { CAutoMemoryPool amp; IMemoryPool *mp = amp.Pmp(); // setup a file-based provider CMDProviderMemory *pmdp = CTestUtils::m_pmdpf; pmdp->AddRef(); CMDAccessor mda(mp, CMDCache::Pcache(), CTestUtils::m_sysidDefault, pmdp); typedef CExpression *(*Pfpexpr)(IMemoryPool*, BOOL); Pfpexpr rgpf[] = { CSubqueryTestUtils::PexprSelectWithAggSubquery, CSubqueryTestUtils::PexprSelectWithAggSubqueryConstComparison, CSubqueryTestUtils::PexprProjectWithAggSubquery, CSubqueryTestUtils::PexprSelectWithAnySubquery, CSubqueryTestUtils::PexprProjectWithAnySubquery, CSubqueryTestUtils::PexprSelectWithAllSubquery, CSubqueryTestUtils::PexprProjectWithAllSubquery, CSubqueryTestUtils::PexprSelectWithExistsSubquery, CSubqueryTestUtils::PexprProjectWithExistsSubquery, CSubqueryTestUtils::PexprSelectWithNotExistsSubquery, CSubqueryTestUtils::PexprProjectWithNotExistsSubquery, CSubqueryTestUtils::PexprSelectWithNestedCmpSubquery, CSubqueryTestUtils::PexprSelectWithCmpSubqueries, CSubqueryTestUtils::PexprSelectWithSubqueryConjuncts, CSubqueryTestUtils::PexprProjectWithSubqueries, CSubqueryTestUtils::PexprSelectWith2LevelsCorrSubquery, CSubqueryTestUtils::PexprJoinWithAggSubquery, CSubqueryTestUtils::PexprSelectWithAggSubqueryOverJoin, CSubqueryTestUtils::PexprSelectWithNestedSubquery, CSubqueryTestUtils::PexprSubqueriesInNullTestContext, CSubqueryTestUtils::PexprSubqueriesInDifferentContexts, CSubqueryTestUtils::PexprSelectWithSubqueryDisjuncts, CSubqueryTestUtils::PexprSelectWithNestedAnySubqueries, CSubqueryTestUtils::PexprSelectWithNestedAllSubqueries, CSubqueryTestUtils::PexprUndecorrelatableAnySubquery, CSubqueryTestUtils::PexprUndecorrelatableAllSubquery, CSubqueryTestUtils::PexprUndecorrelatableExistsSubquery, CSubqueryTestUtils::PexprUndecorrelatableNotExistsSubquery, CSubqueryTestUtils::PexprUndecorrelatableScalarSubquery, }; // xforms to test CXformSet *xform_set = GPOS_NEW(mp) CXformSet(mp); (void) xform_set->ExchangeSet(CXform::ExfSubqJoin2Apply); (void) xform_set->ExchangeSet(CXform::ExfSelect2Apply); (void) xform_set->ExchangeSet(CXform::ExfProject2Apply); BOOL fCorrelated = true; // we generate two expressions using each generator const ULONG size = 2 * GPOS_ARRAY_SIZE(rgpf); for (ULONG ul = 0; ul < size; ul++) { ULONG ulIndex = ul / 2; // install opt context in TLS CAutoOptCtxt aoc ( mp, &mda, NULL, /* pceeval */ CTestUtils::GetCostModel(mp) ); // generate expression CExpression *pexpr = rgpf[ulIndex](mp, fCorrelated); // check for subq xforms CXformSet *pxfsCand = CLogical::PopConvert(pexpr->Pop())->PxfsCandidates(mp); pxfsCand->Intersection(xform_set); CXformSetIter xsi(*pxfsCand); while (xsi.Advance()) { CXform *pxform = CXformFactory::Pxff()->Pxf(xsi.TBit()); GPOS_ASSERT(NULL != pxform); CWStringDynamic str(mp); COstreamString oss(&str); oss << std::endl << "INPUT:" << std::endl << *pexpr << std::endl; CXformContext *pxfctxt = GPOS_NEW(mp) CXformContext(mp); CXformResult *pxfres = GPOS_NEW(mp) CXformResult(mp); // calling the xform to perform subquery to Apply transformation pxform->Transform(pxfctxt, pxfres, pexpr); CExpression *pexprResult = pxfres->PexprNext(); oss << std::endl << "OUTPUT:" << std::endl; if (NULL != pexprResult) { oss << *pexprResult << std::endl; } else { oss << "\tNo subquery unnesting output" << std::endl; } GPOS_TRACE(str.GetBuffer()); str.Reset(); pxfres->Release(); pxfctxt->Release(); } pxfsCand->Release(); pexpr->Release(); fCorrelated = !fCorrelated; } xform_set->Release(); return GPOS_OK; }