Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 28 additions & 23 deletions src/backend/gporca/libgpopt/src/translate/CTranslatorExprToDXL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4964,41 +4964,46 @@ CTranslatorExprToDXL::PdxlnMergeJoin(CExpression *pexprMJ,
// At this point, they all better be merge joinable
GPOS_ASSERT(CPhysicalJoin::FMergeJoinCompatible(
pexprPred, pexprOuterChild, pexprInnerChild));
CExpression *pexprPredOuter = (*pexprPred)[0];
CExpression *pexprPredInner = (*pexprPred)[1];

// align extracted columns with outer and inner children of the join
CColRefSet *pcrsOuterChild = pexprOuterChild->DeriveOutputColumns();
CColRefSet *pcrsPredInner = pexprPredInner->DeriveUsedColumns();
// Extract the two key columns out of pexprPred. Plain equality
// is `a = b` (binary ScalarCmp) but NULL-safe equality (INDF) is
// `NOT (a IS DISTINCT FROM b)`, a *unary* NOT around the binary
// IsDistinctFrom. Indexing [0]/[1] directly works for equality
// but accesses out of bounds for INDF.
CExpression *pexprPredOuter = nullptr;
CExpression *pexprPredInner = nullptr;
IMDId *mdid_scop = nullptr;
CPhysicalJoin::AlignJoinKeyOuterInner(pexprPred, pexprOuterChild,
pexprInnerChild, &pexprPredOuter,
&pexprPredInner, &mdid_scop);

#ifdef GPOS_DEBUG
CColRefSet *pcrsOuterChild = pexprOuterChild->DeriveOutputColumns();
CColRefSet *pcrsInnerChild = pexprInnerChild->DeriveOutputColumns();
CColRefSet *pcrsPredOuter = pexprPredOuter->DeriveUsedColumns();
CColRefSet *pcrsPredInner = pexprPredInner->DeriveUsedColumns();
GPOS_ASSERT(pcrsOuterChild->ContainsAll(pcrsPredOuter) &&
pcrsInnerChild->ContainsAll(pcrsPredInner) &&
"merge join keys are not aligned with children");
#endif

if (pcrsOuterChild->ContainsAll(pcrsPredInner))
pexprPredOuter->AddRef();
pexprPredInner->AddRef();
CExpression *pexprPredNew;
if (CPredicateUtils::IsEqualityOp(pexprPred))
{
GPOS_ASSERT(pcrsInnerChild->ContainsAll(pcrsPredOuter));
std::swap(pexprPredOuter, pexprPredInner);
#ifdef GPOS_DEBUG
std::swap(pcrsPredOuter, pcrsPredInner);
#endif

pexprPredOuter->AddRef();
pexprPredInner->AddRef();
pexprPred =
CUtils::PexprScalarEqCmp(m_mp, pexprPredOuter, pexprPredInner);
pexprPredNew = CUtils::PexprScalarCmp(m_mp, pexprPredOuter,
pexprPredInner, mdid_scop);
}
else
{
pexprPred->AddRef();
GPOS_ASSERT(CPredicateUtils::FINDF(pexprPred));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to have INDF for merge joins? Because in CPhysicalJoin::FMergeJoinCompatible we check:

// Only merge join between ScalarIdents of the same types is currently supported
	if (CPredicateUtils::FEqIdentsOfSameType(pexprPred))
	{
		pexprPredOuter = (*pexprPred)[0];
		pexprPredInner = (*pexprPred)[1];
		mdid_scop = CScalarCmp::PopConvert(pexprPred->Pop())->MdIdOp();
		GPOS_ASSERT(CUtils::FScalarIdent(pexprPredOuter));
		GPOS_ASSERT(CUtils::FScalarIdent(pexprPredInner));
	}
	else
	{
		return false;
	}

So the old code should work since we always check only for valid merge join operands.

Maybe we want to change it in future PR's?

pexprPredNew = CUtils::PexprINDF(m_mp, pexprPredOuter,
pexprPredInner, mdid_scop);
}

GPOS_ASSERT(pcrsOuterChild->ContainsAll(pcrsPredOuter) &&
pcrsInnerChild->ContainsAll(pcrsPredInner) &&
"merge join keys are not aligned with children");

dxlnode_merge_conds->AddChild(PdxlnScalar(pexprPred));
pexprPred->Release();
dxlnode_merge_conds->AddChild(PdxlnScalar(pexprPredNew));
pexprPredNew->Release();
}
pdrgpexprPredicates->Release();

Expand Down
Loading