Skip to content

ORCA: restore non-ASCII column aliases for all target entry kinds#1846

Open
yjhjstz wants to merge 1 commit into
apache:mainfrom
yjhjstz:fix/orca-unknown-locale-alias
Open

ORCA: restore non-ASCII column aliases for all target entry kinds#1846
yjhjstz wants to merge 1 commit into
apache:mainfrom
yjhjstz:fix/orca-unknown-locale-alias

Conversation

@yjhjstz

@yjhjstz yjhjstz commented Jul 10, 2026

Copy link
Copy Markdown
Member

ORCA represents names as wide characters; when the database LC_CTYPE cannot decode a multibyte name (e.g. LC_CTYPE='C' with a UTF-8 alias), clib::Vswprintf substitutes the generic "UNKNOWN" string and the DXL-to-PlStmt translator restores the original name from the query tree (commit 6b19c44). That restore only ran for Var target entries, so with the optimizer enabled

SELECT '한글' AS "한글";

returned a column named UNKNOWN: constants, aggregates, set operation and set-returning-function outputs never took the repair path.

The old repair walked the entire query tree with
update_unknown_locale_walker matching on (resorigtbl, resno). That match key is ambiguous: TargetEntries nested inside Aggref arguments or SubLink subqueries can collide with it, either clobbering an already-restored name (empty column header for the first of two aggregates) or restoring a name from the wrong query level.

Replace the walker with restore_unknown_locale_resname, which scans only the top-level query targetList for the non-junk entry with the same resno. Only the topmost plan node is translated with a context that carries the original query, and its projection list produces the query output columns in order, so the positional top-level match is exact. A legitimate alias literally named "UNKNOWN" self-matches and the restore is a no-op. Call it for every entry translated by TranslateDXLProjList, for the inlined Append targetlist (UNION ALL), and for the ProjectSet targetlists built by SetupAliasParameter (set-returning functions).

Extend gp_locale with alias cases for constants, expressions, aggregates, UNION ALL, set-returning functions, a subquery containing a same-position column, and a legitimate "UNKNOWN" alias.

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


ORCA represents names as wide characters; when the database LC_CTYPE
cannot decode a multibyte name (e.g. LC_CTYPE='C' with a UTF-8 alias),
clib::Vswprintf substitutes the generic "UNKNOWN" string and the
DXL-to-PlStmt translator restores the original name from the query
tree (commit 6b19c44). That restore only ran for Var target
entries, so with the optimizer enabled

    SELECT '한글' AS "한글";

returned a column named UNKNOWN: constants, aggregates, set operation
and set-returning-function outputs never took the repair path.

The old repair walked the entire query tree with
update_unknown_locale_walker matching on (resorigtbl, resno). That
match key is ambiguous: TargetEntries nested inside Aggref arguments
or SubLink subqueries can collide with it, either clobbering an
already-restored name (empty column header for the first of two
aggregates) or restoring a name from the wrong query level.

Replace the walker with restore_unknown_locale_resname, which scans
only the top-level query targetList for the non-junk entry with the
same resno. Only the topmost plan node is translated with a context
that carries the original query, and its projection list produces the
query output columns in order, so the positional top-level match is
exact. A legitimate alias literally named "UNKNOWN" self-matches and
the restore is a no-op. Call it for every entry translated by
TranslateDXLProjList, for the inlined Append targetlist (UNION ALL),
and for the ProjectSet targetlists built by SetupAliasParameter
(set-returning functions).

Extend gp_locale with alias cases for constants, expressions,
aggregates, UNION ALL, set-returning functions, a subquery containing
a same-position column, and a legitimate "UNKNOWN" alias.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant