//--------------------------------------------------------------------------- // @function: // CConstraint::PcnstrFromScalarArrayCmp // // @doc: // Create constraint from scalar array comparison expression // //--------------------------------------------------------------------------- CConstraint * CConstraint::PcnstrFromScalarArrayCmp ( IMemoryPool *pmp, CExpression *pexpr, CColRef *pcr ) { GPOS_ASSERT(NULL != pexpr); GPOS_ASSERT(CUtils::FScalarArrayCmp(pexpr)); CScalarArrayCmp *popScArrayCmp = CScalarArrayCmp::PopConvert(pexpr->Pop()); CScalarArrayCmp::EArrCmpType earrccmpt = popScArrayCmp->Earrcmpt(); if ((CScalarArrayCmp::EarrcmpAny == earrccmpt || CScalarArrayCmp::EarrcmpAll == earrccmpt) && CPredicateUtils::FCompareIdentToConstArray(pexpr)) { // column #ifdef GPOS_DEBUG CScalarIdent *popScId = CScalarIdent::PopConvert((*pexpr)[0]->Pop()); GPOS_ASSERT (pcr == (CColRef *) popScId->Pcr()); #endif // GPOS_DEBUG // get comparison type IMDType::ECmpType ecmpt = CUtils::Ecmpt(popScArrayCmp->PmdidOp()); CExpression *pexprArray = (*pexpr)[1]; const ULONG ulArity = pexprArray->UlArity(); // When array size exceeds the threshold, don't expand it into a DNF COptimizerConfig *poconf = COptCtxt::PoctxtFromTLS()->Poconf(); ULONG ulArrayExpansionThreshold = poconf->Phint()->UlArrayExpansionThreshold(); if (ulArity > ulArrayExpansionThreshold) { return NULL; } DrgPcnstr *pdrgpcnstr = GPOS_NEW(pmp) DrgPcnstr(pmp); for (ULONG ul = 0; ul < ulArity; ul++) { GPOS_ASSERT(CUtils::FScalarConst((*pexprArray)[ul]) && "expecting a constant"); CScalarConst *popScConst = CScalarConst::PopConvert((*pexprArray)[ul]->Pop()); CConstraintInterval *pci = CConstraintInterval::PciIntervalFromColConstCmp(pmp, pcr, ecmpt, popScConst); pdrgpcnstr->Append(pci); } if (earrccmpt == CScalarArrayCmp::EarrcmpAny) { // predicate is of the form 'A IN (1,2,3)' // return a disjunction of ranges {[1,1], [2,2], [3,3]} return GPOS_NEW(pmp) CConstraintDisjunction(pmp, pdrgpcnstr); } // predicate is of the form 'A NOT IN (1,2,3)' // return a conjunctive negation on {[1,1], [2,2], [3,3]} return GPOS_NEW(pmp) CConstraintConjunction(pmp, pdrgpcnstr); } return NULL; }
//--------------------------------------------------------------------------- // @function: // CICGTest::EresUnittest_NegativeIndexApplyTests // // @doc: // Negative IndexApply tests; // optimizer should not be able to generate a plan // //--------------------------------------------------------------------------- GPOS_RESULT CICGTest::EresUnittest_NegativeIndexApplyTests() { // enable (Redistribute, Broadcast) hash join plans CAutoTraceFlag atf(EopttraceEnableRedistributeBroadcastHashJoin, true /*fVal*/); // disable physical scans and NLJ to force using index-apply CAutoTraceFlag atfDTS(EopttraceDisableXformBase + CXform::ExfDynamicGet2DynamicTableScan, true); CAutoTraceFlag atfTS(EopttraceDisableXformBase + CXform::ExfGet2TableScan, true); CAutoTraceFlag atfNLJ(EopttraceDisableXformBase + CXform::ExfInnerJoin2NLJoin, true); CAutoMemoryPool amp(CAutoMemoryPool::ElcNone); IMemoryPool *pmp = amp.Pmp(); GPOS_RESULT eres = GPOS_OK; const ULONG ulTests = GPOS_ARRAY_SIZE(rgszNegativeIndexApplyFileNames); for (ULONG ul = m_ulNegativeIndexApplyTestCounter; ul < ulTests; ul++) { GPOS_TRY { ICostModel *pcm = CTestUtils::Pcm(pmp); COptimizerConfig *poconf = GPOS_NEW(pmp) COptimizerConfig ( CEnumeratorConfig::Pec(pmp, 0 /*ullPlanId*/), CStatisticsConfig::PstatsconfDefault(pmp), CCTEConfig::PcteconfDefault(pmp), pcm, CHint::PhintDefault(pmp) ); CDXLNode *pdxlnPlan = CMinidumperUtils::PdxlnExecuteMinidump ( pmp, rgszNegativeIndexApplyFileNames[ul], GPOPT_TEST_SEGMENTS /*ulSegments*/, 1 /*ulSessionId*/, 1, /*ulCmdId*/ poconf, NULL /*pceeval*/ ); GPOS_CHECK_ABORT; poconf->Release(); pdxlnPlan->Release(); pcm->Release(); // test should have thrown eres = GPOS_FAILED; break; } GPOS_CATCH_EX(ex) { if (GPOS_MATCH_EX(ex, gpopt::ExmaGPOPT, gpopt::ExmiNoPlanFound)) { GPOS_RESET_EX; } else { GPOS_RETHROW(ex); } } GPOS_CATCH_END; m_ulNegativeIndexApplyTestCounter++; } if (GPOS_OK == eres) { m_ulNegativeIndexApplyTestCounter = 0; } return eres; }
//--------------------------------------------------------------------------- // @function: // CICGTest::EresUnittest_RunUnsupportedMinidumpTests // // @doc: // Run all unsupported Minidump-based tests // //--------------------------------------------------------------------------- GPOS_RESULT CICGTest::EresUnittest_RunUnsupportedMinidumpTests() { // enable (Redistribute, Broadcast) hash join plans CAutoTraceFlag atf1(EopttraceEnableRedistributeBroadcastHashJoin, true /*fVal*/); CAutoTraceFlag atf2(EopttraceDisableXformBase + CXform::ExfDynamicGet2DynamicTableScan, true); CAutoMemoryPool amp(CAutoMemoryPool::ElcNone); IMemoryPool *pmp = amp.Pmp(); GPOS_RESULT eres = GPOS_OK; const ULONG ulTests = GPOS_ARRAY_SIZE(unSupportedTestCases); for (ULONG ul = m_ulUnsupportedTestCounter; ul < ulTests; ul++) { const CHAR *szFilename = unSupportedTestCases[ul].szFilename; CDXLMinidump *pdxlmd = CMinidumperUtils::PdxlmdLoad(pmp, szFilename); bool unmatchedException = false; ULONG unmatchedExceptionMajor = 0; ULONG unmatchedExceptionMinor = 0; GPOS_TRY { ICostModel *pcm = CTestUtils::Pcm(pmp); COptimizerConfig *poconf = pdxlmd->Poconf(); CDXLNode *pdxlnPlan = CMinidumperUtils::PdxlnExecuteMinidump ( pmp, szFilename, poconf->Pcm()->UlHosts() /*ulSegments*/, 1 /*ulSessionId*/, 1, /*ulCmdId*/ poconf, NULL /*pceeval*/ ); GPOS_CHECK_ABORT; pdxlnPlan->Release(); pcm->Release(); // test should have thrown eres = GPOS_FAILED; break; } GPOS_CATCH_EX(ex) { unmatchedExceptionMajor = ex.UlMajor(); unmatchedExceptionMinor = ex.UlMinor(); // verify expected exception if (unSupportedTestCases[ul].ulMajor == unmatchedExceptionMajor && unSupportedTestCases[ul].ulMinor == unmatchedExceptionMinor) { eres = GPOS_OK; } else { unmatchedException = true; eres = GPOS_FAILED; } GPOS_RESET_EX; } GPOS_CATCH_END; GPOS_DELETE(pdxlmd); m_ulUnsupportedTestCounter++; if (GPOS_FAILED == eres && unmatchedException) { CAutoTrace at(pmp); at.Os() << "Test failed due to unmatched exceptions." << std::endl; at.Os() << " Expected result: " << unSupportedTestCases[ul].ulMajor << "." << unSupportedTestCases[ul].ulMinor << std::endl; at.Os() << " Actual result: " << unmatchedExceptionMajor << "." << unmatchedExceptionMinor << std::endl; } } if (GPOS_OK == eres) { m_ulUnsupportedTestCounter = 0; } return eres; }
//--------------------------------------------------------------------------- // @function: // PvExec // // @doc: // Function driving execution. // //--------------------------------------------------------------------------- static void * PvExec ( void *pv ) { CMainArgs *pma = (CMainArgs*) pv; CBitVector bv(ITask::PtskSelf()->Pmp(), CUnittest::UlTests()); CHAR ch = '\0'; CHAR *szFileName = NULL; BOOL fMinidump = false; BOOL fUnittest = false; while (pma->FGetopt(&ch)) { CHAR *szTestName = NULL; switch (ch) { case 'U': szTestName = optarg; // fallthru case 'u': CUnittest::FindTest(bv, CUnittest::EttStandard, szTestName); fUnittest = true; break; case 'x': CUnittest::FindTest(bv, CUnittest::EttExtended, NULL /*szTestName*/); fUnittest = true; break; case 'T': CUnittest::SetTraceFlag(optarg); break; case 'd': fMinidump = true; szFileName = optarg; break; default: // ignore other parameters break; } } if (fMinidump && fUnittest) { GPOS_TRACE(GPOS_WSZ_LIT("Cannot specify -d and -U/-u options at the same time")); return NULL; } if (fMinidump) { // initialize DXL support InitDXL(); CMDCache::Init(); CAutoMemoryPool amp; IMemoryPool *pmp = amp.Pmp(); COptimizerConfig* poconf = COptimizerConfig::PoconfDefault(pmp); CDXLNode *pdxlnPlan = CMinidumperUtils::PdxlnExecuteMinidump ( pmp, szFileName, GPOPT_TEST_SEGMENTS, 1 /*ulSessionId*/, 1 /*ulCmdId*/, poconf, NULL /*pceeval*/ ); poconf->Release(); pdxlnPlan->Release(); CMDCache::Shutdown(); } else { GPOS_ASSERT(fUnittest); tests_failed = CUnittest::Driver(&bv); } return NULL; }
//--------------------------------------------------------------------------- // @function: // CMissingStatsTest::EresUnittest_RunTests // // @doc: // Run all Minidump-based tests with plan matching // //--------------------------------------------------------------------------- GPOS_RESULT CMissingStatsTest::EresUnittest_RunTests() { SMissingStatsTestCase rgtc[] = { {"../data/dxl/minidump/MissingStats.mdp", 2}, {"../data/dxl/minidump/NoMissingStatsAfterDroppedCol.mdp", 0}, {"../data/dxl/minidump/NoMissingStats.mdp", 0}, {"../data/dxl/minidump/NoMissingStatsForEmptyTable.mdp", 0}, {"../data/dxl/minidump/NoMissingStatsAskingForSystemColFOJ.mdp", 0}, }; CAutoMemoryPool amp(CAutoMemoryPool::ElcNone); IMemoryPool *pmp = amp.Pmp(); GPOS_RESULT eres = GPOS_OK; const ULONG ulTests = GPOS_ARRAY_SIZE(rgtc); for (ULONG ul = m_ulMissingStatsTestCounter; ((ul < ulTests) && (GPOS_OK == eres)); ul++) { ICostModel *pcm = CTestUtils::Pcm(pmp); CAutoTraceFlag atf1(EopttracePrintColsWithMissingStats, true /*fVal*/); COptimizerConfig *poconf = GPOS_NEW(pmp) COptimizerConfig ( CEnumeratorConfig::Pec(pmp, 0 /*ullPlanId*/), CStatisticsConfig::PstatsconfDefault(pmp), CCTEConfig::PcteconfDefault(pmp), pcm, CHint::PhintDefault(pmp), CWindowOids::Pwindowoids(pmp) ); SMissingStatsTestCase testCase = rgtc[ul]; CDXLNode *pdxlnPlan = CMinidumperUtils::PdxlnExecuteMinidump ( pmp, testCase.m_szInputFile, GPOPT_TEST_SEGMENTS /*ulSegments*/, 1 /*ulSessionId*/, 1, /*ulCmdId*/ poconf, NULL /*pceeval*/ ); CStatisticsConfig *pstatsconf = poconf->Pstatsconf(); DrgPmdid *pdrgmdidCol = GPOS_NEW(pmp) DrgPmdid(pmp); pstatsconf->CollectMissingStatsColumns(pdrgmdidCol); ULONG ulMissingStats = pdrgmdidCol->UlLength(); if (ulMissingStats != testCase.m_ulExpectedMissingStats) { // for debug traces CWStringDynamic str(pmp); COstreamString oss(&str); // print objects oss << std::endl; oss << "Expected Number of Missing Columns: " << testCase.m_ulExpectedMissingStats; oss << std::endl; oss << "Number of Missing Columns: " << ulMissingStats; oss << std::endl; GPOS_TRACE(str.Wsz()); eres = GPOS_FAILED; } GPOS_CHECK_ABORT; poconf->Release(); pdxlnPlan->Release(); m_ulMissingStatsTestCounter++; } if (GPOS_OK == eres) { m_ulMissingStatsTestCounter = 0; } return eres; }
//--------------------------------------------------------------------------- // @function: // CCostTest::EresUnittest_CalibratedCostModel // // @doc: // GPDB's calibrated cost model test // //--------------------------------------------------------------------------- GPOS_RESULT CCostTest::EresUnittest_CalibratedCostModel() { CAutoTraceFlag atf1(EtraceSimulateOOM, false); CAutoTraceFlag atf2(EtraceSimulateAbort, false); CAutoTraceFlag atf3(EtraceSimulateIOError, false); CAutoTraceFlag atf4(EtraceSimulateNetError, false); 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); ICostModel *pcm = GPOS_NEW(pmp) CCostModelGPDB(pmp, GPOPT_TEST_SEGMENTS); pcm->AddRef(); { // install opt context in TLS CAutoOptCtxt aoc ( pmp, &mda, NULL, /* pceeval */ pcm ); TestParams(pmp, true /*fCalibrated*/); } // minidump files const CHAR *rgszFileNamesCalibratedCostModel[] = { "../data/dxl/minidump/PartTbl-MultiWayJoinWithDPE.mdp", "../data/dxl/tpch/q2.mdp", "../data/dxl/minidump/CTE-4.mdp", "../data/dxl/minidump/Lead-Lag-WinFuncs.mdp", }; COptimizerConfig* poconf = COptimizerConfig::PoconfDefault(pmp, pcm); for (ULONG ul = 0; ul < GPOS_ARRAY_SIZE(rgszFileNamesCalibratedCostModel); ul++) { CDXLNode *pdxlnPlan = CMinidumperUtils::PdxlnExecuteMinidump ( pmp, rgszFileNamesCalibratedCostModel[ul], GPOPT_TEST_SEGMENTS, 1 /*ulSessionId*/, 1 /*ulCmdId*/, poconf, NULL /*pceeval*/ ); pdxlnPlan->Release(); } poconf->Release(); return GPOS_OK; }