fix: add SYSTEM_USER to PostgreSQL unparenthesized function names [FaaFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH] - #39418
Conversation
…aFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH] Signed-off-by: waterWang <waterWang@users.noreply.github.com>
terrymanu
left a comment
There was a problem hiding this comment.
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.
Fixes #39384
Changes
Added
SYSTEM_USERtoPostgreSQLFunctionOption.UNPARENTHESIZED_FUNCTION_NAMESso that the PostgreSQL dialect correctly binds the niladic functionSYSTEM_USERinstead of misclassifying it as a column reference.Root Cause
PostgreSQLFunctionOption(line 31-33) lists 11 unparenthesized function names and omitsSYSTEM_USER.ColumnSegmentBinder.isUnparenthesizedFunction()reads this set via.contains()to decide function vs column. When the lookup fails,bind()throwsColumnNotFoundException.MySQLFunctionOptionandSQLServerFunctionOptionalready includeSYSTEM_USER.Verification
SELECT SYSTEM_USERagainst a PostgreSQL-typed schema now correctly binds as a niladic functionOpenGaussDatabaseMetaDatawhich returnsnew PostgreSQLFunctionOption()Signed-off-by: waterWang waterWang@users.noreply.github.com