Exemplo n.º 1
0
//---------------------------------------------------------------------------
//	@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;
}
Exemplo n.º 2
0
//---------------------------------------------------------------------------
//	@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;
}
Exemplo n.º 3
0
//---------------------------------------------------------------------------
//	@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;
}
Exemplo n.º 4
0
//---------------------------------------------------------------------------
//	@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;
}