Example #1
0
//---------------------------------------------------------------------------
//	@function:
//		CConstraint::Phmcolconstr
//
//	@doc:
//		Construct mapping between columns and arrays of constraints
//
//---------------------------------------------------------------------------
HMColConstr *
CConstraint::Phmcolconstr
(
    IMemoryPool *pmp,
    CColRefSet *pcrs,
    DrgPcnstr *pdrgpcnstr
)
const
{
    GPOS_ASSERT(NULL != m_pcrsUsed);

    HMColConstr *phmcolconstr = GPOS_NEW(pmp) HMColConstr(pmp);

    CColRefSetIter crsi(*pcrs);
    while (crsi.FAdvance())
    {
        CColRef *pcr = crsi.Pcr();
        DrgPcnstr *pdrgpcnstrCol = PdrgpcnstrOnColumn(pmp, pdrgpcnstr, pcr, false /*fExclusive*/);

#ifdef GPOS_DEBUG
        BOOL fres =
#endif //GPOS_DEBUG
            phmcolconstr->FInsert(pcr, pdrgpcnstrCol);
        GPOS_ASSERT(fres);
    }

    return phmcolconstr;
}
// mapping between columns and single column constraints in array of constraints
static
HMColConstr *
PhmcolconstrSingleColConstr
	(
		IMemoryPool *pmp,
		DrgPcnstr *drgPcnstr
	)
{
	CAutoRef<DrgPcnstr> arpdrgpcnstr(drgPcnstr);
	HMColConstr *phmcolconstr = GPOS_NEW(pmp) HMColConstr(pmp);

	const ULONG ulLen = arpdrgpcnstr->UlLength();

	for (ULONG ul = 0; ul < ulLen; ul++)
	{
		CConstraint *pcnstrChild = (*arpdrgpcnstr)[ul];
		CColRefSet *pcrs = pcnstrChild->PcrsUsed();

		if (1 == pcrs->CElements())
		{
			CColRef *pcr = pcrs->PcrFirst();
			DrgPcnstr *pcnstrMapped = phmcolconstr->PtLookup(pcr);
			if (NULL == pcnstrMapped)
			{
				pcnstrMapped = GPOS_NEW(pmp) DrgPcnstr(pmp);
				phmcolconstr->FInsert(pcr, pcnstrMapped);
			}
			pcnstrChild->AddRef();
			pcnstrMapped->Append(pcnstrChild);
		}
	}

	return phmcolconstr;
}