ORCA: restore non-ASCII column aliases for all target entry kinds#1846
Open
yjhjstz wants to merge 1 commit into
Open
ORCA: restore non-ASCII column aliases for all target entry kinds#1846yjhjstz wants to merge 1 commit into
yjhjstz wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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
Breaking Changes
Test Plan
make installcheckmake -C src/test installcheck-cbdb-parallelImpact
Performance:
User-facing changes:
Dependencies:
Checklist
Additional Context
CI Skip Instructions