Repository navigation
fix(function): return row-local NULL for fractional powers of negative bases - #33147
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
Queue requested — the merge queue status continues in this comment ↓. |
iamlinjunhong
left a comment
There was a problem hiding this comment.
[P1] Preserve SQL UDF bodies that start with a parenthesized set operand (pkg/sql/plan/base_binder.go:6175).
Run CREATE FUNCTION f_parenthesized_union() RETURNS INT LANGUAGE SQL AS '(select 1 where 1=0) union all select 2'; and then SELECT f_parenthesized_union();. The base binds the body as a query with a single result, 2. On this head the leading ( selects the scalar-expression path. Adding select still produces a *tree.UnionClause, so the unchecked *tree.SelectClause assertion at line 6227 panics and the MySQL request handler returns an error. Existing definitions with this body fail after upgrade as well. Classify the complete query and guard the AST assertion. Cover both this set-operation body and a scalar expression containing a subquery. Earlier review
Reviewed 07494aeb90dc4922aad991085fe607a58e199f6b against the declared main base. A focused parser probe on that head confirmed the AST for the triggering body and the ordinary SELECT control. git diff --check and Loom's artifact check passed. Full BVT and the release upgrade were not repeated locally. Issue #33126
The exact-head CI snapshot contains 34 checks. Fifteen succeeded, 17 were skipped, and two were neutral. No checks failed. Both release and target upgrade compatibility checks were skipped. CI run
|
mo-bot review · Commit: confirmed findings require request_changes; other decisions need no findings |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 7f7158513d95f0b14cdc6a645f981bead7248459
Assessment: request_changes
Released SQL UDFs can lose their preserved POW behavior during prepared execution. Reusing the existing NULL-producing vector helper and retaining a legacy overload are reasonable; the earlier direct CHECK, dump, view, UDF, and parser concerns are addressed, but execute-time rebinding remains open.
Model: gpt-6.1-terra / max
Session: 01a21cb3-a707-7531-b8de-81ca7f1f3651 · slot 0 · generation 24
- P2
pkg/sql/plan/base_binder.go:6234: After upgrading from v4.2.9, call a retained SQL UDF whose body is power($1, 0.5) through a prepared statement with a bare parameter set to -2.
Impact: The released UDF should raise error 1690. Prepared execution can instead select the new overload and return NULL, allowing a statement to succeed or write NULL where the released function failed.
Evidence: The legacy binding context is restored after the UDF body is bound. At execution, ResetParamRefRule in pkg/sql/plan/visit_plan_rule.go:3193 and :3949 rebinds parameterized calls by name using the request context; it has no POW identity preservation, so function.go:701 selects overload 1 instead of the stored overload 0. Preserve the bound overload during prepared rebinding and cover a prepared legacy UDF alongside a fresh-definition control.
Validation:
-
Isolation preflight passed; receipt checks/1795782023512059917-2.json and preflight.log.
-
git diff --check passed for the assigned base and head; receipt checks/1795782533047578738-2.json.
-
The frozen CI snapshot reports successful Ubuntu unit tests and multi-CN PROXY and PESSIMISTIC jobs; upgrade compatibility jobs were skipped.
-
All 18 discussion-index entries were reconciled in discussion-assessment.json.
Limitations:
-
The focused function tests and prepared-rebinding probe did not compile because the Go 1.27.1 toolchain download timed out; receipts checks/1795782521433836228-2.json and checks/1795782800097133600-2.json. The finding is based on the traced source path, not an executed probe.
-
The author reports v4.2.9 shutdown-upgrade and restore checks on earlier PR revisions, but their raw logs were not supplied for independent verification.
# Conflicts: # pkg/sql/plan/build_alter_check_test.go
|
mo-bot review · Commit: discussion changed before publication |
iamlinjunhong
left a comment
There was a problem hiding this comment.
[P1] Preserve existing SQL UDF bodies that start with PERFORM SELECT (pkg/sql/plan/function/udf.go:98).
Create CREATE FUNCTION f_perform() RETURNS INT LANGUAGE SQL AS 'perform select 7'; and call SELECT f_perform();. The base and v4.2.9 parse the body as a *tree.Select and bind it as a scalar subquery returning 7. The new classifier omits the PERFORM token, prepends select , and returns a syntax error for select perform select 7. This also breaks functions already in the catalog after a shutdown upgrade. Recognize the complete PERFORM SELECT form while preserving scalar expressions that use perform as an identifier.
The earlier parenthesized UNION issue is resolved by parsing the complete query. Prepared execution now retains the POW overload selected by the UDF definition during parameter rebinding. The review snapshot contains no direct author replies to the prior findings. Parenthesized UNION review · Prepared execution review
Reviewed head 7a7cf1168906730a84b75ba5330cfe1ff8006a80 against main at 3cb7a5e4a93dc5bd85e0fb107e558a07df934693. A focused parser probe on this head accepted the CREATE FUNCTION and the original body, then reproduced the syntax error after the scalar prefix was added. The base and release behavior was verified by tracing their binders. git diff --check and Loom’s artifact check passed. Local validation was limited to source inspection and the parser probe. Issue #33126
CI Required passed. Of the 37 exact-head checks, 19 succeeded, 16 were skipped, and 2 were neutral. Both upgrade compatibility jobs were skipped. CI run
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 7a7cf1168906730a84b75ba5330cfe1ff8006a80
Assessment: request_changes
The retained overload and restore paths reuse existing owners to preserve persisted POWER semantics. One previously reported SQL UDF compatibility regression remains: the new body classifier rejects valid PERFORM SELECT definitions. Earlier discussion concerns were reconciled against the current source.
Model: gpt-6.1-terra / max
Session: 01a21ea1-c772-7b90-b7f9-8f6ec1038a49 · slot 2 · generation 12
- P2
pkg/sql/plan/function/udf.go:98: A SQL UDF with a body such asperform select 7is invoked, including a function retained across a v4.2.9 shutdown upgrade.
Impact: The UDF call fails during planning with a syntax error, so statements that use an existing definition can no longer execute after upgrade.
Evidence: The baseline and v4.2.9 bind this lowercase body as a query, and the grammar parses it as a Select. The new classifier omits PERFORM and instead attempts to parseselect perform select 7. The focused planner probe reproduced the error while ordinary SELECT and scalar controls bound successfully; perform-udf-probe.log and checks/1795849205965901621-2.json record the result. Recognize complete PERFORM query bodies before the scalar fallback, while preserving scalar expressions that useperformas an identifier.
Validation:
-
Isolation preflight passed. The candidate planner probe confirmed the reported failure; a diagnostic overlay routing PERFORM through the query binder bound the same UDF successfully. The latter is a control, not a test of the unchanged candidate.
-
Reused same-head focused test evidence for the function, planner, frontend, and compiler packages after verifying the patch, source fingerprint, selections, and terminal receipts. Logs and receipts are retained under reused-evidence.
-
The diff whitespace check and clean-source check passed. discussion-assessment.json accounts for all 23 indexed discussion items.
Limitations:
-
The public MySQL UDF call and a release-to-head upgrade were not independently executed. The frozen CI snapshot reports successful unit and multi-CN jobs, but its upgrade compatibility jobs were skipped.
-
Native preparation initially failed because the diagnostic verification used the wrong header path; it passed after that diagnostic was corrected, before the probe ran.
…ersioned routines
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: c479740d295de7fc7740b2807f813d7a4e28cdf1
Assessment: approve
The change restores row-local NULL results while retaining the released POW behavior for persisted definitions. It reuses the existing evaluator and restore owners; the added binding markers and reconstruction paths preserve the distinction for views, SQL functions and table dumps. Earlier CHECK, generated-column, UDF, prepared-execution and parser concerns are addressed in the current source.
Model: gpt-6.1-terra / max
Session: 01a2230f-39de-7f00-bf9a-e19ded95bd85 · slot 0 · generation 39
Validation:
-
Reviewed the complete change, applicable policy, linked issues and all 25 discussion entries. The discussion assessment is recorded in discussion-assessment.json.
-
Isolation preflight, diff whitespace and tracked-source status checks passed; receipts are retained under checks/.
-
The frozen exact-head CI snapshot reports successful Ubuntu unit tests and multi-CN PROXY and PESSIMISTIC BVT jobs.
-
Compared the retained evaluator with the v4.2.9 release implementation and the locally available v4.2.8 hotfix implementation.
Limitations:
-
No Go tests ran locally: the required Go 1.27.1 toolchain download timed out before compilation. The diagnostic is retained in toolchain.log and its receipt under checks/.
-
The author reports v4.2.9 shutdown-upgrade and dump/restore checks on earlier PR revisions, but raw logs were not supplied. The frozen CI upgrade jobs were skipped.
iamlinjunhong
left a comment
There was a problem hiding this comment.
Reviewed c479740d295de7fc7740b2807f813d7a4e28cdf1 against main at 33b96ca4620d0d37b90d2c044e0524d685a47b41. No outstanding findings. Newly bound POW and POWER return NULL for the affected row and preserve valid results in the same batch. Released definitions retain their error behavior. Issue #33126
The previous PERFORM SELECT finding is resolved. The binder now parses it as a complete query and continues to accept perform as a scalar identifier. The earlier parenthesized UNION and prepared-parameter findings are also resolved. The review threads and PR conversation contain no explicit author replies to those findings.
Focused Go tests passed on this head in the function, planner, frontend, and compile packages. They covered POW evaluation, SQL UDF parsing and cloning, prepared execution, stored view binding, ALTER replay, and table-dump recovery. git diff --check passed. The PR description reports v4.2.9 shutdown-upgrade and MOTR runs on earlier revisions. This review did not rerun those integration scenarios.
All 36 checks completed. The snapshot shows 19 successful, 15 skipped, and 2 neutral checks, with zero failures. The upgrade compatibility jobs were skipped. CI run
🚫 Left the queue · pull request dequeued12 min in the queue, with no time running CI. So far
Reason Pull request #33147 has been dequeued Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.
To get back in the queue
Merge conditions not met when it left the queue
Tick the box to put this pull request back in the merge queue (same as
2 merge conditions met
Times in UTC · dashboard · how the merge queue works |
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #33126.
What this PR does / why we need it:
Restore MatrixOne's row-local NULL behavior for
POWandPOWERwhen a finite negative base has a finite non-integer exponent. Both aliases use the same evaluator. For example, a projection ofPOWER(base, 0.5)over bases1, -2, 4now returns1, NULL, 2.Previously, #32863 captured a domain error outside the per-row callback and returned it after evaluating the batch. That made a single invalid row abort the statement with MySQL error 1690. This change restores the behavior from #28375 requested by #33126 and supersedes the MySQL-compatible exception introduced for #31155.
The evaluator passes non-finite results from
math.Powto the existing NULL-on-error vector helper. A shared internal error marker avoids formatting an error for each invalid row. The tests cover both aliases, mixed vectors, masks, aggregates, nullable writes, NOT NULL constraints, and prepared executor reuse. A separate prepared projection uses integer overflow to retain the existing check for recovery after a genuine execution error.Upgrade compatibility for persisted CHECK constraints
An existing CHECK keeps the meaning it had when it was created. MatrixOne v4.2.9 stored both function names as POW overload 0. That overload still raises MySQL error 1690 (SQLSTATE 22003) for a non-finite result. New SQL, including newly created constraints, binds both names to overload 1 and returns NULL for that row. For
CHECK (POWER(b, 0.5) > 0), the two definitions admit the following writes after upgrade.-204orNULLA shutdown upgrade from the official v4.2.9 Linux/arm64 release to commit
50e3a2cfb4reproduced these results on the same persisted table and on a fresh definition. A second constraint with a variable exponent also retained 1690 for overflow and zero to a negative exponent. Restart, CREATE TABLE LIKE and an ALTER of a column outside the constraint preserved the released binding.A retained v4.2.9 CHECK keeps its error behavior when ALTER converts a directly referenced DOUBLE operand of POW to FLOAT. The new input can be represented exactly by the old overload. A conversion that cannot preserve the bound expression requires explicitly redefining the CHECK. A newly declared CHECK uses row-local NULL semantics.
Released backups and views
A v4.2.9 v1 table dump stores SQL and a schema fingerprint. LOAD can recover a released POW binding in a CHECK, a generated column, or a DEFAULT, including a constant DEFAULT whose stored value no longer contains the function ID. The original CREATE and catalog scopes can differ in their column nullability annotations. Recovery checks the complete candidate trees and rejects differences that change the computed expression. It installs the verified definition and the data in one transaction.
LOAD also checks the table and relation fingerprints. It can reproduce the old spelling of an implicit table default when all columns and expressions are independent of text collation, including numeric POW constraints on tables with DATE, DATETIME, UUID, BINARY, or VARBINARY columns. For a v3 dump from an upgraded table, this compatibility path also requires a verified bound-expression payload containing a released POW binding and matching physical and logical fingerprints for the main relation.
At
985a0d35e6, a newly initialized target loaded three v1 archives from the official v4.2.9 release. These covered a STORED generated column with data, a metadata-only STORED column, and a metadata-only VIRTUAL column. All three generated-column catalog payloads matched the release byte for byte, including after restart. The restored columns raised 1690 for a negative base and fractional exponent, while the same expression on a freshly created table produced NULL. A missing data object rolled back both the rows and the expression change. A mismatched target declaration was rejected.Views created on v4.2.9 retain error 1690 when expanded after upgrade, including through nested views. New views and explicit ALTER VIEW statements use row-local NULL. The planner scopes binding to each stored definition, so outer SQL and views from different releases can be combined.
Verified at
a74be94e2busing the official v4.2.9 release on Linux/arm64 and a freshly built macOS/arm64 target with Go 1.27.1. The stopped release data directory was reopened with the target binary for the view checks. The backups were loaded into a separate, newly initialized target.> 0to>= 0failed the schema check.At
ca96bccd40, the official v4.2.9 release rejected-2before and after altering the constrained column to FLOAT. The target reproduced both outcomes on the same released data after a shutdown upgrade. Both NOT NULL column cases and both forms of DEFAULT loaded from v1 archives. The archived result of POWER(2,3) was 8, the runtime default remained a function call, and the upgraded tables could be dumped again and loaded into newly created tables. A DATE/DATETIME schema mismatch and modified v3 fingerprints were rejected.Released generated columns, table dumps, and SQL functions
COPY ALTER preserves the bound POWER operation in retained STORED and VIRTUAL generated columns when the operand conversion is safe. An incompatible change requires an explicit new generated definition. On the released
DOUBLE NOT NULLtoFLOAT NOT NULLcase, the upgraded table still rejects a negative fractional power with 1690 and keeps its valid row.A v3 re-dump can restore a released anonymous CHECK onto the target's generated constraint name. The compatibility check also recognizes the qualified internal CREATE name emitted by the v4.2.9 COPY ALTER implementation for the same logical table. LOAD verifies the declarations, the table and main relation fingerprints and, for v3, the original bound payload.
SQL UDF bodies bind their own POWER calls under the definition's stored semantics. Call arguments keep their caller's semantics. Ordinary arithmetic function bodies retain their original catalog text. Cloning a query-bodied function that references its source database preserves its positional arguments as well as its POWER behavior.
At
4c1adb1583, the clean service reopened stopped databases from the official v4.2.9 release. All five released table shapes loaded from both their original v1 archives and their upgraded v3 re-dumps into freshly created targets. Both formats preserved 1690 for a negative fractional power and 3819 for zero. Recovery rejected a changed binary width, mismatched internal table names and a v3 payload with a different CHECK owner. Direct, nested, view, restart, database clone and snapshot clone probes preserved released and current SQL UDF behavior. The POWER BVT passed 113/113 statements and the existing account snapshot UDF section passed 51/51. Coverage of executable Go statements in blocks touched by this review fix reached 91.3%.SQL function clones, internal queries, and released table recovery
When EXECUTE rebinds a POWER call to the supplied argument types, it preserves the overload selected for the function definition. In a shutdown upgrade from v4.2.9, executing a prepared
SET @out = released_pow(?)with -2 raises error 1690 and leaves the variable unchanged. The same assignment through a newly defined function stores NULL. Both definitions return 4 for 16. These results were verified with SQL PREPARE and the MySQL binary prepared-statement protocol on the upgraded server and after restart.The SQL function binder and database cloner now use the same parser to distinguish complete queries from scalar expressions. This preserves set queries with a parenthesized first operand, TABLE query terms, and queries preceded by empty statements. In a shutdown upgrade from v4.2.9, the stored function with body
(select 1 where 1=0) union all select 2returned2after upgrade, cloning, and restart. Released POWER functions kept error 1690 for a negative fractional power, and newly created functions returned NULL. A released function with bodyperform select 7also returned 7 after upgrade, cloning, and restart. The same tests verified thatperformstill works as a column name in a scalar function body.Database cloning rewrites source-qualified subqueries inside scalar SQL function bodies and preserves the definition's SQL mode, positional arguments and binary literals. The frontend and the internal query compiler use the same decoder for released and current function definitions. A cloned function reads the clone after the source table is dropped. A view calling POWER can also supply rows to
ivf_create.Restoring a released table now accounts for ordinary RENAME and the way released SHOW CREATE prints primary keys, unnamed CHECK constraints and NULL defaults. LOAD verifies the declaration, bound expressions and relation fingerprints. A numeric POWER constraint can be restored alongside JSON and vector values. For regular secondary indexes, LOAD checks the actual key parts and reconstructs the released representation of the packed key before accepting the index objects.
Using the official Linux/arm64 v4.2.9 server, we generated full v1 archives with table and index data. After a shutdown upgrade we generated v3 archives and loaded both formats into recreated tables. Tests checked the stored data after restart, queried the restored secondary index after another write, and verified 1690 for negative fractional powers and 3819 for a false CHECK. Mismatched predicates, constraint names, vector dimensions and mixed index fingerprints were rejected. Changing the bound type of a JSON default or a vector default’s dimension was rejected even after recomputing the v3 expression digest. The target stayed empty. A missing index object rolled back the load and the genuine archive could be retried.
At
07494aeb90, 160 top-level Go tests passed, including the real projection error recovery test on two consecutive runs. Coverage of executable statements in blocks touched by this follow-up was 89.0% (380/427). The POWER BVT passed all 113 statements, and the four affected packages passed the pinned static checks.Validation on macOS arm64 using Go 1.27.1 and a freshly built single-CN CPU service:
Powerand 76.8% for the package.matrixorigin/motr@f0b2def2passed all 28 statements. Both issue reproducers also returned NULL over the MySQL protocol.go vet, the repository-pinnedmolintandgolangci-lintpassed for both changed Go packages. Formatting andgit diff --checkpassed.Review follow-up:
5a7d8a8. Before the update, seven assertions expecting 1690 failed on this evaluator and the other fifteen passed. The updated case verifies five scalar NULL results, both rows of a mixed vector, and a stored NULL. Together with the existing [Bug]: POW with negative base and fractional exponent returns NaN instead of MySQL error #25308 and [Compatibility]: POWER, EXP overflow and COT domain errors abort queries instead of returning NULL #28137 MOTR cases it passed three replays each. Coordinate the MOTR rollout with this kernel change so the updated regression is run against a build containing it.