Skip to content

Commit

Permalink
[ORCA] optimize eliminate self comparison
Browse files Browse the repository at this point in the history
'PexprEliminateSelfComparison' only uses the 'pcrsNotNull'
from the topmost expression to filter the nullable columns.
This can lead the PexprEliminateSelfComparison cannot apply
to the subquery properly.

create table t1(a int not null, b int not null);
create table t2(like t1);
create table t3(like t1);
select * from t2  left join (select  t2.a , t2.b  from t1, t2 where t1.a
	< t1.a) as t on t2. a = t.a;

the plan for it from orca is
 Gather Motion 3:1  (slice1; segments: 3)
   ->  Hash Left Join
         Hash Cond: (t2.a = t2_1.a)
         ->  Seq Scan on t2
         ->  Hash
               ->  Nested Loop
                     Join Filter: true
                     ->  Seq Scan on t2 t2_1
                     ->  Materialize
                           ->  Broadcast Motion 3:3  (slice2; segments: 3)
                                 ->  Seq Scan on t1
                                       Filter: (a < a)
the self comparison in subquery is not eliminated.

This commit is to optimize it by fetching 'pcrsNotNull' from
the current logical expression and apply them to its child
scalar expression.
  • Loading branch information
fanfuxiaoran committed Nov 21, 2024
1 parent b628a60 commit ffb8b2e
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,17 @@ CExpressionPreprocessor::PexprEliminateSelfComparison(CMemoryPool *mp,
GPOS_CHECK_STACK_SIZE;
GPOS_ASSERT(nullptr != mp);
GPOS_ASSERT(nullptr != pexpr);
COperator *pop = pexpr->Pop();

if (CUtils::FScalarCmp(pexpr))
{
return CPredicateUtils::PexprEliminateSelfComparison(mp, pexpr,
pcrsNotNull);
}
if (pop->FLogical())
{
pcrsNotNull = pexpr->DeriveNotNullColumns();
}

// recursively process children
const ULONG arity = pexpr->Arity();
Expand All @@ -94,7 +99,6 @@ CExpressionPreprocessor::PexprEliminateSelfComparison(CMemoryPool *mp,
pdrgpexprChildren->Append(pexprChild);
}

COperator *pop = pexpr->Pop();
pop->AddRef();

return GPOS_NEW(mp) CExpression(mp, pop, pdrgpexprChildren);
Expand Down

0 comments on commit ffb8b2e

Please sign in to comment.