Skip to content

fix: add SYSTEM_USER to PostgreSQL unparenthesized function names [FaaFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH] - #39418

Open
waterWang wants to merge 1 commit into
apache:masterfrom
waterWang:fix/39384-postgresql-system-user-function
Open

fix: add SYSTEM_USER to PostgreSQL unparenthesized function names [FaaFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH]#39418
waterWang wants to merge 1 commit into
apache:masterfrom
waterWang:fix/39384-postgresql-system-user-function

Conversation

@waterWang

Copy link
Copy Markdown

Fixes #39384

Changes

Added SYSTEM_USER to PostgreSQLFunctionOption.UNPARENTHESIZED_FUNCTION_NAMES so that the PostgreSQL dialect correctly binds the niladic function SYSTEM_USER instead of misclassifying it as a column reference.

Root Cause

PostgreSQLFunctionOption (line 31-33) lists 11 unparenthesized function names and omits SYSTEM_USER. ColumnSegmentBinder.isUnparenthesizedFunction() reads this set via .contains() to decide function vs column. When the lookup fails, bind() throws ColumnNotFoundException.

MySQLFunctionOption and SQLServerFunctionOption already include SYSTEM_USER.

Verification

  • SELECT SYSTEM_USER against a PostgreSQL-typed schema now correctly binds as a niladic function
  • No grammar change required (SYSTEM_USER already lexes as an identifier in PostgreSQL)
  • openGauss inherits this change via OpenGaussDatabaseMetaData which returns new PostgreSQLFunctionOption()

Signed-off-by: waterWang waterWang@users.noreply.github.com

…aFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH]

Signed-off-by: waterWang <waterWang@users.noreply.github.com>

@terrymanu terrymanu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Result

Review Result: Not Mergeable

Feedback Mode: Needs Discussion

Blocking Issues: 1

The patch fixes the narrow no-table reproducer, but does not model PostgreSQL 16’s SYSTEM_USER semantics correctly.

Blocking Issues

1. SYSTEM_USER remains an ordinary column expression

Evidence: PostgreSQL 16 defines SYSTEM_USER as a reserved keyword and its grammar constructs a system_user function call; the official manual documents the unparenthesized expression. At the reviewed head, PostgreSQL’s reservedKeyword and functionExprCommonSubexpr still omit SYSTEM_USER. Exact-head-equivalent parser verification consequently produced ColumnProjectionSegment for SYSTEM_USER, versus ExpressionProjectionSegment for CURRENT_USER.

The added metadata entry is only consulted after column resolution in ColumnSegmentBinder. Therefore, when table metadata contains a quoted system_user column, unquoted SELECT SYSTEM_USER FROM t is bound as that physical column even though PostgreSQL 16 evaluates the reserved function. The added membership assertion cannot detect this path.

Impact: Column-bound processing can treat the function result as table data—for example, MaskMergedResult consumes that bound table/column identity. This leaves issue #39384 incomplete for valid PostgreSQL 16 schemas.

Discussion Needed: Establish whether PostgreSQL ≥16 syntax should be owned by the lexer/parser or handled through a version-aware fallback, including compatibility with older PostgreSQL versions. Also resolve openGauss separately: it inherits PostgreSQLFunctionOption, while its official documentation describes system_user() as parenthesized and its keyword table does not classify SYSTEM_USER as an openGauss keyword. The agreed model needs parser-to-binder behavioral coverage, including same-name column handling.

Coverage

  • Reviewed head: 303b4deb795598b5ade8ec47108853409730e1e2; base: c7bf30fc66598831afe237f71f8a0e8e7f93146b.
  • Accounted for both authoritative GitHub files and linked requirement #39384; public comments and reviews were empty.
  • Reviewed clusters: PostgreSQL function classification and its assertion-only test.
  • Traced parser → projection → column binder → result-processing paths; checked PostgreSQL, openGauss, and the cited SQL92 issue #39099.
  • Completed root-cause, blast-radius/contracts, tests/runtime, and final convergence passes. No evidence gap remains that could change the blocker set.
  • Verification: scoped PostgreSQL parser compilation succeeded; runtime parser comparison confirmed the projection-type mismatch.
  • Code-correctness review only. GitHub Actions and CI were not reviewed.

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.

PostgreSQL dialect omits SYSTEM_USER from unparenthesized function names

2 participants