//--------------------------------------------------------------------------- // @function: // CXformTest::ApplyExprXforms // // @doc: // Apply different xforms for the given expression // //--------------------------------------------------------------------------- void CXformTest::ApplyExprXforms ( IMemoryPool *pmp, IOstream &os, CExpression *pexpr ) { os << std::endl << "EXPR:" << std::endl; (void) pexpr->OsPrint(os); for (ULONG ulXformId = 0; ulXformId < CXform::ExfSentinel; ulXformId++) { CXform *pxform = CXformFactory::Pxff()->Pxf((CXform::EXformId) ulXformId); os << std::endl <<"XFORM " << pxform->SzId() << ":" << std::endl; CXformContext *pxfctxt = GPOS_NEW(pmp) CXformContext(pmp); CXformResult *pxfres = GPOS_NEW(pmp) CXformResult(pmp); #ifdef GPOS_DEBUG if (pxform->FCheckPattern(pexpr) && CXform::FPromising(pmp, pxform, pexpr)) { if (CXform::ExfExpandNAryJoinMinCard == pxform->Exfid()) { GPOS_ASSERT(COperator::EopLogicalNAryJoin == pexpr->Pop()->Eopid()); // derive stats on NAry join expression CExpressionHandle exprhdl(pmp); exprhdl.Attach(pexpr); exprhdl.DeriveStats(pmp, pmp, NULL /*prprel*/, NULL /*pdrgpstatCtxt*/); } pxform->Transform(pxfctxt, pxfres, pexpr); CExpression *pexprResult = pxfres->PexprNext(); while (NULL != pexprResult) { GPOS_ASSERT(pexprResult->FMatchDebug(pexprResult)); pexprResult = pxfres->PexprNext(); } (void) pxfres->OsPrint(os); } #endif // GPOS_DEBUG pxfres->Release(); pxfctxt->Release(); } }
//--------------------------------------------------------------------------- // @function: // CXformFactoryTest::EresUnittest_Basic // // @doc: // create factory and instantiate // //--------------------------------------------------------------------------- GPOS_RESULT CXformFactoryTest::EresUnittest_Basic() { #ifdef GPOS_DEBUG CXform *pxf = CXformFactory::Pxff()->Pxf(CXform::ExfGet2TableScan); GPOS_ASSERT(CXform::ExfGet2TableScan == pxf->Exfid()); pxf = CXformFactory::Pxff()->Pxf(CXform::ExfInnerJoin2NLJoin); GPOS_ASSERT(CXform::ExfInnerJoin2NLJoin == pxf->Exfid()); pxf = CXformFactory::Pxff()->Pxf(CXform::ExfGbAgg2HashAgg); GPOS_ASSERT(CXform::ExfGbAgg2HashAgg == pxf->Exfid()); pxf = CXformFactory::Pxff()->Pxf(CXform::ExfJoinCommutativity); GPOS_ASSERT(CXform::ExfJoinCommutativity == pxf->Exfid()); pxf = CXformFactory::Pxff()->Pxf(CXform::ExfJoinAssociativity); GPOS_ASSERT(CXform::ExfJoinAssociativity == pxf->Exfid()); #endif // GPOS_DEBUG return GPOS_OK; }
//--------------------------------------------------------------------------- // @function: // COptTasks::SetXform // // @doc: // Enable/Disable a given xform // //--------------------------------------------------------------------------- bool COptTasks::SetXform ( char *xform_str, bool should_disable ) { CXform *xform = CXformFactory::Pxff()->Pxf(xform_str); if (NULL != xform) { optimizer_xforms[xform->Exfid()] = should_disable; return true; } return false; }
//--------------------------------------------------------------------------- // @function: // CJobTransformation::EevtTransform // // @doc: // Apply transformation action // //--------------------------------------------------------------------------- CJobTransformation::EEvent CJobTransformation::EevtTransform ( CSchedulerContext *psc, CJob *pjOwner ) { // get a job pointer CJobTransformation *pjt = PjConvert(pjOwner); IMemoryPool *pmpGlobal = psc->PmpGlobal(); IMemoryPool *pmpLocal = psc->PmpLocal(); CGroupExpression *pgexpr = pjt->m_pgexpr; CXform *pxform = pjt->m_pxform; // insert transformation results to memo CXformResult *pxfres = GPOS_NEW(pmpGlobal) CXformResult(pmpGlobal); ULONG ulElapsedTime = 0; pgexpr->Transform(pmpGlobal, pmpLocal, pxform, pxfres, &ulElapsedTime); psc->Peng()->InsertXformResult(pgexpr->Pgroup(), pxfres, pxform->Exfid(), pgexpr, ulElapsedTime); pxfres->Release(); return eevCompleted; }