hawq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ent...@apache.org
Subject [2/4] incubator-hawq git commit: HAWQ-246. Refactor and cleanup of memory management of the new optimizer.
Date Fri, 11 Dec 2015 01:39:49 GMT
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/9b65a5ad/src/backend/gpopt/translate/CTranslatorRelcacheToDXL.cpp
----------------------------------------------------------------------
diff --git a/src/backend/gpopt/translate/CTranslatorRelcacheToDXL.cpp b/src/backend/gpopt/translate/CTranslatorRelcacheToDXL.cpp
index 65c0f0c..80a81ee 100644
--- a/src/backend/gpopt/translate/CTranslatorRelcacheToDXL.cpp
+++ b/src/backend/gpopt/translate/CTranslatorRelcacheToDXL.cpp
@@ -279,8 +279,8 @@ CTranslatorRelcacheToDXL::PmdnameRel
 	GPOS_ASSERT(NULL != rel);
 	CHAR *szRelName = NameStr(rel->rd_rel->relname);
 	CWStringDynamic *pstrRelName = CDXLUtils::PstrFromSz(pmp, szRelName);
-	CMDName *pmdname = New(pmp) CMDName(pmp, pstrRelName);
-	delete pstrRelName;
+	CMDName *pmdname = GPOS_NEW(pmp) CMDName(pmp, pstrRelName);
+	GPOS_DELETE(pstrRelName);
 	return pmdname;
 }
 
@@ -300,7 +300,7 @@ CTranslatorRelcacheToDXL::PdrgpmdidRelIndexes
 	)
 {
 	GPOS_ASSERT(NULL != rel);
-	DrgPmdid *pdrgpmdidIndexes = New(pmp) DrgPmdid(pmp);
+	DrgPmdid *pdrgpmdidIndexes = GPOS_NEW(pmp) DrgPmdid(pmp);
 
 	List *plIndexOids = NIL;
 	
@@ -429,7 +429,7 @@ CTranslatorRelcacheToDXL::PdrgpmdidTriggers
 		}
 	}
 
-	DrgPmdid *pdrgpmdidTriggers = New(pmp) DrgPmdid(pmp);
+	DrgPmdid *pdrgpmdidTriggers = GPOS_NEW(pmp) DrgPmdid(pmp);
 	const ULONG ulTriggers = rel->rd_rel->reltriggers;
 
 	for (ULONG ul = 0; ul < ulTriggers; ul++)
@@ -458,7 +458,7 @@ CTranslatorRelcacheToDXL::PdrgpmdidCheckConstraints
 	OID oid
 	)
 {
-	DrgPmdid *pdrgpmdidCheckConstraints = New(pmp) DrgPmdid(pmp);
+	DrgPmdid *pdrgpmdidCheckConstraints = GPOS_NEW(pmp) DrgPmdid(pmp);
 	List *plOidCheckConstraints = gpdb::PlCheckConstraint(oid);
 
 	ListCell *plcOid = NULL;
@@ -661,8 +661,8 @@ CTranslatorRelcacheToDXL::Pmdrel
 
 		fTemporary = rel->rd_istemp;
 		fHasOids = rel->rd_rel->relhasoids;
-
-		delete [] pulAttnoMapping;
+	
+		GPOS_DELETE_ARRAY(pulAttnoMapping);
 		gpdb::CloseRelation(rel);
 	}
 	GPOS_CATCH_EX(ex)
@@ -688,7 +688,7 @@ CTranslatorRelcacheToDXL::Pmdrel
 			pmdidFmtErrTbl = CTranslatorUtils::PmdidWithVersion(pmp, extentry->fmterrtbl);
 		}
 
-		pmdrel = New(pmp) CMDRelationExternalGPDB
+		pmdrel = GPOS_NEW(pmp) CMDRelationExternalGPDB
 							(
 							pmp,
 							pmdid,
@@ -711,7 +711,7 @@ CTranslatorRelcacheToDXL::Pmdrel
 		// get part constraint
 		CMDPartConstraintGPDB *pmdpartcnstr = PmdpartcnstrRelation(pmp, pmda, oid, pdrgpmdcol);
 
-		pmdrel = New(pmp) CMDRelationGPDB
+		pmdrel = GPOS_NEW(pmp) CMDRelationGPDB
 							(
 							pmp,
 							pmdid,
@@ -752,7 +752,7 @@ CTranslatorRelcacheToDXL::Pdrgpmdcol
 	IMDRelation::Erelstoragetype erelstorage
 	)
 {
-	DrgPmdcol *pdrgpmdcol = New(pmp) DrgPmdcol(pmp);
+	DrgPmdcol *pdrgpmdcol = GPOS_NEW(pmp) DrgPmdcol(pmp);
 
 	for (ULONG ul = 0;  ul < (ULONG) rel->rd_att->natts; ul++)
 	{
@@ -774,7 +774,7 @@ CTranslatorRelcacheToDXL::Pdrgpmdcol
 			ulColLen = (ULONG) att->atttypmod - VARHDRSZ;
 		}
 
-		CMDColumn *pmdcol = New(pmp) CMDColumn
+		CMDColumn *pmdcol = GPOS_NEW(pmp) CMDColumn
 										(
 										pmdnameCol,
 										att->attnum,
@@ -928,7 +928,7 @@ CTranslatorRelcacheToDXL::PdrpulDistrCols
 	ULONG ulSize
 	)
 {
-	ULONG *pul = New(pmp) ULONG[ulSize];
+	ULONG *pul = GPOS_NEW_ARRAY(pmp , ULONG, ulSize);
 
 	for (ULONG ul = 0;  ul < pdrgpmdcol->UlLength(); ul++)
 	{
@@ -939,15 +939,15 @@ CTranslatorRelcacheToDXL::PdrpulDistrCols
 		pul[ulIndex] = ul;
 	}
 
-	DrgPul *pdrpulDistrCols = New(pmp) DrgPul(pmp);
+	DrgPul *pdrpulDistrCols = GPOS_NEW(pmp) DrgPul(pmp);
 
 	for (ULONG ul = 0; ul < (ULONG) pgppolicy->nattrs; ul++)
 	{
 		AttrNumber attno = pgppolicy->attrs[ul];
-		pdrpulDistrCols->Append(New(pmp) ULONG(UlPosition(attno, pul)));
+		pdrpulDistrCols->Append(GPOS_NEW(pmp) ULONG(UlPosition(attno, pul)));
 	}
 
-	delete[] pul;
+	GPOS_DELETE_ARRAY(pul);
 	return pdrpulDistrCols;
 }
 
@@ -989,9 +989,9 @@ CTranslatorRelcacheToDXL::AddSystemColumns
 		GPOS_ASSERT(NULL != pstrSysColName);
 
 		// copy string into column name
-		CMDName *pmdnameCol = New(pmp) CMDName(pmp, pstrSysColName);
+		CMDName *pmdnameCol = GPOS_NEW(pmp) CMDName(pmp, pstrSysColName);
 
-		CMDColumn *pmdcol = New(pmp) CMDColumn
+		CMDColumn *pmdcol = GPOS_NEW(pmp) CMDColumn
 										(
 										pmdnameCol, 
 										attno, 
@@ -1103,8 +1103,8 @@ CTranslatorRelcacheToDXL::Pmdindex
 		// get the index name
 		CHAR *szIndexName = NameStr(relIndex->rd_rel->relname);
 		CWStringDynamic *pstrName = CDXLUtils::PstrFromSz(pmp, szIndexName);
-		pmdname = New(pmp) CMDName(pmp, pstrName);
-		delete pstrName;
+		pmdname = GPOS_NEW(pmp) CMDName(pmp, pstrName);
+		GPOS_DELETE(pstrName);
 		pmdidRel->Release();
 		gpdb::CloseRelation(relIndex);
 	}
@@ -1124,20 +1124,20 @@ CTranslatorRelcacheToDXL::Pmdindex
 	DrgPul *pdrgpulIncludeCols = PdrgpulIndexIncludedColumns(pmp, pmdrel);
 
 	// extract the position of the key columns
-	DrgPul *pdrgpulKeyCols = New(pmp) DrgPul(pmp);
+	DrgPul *pdrgpulKeyCols = GPOS_NEW(pmp) DrgPul(pmp);
 	ULONG ulKeys = pgIndex->indnatts;
 	for (ULONG ul = 0; ul < ulKeys; ul++)
 	{
 		INT iAttno = pgIndex->indkey.values[ul];
 		GPOS_ASSERT(0 != iAttno && "Index expressions not supported");
 
-		pdrgpulKeyCols->Append(New(pmp) ULONG(UlPosition(iAttno, pul)));
+		pdrgpulKeyCols->Append(GPOS_NEW(pmp) ULONG(UlPosition(iAttno, pul)));
 	}
 
 	pmdidIndex->AddRef();	
 	DrgPmdid *pdrgpmdidOpClasses = PdrgpmdidIndexOpClasses(pmp, pmdidIndex);
 	
-	CMDIndexGPDB *pmdindex = New(pmp) CMDIndexGPDB
+	CMDIndexGPDB *pmdindex = GPOS_NEW(pmp) CMDIndexGPDB
 										(
 										pmp,
 										pmdidIndex,
@@ -1153,7 +1153,7 @@ CTranslatorRelcacheToDXL::Pmdindex
 										NULL // pmdpartcnstr
 										);
 
-	delete [] pul;
+	GPOS_DELETE_ARRAY(pul);
 
 	return pmdindex;
 }
@@ -1274,14 +1274,14 @@ CTranslatorRelcacheToDXL::PmdindexPartTable
 	DrgPul *pdrgpulIncludeCols = PdrgpulIndexIncludedColumns(pmp, pmdrel);
 
 	// extract the position of the key columns
-	DrgPul *pdrgpulKeyCols = New(pmp) DrgPul(pmp);
+	DrgPul *pdrgpulKeyCols = GPOS_NEW(pmp) DrgPul(pmp);
 	const ULONG ulKeys = pidxinfo->nColumns;
 	for (ULONG ul = 0; ul < ulKeys; ul++)
 	{
 		INT iAttno = pidxinfo->indexKeys[ul];
 		GPOS_ASSERT(0 != iAttno && "Index expressions not supported");
 
-		pdrgpulKeyCols->Append(New(pmp) ULONG(UlPosition(iAttno, pulAttrMap)));
+		pdrgpulKeyCols->Append(GPOS_NEW(pmp) ULONG(UlPosition(iAttno, pulAttrMap)));
 	}
 	
 	Node *pnodePartCnstr = pidxinfo->partCons;
@@ -1302,12 +1302,12 @@ CTranslatorRelcacheToDXL::PmdindexPartTable
 		fUnbounded = fUnbounded && FDefaultPartition(plDefaultLevelsRel, ul);
 	}
 
-	DrgPul *pdrgpulDefaultLevels = New(pmp) DrgPul(pmp);
+	DrgPul *pdrgpulDefaultLevels = GPOS_NEW(pmp) DrgPul(pmp);
 	for (ULONG ul = 0; ul < ulLevels; ul++)
 	{
 		if (fUnbounded || FDefaultPartition(plDefaultLevels, ul))
 		{
-			pdrgpulDefaultLevels->Append(New(pmp) ULONG(ul));
+			pdrgpulDefaultLevels->Append(GPOS_NEW(pmp) ULONG(ul));
 		}
 	}
 
@@ -1344,7 +1344,7 @@ CTranslatorRelcacheToDXL::PmdindexPartTable
 	
 	DrgPmdid *pdrgpmdidOpClasses = PdrgpmdidIndexOpClasses(pmp, pmdidIndex);
 	
-	CMDIndexGPDB *pmdindex = New(pmp) CMDIndexGPDB
+	CMDIndexGPDB *pmdindex = GPOS_NEW(pmp) CMDIndexGPDB
 										(
 										pmp,
 										pmdidIndex,
@@ -1360,7 +1360,7 @@ CTranslatorRelcacheToDXL::PmdindexPartTable
 										pmdpartcnstr
 										);
 	
-	delete [] pulAttrMap;
+	GPOS_DELETE_ARRAY(pulAttrMap);
 	
 	return pmdindex;
 }
@@ -1416,13 +1416,13 @@ CTranslatorRelcacheToDXL::PdrgpulIndexIncludedColumns
 	// TODO: raghav, 3/19/2012; currently we assume that all the columns
 	// in the table are available from the index.
 
-	DrgPul *pdrgpulIncludeCols = New(pmp) DrgPul(pmp);
+	DrgPul *pdrgpulIncludeCols = GPOS_NEW(pmp) DrgPul(pmp);
 	const ULONG ulIncludedCols = pmdrel->UlColumns();
 	for (ULONG ul = 0;  ul < ulIncludedCols; ul++)
 	{
 		if (!pmdrel->Pmdcol(ul)->FDropped())
 		{
-			pdrgpulIncludeCols->Append(New(pmp) ULONG(ul));
+			pdrgpulIncludeCols->Append(GPOS_NEW(pmp) ULONG(ul));
 		}
 	}
 	
@@ -1472,7 +1472,7 @@ CTranslatorRelcacheToDXL::PulAttnoPositionMap
 	const ULONG ulIncludedCols = pmdrel->UlColumns();
 
 	GPOS_ASSERT(ulIncludedCols <= ulSize);
-	ULONG *pul = New(pmp) ULONG[ulSize];
+	ULONG *pul = GPOS_NEW_ARRAY(pmp , ULONG, ulSize);
 
 	for (ULONG ul = 0; ul < ulSize; ul++)
 	{
@@ -1516,19 +1516,19 @@ CTranslatorRelcacheToDXL::Pmdtype
 	switch (oidType)
 	{
 		case GPDB_INT2_OID:
-			return New(pmp) CMDTypeInt2GPDB(pmp);
+			return GPOS_NEW(pmp) CMDTypeInt2GPDB(pmp);
 
 		case GPDB_INT4_OID:
-			return New(pmp) CMDTypeInt4GPDB(pmp);
+			return GPOS_NEW(pmp) CMDTypeInt4GPDB(pmp);
 
 		case GPDB_INT8_OID:
-			return New(pmp) CMDTypeInt8GPDB(pmp);
+			return GPOS_NEW(pmp) CMDTypeInt8GPDB(pmp);
 
 		case GPDB_BOOL:
-			return New(pmp) CMDTypeBoolGPDB(pmp);
+			return GPOS_NEW(pmp) CMDTypeBoolGPDB(pmp);
 
 		case GPDB_OID_OID:
-			return New(pmp) CMDTypeOidGPDB(pmp);
+			return GPOS_NEW(pmp) CMDTypeOidGPDB(pmp);
 	}
 
 	// continue to construct a generic type
@@ -1585,7 +1585,7 @@ CTranslatorRelcacheToDXL::Pmdtype
 
 	pmdid->AddRef();
 
-	return New(pmp) CMDTypeGenericGPDB
+	return GPOS_NEW(pmp) CMDTypeGenericGPDB
 						 (
 						 pmp,
 						 pmdid,
@@ -1702,7 +1702,7 @@ CTranslatorRelcacheToDXL::Pmdscop
 	BOOL fReturnsNullOnNullInput = gpdb::FOpStrict(oidOp);
 
 	pmdid->AddRef();
-	CMDScalarOpGPDB *pmdscop = New(pmp) CMDScalarOpGPDB
+	CMDScalarOpGPDB *pmdscop = GPOS_NEW(pmp) CMDScalarOpGPDB
 											(
 											pmp,
 											pmdid,
@@ -1799,10 +1799,10 @@ CTranslatorRelcacheToDXL::Pmdfunc
 	}
 
 	CWStringDynamic *pstrFuncName = CDXLUtils::PstrFromSz(pmp, szName);
-	CMDName *pmdname = New(pmp) CMDName(pmp, pstrFuncName);
+	CMDName *pmdname = GPOS_NEW(pmp) CMDName(pmp, pstrFuncName);
 
 	// CMDName ctor created a copy of the string
-	delete pstrFuncName;
+	GPOS_DELETE(pstrFuncName);
 
 	// get result type
 	OID oidResult = gpdb::OidFuncRetType(oidFunc);
@@ -1818,7 +1818,7 @@ CTranslatorRelcacheToDXL::Pmdfunc
 	if (NULL != plOutArgTypes)
 	{
 		ListCell *plc = NULL;
-		pdrgpmdidArgTypes = New(pmp) DrgPmdid(pmp);
+		pdrgpmdidArgTypes = GPOS_NEW(pmp) DrgPmdid(pmp);
 
 		ForEach (plc, plOutArgTypes)
 		{
@@ -1838,7 +1838,7 @@ CTranslatorRelcacheToDXL::Pmdfunc
 	LookupFuncProps(oidFunc, &efs, &efda, &fStrict, &fReturnsSet);
 
 	pmdid->AddRef();
-	CMDFunctionGPDB *pmdfunc = New(pmp) CMDFunctionGPDB
+	CMDFunctionGPDB *pmdfunc = GPOS_NEW(pmp) CMDFunctionGPDB
 											(
 											pmp,
 											pmdid,
@@ -1883,10 +1883,10 @@ CTranslatorRelcacheToDXL::Pmdagg
 	}
 
 	CWStringDynamic *pstrAggName = CDXLUtils::PstrFromSz(pmp, szName);
-	CMDName *pmdname = New(pmp) CMDName(pmp, pstrAggName);
+	CMDName *pmdname = GPOS_NEW(pmp) CMDName(pmp, pstrAggName);
 
 	// CMDName ctor created a copy of the string
-	delete pstrAggName;
+	GPOS_DELETE(pstrAggName);
 
 	// get result type
 	OID oidResult = gpdb::OidFuncRetType(oidAgg);
@@ -1908,7 +1908,7 @@ CTranslatorRelcacheToDXL::Pmdagg
 	// due to the fact that hashAgg may spill
 	BOOL fHashAggCapable = !fOrdered && gpdb::FAggHasPrelimFunc(oidAgg);
 
-	CMDAggregateGPDB *pmdagg = New(pmp) CMDAggregateGPDB
+	CMDAggregateGPDB *pmdagg = GPOS_NEW(pmp) CMDAggregateGPDB
 											(
 											pmp,
 											pmdid,
@@ -1950,8 +1950,8 @@ CTranslatorRelcacheToDXL::Pmdtrigger
 	}
 
 	CWStringDynamic *pstrTriggerName = CDXLUtils::PstrFromSz(pmp, szName);
-	CMDName *pmdname = New(pmp) CMDName(pmp, pstrTriggerName);
-	delete pstrTriggerName;
+	CMDName *pmdname = GPOS_NEW(pmp) CMDName(pmp, pstrTriggerName);
+	GPOS_DELETE(pstrTriggerName);
 
 	// get relation oid
 	OID oidRel = gpdb::OidTriggerRelid(oidTrigger);
@@ -1970,7 +1970,7 @@ CTranslatorRelcacheToDXL::Pmdtrigger
 	BOOL fEnabled = gpdb::FTriggerEnabled(oidTrigger);
 
 	pmdid->AddRef();
-	CMDTriggerGPDB *pmdtrigger = New(pmp) CMDTriggerGPDB
+	CMDTriggerGPDB *pmdtrigger = GPOS_NEW(pmp) CMDTriggerGPDB
 											(
 											pmp,
 											pmdid,
@@ -2009,8 +2009,8 @@ CTranslatorRelcacheToDXL::Pmdcheckconstraint
 		GPOS_RAISE(gpdxl::ExmaMD, gpdxl::ExmiMDCacheEntryNotFound, pmdid->Wsz());
 	}
 	CWStringDynamic *pstrCheckConstraintName = CDXLUtils::PstrFromSz(pmp, szName);
-	CMDName *pmdname = New(pmp) CMDName(pmp, pstrCheckConstraintName);
-	delete pstrCheckConstraintName;
+	CMDName *pmdname = GPOS_NEW(pmp) CMDName(pmp, pstrCheckConstraintName);
+	GPOS_DELETE(pstrCheckConstraintName);
 
 	// get relation oid associated with the check constraint
 	OID oidRel = gpdb::OidCheckConstraintRelid(oidCheckConstraint);
@@ -2036,19 +2036,19 @@ CTranslatorRelcacheToDXL::Pmdcheckconstraint
 							);
 
 	// generate a mock mapping between var to column information
-	CMappingVarColId *pmapvarcolid = New(pmp) CMappingVarColId(pmp);
-	DrgPdxlcd *pdrgpdxlcd = New(pmp) DrgPdxlcd(pmp);
+	CMappingVarColId *pmapvarcolid = GPOS_NEW(pmp) CMappingVarColId(pmp);
+	DrgPdxlcd *pdrgpdxlcd = GPOS_NEW(pmp) DrgPdxlcd(pmp);
 	const IMDRelation *pmdrel = pmda->Pmdrel(pmdidRel);
 	const ULONG ulLen = pmdrel->UlColumns();
 	for (ULONG ul = 0; ul < ulLen; ul++)
 	{
 		const IMDColumn *pmdcol = pmdrel->Pmdcol(ul);
-		CMDName *pmdnameCol = New(pmp) CMDName(pmp, pmdcol->Mdname().Pstr());
+		CMDName *pmdnameCol = GPOS_NEW(pmp) CMDName(pmp, pmdcol->Mdname().Pstr());
 		CMDIdGPDB *pmdidColType = CMDIdGPDB::PmdidConvert(pmdcol->PmdidType());
 		pmdidColType->AddRef();
 
 		// create a column descriptor for the column
-		CDXLColDescr *pdxlcd = New(pmp) CDXLColDescr
+		CDXLColDescr *pdxlcd = GPOS_NEW(pmp) CDXLColDescr
 										(
 										pmp,
 										pmdnameCol,
@@ -2066,11 +2066,11 @@ CTranslatorRelcacheToDXL::Pmdcheckconstraint
 
 	// cleanup
 	pdrgpdxlcd->Release();
-	delete pmapvarcolid;
+	GPOS_DELETE(pmapvarcolid);
 
 	pmdid->AddRef();
 
-	return New(pmp) CMDCheckConstraintGPDB
+	return GPOS_NEW(pmp) CMDCheckConstraintGPDB
 						(
 						pmp,
 						pmdid,
@@ -2103,10 +2103,10 @@ CTranslatorRelcacheToDXL::PmdnameType
 	GPOS_ASSERT(NULL != szTypeName);
 
 	CWStringDynamic *pstrName = CDXLUtils::PstrFromSz(pmp, szTypeName);
-	CMDName *pmdname = New(pmp) CMDName(pmp, pstrName);
+	CMDName *pmdname = GPOS_NEW(pmp) CMDName(pmp, pstrName);
 
 	// cleanup
-	delete pstrName;
+	GPOS_DELETE(pstrName);
 	return pmdname;
 }
 
@@ -2232,7 +2232,7 @@ CTranslatorRelcacheToDXL::PmdidFunc
 		GPOS_RAISE(gpdxl::ExmaMD, gpdxl::ExmiMDCacheEntryNotFound, wszFuncName);
 	}
 
-	delete [] szFuncName;
+	GPOS_DELETE_ARRAY(szFuncName);
 	return CTranslatorUtils::PmdidWithVersion(pmp, fcl->oid);
 }
 
@@ -2269,9 +2269,9 @@ CTranslatorRelcacheToDXL::PimdobjRelStats
 		// get rel name
 		CHAR *szRelName = NameStr(rel->rd_rel->relname);
 		CWStringDynamic *pstrRelName = CDXLUtils::PstrFromSz(pmp, szRelName);
-		pmdname = New(pmp) CMDName(pmp, pstrRelName);
+		pmdname = GPOS_NEW(pmp) CMDName(pmp, pstrRelName);
 		// CMDName ctor created a copy of the string
-		delete pstrRelName;
+		GPOS_DELETE(pstrRelName);
 
 		BlockNumber pages = 0;
 		GpPolicy *pgppolicy = gpdb::Pdistrpolicy(rel);
@@ -2300,7 +2300,7 @@ CTranslatorRelcacheToDXL::PimdobjRelStats
 		fEmptyStats = true;
 	}
 		
-	CDXLRelStats *pdxlrelstats = New(pmp) CDXLRelStats
+	CDXLRelStats *pdxlrelstats = GPOS_NEW(pmp) CDXLRelStats
 												(
 												pmp,
 												pmdidRelStats,
@@ -2348,11 +2348,11 @@ CTranslatorRelcacheToDXL::PimdobjColStats
 	CDouble dRows(rel->rd_rel->reltuples);
 
 	// extract column name and type
-	CMDName *pmdnameCol = New(pmp) CMDName(pmp, pmdcol->Mdname().Pstr());
+	CMDName *pmdnameCol = GPOS_NEW(pmp) CMDName(pmp, pmdcol->Mdname().Pstr());
 	OID oidAttType = CMDIdGPDB::PmdidConvert(pmdcol->PmdidType())->OidObjectId();
 	gpdb::CloseRelation(rel);
 
-	DrgPdxlbucket *pdrgpdxlbucket = New(pmp) DrgPdxlbucket(pmp);
+	DrgPdxlbucket *pdrgpdxlbucket = GPOS_NEW(pmp) DrgPdxlbucket(pmp);
 
 	if (0 > attrnum)
 	{
@@ -2383,7 +2383,7 @@ CTranslatorRelcacheToDXL::PimdobjColStats
 
 		if (!pmdcol->FDropped())
 		{
-			CMDIdGPDB *pmdidAttType = New(pmp) CMDIdGPDB(oidAttType);
+			CMDIdGPDB *pmdidAttType = GPOS_NEW(pmp) CMDIdGPDB(oidAttType);
 			IMDType *pmdtype = Pmdtype(pmp, pmdidAttType);
 			dWidth = CStatisticsUtils::DDefaultColumnWidth(pmdtype);
 			pmdtype->Release();
@@ -2525,7 +2525,7 @@ CTranslatorRelcacheToDXL::PimdobjColStats
 
 	// create col stats object
 	pmdidColStats->AddRef();
-	CDXLColStats *pdxlcolstats = New(pmp) CDXLColStats
+	CDXLColStats *pdxlcolstats = GPOS_NEW(pmp) CDXLColStats
 											(
 											pmp,
 											pmdidColStats,
@@ -2569,7 +2569,7 @@ CTranslatorRelcacheToDXL::PdxlcolstatsSystemColumn
        GPOS_ASSERT(0 > attrnum);
        GPOS_ASSERT(NULL != pdrgpdxlbucket);
 
-       CMDIdGPDB *pmdidAttType = New(pmp) CMDIdGPDB(oidAttType);
+       CMDIdGPDB *pmdidAttType = GPOS_NEW(pmp) CMDIdGPDB(oidAttType);
        IMDType *pmdtype = Pmdtype(pmp, pmdidAttType);
        GPOS_ASSERT(pmdtype->FFixedLength());
 
@@ -2613,7 +2613,7 @@ CTranslatorRelcacheToDXL::PdxlcolstatsSystemColumn
        pmdidAttType->Release();
        pmdtype->Release();
 
-       return New(pmp) CDXLColStats
+       return GPOS_NEW(pmp) CDXLColStats
                        (
                        pmp,
                        pmdidColStats,
@@ -2721,7 +2721,7 @@ CTranslatorRelcacheToDXL::PimdobjCast
 	CMDName *pmdname = CDXLUtils::PmdnameFromSz(pmp, szFuncName);
 	
 	CMDIdGPDB *pmdidCastFunc = CTranslatorUtils::PmdidWithVersion(pmp, oidCastFunc);
-	return New(pmp) CMDCastGPDB(pmp, pmdid, pmdname, pmdidSrc, pmdidDest, fBinaryCoercible, pmdidCastFunc);
+	return GPOS_NEW(pmp) CMDCastGPDB(pmp, pmdid, pmdname, pmdidSrc, pmdidDest, fBinaryCoercible, pmdidCastFunc);
 }
 
 //---------------------------------------------------------------------------
@@ -2770,7 +2770,7 @@ CTranslatorRelcacheToDXL::PmdobjScCmp
 	CMDName *pmdname = CDXLUtils::PmdnameFromSz(pmp, szName);
 
 	CMDIdGPDB *pmdidCmp = CTranslatorUtils::PmdidWithVersion(pmp, oidScCmp);
-	return New(pmp) CMDScCmpGPDB(pmp, pmdid, pmdname, pmdidLeft, pmdidRight, ecmpt, pmdidCmp);
+	return GPOS_NEW(pmp) CMDScCmpGPDB(pmp, pmdid, pmdname, pmdidLeft, pmdidRight, ecmpt, pmdidCmp);
 }
 
 //---------------------------------------------------------------------------
@@ -2853,23 +2853,23 @@ CTranslatorRelcacheToDXL::PdrgpdxlbucketTransformStats
 		// both histogram and MCVs exist and have significant info, merge MCV and histogram buckets
 		CHistogram *phistMerged = CStatisticsUtils::PhistMergeMcvHist(pmp, phistGPDBMCV, phistGPDBHist);
 		pdrgpdxlbucket = Pdrgpdxlbucket(pmp, pmdtype, phistMerged);
-		delete phistMerged;
+		GPOS_DELETE(phistMerged);
 	}
 	else
 	{
 		// no MCVs nor histogram
 		GPOS_ASSERT(!fHasHist && !fHasMCV);
-		pdrgpdxlbucket = New(pmp) DrgPdxlbucket(pmp);
+		pdrgpdxlbucket = GPOS_NEW(pmp) DrgPdxlbucket(pmp);
 	}
 
 	// cleanup
 	pmdidAttType->Release();
 	pmdtype->Release();
-	delete phistGPDBMCV;
+	GPOS_DELETE(phistGPDBMCV);
 
 	if (NULL != phistGPDBHist)
 	{
-		delete phistGPDBHist;
+		GPOS_DELETE(phistGPDBHist);
 	}
 
 	return pdrgpdxlbucket;
@@ -2893,15 +2893,15 @@ CTranslatorRelcacheToDXL::PhistTransformGPDBMCV
 	ULONG ulNumMCVValues
 	)
 {
-	DrgPdatum *pdrgpdatum = New(pmp) DrgPdatum(pmp);
-	DrgPdouble *pdrgpdFreq = New(pmp) DrgPdouble(pmp);
+	DrgPdatum *pdrgpdatum = GPOS_NEW(pmp) DrgPdatum(pmp);
+	DrgPdouble *pdrgpdFreq = GPOS_NEW(pmp) DrgPdouble(pmp);
 
 	for (ULONG ul = 0; ul < ulNumMCVValues; ul++)
 	{
 		Datum datumMCV = pdrgdatumMCVValues[ul];
 		IDatum *pdatum = CTranslatorScalarToDXL::Pdatum(pmp, pmdtype, false /* fNull */, datumMCV);
 		pdrgpdatum->Append(pdatum);
-		pdrgpdFreq->Append(New(pmp) CDouble(pdrgfMCVFrequencies[ul]));
+		pdrgpdFreq->Append(GPOS_NEW(pmp) CDouble(pdrgfMCVFrequencies[ul]));
 
 		if (!pdatum->FStatsComparable(pdatum))
 		{
@@ -2909,7 +2909,7 @@ CTranslatorRelcacheToDXL::PhistTransformGPDBMCV
 			// building a histogram. return an empty histogram
 			pdrgpdatum->Release();
 			pdrgpdFreq->Release();
-			return New(pmp) CHistogram(New(pmp) DrgPbucket(pmp));
+			return GPOS_NEW(pmp) CHistogram(GPOS_NEW(pmp) DrgPbucket(pmp));
 		}
 	}
 
@@ -2954,7 +2954,7 @@ CTranslatorRelcacheToDXL::PhistTransformGPDBHist
 
 	const ULONG ulBuckets = ulNumHistValues - 1;
 	// create buckets
-	DrgPbucket *pdrgppbucket = New(pmp) DrgPbucket(pmp);
+	DrgPbucket *pdrgppbucket = GPOS_NEW(pmp) DrgPbucket(pmp);
 	for (ULONG ul = 0; ul < ulBuckets; ul++)
 	{
 		Datum datumMin = pdrgdatumHistValues[ul];
@@ -2971,10 +2971,10 @@ CTranslatorRelcacheToDXL::PhistTransformGPDBHist
 			fUpperClosed = true;
 		}
 
-		CBucket *pbucket = New(pmp) CBucket
+		CBucket *pbucket = GPOS_NEW(pmp) CBucket
 									(
-									New(pmp) CPoint(pdatumMin),
-									New(pmp) CPoint(pdatumMax),
+									GPOS_NEW(pmp) CPoint(pdatumMin),
+									GPOS_NEW(pmp) CPoint(pdatumMax),
 									fLowerClosed,
 									fUpperClosed,
 									dFreqPerBucket,
@@ -2992,11 +2992,11 @@ CTranslatorRelcacheToDXL::PhistTransformGPDBHist
 			// order is different in GPDB, and use const expression eval to compare
 			// datums in Orca (MPP-22780)
 			pdrgppbucket->Release();
-			return New(pmp) CHistogram(New(pmp) DrgPbucket(pmp));
+			return GPOS_NEW(pmp) CHistogram(GPOS_NEW(pmp) DrgPbucket(pmp));
 		}
 	}
 
-	CHistogram *phist = New(pmp) CHistogram(pdrgppbucket);
+	CHistogram *phist = GPOS_NEW(pmp) CHistogram(pdrgppbucket);
 	return phist;
 }
 
@@ -3017,7 +3017,7 @@ CTranslatorRelcacheToDXL::Pdrgpdxlbucket
 	const CHistogram *phist
 	)
 {
-	DrgPdxlbucket *pdrgpdxlbucket = New(pmp) DrgPdxlbucket(pmp);
+	DrgPdxlbucket *pdrgpdxlbucket = GPOS_NEW(pmp) DrgPdxlbucket(pmp);
 	const DrgPbucket *pdrgpbucket = phist->Pdrgpbucket();
 	ULONG ulNumBuckets = pdrgpbucket->UlLength();
 	for (ULONG ul = 0; ul < ulNumBuckets; ul++)
@@ -3027,7 +3027,7 @@ CTranslatorRelcacheToDXL::Pdrgpdxlbucket
 		CDXLDatum *pdxldatumLB = pmdtype->Pdxldatum(pmp, pdatumLB);
 		IDatum *pdatumUB = pbucket->PpUpper()->Pdatum();
 		CDXLDatum *pdxldatumUB = pmdtype->Pdxldatum(pmp, pdatumUB);
-		CDXLBucket *pdxlbucket = New (pmp) CDXLBucket
+		CDXLBucket *pdxlbucket = GPOS_NEW(pmp) CDXLBucket
 											(
 											pdxldatumLB,
 											pdxldatumUB,
@@ -3108,7 +3108,7 @@ CTranslatorRelcacheToDXL::PdrgpulPartKeys
 
 	// TODO: antovl - Feb 23, 2012; support intermediate levels
 
-	DrgPul *pdrgpulPartKeys = New(pmp) DrgPul(pmp);
+	DrgPul *pdrgpulPartKeys = GPOS_NEW(pmp) DrgPul(pmp);
 
 	MemoryContext mcxt = CurrentMemoryContext;
 	PartitionNode *pn = gpdb::PpnParts(oid, 0 /*level*/, 0 /*parent*/, false /*inctemplate*/, mcxt, true /*includesubparts*/);
@@ -3133,7 +3133,7 @@ CTranslatorRelcacheToDXL::PdrgpulPartKeys
 
 		INT iAttno = linitial_int(plPartKey);
 		GPOS_ASSERT(0 < iAttno);
-		pdrgpulPartKeys->Append(New(pmp) ULONG(iAttno - 1));
+		pdrgpulPartKeys->Append(GPOS_NEW(pmp) ULONG(iAttno - 1));
 	}
 
 	return pdrgpulPartKeys;
@@ -3162,7 +3162,7 @@ CTranslatorRelcacheToDXL::PulAttnoMapping
 
 	// build a mapping for attnos->positions
 	const ULONG ulCols = pdrgpmdcol->UlLength();
-	ULONG *pul = New(pmp) ULONG[ulMaxCols];
+	ULONG *pul = GPOS_NEW_ARRAY(pmp, ULONG, ulMaxCols);
 
 	// initialize all positions to ULONG_MAX
 	for (ULONG ul = 0;  ul < ulMaxCols; ul++)
@@ -3200,7 +3200,7 @@ CTranslatorRelcacheToDXL::PdrgpdrgpulKeys
 	ULONG *pulMapping
 	)
 {
-	DrgPdrgPul *pdrgpdrgpul = New(pmp) DrgPdrgPul(pmp);
+	DrgPdrgPul *pdrgpdrgpul = GPOS_NEW(pmp) DrgPdrgPul(pmp);
 
 	List *plKeys = gpdb::PlRelationKeys(oid);
 
@@ -3209,14 +3209,14 @@ CTranslatorRelcacheToDXL::PdrgpdrgpulKeys
 	{
 		List *plKey = (List *) lfirst(plcKey);
 
-		DrgPul *pdrgpulKey = New(pmp) DrgPul(pmp);
+		DrgPul *pdrgpulKey = GPOS_NEW(pmp) DrgPul(pmp);
 
 		ListCell *plcKeyElem = NULL;
 		ForEach (plcKeyElem, plKey)
 		{
 			INT iKey = lfirst_int(plcKeyElem);
 			ULONG ulPos = UlPosition(iKey, pulMapping);
-			pdrgpulKey->Append(New(pmp) ULONG(ulPos));
+			pdrgpulKey->Append(GPOS_NEW(pmp) ULONG(ulPos));
 		}
 		GPOS_ASSERT(0 < pdrgpulKey->UlLength());
 
@@ -3227,17 +3227,17 @@ CTranslatorRelcacheToDXL::PdrgpdrgpulKeys
 	
 	if (fAddDefaultKeys)
 	{
-		DrgPul *pdrgpulKey = New(pmp) DrgPul(pmp);
+		DrgPul *pdrgpulKey = GPOS_NEW(pmp) DrgPul(pmp);
 		if (fPartitioned)
 		{
 			// TableOid is part of default key for partitioned tables
 			ULONG ulPosTableOid = UlPosition(TableOidAttributeNumber, pulMapping);
-			pdrgpulKey->Append(New(pmp) ULONG(ulPosTableOid));
+			pdrgpulKey->Append(GPOS_NEW(pmp) ULONG(ulPosTableOid));
 		}
 		ULONG ulPosSegid= UlPosition(GpSegmentIdAttributeNumber, pulMapping);
 		ULONG ulPosCtid = UlPosition(SelfItemPointerAttributeNumber, pulMapping);
-		pdrgpulKey->Append(New(pmp) ULONG(ulPosSegid));
-		pdrgpulKey->Append(New(pmp) ULONG(ulPosCtid));
+		pdrgpulKey->Append(GPOS_NEW(pmp) ULONG(ulPosSegid));
+		pdrgpulKey->Append(GPOS_NEW(pmp) ULONG(ulPosCtid));
 		
 		pdrgpdrgpul->Append(pdrgpulKey);
 	}
@@ -3337,18 +3337,18 @@ CTranslatorRelcacheToDXL::PmdpartcnstrIndex
 	BOOL fUnbounded
 	)
 {
-	DrgPdxlcd *pdrgpdxlcd = New(pmp) DrgPdxlcd(pmp);
+	DrgPdxlcd *pdrgpdxlcd = GPOS_NEW(pmp) DrgPdxlcd(pmp);
 	const ULONG ulColumns = pmdrel->UlColumns();
 	
 	for (ULONG ul = 0; ul < ulColumns; ul++)
 	{
 		const IMDColumn *pmdcol = pmdrel->Pmdcol(ul);
-		CMDName *pmdnameCol = New(pmp) CMDName(pmp, pmdcol->Mdname().Pstr());
+		CMDName *pmdnameCol = GPOS_NEW(pmp) CMDName(pmp, pmdcol->Mdname().Pstr());
 		CMDIdGPDB *pmdidColType = CMDIdGPDB::PmdidConvert(pmdcol->PmdidType());
 		pmdidColType->AddRef();
 
 		// create a column descriptor for the column
-		CDXLColDescr *pdxlcd = New(pmp) CDXLColDescr
+		CDXLColDescr *pdxlcd = GPOS_NEW(pmp) CDXLColDescr
 										(
 										pmp,
 										pmdnameCol,
@@ -3393,12 +3393,12 @@ CTranslatorRelcacheToDXL::PmdpartcnstrRelation
 	gpdb::FreeList(plPartKeys);
 
 	BOOL fUnbounded = true;
-	DrgPul *pdrgpulDefaultLevels = New(pmp) DrgPul(pmp);
+	DrgPul *pdrgpulDefaultLevels = GPOS_NEW(pmp) DrgPul(pmp);
 	for (ULONG ul = 0; ul < ulLevels; ul++)
 	{
 		if (FDefaultPartition(plDefaultLevelsRel, ul))
 		{
-			pdrgpulDefaultLevels->Append(New(pmp) ULONG(ul));
+			pdrgpulDefaultLevels->Append(GPOS_NEW(pmp) ULONG(ul));
 		}
 		else
 		{
@@ -3406,17 +3406,17 @@ CTranslatorRelcacheToDXL::PmdpartcnstrRelation
 		}
 	}
 
-	DrgPdxlcd *pdrgpdxlcd = New(pmp) DrgPdxlcd(pmp);
+	DrgPdxlcd *pdrgpdxlcd = GPOS_NEW(pmp) DrgPdxlcd(pmp);
 	const ULONG ulColumns = pdrgpmdcol->UlLength();
 	for (ULONG ul = 0; ul < ulColumns; ul++)
 	{
 		const IMDColumn *pmdcol = (*pdrgpmdcol)[ul];
-		CMDName *pmdnameCol = New(pmp) CMDName(pmp, pmdcol->Mdname().Pstr());
+		CMDName *pmdnameCol = GPOS_NEW(pmp) CMDName(pmp, pmdcol->Mdname().Pstr());
 		CMDIdGPDB *pmdidColType = CMDIdGPDB::PmdidConvert(pmdcol->PmdidType());
 		pmdidColType->AddRef();
 
 		// create a column descriptor for the column
-		CDXLColDescr *pdxlcd = New(pmp) CDXLColDescr
+		CDXLColDescr *pdxlcd = GPOS_NEW(pmp) CDXLColDescr
 										(
 										pmp,
 										pmdnameCol,
@@ -3475,7 +3475,7 @@ CTranslatorRelcacheToDXL::PmdpartcnstrFromNode
 							);
 
 	// generate a mock mapping between var to column information
-	CMappingVarColId *pmapvarcolid = New(pmp) CMappingVarColId(pmp);
+	CMappingVarColId *pmapvarcolid = GPOS_NEW(pmp) CMappingVarColId(pmp);
 
 	pmapvarcolid->LoadColumns(0 /*ulQueryLevel */, 1 /* rteIndex */, pdrgpdxlcd);
 
@@ -3483,10 +3483,10 @@ CTranslatorRelcacheToDXL::PmdpartcnstrFromNode
 	CDXLNode *pdxlnScalar = sctranslator.PdxlnScOpFromExpr((Expr *) pnodeCnstr, pmapvarcolid);
 
 	// cleanup
-	delete pmapvarcolid;
+	GPOS_DELETE(pmapvarcolid);
 
 	pdrgpulDefaultParts->AddRef();
-	return New(pmp) CMDPartConstraintGPDB(pmp, pdxlnScalar, pdrgpulDefaultParts, fUnbounded);
+	return GPOS_NEW(pmp) CMDPartConstraintGPDB(pmp, pdxlnScalar, pdrgpulDefaultParts, fUnbounded);
 }
 
 //---------------------------------------------------------------------------
@@ -3579,7 +3579,7 @@ CTranslatorRelcacheToDXL::PdrgpmdidIndexOpClasses
 	)
 {
 	List *plOpClasses = gpdb::PlIndexOpClasses(CMDIdGPDB::PmdidConvert(pmdidIndex)->OidObjectId());
-	DrgPmdid *pdrgpmdid = New(pmp) DrgPmdid(pmp);
+	DrgPmdid *pdrgpmdid = GPOS_NEW(pmp) DrgPmdid(pmp);
 	
 	ListCell *plc = NULL;
 	
@@ -3609,7 +3609,7 @@ CTranslatorRelcacheToDXL::PdrgpmdidScOpOpClasses
 	)
 {
 	List *plOpClasses = gpdb::PlScOpOpClasses(CMDIdGPDB::PmdidConvert(pmdidScOp)->OidObjectId());
-	DrgPmdid *pdrgpmdid = New(pmp) DrgPmdid(pmp);
+	DrgPmdid *pdrgpmdid = GPOS_NEW(pmp) DrgPmdid(pmp);
 	
 	ListCell *plc = NULL;
 	

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/9b65a5ad/src/backend/gpopt/translate/CTranslatorScalarToDXL.cpp
----------------------------------------------------------------------
diff --git a/src/backend/gpopt/translate/CTranslatorScalarToDXL.cpp b/src/backend/gpopt/translate/CTranslatorScalarToDXL.cpp
index b758f11..2be912b 100644
--- a/src/backend/gpopt/translate/CTranslatorScalarToDXL.cpp
+++ b/src/backend/gpopt/translate/CTranslatorScalarToDXL.cpp
@@ -191,13 +191,13 @@ CTranslatorScalarToDXL::PdxlnScIdFromVar
 	{
 		ulId = m_pidgtorCol->UlNextId();
 	}
-	CMDName *pmdname = New(m_pmp) CMDName(m_pmp, pstr);
+	CMDName *pmdname = GPOS_NEW(m_pmp) CMDName(m_pmp, pstr);
 
 	// create a column reference for the given var
-	CDXLColRef *pdxlcr = New(m_pmp) CDXLColRef(m_pmp, pmdname, ulId);
+	CDXLColRef *pdxlcr = GPOS_NEW(m_pmp) CDXLColRef(m_pmp, pmdname, ulId);
 
 	// create the scalar ident operator
-	CDXLScalarIdent *pdxlopIdent = New(m_pmp) CDXLScalarIdent
+	CDXLScalarIdent *pdxlopIdent = GPOS_NEW(m_pmp) CDXLScalarIdent
 			(
 			m_pmp,
 			pdxlcr,
@@ -205,7 +205,7 @@ CTranslatorScalarToDXL::PdxlnScIdFromVar
 			);
 
 	// create the DXL node holding the scalar ident operator
-	CDXLNode *pdxln = New(m_pmp) CDXLNode(m_pmp, pdxlopIdent);
+	CDXLNode *pdxln = GPOS_NEW(m_pmp) CDXLNode(m_pmp, pdxlopIdent);
 
 	return pdxln;
 }
@@ -238,7 +238,7 @@ CTranslatorScalarToDXL::PdxlnScIdFromParam
 		return NULL;
 	}
 
-	return New(m_pmp) CDXLNode(m_pmp, pdxlopIdent);
+	return GPOS_NEW(m_pmp) CDXLNode(m_pmp, pdxlopIdent);
 }
 
 //---------------------------------------------------------------------------
@@ -261,8 +261,8 @@ CTranslatorScalarToDXL::PdxlnSubPlanFromSubPlan
 	const SubPlan * psubplan = (SubPlan *)pexpr;
 
 	// outer references
-	DrgPdxlcr *pdrgdxlcr = New(m_pmp) DrgPdxlcr(m_pmp);
-	DrgPmdid *pdrgmdid = New(m_pmp) DrgPmdid(m_pmp);
+	DrgPdxlcr *pdrgdxlcr = GPOS_NEW(m_pmp) DrgPdxlcr(m_pmp);
+	DrgPmdid *pdrgmdid = GPOS_NEW(m_pmp) DrgPmdid(m_pmp);
 
 	ListCell *plc = NULL;
 	ULONG ul = 0;
@@ -298,10 +298,10 @@ CTranslatorScalarToDXL::PdxlnSubPlanFromSubPlan
 			ulId = m_pidgtorCol->UlNextId();
 		}
 
-		CMDName *pmdname = New(m_pmp) CMDName(m_pmp, pstr);
+		CMDName *pmdname = GPOS_NEW(m_pmp) CMDName(m_pmp, pstr);
 
 		// create a column reference for the given var
-		CDXLColRef *pdxlcr = New(m_pmp) CDXLColRef(m_pmp, pmdname, ulId);
+		CDXLColRef *pdxlcr = GPOS_NEW(m_pmp) CDXLColRef(m_pmp, pmdname, ulId);
 
 		pdrgdxlcr->Append(pdxlcr);
 		pdrgmdid->Append(CTranslatorUtils::PmdidWithVersion(m_pmp,pvar->vartype));
@@ -318,7 +318,19 @@ CTranslatorScalarToDXL::PdxlnSubPlanFromSubPlan
 
 	// create the DXL node holding the scalar subplan
 	EdxlSubPlanType edxlsubplantype = CTranslatorUtils::Edxlsubplantype(psubplan->subLinkType);
-	CDXLNode *pdxln = New(m_pmp) CDXLNode(m_pmp, New(m_pmp) CDXLScalarSubPlan(m_pmp, pmdid, pdrgdxlcr, pdrgmdid, edxlsubplantype, pdxlnTestExpr));
+	CDXLNode *pdxln = GPOS_NEW(m_pmp) CDXLNode
+										(
+										m_pmp,
+										GPOS_NEW(m_pmp) CDXLScalarSubPlan
+															(
+															m_pmp,
+															pmdid,
+															pdrgdxlcr,
+															pdrgmdid,
+															edxlsubplantype,
+															pdxlnTestExpr
+															)
+										);
 
 	// get the actual sub plan from the plstmt
 	Plan *pplanChild = (Plan *) gpdb::PvListNth(m_pplstmt->subplans, psubplan->plan_id - 1);
@@ -463,11 +475,11 @@ CTranslatorScalarToDXL::PdxlnScDistCmpFromDistExpr
 	GPOS_ASSERT(NULL != pdxlnLeft);
 	GPOS_ASSERT(NULL != pdxlnRight);
 
-	CDXLScalarDistinctComp *pdxlop = New(m_pmp) CDXLScalarDistinctComp(m_pmp,
+	CDXLScalarDistinctComp *pdxlop = GPOS_NEW(m_pmp) CDXLScalarDistinctComp(m_pmp,
 			CTranslatorUtils::PmdidWithVersion(m_pmp, pdistexpr->opno));
 
 	// create the DXL node holding the scalar distinct comparison operator
-	CDXLNode *pdxln = New(m_pmp) CDXLNode(m_pmp, pdxlop);
+	CDXLNode *pdxln = GPOS_NEW(m_pmp) CDXLNode(m_pmp, pdxlop);
 
 	// add children in the right order
 	pdxln->AddChild(pdxlnLeft);
@@ -514,10 +526,10 @@ CTranslatorScalarToDXL::PdxlnScCmpFromOpExpr
 	// get operator name
 	const CWStringConst *pstr = PstrOpName(pmdid);
 
-	CDXLScalarComp *pdxlop = New(m_pmp) CDXLScalarComp(m_pmp, pmdid, New(m_pmp) CWStringConst(pstr->Wsz()));
+	CDXLScalarComp *pdxlop = GPOS_NEW(m_pmp) CDXLScalarComp(m_pmp, pmdid, GPOS_NEW(m_pmp) CWStringConst(pstr->Wsz()));
 
 	// create the DXL node holding the scalar comparison operator
-	CDXLNode *pdxln = New(m_pmp) CDXLNode(m_pmp, pdxlop);
+	CDXLNode *pdxln = GPOS_NEW(m_pmp) CDXLNode(m_pmp, pdxlop);
 
 	// add children in the right order
 	pdxln->AddChild(pdxlnLeft);
@@ -564,10 +576,10 @@ CTranslatorScalarToDXL::PdxlnScOpExprFromExpr
 	IMDId *pmdid = CTranslatorUtils::PmdidWithVersion(m_pmp, popexpr->opno);
 	const CWStringConst *pstr = PstrOpName(pmdid);
 
-	CDXLScalarOpExpr *pdxlop = New(m_pmp) CDXLScalarOpExpr(m_pmp, pmdid, pmdidReturnType, New(m_pmp) CWStringConst(pstr->Wsz()));
+	CDXLScalarOpExpr *pdxlop = GPOS_NEW(m_pmp) CDXLScalarOpExpr(m_pmp, pmdid, pmdidReturnType, GPOS_NEW(m_pmp) CWStringConst(pstr->Wsz()));
 
 	// create the DXL node holding the scalar opexpr
-	CDXLNode *pdxln = New(m_pmp) CDXLNode(m_pmp, pdxlop);
+	CDXLNode *pdxln = GPOS_NEW(m_pmp) CDXLNode(m_pmp, pdxlop);
 
 	// process arguments
 	TranslateScalarChildren(pdxln, popexpr->args, pmapvarcolid);
@@ -594,14 +606,14 @@ CTranslatorScalarToDXL::PdxlnScNullIfFromExpr
 
 	GPOS_ASSERT(2 == gpdb::UlListLength(pnullifexpr->args));
 
-	CDXLScalarNullIf *pdxlop = New(m_pmp) CDXLScalarNullIf
+	CDXLScalarNullIf *pdxlop = GPOS_NEW(m_pmp) CDXLScalarNullIf
 			(
 			m_pmp,
 			CTranslatorUtils::PmdidWithVersion(m_pmp, pnullifexpr->opno),
 			CTranslatorUtils::PmdidWithVersion(m_pmp, gpdb::OidExprType((Node *)pnullifexpr))
 			);
 
-	CDXLNode *pdxln = New(m_pmp) CDXLNode(m_pmp, pdxlop);
+	CDXLNode *pdxln = GPOS_NEW(m_pmp) CDXLNode(m_pmp, pdxlop);
 
 	// process arguments
 	TranslateScalarChildren(pdxln, pnullifexpr->args, pmapvarcolid);
@@ -670,16 +682,16 @@ CTranslatorScalarToDXL::PdxlnScArrayCompFromExpr
 		edxlarraycomptype = Edxlarraycomptypeall;
 	}
 
-	CDXLScalarArrayComp *pdxlop = New(m_pmp) CDXLScalarArrayComp
+	CDXLScalarArrayComp *pdxlop = GPOS_NEW(m_pmp) CDXLScalarArrayComp
 			(
 			m_pmp,
 			CTranslatorUtils::PmdidWithVersion(m_pmp, pscarrayopexpr->opno),
-			New(m_pmp) CWStringConst(pstr->Wsz()),
+			GPOS_NEW(m_pmp) CWStringConst(pstr->Wsz()),
 			edxlarraycomptype
 			);
 
 	// create the DXL node holding the scalar opexpr
-	CDXLNode *pdxln = New(m_pmp) CDXLNode(m_pmp, pdxlop);
+	CDXLNode *pdxln = GPOS_NEW(m_pmp) CDXLNode(m_pmp, pdxlop);
 
 	// add children in the right order
 	pdxln->AddChild(pdxlnLeft);
@@ -705,10 +717,10 @@ CTranslatorScalarToDXL::PdxlnScConstFromExpr
 	GPOS_ASSERT(IsA(pexpr, Const));
 	const Const *pconst = (Const *) pexpr;
 
-	CDXLNode *pdxln = New(m_pmp) CDXLNode
+	CDXLNode *pdxln = GPOS_NEW(m_pmp) CDXLNode
 									(
 									m_pmp,
-									New(m_pmp) CDXLScalarConstValue
+									GPOS_NEW(m_pmp) CDXLScalarConstValue
 												(
 												m_pmp,
 												Pdxldatum(pconst)
@@ -788,7 +800,7 @@ CTranslatorScalarToDXL::PdxlnScBoolExprFromExpr
 	GPOS_ASSERT(EdxlBoolExprTypeSentinel != boolexptype);
 
 	// create the DXL node holding the scalar boolean operator
-	CDXLNode *pdxln = New(m_pmp) CDXLNode(m_pmp, New(m_pmp) CDXLScalarBoolExpr(m_pmp, boolexptype));
+	CDXLNode *pdxln = GPOS_NEW(m_pmp) CDXLNode(m_pmp, GPOS_NEW(m_pmp) CDXLScalarBoolExpr(m_pmp, boolexptype));
 
 	ULONG ulCount = gpdb::UlListLength(pboolexpr->args);
 
@@ -864,10 +876,10 @@ CTranslatorScalarToDXL::PdxlnScBooleanTestFromExpr
 	GPOS_ASSERT(EdxlbooleantestSentinel != edxlbt && "Invalid boolean test type");
 
 	// create the DXL node holding the scalar boolean test operator
-	CDXLNode *pdxln = New(m_pmp) CDXLNode
+	CDXLNode *pdxln = GPOS_NEW(m_pmp) CDXLNode
 									(
 									m_pmp,
-									New(m_pmp) CDXLScalarBooleanTest(m_pmp,edxlbt)
+									GPOS_NEW(m_pmp) CDXLScalarBooleanTest(m_pmp,edxlbt)
 									);
 
 	CDXLNode *pdxlnArg = PdxlnScOpFromExpr(pbooleantest->arg, pmapvarcolid);
@@ -908,7 +920,7 @@ CTranslatorScalarToDXL::PdxlnScNullTestFromNullTest
 	}
 
 	// create the DXL node holding the scalar NullTest operator
-	CDXLNode *pdxln = New(m_pmp) CDXLNode(m_pmp, New(m_pmp) CDXLScalarNullTest(m_pmp, fIsNull));
+	CDXLNode *pdxln = GPOS_NEW(m_pmp) CDXLNode(m_pmp, GPOS_NEW(m_pmp) CDXLScalarNullTest(m_pmp, fIsNull));
 	pdxln->AddChild(pdxlnChild);
 
 	return pdxln;
@@ -933,13 +945,13 @@ CTranslatorScalarToDXL::PdxlnScCoalesceFromExpr
 	CoalesceExpr *pcoalesceexpr = (CoalesceExpr *) pexpr;
 	GPOS_ASSERT(NULL != pcoalesceexpr->args);
 
-	CDXLScalarCoalesce *pdxlop = New(m_pmp) CDXLScalarCoalesce
+	CDXLScalarCoalesce *pdxlop = GPOS_NEW(m_pmp) CDXLScalarCoalesce
 											(
 											m_pmp,
 											CTranslatorUtils::PmdidWithVersion(m_pmp, pcoalesceexpr->coalescetype)
 											);
 
-	CDXLNode *pdxln = New(m_pmp) CDXLNode(m_pmp, pdxlop);
+	CDXLNode *pdxln = GPOS_NEW(m_pmp) CDXLNode(m_pmp, pdxlop);
 
 	TranslateScalarChildren(pdxln, pcoalesceexpr->args, pmapvarcolid);
 
@@ -976,14 +988,14 @@ CTranslatorScalarToDXL::PdxlnScMinMaxFromExpr
 		emmt = CDXLScalarMinMax::EmmtMin;
 	}
 
-	CDXLScalarMinMax *pdxlop = New(m_pmp) CDXLScalarMinMax
+	CDXLScalarMinMax *pdxlop = GPOS_NEW(m_pmp) CDXLScalarMinMax
 											(
 											m_pmp,
-											New(m_pmp) CMDIdGPDB(pminmaxexpr->minmaxtype),
+											GPOS_NEW(m_pmp) CMDIdGPDB(pminmaxexpr->minmaxtype),
 											emmt
 											);
 
-	CDXLNode *pdxln = New(m_pmp) CDXLNode(m_pmp, pdxlop);
+	CDXLNode *pdxln = GPOS_NEW(m_pmp) CDXLNode(m_pmp, pdxlop);
 
 	TranslateScalarChildren(pdxln, pminmaxexpr->args, pmapvarcolid);
 
@@ -1074,12 +1086,12 @@ CTranslatorScalarToDXL::PdxlnScSwitchFromCaseExpr
 {
 	GPOS_ASSERT (NULL != pcaseexpr->arg);
 
-	CDXLScalarSwitch *pdxlop = New(m_pmp) CDXLScalarSwitch
+	CDXLScalarSwitch *pdxlop = GPOS_NEW(m_pmp) CDXLScalarSwitch
 												(
 												m_pmp,
 												CTranslatorUtils::PmdidWithVersion(m_pmp, pcaseexpr->casetype)
 												);
-	CDXLNode *pdxlnSwitch = New(m_pmp) CDXLNode(m_pmp, pdxlop);
+	CDXLNode *pdxlnSwitch = GPOS_NEW(m_pmp) CDXLNode(m_pmp, pdxlop);
 
 	// translate the switch expression
 	CDXLNode *pdxlnArg = PdxlnScOpFromExpr(pcaseexpr->arg, pmapvarcolid);
@@ -1091,8 +1103,8 @@ CTranslatorScalarToDXL::PdxlnScSwitchFromCaseExpr
 	{
 		CaseWhen *pexpr = (CaseWhen *) lfirst(plc);
 
-		CDXLScalarSwitchCase *pdxlopCase = New(m_pmp) CDXLScalarSwitchCase(m_pmp);
-		CDXLNode *pdxlnCase = New(m_pmp) CDXLNode(m_pmp, pdxlopCase);
+		CDXLScalarSwitchCase *pdxlopCase = GPOS_NEW(m_pmp) CDXLScalarSwitchCase(m_pmp);
+		CDXLNode *pdxlnCase = GPOS_NEW(m_pmp) CDXLNode(m_pmp, pdxlopCase);
 
 		CDXLNode *pdxlnCmpExpr = PdxlnScOpFromExpr(pexpr->expr, pmapvarcolid);
 		GPOS_ASSERT(NULL != pdxlnCmpExpr);
@@ -1136,13 +1148,13 @@ CTranslatorScalarToDXL::PdxlnScCaseTestFromExpr
 {
 	GPOS_ASSERT(IsA(pexpr, CaseTestExpr));
 	const CaseTestExpr *pcasetestexpr = (CaseTestExpr *) pexpr;
-	CDXLScalarCaseTest *pdxlop = New(m_pmp) CDXLScalarCaseTest
+	CDXLScalarCaseTest *pdxlop = GPOS_NEW(m_pmp) CDXLScalarCaseTest
 												(
 												m_pmp,
 												CTranslatorUtils::PmdidWithVersion(m_pmp, pcasetestexpr->typeId)
 												);
 
-	return New(m_pmp) CDXLNode(m_pmp, pdxlop);
+	return GPOS_NEW(m_pmp) CDXLNode(m_pmp, pdxlop);
 }
 
 //---------------------------------------------------------------------------
@@ -1167,13 +1179,13 @@ CTranslatorScalarToDXL::PdxlnScIfStmtFromCaseExpr
 
 	for (ULONG ul = 0; ul < ulWhenClauseCount; ul++)
 	{
-		CDXLScalarIfStmt *pdxlopIfstmtNew = New(m_pmp) CDXLScalarIfStmt
+		CDXLScalarIfStmt *pdxlopIfstmtNew = GPOS_NEW(m_pmp) CDXLScalarIfStmt
 															(
 															m_pmp,
 															CTranslatorUtils::PmdidWithVersion(m_pmp, pcaseexpr->casetype)
 															);
 
-		CDXLNode *pdxlnIfStmtNew = New(m_pmp) CDXLNode(m_pmp, pdxlopIfstmtNew);
+		CDXLNode *pdxlnIfStmtNew = GPOS_NEW(m_pmp) CDXLNode(m_pmp, pdxlopIfstmtNew);
 
 		CaseWhen *pexpr = (CaseWhen *) gpdb::PvListNth(pcaseexpr->args, ul);
 		GPOS_ASSERT(IsA(pexpr, CaseWhen));
@@ -1233,10 +1245,10 @@ CTranslatorScalarToDXL::PdxlnScCastFromRelabelType
 	GPOS_ASSERT(NULL != pdxlnChild);
 
 	// create the DXL node holding the scalar boolean operator
-	CDXLNode *pdxln = New(m_pmp) CDXLNode
+	CDXLNode *pdxln = GPOS_NEW(m_pmp) CDXLNode
 									(
 									m_pmp,
-									New(m_pmp) CDXLScalarCast
+									GPOS_NEW(m_pmp) CDXLScalarCast
 												(
 												m_pmp,
 												CTranslatorUtils::PmdidWithVersion(m_pmp, prelabeltype->resulttype),
@@ -1274,10 +1286,10 @@ CTranslatorScalarToDXL::PdxlnScCoerceFromCoerce
         GPOS_ASSERT(NULL != pdxlnChild);
 
         // create the DXL node holding the scalar boolean operator
-        CDXLNode *pdxln = New(m_pmp) CDXLNode
+        CDXLNode *pdxln = GPOS_NEW(m_pmp) CDXLNode
                                                                         (
                                                                         m_pmp,
-                                                                        New(m_pmp) CDXLScalarCoerceToDomain
+                                                                        GPOS_NEW(m_pmp) CDXLScalarCoerceToDomain
                                                                                                 (
                                                                                                 m_pmp,
                                                                                                 CTranslatorUtils::PmdidWithVersion(m_pmp, pcoerce->resulttype),
@@ -1311,10 +1323,10 @@ CTranslatorScalarToDXL::PdxlnScFuncExprFromFuncExpr
 	CMDIdGPDB *pmdidFunc = CTranslatorUtils::PmdidWithVersion(m_pmp, pfuncexpr->funcid);
 
 	// create the DXL node holding the scalar funcexpr
-	CDXLNode *pdxln = New(m_pmp) CDXLNode
+	CDXLNode *pdxln = GPOS_NEW(m_pmp) CDXLNode
 									(
 									m_pmp,
-									New(m_pmp) CDXLScalarFuncExpr
+									GPOS_NEW(m_pmp) CDXLScalarFuncExpr
 												(
 												m_pmp,
 												pmdidFunc,
@@ -1409,10 +1421,10 @@ CTranslatorScalarToDXL::PdxlnScAggrefFromAggref
 		pmdidResolvedRetType = CTranslatorUtils::PmdidWithVersion(m_pmp, paggref->aggtype);
 	}
 
-	CDXLScalarAggref *pdxlopAggref = New(m_pmp) CDXLScalarAggref(m_pmp, pmdidAgg, pmdidResolvedRetType, paggref->aggdistinct, edxlaggstage);
+	CDXLScalarAggref *pdxlopAggref = GPOS_NEW(m_pmp) CDXLScalarAggref(m_pmp, pmdidAgg, pmdidResolvedRetType, paggref->aggdistinct, edxlaggstage);
 
 	// create the DXL node holding the scalar aggref
-	CDXLNode *pdxln = New(m_pmp) CDXLNode(m_pmp, pdxlopAggref);
+	CDXLNode *pdxln = GPOS_NEW(m_pmp) CDXLNode(m_pmp, pdxlopAggref);
 
 	TranslateScalarChildren(pdxln, paggref->args, pmapvarcolid);
 
@@ -1522,8 +1534,8 @@ CTranslatorScalarToDXL::Pdxlwf
 	}
 	GPOS_ASSERT(EdxlfesSentinel != edxlfes && "Invalid window frame exclusion");
 
-	CDXLNode *pdxlnLeadEdge = New(m_pmp) CDXLNode(m_pmp, New(m_pmp) CDXLScalarWindowFrameEdge(m_pmp, true /* fLeading */, edxlfbLead));
-	CDXLNode *pdxlnTrailEdge = New(m_pmp) CDXLNode(m_pmp, New(m_pmp) CDXLScalarWindowFrameEdge(m_pmp, false /* fLeading */, edxlfbTrail));
+	CDXLNode *pdxlnLeadEdge = GPOS_NEW(m_pmp) CDXLNode(m_pmp, GPOS_NEW(m_pmp) CDXLScalarWindowFrameEdge(m_pmp, true /* fLeading */, edxlfbLead));
+	CDXLNode *pdxlnTrailEdge = GPOS_NEW(m_pmp) CDXLNode(m_pmp, GPOS_NEW(m_pmp) CDXLScalarWindowFrameEdge(m_pmp, false /* fLeading */, edxlfbTrail));
 
 	// translate the lead and trail value
 	if (NULL != pwindowframe->lead->val)
@@ -1536,7 +1548,7 @@ CTranslatorScalarToDXL::Pdxlwf
 		pdxlnTrailEdge->AddChild(PdxlnWindowFrameEdgeVal(pwindowframe->trail->val, pmapvarcolid, pdxlnNewChildScPrL, pfHasDistributedTables));
 	}
 
-	CDXLWindowFrame *pdxlWf = New(m_pmp) CDXLWindowFrame(m_pmp, edxlfs, edxlfes, pdxlnLeadEdge, pdxlnTrailEdge);
+	CDXLWindowFrame *pdxlWf = GPOS_NEW(m_pmp) CDXLWindowFrame(m_pmp, edxlfs, edxlfes, pdxlnLeadEdge, pdxlnTrailEdge);
 
 	return pdxlWf;
 }
@@ -1564,30 +1576,30 @@ CTranslatorScalarToDXL::PdxlnWindowFrameEdgeVal
 	{
 		GPOS_ASSERT(NULL != pdxlnNewChildScPrL);
 		CWStringConst strUnnamedCol(GPOS_WSZ_LIT("?column?"));
-		CMDName *pmdnameAlias = New(m_pmp) CMDName(m_pmp, &strUnnamedCol);
+		CMDName *pmdnameAlias = GPOS_NEW(m_pmp) CMDName(m_pmp, &strUnnamedCol);
 		ULONG ulPrElId = m_pidgtorCol->UlNextId();
 
 		// construct a projection element
-		CDXLNode *pdxlnPrEl = New(m_pmp) CDXLNode(m_pmp, New(m_pmp) CDXLScalarProjElem(m_pmp, ulPrElId, pmdnameAlias));
+		CDXLNode *pdxlnPrEl = GPOS_NEW(m_pmp) CDXLNode(m_pmp, GPOS_NEW(m_pmp) CDXLScalarProjElem(m_pmp, ulPrElId, pmdnameAlias));
 		pdxlnPrEl->AddChild(pdxlnVal);
 
 		// add it to the computed columns project list
 		pdxlnNewChildScPrL->AddChild(pdxlnPrEl);
 
 		// construct a new scalar ident
-		CDXLScalarIdent *pdxlopIdent = New(m_pmp) CDXLScalarIdent
+		CDXLScalarIdent *pdxlopIdent = GPOS_NEW(m_pmp) CDXLScalarIdent
 													(
 													m_pmp,
-													New(m_pmp) CDXLColRef
+													GPOS_NEW(m_pmp) CDXLColRef
 																(
 																m_pmp,
-																New(m_pmp) CMDName(m_pmp, &strUnnamedCol),
+																GPOS_NEW(m_pmp) CMDName(m_pmp, &strUnnamedCol),
 																ulPrElId
 																),
 													CTranslatorUtils::PmdidWithVersion(m_pmp, gpdb::OidExprType(const_cast<Node*>(pnode)))
 													);
 
-		pdxlnVal = New(m_pmp) CDXLNode(m_pmp, pdxlopIdent);
+		pdxlnVal = GPOS_NEW(m_pmp) CDXLNode(m_pmp, pdxlopIdent);
 	}
 
 	return pdxlnVal;
@@ -1644,7 +1656,7 @@ CTranslatorScalarToDXL::PdxlnScWindowref
 		GPOS_RAISE(gpdxl::ExmaDXL, gpdxl::ExmiQuery2DXLUnsupportedFeature, GPOS_WSZ_LIT("Window functions with outer references"));
 	}
 
-	CDXLScalarWindowRef *pdxlopWinref = New(m_pmp) CDXLScalarWindowRef
+	CDXLScalarWindowRef *pdxlopWinref = GPOS_NEW(m_pmp) CDXLScalarWindowRef
 													(
 													m_pmp,
 													CTranslatorUtils::PmdidWithVersion(m_pmp, pwindowref->winfnoid),
@@ -1655,7 +1667,7 @@ CTranslatorScalarToDXL::PdxlnScWindowref
 													);
 
 	// create the DXL node holding the scalar aggref
-	CDXLNode *pdxln = New(m_pmp) CDXLNode(m_pmp, pdxlopWinref);
+	CDXLNode *pdxln = GPOS_NEW(m_pmp) CDXLNode(m_pmp, pdxlopWinref);
 
 	TranslateScalarChildren(pdxln, pwindowref->args, pmapvarcolid);
 
@@ -1693,7 +1705,7 @@ CTranslatorScalarToDXL::PdxlnScCondFromQual
 	{
 		// GPDB assumes that if there are a list of qual conditions then it is an implicit AND operation
 		// Here we build the left deep AND tree
-		CDXLNode *pdxln = New(m_pmp) CDXLNode(m_pmp, New(m_pmp) CDXLScalarBoolExpr(m_pmp, Edxland));
+		CDXLNode *pdxln = GPOS_NEW(m_pmp) CDXLNode(m_pmp, GPOS_NEW(m_pmp) CDXLScalarBoolExpr(m_pmp, Edxland));
 
 		TranslateScalarChildren(pdxln, plQual, pmapvarcolid, pfHasDistributedTables);
 
@@ -1724,20 +1736,20 @@ CTranslatorScalarToDXL::PdxlnFilterFromQual
 	switch (edxlopFilterType)
 	{
 		case EdxlopScalarFilter:
-			pdxlop = New(m_pmp) CDXLScalarFilter(m_pmp);
+			pdxlop = GPOS_NEW(m_pmp) CDXLScalarFilter(m_pmp);
 			break;
 		case EdxlopScalarJoinFilter:
-			pdxlop = New(m_pmp) CDXLScalarJoinFilter(m_pmp);
+			pdxlop = GPOS_NEW(m_pmp) CDXLScalarJoinFilter(m_pmp);
 			break;
 		case EdxlopScalarOneTimeFilter:
-			pdxlop = New(m_pmp) CDXLScalarOneTimeFilter(m_pmp);
+			pdxlop = GPOS_NEW(m_pmp) CDXLScalarOneTimeFilter(m_pmp);
 			break;
 		default:
 			GPOS_ASSERT(!"Unrecognized filter type");
 	}
 
 
-	CDXLNode *pdxlnFilter = New(m_pmp) CDXLNode(m_pmp, pdxlop);
+	CDXLNode *pdxlnFilter = GPOS_NEW(m_pmp) CDXLNode(m_pmp, pdxlop);
 
 	CDXLNode *pdxlnCond = PdxlnScCondFromQual(plQual, pmapvarcolid, pfHasDistributedTables);
 
@@ -1861,27 +1873,27 @@ CTranslatorScalarToDXL::PdxlnQuantifiedSubqueryFromSublink
 	GPOS_ASSERT(ALL_SUBLINK == psublink->subLinkType || ANY_SUBLINK == psublink->subLinkType);
 	if (ALL_SUBLINK == psublink->subLinkType)
 	{
-		pdxlopSubquery = New (m_pmp) CDXLScalarSubqueryAll
+		pdxlopSubquery = GPOS_NEW(m_pmp) CDXLScalarSubqueryAll
 								(
 								m_pmp,
 								pmdid,
-								New(m_pmp) CMDName(m_pmp, pstr),
+								GPOS_NEW(m_pmp) CMDName(m_pmp, pstr),
 								ulColId
 								);
 
 	}
 	else
 	{
-		pdxlopSubquery = New (m_pmp) CDXLScalarSubqueryAny
+		pdxlopSubquery = GPOS_NEW(m_pmp) CDXLScalarSubqueryAny
 								(
 								m_pmp,
 								pmdid,
-								New(m_pmp) CMDName(m_pmp, pstr),
+								GPOS_NEW(m_pmp) CMDName(m_pmp, pstr),
 								ulColId
 								);
 	}
 
-	pdxln = New(m_pmp) CDXLNode(m_pmp, pdxlopSubquery);
+	pdxln = GPOS_NEW(m_pmp) CDXLNode(m_pmp, pdxlopSubquery);
 
 	pdxln->AddChild(pdxlnOuter);
 	pdxln->AddChild(pdxlnInner);
@@ -1942,7 +1954,7 @@ CTranslatorScalarToDXL::PdxlnScSubqueryFromSublink
 	const CDXLColRef *pdxlcr = pdxlopIdent->Pdxlcr();
 	const ULONG ulColId = pdxlcr->UlID();
 
-	CDXLNode *pdxln = New(m_pmp) CDXLNode(m_pmp, New (m_pmp) CDXLScalarSubquery(m_pmp, ulColId));
+	CDXLNode *pdxln = GPOS_NEW(m_pmp) CDXLNode(m_pmp, GPOS_NEW(m_pmp) CDXLScalarSubquery(m_pmp, ulColId));
 
 	pdxln->AddChild(pdxlnSubQuery);
 
@@ -1969,7 +1981,7 @@ CTranslatorScalarToDXL::PdxlnArray
 	const ArrayExpr *parrayexpr = (ArrayExpr *) pexpr;
 
 	CDXLScalarArray *pdxlop =
-			New(m_pmp) CDXLScalarArray
+			GPOS_NEW(m_pmp) CDXLScalarArray
 						(
 						m_pmp,
 						CTranslatorUtils::PmdidWithVersion(m_pmp, parrayexpr->element_typeid),
@@ -1977,7 +1989,7 @@ CTranslatorScalarToDXL::PdxlnArray
 						parrayexpr->multidims
 						);
 
-	CDXLNode *pdxln = New(m_pmp) CDXLNode(m_pmp, pdxlop);
+	CDXLNode *pdxln = GPOS_NEW(m_pmp) CDXLNode(m_pmp, pdxlop);
 
 	TranslateScalarChildren(pdxln, parrayexpr->elements, pmapvarcolid);
 
@@ -2004,7 +2016,7 @@ CTranslatorScalarToDXL::PdxlnArrayRef
 	const ArrayRef *parrayref = (ArrayRef *) pexpr;
 
 	CDXLScalarArrayRef *pdxlop =
-			New(m_pmp) CDXLScalarArrayRef
+			GPOS_NEW(m_pmp) CDXLScalarArrayRef
 						(
 						m_pmp,
 						CTranslatorUtils::PmdidWithVersion(m_pmp, parrayref->refelemtype),
@@ -2012,7 +2024,7 @@ CTranslatorScalarToDXL::PdxlnArrayRef
 						CTranslatorUtils::PmdidWithVersion(m_pmp, parrayref->refrestype)
 						);
 
-	CDXLNode *pdxln = New(m_pmp) CDXLNode(m_pmp, pdxlop);
+	CDXLNode *pdxln = GPOS_NEW(m_pmp) CDXLNode(m_pmp, pdxlop);
 
 	// add children
 	AddArrayIndexList(pdxln, parrayref->reflowerindexpr, CDXLScalarArrayRefIndexList::EilbLower, pmapvarcolid);
@@ -2050,10 +2062,10 @@ CTranslatorScalarToDXL::AddArrayIndexList
 	GPOS_ASSERT(CDXLScalarArrayRefIndexList::EilbSentinel > eilb);
 
 	CDXLNode *pdxlnIndexList =
-			New(m_pmp) CDXLNode
+			GPOS_NEW(m_pmp) CDXLNode
 					(
 					m_pmp,
-					New(m_pmp) CDXLScalarArrayRefIndexList(m_pmp, eilb)
+					GPOS_NEW(m_pmp) CDXLScalarArrayRefIndexList(m_pmp, eilb)
 					);
 
 	TranslateScalarChildren(pdxlnIndexList, plist, pmapvarcolid);
@@ -2119,7 +2131,7 @@ CTranslatorScalarToDXL::PdxlnExistSubqueryFromSublink
 	CUtils::AddRefAppend(m_pdrgpdxlnCTE, pdrgpdxlnCTE);
 	m_fHasDistributedTables = m_fHasDistributedTables || ptrquerytodxl->FHasDistributedTables();
 	
-	CDXLNode *pdxln = New(m_pmp) CDXLNode(m_pmp, New (m_pmp) CDXLScalarSubqueryExists(m_pmp));
+	CDXLNode *pdxln = GPOS_NEW(m_pmp) CDXLNode(m_pmp, GPOS_NEW(m_pmp) CDXLScalarSubqueryExists(m_pmp));
 	pdxln->AddChild(pdxlnRoot);
 
 	return pdxln;
@@ -2176,7 +2188,7 @@ CTranslatorScalarToDXL::PdxlnInitPlanFromParam
 	GPOS_ASSERT(NULL != pparam);
 
 	// TODO: Venky; Need to handle when parameters that are passed to the plan
-	CDXLNode *pdxlnInitPlan = New(m_pmp) CDXLNode(m_pmp, New(m_pmp) CDXLScalarInitPlan(m_pmp));
+	CDXLNode *pdxlnInitPlan = GPOS_NEW(m_pmp) CDXLNode(m_pmp, GPOS_NEW(m_pmp) CDXLScalarInitPlan(m_pmp));
 
 	GPOS_ASSERT(NULL != m_pplstmt->subplans && "We only support parameters that are generated by initplans");
 
@@ -2264,7 +2276,7 @@ CTranslatorScalarToDXL::PdxldatumGeneric
 	)
 {
 	CMDIdGPDB *pmdidMDC = CMDIdGPDB::PmdidConvert(pmdtype->Pmdid());
-	CMDIdGPDB *pmdid = New(pmp) CMDIdGPDB(*pmdidMDC);
+	CMDIdGPDB *pmdid = GPOS_NEW(pmp) CMDIdGPDB(*pmdidMDC);
 
 	BOOL fConstByVal = pmdtype->FByValue();
 	BYTE *pba = Pba(pmp, pmdtype, fNull, ulLen, datum);
@@ -2309,9 +2321,9 @@ CTranslatorScalarToDXL::PdxldatumBool
 {
 	GPOS_ASSERT(pmdtype->FByValue());
 	CMDIdGPDB *pmdidMDC = CMDIdGPDB::PmdidConvert(pmdtype->Pmdid());
-	CMDIdGPDB *pmdid = New(pmp) CMDIdGPDB(*pmdidMDC);
+	CMDIdGPDB *pmdid = GPOS_NEW(pmp) CMDIdGPDB(*pmdidMDC);
 
-	return New(pmp) CDXLDatumBool(pmp, pmdid, fNull, gpdb::FBoolFromDatum(datum));
+	return GPOS_NEW(pmp) CDXLDatumBool(pmp, pmdid, fNull, gpdb::FBoolFromDatum(datum));
 }
 
 
@@ -2334,9 +2346,9 @@ CTranslatorScalarToDXL::PdxldatumOid
 {
 	GPOS_ASSERT(pmdtype->FByValue());
 	CMDIdGPDB *pmdidMDC = CMDIdGPDB::PmdidConvert(pmdtype->Pmdid());
-	CMDIdGPDB *pmdid = New(pmp) CMDIdGPDB(*pmdidMDC);
+	CMDIdGPDB *pmdid = GPOS_NEW(pmp) CMDIdGPDB(*pmdidMDC);
 
-	return New(pmp) CDXLDatumOid(pmp, pmdid, fNull, gpdb::OidFromDatum(datum));
+	return GPOS_NEW(pmp) CDXLDatumOid(pmp, pmdid, fNull, gpdb::OidFromDatum(datum));
 }
 
 
@@ -2359,9 +2371,9 @@ CTranslatorScalarToDXL::PdxldatumInt2
 {
 	GPOS_ASSERT(pmdtype->FByValue());
 	CMDIdGPDB *pmdidMDC = CMDIdGPDB::PmdidConvert(pmdtype->Pmdid());
-	CMDIdGPDB *pmdid = New(pmp) CMDIdGPDB(*pmdidMDC);
+	CMDIdGPDB *pmdid = GPOS_NEW(pmp) CMDIdGPDB(*pmdidMDC);
 
-	return New(pmp) CDXLDatumInt2(pmp, pmdid, fNull, gpdb::SInt16FromDatum(datum));
+	return GPOS_NEW(pmp) CDXLDatumInt2(pmp, pmdid, fNull, gpdb::SInt16FromDatum(datum));
 }
 
 
@@ -2384,9 +2396,9 @@ CTranslatorScalarToDXL::PdxldatumInt4
 {
 	GPOS_ASSERT(pmdtype->FByValue());
 	CMDIdGPDB *pmdidMDC = CMDIdGPDB::PmdidConvert(pmdtype->Pmdid());
-	CMDIdGPDB *pmdid = New(pmp) CMDIdGPDB(*pmdidMDC);
+	CMDIdGPDB *pmdid = GPOS_NEW(pmp) CMDIdGPDB(*pmdidMDC);
 
-	return New(pmp) CDXLDatumInt4(pmp, pmdid, fNull, gpdb::IInt32FromDatum(datum));
+	return GPOS_NEW(pmp) CDXLDatumInt4(pmp, pmdid, fNull, gpdb::IInt32FromDatum(datum));
 }
 
 
@@ -2409,9 +2421,9 @@ CTranslatorScalarToDXL::PdxldatumInt8
 {
 	GPOS_ASSERT(pmdtype->FByValue());
 	CMDIdGPDB *pmdidMDC = CMDIdGPDB::PmdidConvert(pmdtype->Pmdid());
-	CMDIdGPDB *pmdid = New(pmp) CMDIdGPDB(*pmdidMDC);
+	CMDIdGPDB *pmdid = GPOS_NEW(pmp) CMDIdGPDB(*pmdidMDC);
 
-	return New(pmp) CDXLDatumInt8(pmp, pmdid, fNull, gpdb::LlInt64FromDatum(datum));
+	return GPOS_NEW(pmp) CDXLDatumInt8(pmp, pmdid, fNull, gpdb::LlInt64FromDatum(datum));
 }
 
 
@@ -2514,7 +2526,7 @@ CTranslatorScalarToDXL::Pba
 	ulLength = (ULONG) gpdb::SDatumSize(datum, pmdtype->FByValue(), ulLen);
 	GPOS_ASSERT(ulLength > 0);
 
-	pba = New(pmp) BYTE[ulLength];
+	pba = GPOS_NEW_ARRAY(pmp, BYTE, ulLength);
 
 	if (pmdtype->FByValue())
 	{

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/9b65a5ad/src/backend/gpopt/translate/CTranslatorUtils.cpp
----------------------------------------------------------------------
diff --git a/src/backend/gpopt/translate/CTranslatorUtils.cpp b/src/backend/gpopt/translate/CTranslatorUtils.cpp
index f0ac652..30f00a8 100644
--- a/src/backend/gpopt/translate/CTranslatorUtils.cpp
+++ b/src/backend/gpopt/translate/CTranslatorUtils.cpp
@@ -139,13 +139,13 @@ CTranslatorUtils::PreloadMD
 	const IMDType *pmdtypeOid = pmda->PtMDType<IMDTypeOid>(sysid);
 	PreloadMDType(pmda, pmdtypeOid);
 
-	CMDIdGPDB *pmdidDate = New(pmp) CMDIdGPDB(CMDIdGPDB::m_mdidDate.OidObjectId());
+	CMDIdGPDB *pmdidDate = GPOS_NEW(pmp) CMDIdGPDB(CMDIdGPDB::m_mdidDate.OidObjectId());
 	(void) pmda->Pmdtype(pmdidDate);
 
-	CMDIdGPDB *pmdidNumeric = New(pmp) CMDIdGPDB(CMDIdGPDB::m_mdidNumeric.OidObjectId());
+	CMDIdGPDB *pmdidNumeric = GPOS_NEW(pmp) CMDIdGPDB(CMDIdGPDB::m_mdidNumeric.OidObjectId());
 	(void) pmda->Pmdtype(pmdidNumeric);
 
-	CMDIdGPDB *pmdidTimestamp = New(pmp) CMDIdGPDB(CMDIdGPDB::m_mdidTimestamp.OidObjectId());
+	CMDIdGPDB *pmdidTimestamp = GPOS_NEW(pmp) CMDIdGPDB(CMDIdGPDB::m_mdidTimestamp.OidObjectId());
 	(void) pmda->Pmdtype(pmdidTimestamp);
 
 	pmdidDate->Release();
@@ -263,7 +263,7 @@ CTranslatorUtils::PreloadMDStats
 	for (ULONG ulAttNo = 0; ulAttNo < pmdrelation->UlColumns(); ulAttNo++)
 	{
 		pmdidgpdbRel->AddRef();
-		CMDIdColStats *pmdidColStats = New(pmp) CMDIdColStats(pmdidgpdbRel, ulAttNo);
+		CMDIdColStats *pmdidColStats = GPOS_NEW(pmp) CMDIdColStats(pmdidgpdbRel, ulAttNo);
 		(void *) pmda->Pmdcolstats(pmdidColStats);
 		pmdidColStats->Release();
 	}
@@ -271,7 +271,7 @@ CTranslatorUtils::PreloadMDStats
 	// preload relation stats
 	{
 		pmdidgpdbRel->AddRef();
-		CMDIdRelStats *pmdidRelStats = New(pmp) CMDIdRelStats(pmdidgpdbRel);
+		CMDIdRelStats *pmdidRelStats = GPOS_NEW(pmp) CMDIdRelStats(pmdidgpdbRel);
 		(void *) pmda->Pmdrelstats(pmdidRelStats);
 		pmdidRelStats->Release();
 	}
@@ -368,7 +368,7 @@ CTranslatorUtils::PmdidWithVersion
 	}
 
 	// TODO: gcaragea - Feb 6, 2015; Refactor CMDIdGPDB to eliminate need for casting
-	return New(pmp) CMDIdGPDB(oidObj, (ULONG) ullDDLv, (ULONG) ullDMLv);
+	return GPOS_NEW(pmp) CMDIdGPDB(oidObj, (ULONG) ullDDLv, (ULONG) ullDMLv);
 }
 
 
@@ -390,9 +390,9 @@ CTranslatorUtils::Pdxlid
 {
 	const IMDIndex *pmdindex = pmda->Pmdindex(pmdid);
 	const CWStringConst *pstrIndexName = pmdindex->Mdname().Pstr();
-	CMDName *pmdnameIdx = New(pmp) CMDName(pmp, pstrIndexName);
+	CMDName *pmdnameIdx = GPOS_NEW(pmp) CMDName(pmp, pstrIndexName);
 
-	return New (pmp) CDXLIndexDescr(pmp, pmdid, pmdnameIdx);
+	return GPOS_NEW(pmp) CDXLIndexDescr(pmp, pmdid, pmdnameIdx);
 }
 
 //---------------------------------------------------------------------------
@@ -421,9 +421,9 @@ CTranslatorUtils::Pdxltabdesc
 	
 	// look up table name
 	const CWStringConst *pstrTblName = pmdrel->Mdname().Pstr();
-	CMDName *pmdnameTbl = New(pmp) CMDName(pmp, pstrTblName);
+	CMDName *pmdnameTbl = GPOS_NEW(pmp) CMDName(pmp, pstrTblName);
 
-	CDXLTableDescr *pdxltabdesc = New(pmp) CDXLTableDescr(pmp, pmdid, pmdnameTbl, prte->checkAsUser);
+	CDXLTableDescr *pdxltabdesc = GPOS_NEW(pmp) CDXLTableDescr(pmp, pmdid, pmdnameTbl, prte->checkAsUser);
 
 	const ULONG ulLen = pmdrel->UlColumns();
 	
@@ -450,12 +450,12 @@ CTranslatorUtils::Pdxltabdesc
 			continue;
 		}
 		
-		CMDName *pmdnameCol = New(pmp) CMDName(pmp, pmdcol->Mdname().Pstr());
+		CMDName *pmdnameCol = GPOS_NEW(pmp) CMDName(pmp, pmdcol->Mdname().Pstr());
 		CMDIdGPDB *pmdidColType = CMDIdGPDB::PmdidConvert(pmdcol->PmdidType());
 		pmdidColType->AddRef();
 
 		// create a column descriptor for the column
-		CDXLColDescr *pdxlcd = New(pmp) CDXLColDescr
+		CDXLColDescr *pdxlcd = GPOS_NEW(pmp) CDXLColDescr
 											(
 											pmp,
 											pmdnameCol,
@@ -608,9 +608,9 @@ CTranslatorUtils::Pdxltvf
 		pdrgdxlcd = PdrgdxlcdBase(pmp, pidgtor, pmdidRetType, &mdnameFunc);
 	}
 
-	CMDName *pmdfuncname = New(pmp) CMDName(pmp, pmdfunc->Mdname().Pstr());
+	CMDName *pmdfuncname = GPOS_NEW(pmp) CMDName(pmp, pmdfunc->Mdname().Pstr());
 
-	CDXLLogicalTVF *pdxlopTVF = New(pmp) CDXLLogicalTVF(pmp, pmdidFunc, pmdidRetType, pmdfuncname, pdrgdxlcd);
+	CDXLLogicalTVF *pdxlopTVF = GPOS_NEW(pmp) CDXLLogicalTVF(pmp, pmdidFunc, pmdidRetType, pmdfuncname, pdrgdxlcd);
 
 	return pdxlopTVF;
 }
@@ -667,7 +667,7 @@ CTranslatorUtils::PdrgpmdidResolvePolymorphicTypes
 	}
 
 	// generate a new array of mdids based on the resolved types
-	DrgPmdid *pdrgpmdidResolved = New(pmp) DrgPmdid(pmp);
+	DrgPmdid *pdrgpmdidResolved = GPOS_NEW(pmp) DrgPmdid(pmp);
 
 	const ULONG ulLen = pdrgpmdidTypes->UlLength();
 	for (ULONG ul = 0; ul < ulLen; ul++)
@@ -780,7 +780,7 @@ CTranslatorUtils::PdrgdxlcdRecord
 	ListCell *plcColType = NULL;
 
 	ULONG ul = 0;
-	DrgPdxlcd *pdrgdxlcd = New(pmp) DrgPdxlcd(pmp);
+	DrgPdxlcd *pdrgdxlcd = GPOS_NEW(pmp) DrgPdxlcd(pmp);
 
 	ForBoth (plcColName, plColNames,
 			plcColType, plColTypes)
@@ -790,12 +790,12 @@ CTranslatorUtils::PdrgdxlcdRecord
 
 		CHAR *szColName = strVal(pvalue);
 		CWStringDynamic *pstrColName = CDXLUtils::PstrFromSz(pmp, szColName);
-		CMDName *pmdColName = New(pmp) CMDName(pmp, pstrColName);
-		delete(pstrColName);
+		CMDName *pmdColName = GPOS_NEW(pmp) CMDName(pmp, pstrColName);
+		GPOS_DELETE(pstrColName);
 
 		IMDId *pmdidColType = CTranslatorUtils::PmdidWithVersion(pmp, coltype);
 
-		CDXLColDescr *pdxlcd = New(pmp) CDXLColDescr
+		CDXLColDescr *pdxlcd = GPOS_NEW(pmp) CDXLColDescr
 										(
 										pmp,
 										pmdColName,
@@ -832,7 +832,7 @@ CTranslatorUtils::PdrgdxlcdRecord
 	ListCell *plcColName = NULL;
 
 	ULONG ul = 0;
-	DrgPdxlcd *pdrgdxlcd = New(pmp) DrgPdxlcd(pmp);
+	DrgPdxlcd *pdrgdxlcd = GPOS_NEW(pmp) DrgPdxlcd(pmp);
 
 	ForEach (plcColName, plColNames)
 	{
@@ -840,13 +840,13 @@ CTranslatorUtils::PdrgdxlcdRecord
 
 		CHAR *szColName = strVal(pvalue);
 		CWStringDynamic *pstrColName = CDXLUtils::PstrFromSz(pmp, szColName);
-		CMDName *pmdColName = New(pmp) CMDName(pmp, pstrColName);
-		delete(pstrColName);
+		CMDName *pmdColName = GPOS_NEW(pmp) CMDName(pmp, pstrColName);
+		GPOS_DELETE(pstrColName);
 
 		IMDId *pmdidColType = (*pdrgpmdidOutArgTypes)[ul];
 		pmdidColType->AddRef();
 
-		CDXLColDescr *pdxlcd = New(pmp) CDXLColDescr
+		CDXLColDescr *pdxlcd = GPOS_NEW(pmp) CDXLColDescr
 										(
 										pmp,
 										pmdColName,
@@ -879,12 +879,12 @@ CTranslatorUtils::PdrgdxlcdBase
 	CMDName *pmdName
 	)
 {
-	DrgPdxlcd *pdrgdxlcd = New(pmp) DrgPdxlcd(pmp);
+	DrgPdxlcd *pdrgdxlcd = GPOS_NEW(pmp) DrgPdxlcd(pmp);
 
 	pmdidRetType->AddRef();
-	CMDName *pmdColName = New(pmp) CMDName(pmp, pmdName->Pstr());
+	CMDName *pmdColName = GPOS_NEW(pmp) CMDName(pmp, pmdName->Pstr());
 
-	CDXLColDescr *pdxlcd = New(pmp) CDXLColDescr
+	CDXLColDescr *pdxlcd = GPOS_NEW(pmp) CDXLColDescr
 									(
 									pmp,
 									pmdColName,
@@ -918,17 +918,17 @@ CTranslatorUtils::PdrgdxlcdComposite
 {
 	DrgPmdcol *pdrgPmdCol = ExpandCompositeType(pmp, pmda, pmdType);
 
-	DrgPdxlcd *pdrgdxlcd = New(pmp) DrgPdxlcd(pmp);
+	DrgPdxlcd *pdrgdxlcd = GPOS_NEW(pmp) DrgPdxlcd(pmp);
 
 	for (ULONG ul = 0; ul < pdrgPmdCol->UlLength(); ul++)
 	{
 		CMDColumn *pmdcol = (*pdrgPmdCol)[ul];
 
-		CMDName *pmdColName = New(pmp) CMDName(pmp, pmdcol->Mdname().Pstr());
+		CMDName *pmdColName = GPOS_NEW(pmp) CMDName(pmp, pmdcol->Mdname().Pstr());
 		IMDId *pmdidColType = pmdcol->PmdidType();
 
 		pmdidColType->AddRef();
-		CDXLColDescr *pdxlcd = New(pmp) CDXLColDescr
+		CDXLColDescr *pdxlcd = GPOS_NEW(pmp) CDXLColDescr
 										(
 										pmp,
 										pmdColName,
@@ -968,7 +968,7 @@ CTranslatorUtils::ExpandCompositeType
 	const IMDRelation *pmdrel = pmda->Pmdrel(pmdidRel);
 	GPOS_ASSERT(NULL != pmdrel);
 
-	DrgPmdcol *pdrgPmdcol = New(pmp) DrgPmdcol(pmp);
+	DrgPmdcol *pdrgPmdcol = GPOS_NEW(pmp) DrgPmdcol(pmp);
 
 	for(ULONG ul = 0; ul < pmdrel->UlColumns(); ul++)
 	{
@@ -1394,7 +1394,7 @@ CTranslatorUtils::PtemapCopy
 	TEMap *ptemap
 	)
 {
-	TEMap *ptemapCopy = New(pmp) TEMap(pmp);
+	TEMap *ptemapCopy = GPOS_NEW(pmp) TEMap(pmp);
 
 	// iterate over full map
 	TEMapIter temapiter(ptemap);
@@ -1403,7 +1403,7 @@ CTranslatorUtils::PtemapCopy
 		CMappingElementColIdTE *pmapelement =  const_cast<CMappingElementColIdTE *>(temapiter.Pt());
 
 		const ULONG ulColId = pmapelement->UlColId();
-		ULONG *pulKey1 = New(pmp) ULONG(ulColId);
+		ULONG *pulKey1 = GPOS_NEW(pmp) ULONG(ulColId);
 		pmapelement->AddRef();
 
 #ifdef GPOS_DEBUG
@@ -1521,7 +1521,7 @@ CTranslatorUtils::PdrgpulGroupingCols
 	HMIUl *phmiulSortGrpColsColId
 	)
 {
-	DrgPul *pdrgpul = New (pmp) DrgPul(pmp);
+	DrgPul *pdrgpul = GPOS_NEW(pmp) DrgPul(pmp);
 
 	if (NULL != pbsGroupByCols)
 	{
@@ -1530,7 +1530,7 @@ CTranslatorUtils::PdrgpulGroupingCols
 		while (bsi.FAdvance())
 		{
 			const ULONG ulColId = UlColId(bsi.UlBit(), phmiulSortGrpColsColId);
-			pdrgpul->Append(New(pmp) ULONG(ulColId));
+			pdrgpul->Append(GPOS_NEW(pmp) ULONG(ulColId));
 		}
 	}
 
@@ -1566,7 +1566,7 @@ CTranslatorUtils::PdrgpbsGroupBy
 	{
 		// simple group by
 		CBitSet *pbsGroupingSet = PbsGroupingSet(pmp, plGroupClause, ulCols, phmululGrpColPos, pbsGrpCols);
-		DrgPbs *pdrgpbs = New(pmp) DrgPbs(pmp);
+		DrgPbs *pdrgpbs = GPOS_NEW(pmp) DrgPbs(pmp);
 		pdrgpbs->Append(pbsGroupingSet);
 		return pdrgpbs;
 	}
@@ -1594,7 +1594,7 @@ CTranslatorUtils::PdrgpbsGroupBy
 		GPOS_RAISE(gpdxl::ExmaDXL, gpdxl::ExmiQuery2DXLUnsupportedFeature, GPOS_WSZ_LIT("Rollup and cube"));
 	}
 
-	DrgPbs *pdrgpbs = New(pmp) DrgPbs(pmp);
+	DrgPbs *pdrgpbs = GPOS_NEW(pmp) DrgPbs(pmp);
 
 	ListCell *plcGroupingSet = NULL;
 	ForEach (plcGroupingSet, pgrcl->groupsets)
@@ -1605,7 +1605,7 @@ CTranslatorUtils::PdrgpbsGroupBy
 		if (IsA(pnodeGroupingSet, GroupClause))
 		{
 			// grouping set contains a single grouping column
-			pbs = New(pmp) CBitSet(pmp, ulCols);
+			pbs = GPOS_NEW(pmp) CBitSet(pmp, ulCols);
 			ULONG ulSortGrpRef = ((GroupClause *) pnodeGroupingSet)->tleSortGroupRef;
 			pbs->FExchangeSet(ulSortGrpRef);
 			UpdateGrpColMapping(pmp, phmululGrpColPos, pbsGrpCols, ulSortGrpRef);
@@ -1648,12 +1648,12 @@ CTranslatorUtils::PdrgpbsRollup
 {
 	GPOS_ASSERT(NULL != pgrcl);
 
-	DrgPbs *pdrgpbsGroupingSets = New(pmp) DrgPbs(pmp);
+	DrgPbs *pdrgpbsGroupingSets = GPOS_NEW(pmp) DrgPbs(pmp);
 	ListCell *plcGroupingSet = NULL;
 	ForEach (plcGroupingSet, pgrcl->groupsets)
 	{
 		Node *pnode = (Node *) lfirst(plcGroupingSet);
-		CBitSet *pbs = New(pmp) CBitSet(pmp);
+		CBitSet *pbs = GPOS_NEW(pmp) CBitSet(pmp);
 		if (IsA(pnode, GroupClause))
 		{
 			// simple group clause, create a singleton grouping set
@@ -1694,12 +1694,12 @@ CTranslatorUtils::PdrgpbsRollup
 	}
 
 	const ULONG ulGroupingSets = pdrgpbsGroupingSets->UlLength();
-	DrgPbs *pdrgpbs = New(pmp) DrgPbs(pmp);
+	DrgPbs *pdrgpbs = GPOS_NEW(pmp) DrgPbs(pmp);
 
 	// compute prefixes of grouping sets array
 	for (ULONG ulPrefix = 0; ulPrefix <= ulGroupingSets; ulPrefix++)
 	{
-		CBitSet *pbs = New(pmp) CBitSet(pmp);
+		CBitSet *pbs = GPOS_NEW(pmp) CBitSet(pmp);
 		for (ULONG ulIdx = 0; ulIdx < ulPrefix; ulIdx++)
 		{
 			CBitSet *pbsCurrent = (*pdrgpbsGroupingSets)[ulIdx];
@@ -1734,7 +1734,7 @@ CTranslatorUtils::PbsGroupingSet
 	GPOS_ASSERT(NULL != plGroupElems);
 	GPOS_ASSERT(0 < gpdb::UlListLength(plGroupElems));
 
-	CBitSet *pbs = New(pmp) CBitSet(pmp, ulCols);
+	CBitSet *pbs = GPOS_NEW(pmp) CBitSet(pmp, ulCols);
 
 	ListCell *plc = NULL;
 	ForEach (plc, plGroupElems)
@@ -1789,7 +1789,7 @@ CTranslatorUtils::PdrgpulGenerateColIds
 
 	ULONG ulColPos = 0;
 	ListCell *plcTE = NULL;
-	DrgPul *pdrgpul = New(pmp) DrgPul(pmp);
+	DrgPul *pdrgpul = GPOS_NEW(pmp) DrgPul(pmp);
 
 	ForEach (plcTE, plTargetList)
 	{
@@ -1816,7 +1816,7 @@ CTranslatorUtils::PdrgpulGenerateColIds
 			}
 			GPOS_ASSERT(ULONG_MAX != ulColId);
 			
-			pdrgpul->Append(New(pmp) ULONG(ulColId));
+			pdrgpul->Append(GPOS_NEW(pmp) ULONG(ulColId));
 
 			ulColPos++;
 		}
@@ -1954,7 +1954,7 @@ CTranslatorUtils::Pdrgpdxlcd
 	GPOS_ASSERT(NULL != pdrgpulColIds);
 
 	ListCell *plcTE = NULL;
-	DrgPdxlcd *pdrgpdxlcd = New(pmp) DrgPdxlcd(pmp);
+	DrgPdxlcd *pdrgpdxlcd = GPOS_NEW(pmp) DrgPdxlcd(pmp);
 	ULONG ul = 0;
 	ForEach (plcTE, plTargetList)
 	{
@@ -1995,7 +1995,7 @@ CTranslatorUtils::PdrgpulPosInTargetList
 	GPOS_ASSERT(NULL != plTargetList);
 
 	ListCell *plcTE = NULL;
-	DrgPul *pdrgul = New(pmp) DrgPul(pmp);
+	DrgPul *pdrgul = GPOS_NEW(pmp) DrgPul(pmp);
 	ULONG ul = 0;
 	ForEach (plcTE, plTargetList)
 	{
@@ -2006,7 +2006,7 @@ CTranslatorUtils::PdrgpulPosInTargetList
 			continue;
 		}
 
-		pdrgul->Append(New(pmp) ULONG(ul));
+		pdrgul->Append(GPOS_NEW(pmp) ULONG(ul));
 		ul++;
 	}
 
@@ -2037,20 +2037,20 @@ CTranslatorUtils::Pdxlcd
 	if (NULL == pte->resname)
 	{
 		CWStringConst strUnnamedCol(GPOS_WSZ_LIT("?column?"));
-		pmdname = New(pmp) CMDName(pmp, &strUnnamedCol);
+		pmdname = GPOS_NEW(pmp) CMDName(pmp, &strUnnamedCol);
 	}
 	else
 	{
 		CWStringDynamic *pstrAlias = CDXLUtils::PstrFromSz(pmp, pte->resname);
-		pmdname = New(pmp) CMDName(pmp, pstrAlias);
+		pmdname = GPOS_NEW(pmp) CMDName(pmp, pstrAlias);
 		// CName constructor copies string
-		delete pstrAlias;
+		GPOS_DELETE(pstrAlias);
 	}
 
 	// create a column descriptor
 	OID oidType = gpdb::OidExprType((Node *) pte->expr);
 	CMDIdGPDB *pmdidColType = CTranslatorUtils::PmdidWithVersion(pmp, oidType);
-	CDXLColDescr *pdxlcd = New(pmp) CDXLColDescr
+	CDXLColDescr *pdxlcd = GPOS_NEW(pmp) CDXLColDescr
 									(
 									pmp,
 									pmdname,
@@ -2080,24 +2080,24 @@ CTranslatorUtils::PdxlnDummyPrElem
 	)
 {
 	CMDIdGPDB *pmdidOriginal = CMDIdGPDB::PmdidConvert(pdxlcdOutput->PmdidType());
-	CMDIdGPDB *pmdidCopy = New(pmp) CMDIdGPDB(pmdidOriginal->OidObjectId(), pmdidOriginal->UlVersionMajor(), pmdidOriginal->UlVersionMinor());
+	CMDIdGPDB *pmdidCopy = GPOS_NEW(pmp) CMDIdGPDB(pmdidOriginal->OidObjectId(), pmdidOriginal->UlVersionMajor(), pmdidOriginal->UlVersionMinor());
 
 	// create a column reference for the scalar identifier to be casted
 	ULONG ulColId = pdxlcdOutput->UlID();
-	CMDName *pmdname = New(pmp) CMDName(pmp, pdxlcdOutput->Pmdname()->Pstr());
-	CDXLColRef *pdxlcr = New(pmp) CDXLColRef(pmp, pmdname, ulColIdInput);
-	CDXLScalarIdent *pdxlopIdent = New(pmp) CDXLScalarIdent(pmp, pdxlcr, pmdidCopy);
+	CMDName *pmdname = GPOS_NEW(pmp) CMDName(pmp, pdxlcdOutput->Pmdname()->Pstr());
+	CDXLColRef *pdxlcr = GPOS_NEW(pmp) CDXLColRef(pmp, pmdname, ulColIdInput);
+	CDXLScalarIdent *pdxlopIdent = GPOS_NEW(pmp) CDXLScalarIdent(pmp, pdxlcr, pmdidCopy);
 
-	CDXLNode *pdxlnPrEl = New(pmp) CDXLNode
+	CDXLNode *pdxlnPrEl = GPOS_NEW(pmp) CDXLNode
 										(
 										pmp,
-										New(pmp) CDXLScalarProjElem
+										GPOS_NEW(pmp) CDXLScalarProjElem
 													(
 													pmp,
 													ulColIdOutput,
-													New(pmp) CMDName(pmp, pdxlcdOutput->Pmdname()->Pstr())
+													GPOS_NEW(pmp) CMDName(pmp, pdxlcdOutput->Pmdname()->Pstr())
 													),
-										New(pmp) CDXLNode(pmp, pdxlopIdent)
+										GPOS_NEW(pmp) CDXLNode(pmp, pdxlopIdent)
 										);
 
 	return pdxlnPrEl;
@@ -2122,7 +2122,7 @@ CTranslatorUtils::PdrgpulColIds
 	GPOS_ASSERT(NULL != plTargetList);
 	GPOS_ASSERT(NULL != phmiulAttnoColId);
 
-	DrgPul *pdrgpul = New(pmp) DrgPul(pmp);
+	DrgPul *pdrgpul = GPOS_NEW(pmp) DrgPul(pmp);
 
 	ListCell *plcTE = NULL;
 	ForEach (plcTE, plTargetList)
@@ -2137,7 +2137,7 @@ CTranslatorUtils::PdrgpulColIds
 			GPOS_RAISE(gpdxl::ExmaDXL, gpdxl::ExmiQuery2DXLAttributeNotFound, ulResNo);
 		}
 
-		pdrgpul->Append(New(pmp) ULONG(*pul));
+		pdrgpul->Append(GPOS_NEW(pmp) ULONG(*pul));
 	}
 
 	return pdrgpul;
@@ -2304,11 +2304,11 @@ CTranslatorUtils::PdxlnInt4Const
 	const IMDTypeInt4 *pmdtypeint4 = pmda->PtMDType<IMDTypeInt4>();
 	pmdtypeint4->Pmdid()->AddRef();
 
-	CDXLDatumInt4 *pdxldatum = New(pmp) CDXLDatumInt4(pmp, pmdtypeint4->Pmdid(), false /*fConstNull*/, iVal);
+	CDXLDatumInt4 *pdxldatum = GPOS_NEW(pmp) CDXLDatumInt4(pmp, pmdtypeint4->Pmdid(), false /*fConstNull*/, iVal);
 
-	CDXLScalarConstValue *pdxlConst = New(pmp) CDXLScalarConstValue(pmp, pdxldatum);
+	CDXLScalarConstValue *pdxlConst = GPOS_NEW(pmp) CDXLScalarConstValue(pmp, pdxldatum);
 
-	return New(pmp) CDXLNode(pmp, pdxlConst);
+	return GPOS_NEW(pmp) CDXLNode(pmp, pdxlConst);
 }
 
 
@@ -2620,7 +2620,7 @@ CTranslatorUtils::PhmululMap
 	GPOS_ASSERT(NULL != pdrgpulNew);
 	GPOS_ASSERT(pdrgpulNew->UlLength() == pdrgpulOld->UlLength());
 	
-	HMUlUl *phmulul = New(pmp) HMUlUl(pmp);
+	HMUlUl *phmulul = GPOS_NEW(pmp) HMUlUl(pmp);
 	const ULONG ulCols = pdrgpulOld->UlLength();
 	for (ULONG ul = 0; ul < ulCols; ul++)
 	{
@@ -2629,7 +2629,7 @@ CTranslatorUtils::PhmululMap
 #ifdef GPOS_DEBUG
 		BOOL fResult = 
 #endif // GPOS_DEBUG
-		phmulul->FInsert(New(pmp) ULONG(ulColIdOld), New(pmp) ULONG(ulColIdNew));
+		phmulul->FInsert(GPOS_NEW(pmp) ULONG(ulColIdOld), GPOS_NEW(pmp) ULONG(ulColIdNew));
 		GPOS_ASSERT(fResult);
 	}
 	
@@ -2756,7 +2756,7 @@ CTranslatorUtils::PdxlnPrElNull
 	CHAR *szColumnName = CDXLUtils::SzFromWsz(pmp, wszColName);
 	CDXLNode *pdxlnPrE = PdxlnPrElNull(pmp, pmda, pmdid, ulColId, szColumnName);
 
-	delete[] szColumnName;
+	GPOS_DELETE_ARRAY(szColumnName);
 
 	return pdxlnPrE;
 }
@@ -2786,36 +2786,36 @@ CTranslatorUtils::PdxlnPrElNull
 	if (NULL == szAliasName)
 	{
 		CWStringConst strUnnamedCol(GPOS_WSZ_LIT("?column?"));
-		pmdnameAlias = New(pmp) CMDName(pmp, &strUnnamedCol);
+		pmdnameAlias = GPOS_NEW(pmp) CMDName(pmp, &strUnnamedCol);
 	}
 	else
 	{
 		CWStringDynamic *pstrAlias = CDXLUtils::PstrFromSz(pmp, szAliasName);
-		pmdnameAlias = New(pmp) CMDName(pmp, pstrAlias);
-		delete pstrAlias;
+		pmdnameAlias = GPOS_NEW(pmp) CMDName(pmp, pstrAlias);
+		GPOS_DELETE(pstrAlias);
 	}
 
 	pmdid->AddRef();
 	CDXLDatum *pdxldatum = NULL;
 	if (pmdid->FEquals(&CMDIdGPDB::m_mdidInt2))
 	{
-		pdxldatum = New(pmp) CDXLDatumInt2(pmp, pmdid, true /*fConstNull*/, 0 /*value*/);
+		pdxldatum = GPOS_NEW(pmp) CDXLDatumInt2(pmp, pmdid, true /*fConstNull*/, 0 /*value*/);
 	}
 	else if (pmdid->FEquals(&CMDIdGPDB::m_mdidInt4))
 	{
-		pdxldatum = New(pmp) CDXLDatumInt4(pmp, pmdid, true /*fConstNull*/, 0 /*value*/);
+		pdxldatum = GPOS_NEW(pmp) CDXLDatumInt4(pmp, pmdid, true /*fConstNull*/, 0 /*value*/);
 	}
 	else if (pmdid->FEquals(&CMDIdGPDB::m_mdidInt8))
 	{
-		pdxldatum = New(pmp) CDXLDatumInt8(pmp, pmdid, true /*fConstNull*/, 0 /*value*/);
+		pdxldatum = GPOS_NEW(pmp) CDXLDatumInt8(pmp, pmdid, true /*fConstNull*/, 0 /*value*/);
 	}
 	else if (pmdid->FEquals(&CMDIdGPDB::m_mdidBool))
 	{
-		pdxldatum = New(pmp) CDXLDatumBool(pmp, pmdid, true /*fConstNull*/, 0 /*value*/);
+		pdxldatum = GPOS_NEW(pmp) CDXLDatumBool(pmp, pmdid, true /*fConstNull*/, 0 /*value*/);
 	}
 	else if (pmdid->FEquals(&CMDIdGPDB::m_mdidOid))
 	{
-		pdxldatum = New(pmp) CDXLDatumOid(pmp, pmdid, true /*fConstNull*/, 0 /*value*/);
+		pdxldatum = GPOS_NEW(pmp) CDXLDatumOid(pmp, pmdid, true /*fConstNull*/, 0 /*value*/);
 	}
 	else
 	{
@@ -2832,9 +2832,9 @@ CTranslatorUtils::PdxlnPrElNull
 										);
 	}
 
-	CDXLNode *pdxlnConst = New(pmp) CDXLNode(pmp, New(pmp) CDXLScalarConstValue(pmp, pdxldatum));
+	CDXLNode *pdxlnConst = GPOS_NEW(pmp) CDXLNode(pmp, GPOS_NEW(pmp) CDXLScalarConstValue(pmp, pdxldatum));
 
-	return New(pmp) CDXLNode(pmp, New(pmp) CDXLScalarProjElem(pmp, ulColId, pmdnameAlias), pdxlnConst);
+	return GPOS_NEW(pmp) CDXLNode(pmp, GPOS_NEW(pmp) CDXLScalarProjElem(pmp, ulColId, pmdnameAlias), pdxlnConst);
 }
 
 
@@ -2909,7 +2909,7 @@ CTranslatorUtils::UpdateGrpColMapping
 #ifdef GPOS_DEBUG
 		BOOL fResult = 
 #endif
-		phmululGrpColPos->FInsert(New(pmp) ULONG (ulUniqueGrpCols), New(pmp) ULONG(ulSortGrpRef));
+		phmululGrpColPos->FInsert(GPOS_NEW(pmp) ULONG (ulUniqueGrpCols), GPOS_NEW(pmp) ULONG(ulSortGrpRef));
 		(void) pbsGrpCols->FExchangeSet(ulSortGrpRef);
 	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/9b65a5ad/src/backend/gpopt/unexported_symbols_list.txt
----------------------------------------------------------------------
diff --git a/src/backend/gpopt/unexported_symbols_list.txt b/src/backend/gpopt/unexported_symbols_list.txt
deleted file mode 100644
index 15e32d2..0000000
--- a/src/backend/gpopt/unexported_symbols_list.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-__ZdaPv
-__ZdaPvRKSt9nothrow_t
-__ZdlPv
-__ZdlPvRKSt9nothrow_t
-__ZdlPvS_
-__Znam
-__ZnamRKSt9nothrow_t
-__Znwm
-__ZnwmPv
-__ZnwmRKSt9nothrow_t
-

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/9b65a5ad/src/backend/gpopt/utils/CConstExprEvaluatorProxy.cpp
----------------------------------------------------------------------
diff --git a/src/backend/gpopt/utils/CConstExprEvaluatorProxy.cpp b/src/backend/gpopt/utils/CConstExprEvaluatorProxy.cpp
index 71aa7fd..f1be886 100644
--- a/src/backend/gpopt/utils/CConstExprEvaluatorProxy.cpp
+++ b/src/backend/gpopt/utils/CConstExprEvaluatorProxy.cpp
@@ -112,7 +112,7 @@ CConstExprEvaluatorProxy::PdxlnEvaluateExpr
 
 	Const *pconstResult = (Const *)pexprResult;
 	CDXLDatum *pdxldatum = CTranslatorScalarToDXL::Pdxldatum(m_pmp, m_pmda, pconstResult);
-	CDXLNode *pdxlnResult = New(m_pmp) CDXLNode(m_pmp, New(m_pmp) CDXLScalarConstValue(m_pmp, pdxldatum));
+	CDXLNode *pdxlnResult = GPOS_NEW(m_pmp) CDXLNode(m_pmp, GPOS_NEW(m_pmp) CDXLScalarConstValue(m_pmp, pdxldatum));
 	gpdb::GPDBFree(pexprResult);
 	gpdb::GPDBFree(pexpr);
 

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/9b65a5ad/src/backend/gpopt/utils/COptTasks.cpp
----------------------------------------------------------------------
diff --git a/src/backend/gpopt/utils/COptTasks.cpp b/src/backend/gpopt/utils/COptTasks.cpp
index 29f20fa..893cde2 100644
--- a/src/backend/gpopt/utils/COptTasks.cpp
+++ b/src/backend/gpopt/utils/COptTasks.cpp
@@ -355,7 +355,7 @@ COptTasks::SzAllocate
 		}
 		else
 		{
-			sz = New(pmp) CHAR[ulSize];
+			sz = GPOS_NEW_ARRAY(pmp, CHAR, ulSize);
 		}
 	}
 	GPOS_CATCH_EX(ex)
@@ -422,16 +422,16 @@ COptTasks::PvMDCast
 	CAutoMemoryPool amp(CAutoMemoryPool::ElcExc);
 	IMemoryPool *pmp = amp.Pmp();
 
-	DrgPimdobj *pdrgpmdobj = New(pmp) DrgPimdobj(pmp);
+	DrgPimdobj *pdrgpmdobj = GPOS_NEW(pmp) DrgPimdobj(pmp);
 
-	IMDId *pmdidCast = New(pmp) CMDIdCast
+	IMDId *pmdidCast = GPOS_NEW(pmp) CMDIdCast
 			(
 			CTranslatorUtils::PmdidWithVersion(pmp, oidSrc),
 			CTranslatorUtils::PmdidWithVersion(pmp, oidDest)
 			);
 
 	// relcache MD provider
-	CMDProviderRelcache *pmdpr = New(pmp) CMDProviderRelcache(pmp);
+	CMDProviderRelcache *pmdpr = GPOS_NEW(pmp) CMDProviderRelcache(pmp);
 	
 	{
 		CAutoMDAccessor amda(pmp, pmdpr, sysidDefault);
@@ -486,9 +486,9 @@ COptTasks::PvMDScCmp
 	CAutoMemoryPool amp(CAutoMemoryPool::ElcExc);
 	IMemoryPool *pmp = amp.Pmp();
 
-	DrgPimdobj *pdrgpmdobj = New(pmp) DrgPimdobj(pmp);
+	DrgPimdobj *pdrgpmdobj = GPOS_NEW(pmp) DrgPimdobj(pmp);
 
-	IMDId *pmdidScCmp = New(pmp) CMDIdScCmp
+	IMDId *pmdidScCmp = GPOS_NEW(pmp) CMDIdScCmp
 			(
 			CTranslatorUtils::PmdidWithVersion(pmp, oidLeft),
 			CTranslatorUtils::PmdidWithVersion(pmp, oidRight),
@@ -496,7 +496,7 @@ COptTasks::PvMDScCmp
 			);
 
 	// relcache MD provider
-	CMDProviderRelcache *pmdpr = New(pmp) CMDProviderRelcache(pmp);
+	CMDProviderRelcache *pmdpr = GPOS_NEW(pmp) CMDProviderRelcache(pmp);
 	
 	{
 		CAutoMDAccessor amda(pmp, pmdpr, sysidDefault);
@@ -577,7 +577,7 @@ COptTasks::Execute
 		elog(LOG, "%s", SzFromWsz((WCHAR *)err_buf));
 	}
 
-	delete []err_buf;
+	GPOS_DELETE_ARRAY(err_buf);
 }
 
 
@@ -606,14 +606,14 @@ COptTasks::PvDXLFromQueryTask
 	IMemoryPool *pmp = amp.Pmp();
 
 	// ColId generator
-	CIdGenerator *pidgtorCol = New(pmp) CIdGenerator(GPDXL_COL_ID_START);
-	CIdGenerator *pidgtorCTE = New(pmp) CIdGenerator(GPDXL_CTE_ID_START);
+	CIdGenerator *pidgtorCol = GPOS_NEW(pmp) CIdGenerator(GPDXL_COL_ID_START);
+	CIdGenerator *pidgtorCTE = GPOS_NEW(pmp) CIdGenerator(GPDXL_CTE_ID_START);
 
 	// map that stores gpdb att to optimizer col mapping
-	CMappingVarColId *pmapvarcolid = New(pmp) CMappingVarColId(pmp);
+	CMappingVarColId *pmapvarcolid = GPOS_NEW(pmp) CMappingVarColId(pmp);
 
 	// relcache MD provider
-	CMDProviderRelcache *pmdpr = New(pmp) CMDProviderRelcache(pmp);
+	CMDProviderRelcache *pmdpr = GPOS_NEW(pmp) CMDProviderRelcache(pmp);
 
 	{
 		CAutoMDAccessor amda(pmp, pmdpr, sysidDefault);
@@ -634,8 +634,8 @@ COptTasks::PvDXLFromQueryTask
 		DrgPdxln *pdrgpdxlnCTE = ptrquerytodxl->PdrgpdxlnCTE();
 		GPOS_ASSERT(NULL != pdrgpdxlnQueryOutput);
 
-		delete pidgtorCol;
-		delete pidgtorCTE;
+		GPOS_DELETE(pidgtorCol);
+		GPOS_DELETE(pidgtorCTE);
 
 		CWStringDynamic str(pmp);
 		COstreamString oss(&str);
@@ -654,7 +654,7 @@ COptTasks::PvDXLFromQueryTask
 
 		// clean up
 		pdxlnQuery->Release();
-		delete pstrDXL;
+		GPOS_DELETE(pstrDXL);
 	}
 
 	return NULL;
@@ -744,7 +744,7 @@ COptTasks::PdrgPssLoad
 	}
 	GPOS_CATCH_END;
 
-	delete pphDXL;
+	GPOS_DELETE(pphDXL);
 
 	return pdrgpss;
 }
@@ -775,11 +775,11 @@ COptTasks::PoconfCreate
 
 	ULONG ulCTEInliningCutoff =  (ULONG) optimizer_cte_inlining_bound;
 
-	return New(pmp) COptimizerConfig
+	return GPOS_NEW(pmp) COptimizerConfig
 						(
-						New(pmp) CEnumeratorConfig(pmp, ullPlanId, ullSamples, dCostThreshold),
-						New(pmp) CStatisticsConfig(pmp, dDampingFactorFilter, dDampingFactorJoin, dDampingFactorGroupBy),
-						New(pmp) CCTEConfig(ulCTEInliningCutoff),
+						GPOS_NEW(pmp) CEnumeratorConfig(pmp, ullPlanId, ullSamples, dCostThreshold),
+						GPOS_NEW(pmp) CStatisticsConfig(pmp, dDampingFactorFilter, dDampingFactorJoin, dDampingFactorGroupBy),
+						GPOS_NEW(pmp) CCTEConfig(ulCTEInliningCutoff),
 						pcm
 						);
 }
@@ -913,11 +913,11 @@ COptTasks::Pcm
 	ICostModel *pcm = NULL;
 	if (OPTIMIZER_GPDB_CALIBRATED == optimizer_cost_model)
 	{
-		pcm = New(pmp) CCostModelGPDB(pmp, ulSegments);
+		pcm = GPOS_NEW(pmp) CCostModelGPDB(pmp, ulSegments);
 	}
 	else
 	{
-		pcm = New(pmp) CCostModelGPDBLegacy(pmp, ulSegments);
+		pcm = GPOS_NEW(pmp) CCostModelGPDBLegacy(pmp, ulSegments);
 	}
 
 	SetCostModelParams(pcm);
@@ -977,7 +977,7 @@ COptTasks::PvOptimizeTask
 		SetTraceflags(pmp, pbsTraceFlags, &pbsEnabled, &pbsDisabled);
 
 		// set up relcache MD provider
-		CMDProviderRelcache *pmdpRelcache = New(pmp) CMDProviderRelcache(pmp);
+		CMDProviderRelcache *pmdpRelcache = GPOS_NEW(pmp) CMDProviderRelcache(pmp);
 
 		{
 			// scope for MD accessor
@@ -988,7 +988,7 @@ COptTasks::PvOptimizeTask
 			CIdGenerator idgtorCTE(GPDXL_CTE_ID_START);
 
 			// map that stores gpdb att to optimizer col mapping
-			CMappingVarColId *pmapvarcolid = New(pmp) CMappingVarColId(pmp);
+			CMappingVarColId *pmapvarcolid = GPOS_NEW(pmp) CMappingVarColId(pmp);
 
 			ULONG ulSegments = gpdb::UlSegmentCountGP();
 			ULONG ulSegmentsForCosting = optimizer_segments;
@@ -1013,7 +1013,7 @@ COptTasks::PvOptimizeTask
 			COptimizerConfig *pocconf = PoconfCreate(pmp, pcm);
 			CConstExprEvaluatorProxy ceevalproxy(pmp, &mda);
 			IConstExprEvaluator *pceeval =
-					New(pmp) CConstExprEvaluatorDXL(pmp, &mda, &ceevalproxy);
+					GPOS_NEW(pmp) CConstExprEvaluatorDXL(pmp, &mda, &ceevalproxy);
 
 			// preload metadata if optimizer uses multiple threads
 			if (optimizer_parallel)
@@ -1054,7 +1054,7 @@ COptTasks::PvOptimizeTask
 				// serialize DXL to xml
 				CWStringDynamic *pstrPlan = CDXLUtils::PstrSerializePlan(pmp, pdxlnPlan, pocconf->Pec()->UllPlanId(), pocconf->Pec()->UllPlanSpaceSize(), true /*fSerializeHeaderFooter*/, true /*fIndent*/);
 				poctx->m_szPlanDXL = SzFromWsz(pstrPlan->Wsz());
-				delete pstrPlan;
+				GPOS_DELETE(pstrPlan);
 			}
 
 			// translate DXL->PlStmt only when needed
@@ -1064,10 +1064,10 @@ COptTasks::PvOptimizeTask
 			}
 
 			CStatisticsConfig *pstatsconf = pocconf->Pstatsconf();
-			pdrgmdidCol = New(pmp) DrgPmdid(pmp);
+			pdrgmdidCol = GPOS_NEW(pmp) DrgPmdid(pmp);
 			pstatsconf->CollectMissingStatsColumns(pdrgmdidCol);
 
-			phmmdidRel = New(pmp) HMMDIdMDId(pmp);
+			phmmdidRel = GPOS_NEW(pmp) HMMDIdMDId(pmp);
 			PrintMissingStatsWarning(pmp, &mda, pdrgmdidCol, phmmdidRel);
 
 			phmmdidRel->Release();
@@ -1245,7 +1245,7 @@ COptTasks::PvOptimizeMinidumpTask
 						true // fIndent
 						);
 	poptmdpctxt->m_szDXLResult = SzFromWsz(pstrDXL->Wsz());
-	delete pstrDXL;
+	GPOS_DELETE(pstrDXL);
 	CRefCount::SafeRelease(pdxlnResult);
 	pocconf->Release();
 
@@ -1280,7 +1280,7 @@ COptTasks::PvDXLFromPlstmtTask
 	CIdGenerator idgtor(1);
 
 	// relcache MD provider
-	CMDProviderRelcache *pmdpr = New(pmp) CMDProviderRelcache(pmp);
+	CMDProviderRelcache *pmdpr = GPOS_NEW(pmp) CMDProviderRelcache(pmp);
 
 	{
 		CAutoMDAccessor amda(pmp, pmdpr, sysidDefault);
@@ -1302,7 +1302,7 @@ COptTasks::PvDXLFromPlstmtTask
 		poctx->m_szPlanDXL = SzFromWsz(pstrDXL->Wsz());
 
 		// cleanup
-		delete pstrDXL;
+		GPOS_DELETE(pstrDXL);
 		pdxlnPlan->Release();
 	}
 
@@ -1360,7 +1360,7 @@ COptTasks::PvPlstmtFromDXLTask
 							);
 
 	// relcache MD provider
-	CMDProviderRelcache *pmdpr = New(pmp) CMDProviderRelcache(pmp);
+	CMDProviderRelcache *pmdpr = GPOS_NEW(pmp) CMDProviderRelcache(pmp);
 
 	{
 		CAutoMDAccessor amda(pmp, pmdpr, sysidDefault);
@@ -1419,13 +1419,13 @@ COptTasks::PvQueryFromDXLTask
 	GPOS_ASSERT(NULL != ptroutput->Pdxln());
 
 	// relcache MD provider
-	CMDProviderRelcache *pmdpr = New(pmp) CMDProviderRelcache(pmp);
+	CMDProviderRelcache *pmdpr = GPOS_NEW(pmp) CMDProviderRelcache(pmp);
 
 	{
 		CAutoMDAccessor amda(pmp, pmdpr, sysidDefault);
 
 		// initialize hash table that maintains the mapping between ColId and Var
-		TEMap *ptemap = New (pmp) TEMap(pmp);
+		TEMap *ptemap = GPOS_NEW(pmp) TEMap(pmp);
 
 		CTranslatorDXLToQuery trdxlquery(pmp, amda.Pmda(), gpdb::UlSegmentCountGP());
 		CStateDXLToQuery statedxltoquery(pmp);
@@ -1433,7 +1433,7 @@ COptTasks::PvQueryFromDXLTask
 		Query *pquery = trdxlquery.PqueryFromDXL(ptroutput->Pdxln(), ptroutput->PdrgpdxlnOutputCols(), &statedxltoquery, ptemap, GPDXL_QUERY_LEVEL);
 
 		CRefCount::SafeRelease(ptemap);
-		delete ptroutput;
+		GPOS_DELETE(ptroutput);
 
 		GPOS_ASSERT(NULL != pquery);
 		GPOS_ASSERT(NULL != CurrentMemoryContext);
@@ -1467,10 +1467,10 @@ COptTasks::PvDXLFromMDObjsTask
 	AUTO_MEM_POOL(amp);
 	IMemoryPool *pmp = amp.Pmp();
 
-	DrgPimdobj *pdrgpmdobj = New(pmp) DrgPimdobj(pmp, 1024, 1024);
+	DrgPimdobj *pdrgpmdobj = GPOS_NEW(pmp) DrgPimdobj(pmp, 1024, 1024);
 
 	// relcache MD provider
-	CMDProviderRelcache *pmdp = New(pmp) CMDProviderRelcache(pmp);
+	CMDProviderRelcache *pmdp = GPOS_NEW(pmp) CMDProviderRelcache(pmp);
 	{
 		CAutoMDAccessor amda(pmp, pmdp, sysidDefault);
 		ListCell *plc = NULL;
@@ -1537,12 +1537,12 @@ COptTasks::PvDXLFromRelStatsTask
 	IMemoryPool *pmp = amp.Pmp();
 
 	// relcache MD provider
-	CMDProviderRelcache *pmdpr = New(pmp) CMDProviderRelcache(pmp);
+	CMDProviderRelcache *pmdpr = GPOS_NEW(pmp) CMDProviderRelcache(pmp);
 	CAutoMDAccessor amda(pmp, pmdpr, sysidDefault);
 	ICostModel *pcm = Pcm(pmp, gpdb::UlSegmentCountGP());
 	CAutoOptCtxt aoc(pmp, amda.Pmda(), NULL /*pceeval*/, pcm);
 
-	DrgPimdobj *pdrgpmdobj = New(pmp) DrgPimdobj(pmp);
+	DrgPimdobj *pdrgpmdobj = GPOS_NEW(pmp) DrgPimdobj(pmp);
 
 	ListCell *plc = NULL;
 	ForEach (plc, pctxrelcache->m_plistOids)
@@ -1553,7 +1553,7 @@ COptTasks::PvDXLFromRelStatsTask
 		CMDIdGPDB *pmdid = CTranslatorUtils::PmdidWithVersion(pmp, oidRelation);
 
 		// generate mdid for relstats
-		CMDIdRelStats *pmdidRelStats = New(pmp) CMDIdRelStats(pmdid);
+		CMDIdRelStats *pmdidRelStats = GPOS_NEW(pmp) CMDIdRelStats(pmdid);
 		IMDRelStats *pimdobjrelstats = const_cast<IMDRelStats *>(amda.Pmda()->Pmdrelstats(pmdidRelStats));
 		pdrgpmdobj->Append(dynamic_cast<IMDCacheObject *>(pimdobjrelstats));
 
@@ -1565,7 +1565,7 @@ COptTasks::PvDXLFromRelStatsTask
 			if (!rel->rd_att->attrs[ul]->attisdropped)
 			{
 				pmdid->AddRef();
-				CMDIdColStats *pmdidColStats = New(pmp) CMDIdColStats(pmdid, ulPosCounter);
+				CMDIdColStats *pmdidColStats = GPOS_NEW(pmp) CMDIdColStats(pmdid, ulPosCounter);
 				ulPosCounter++;
 				IMDColStats *pimdobjcolstats = const_cast<IMDColStats *>(amda.Pmda()->Pmdcolstats(pmdidColStats));
 				pdrgpmdobj->Append(dynamic_cast<IMDCacheObject *>(pimdobjcolstats));
@@ -1642,7 +1642,7 @@ COptTasks::PvEvalExprFromDXLTask
 	GPOS_TRY
 	{
 		// set up relcache MD provider
-		CMDProviderRelcache *pmdpRelcache = New(pmp) CMDProviderRelcache(pmp);
+		CMDProviderRelcache *pmdpRelcache = GPOS_NEW(pmp) CMDProviderRelcache(pmp);
 		{
 			// scope for MD accessor
 			CMDAccessor mda(pmp, CMDCache::Pcache(), sysidDefault, pmdpRelcache);
@@ -1686,7 +1686,7 @@ COptTasks::PvEvalExprFromDXLTask
 						true // fIndent
 						);
 	pevalctxt->m_szDXLResult = SzFromWsz(pstrDXL->Wsz());
-	delete pstrDXL;
+	GPOS_DELETE(pstrDXL);
 	CRefCount::SafeRelease(pdxlnResult);
 	pdxlnInput->Release();
 


Mime
View raw message