Skip to content

ORCA: accept coerced join alias vars in USING joins - #2148

Open
yjhjstz wants to merge 1 commit into
apache:mainfrom
yjhjstz:fix/orca-using-join-relabeltype
Open

yjhjstz wants to merge 1 commit into
apache:mainfrom
yjhjstz:fix/orca-using-join-relabeltype

Conversation

@yjhjstz

@yjhjstz yjhjstz commented Oct 16, 2026

Copy link
Copy Markdown
Member

The merged column of a USING join is the left input coerced to the common type when the two input types differ. For binary-compatible types such as varchar vs text or int vs oid the parser emits a RelabelType, which CTranslatorQueryToDXL::TranslateJoinExprInFromToDXL rejected with an assertion that only allowed Var, FuncExpr and CoalesceExpr. On assert-enabled builds every such query fell back to the Postgres planner:

CTranslatorQueryToDXL.cpp:4145: Failed assertion:
IsA(join_alias_node, Var) || IsA(join_alias_node, FuncExpr) ||
IsA(join_alias_node, CoalesceExpr)

References to join alias columns are flattened by
CQueryMutators::NormalizeQuery before the join itself is translated, which is why the FuncExpr case already worked without any special handling. The projection element only has to be an expression the scalar translator understands, so drop the enumeration. Nodes the scalar translator does not support still raise the regular unsupported-feature exception and fall back cleanly.

Add a regression case to join_gp covering varchar/text and int/oid USING columns, including the nested left join shape from the aggregates test.

Fixes #ISSUE_Number

What does this PR do?

Type of Change

  • Bug fix (non-breaking change)
  • New feature (non-breaking change)
  • Breaking change (fix or feature with breaking changes)
  • Documentation update

Breaking Changes

Test Plan

  • Unit tests added/updated
  • Integration tests added/updated
  • Passed make installcheck
  • Passed make -C src/test installcheck-cbdb-parallel

Impact

Performance:

User-facing changes:

Dependencies:

Checklist

Additional Context

CI Skip Instructions


The merged column of a USING join is the left input coerced to the
common type when the two input types differ. For binary-compatible
types such as varchar vs text or int vs oid the parser emits a
RelabelType, which CTranslatorQueryToDXL::TranslateJoinExprInFromToDXL
rejected with an assertion that only allowed Var, FuncExpr and
CoalesceExpr. On assert-enabled builds every such query fell back to
the Postgres planner:

  CTranslatorQueryToDXL.cpp:4145: Failed assertion:
  IsA(join_alias_node, Var) || IsA(join_alias_node, FuncExpr) ||
  IsA(join_alias_node, CoalesceExpr)

References to join alias columns are flattened by
CQueryMutators::NormalizeQuery before the join itself is translated,
which is why the FuncExpr case already worked without any special
handling. The projection element only has to be an expression the
scalar translator understands, so drop the enumeration. Nodes the
scalar translator does not support still raise the regular
unsupported-feature exception and fall back cleanly.

Add a regression case to join_gp covering varchar/text and int/oid
USING columns, including the nested left join shape from the
aggregates test.
@yjhjstz yjhjstz added the type: Bug Something isn't working label Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant