Repository navigation
fix(function): align QUOTE with MySQL - #28443
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? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
GPT-6 Astra medium deep review of exact head cfc81a157beec91b16e27e6c96d82106dfa7b291 against base/merge-base 6d44c50e964cf5ecd3eed02d478bd222c07d777a.
Found one P2 result-type boundary issue below; recommendation: fix before merge. Submitted as COMMENT because this is the author's own PR.
Coverage: read all five changed files and traced the R2 SQL-result closure through function resolution/return-width and charset inference, vector result ownership, SELECT-list masking, CTAS consumers, and text/binary protocol NULL handling. Ordinary compatibility bug fix; no feature-design gate. The four escape classes, preserved LF/CR/TAB, empty strings, invalid UTF-8/binary byte preservation, and actual NULL versus masked rows are internally consistent. Existing nullable metadata remains conservative for nullable input; no new prepared-parameter or wire-encoding defect was found. Binary/invalid-UTF-8 preservation is the explicitly retained MO contract, not a claim of full MySQL charset coercion equivalence.
Unhappy-path closure:
| Check | Result |
|---|---|
| Q1 ownership | Writer appends into the result vector; append failures roll back; FunctionResult.Free owns vector release. QuoteString buffers are local/GC-owned. |
| Q2 liveness | No added waits, goroutines, locks, callbacks that outlive the call, or network operations; work is finite over input bytes. |
| Q3 bounds/performance | SQL path retains the existing result-size cap and direct final-buffer writer, with O(n) sizing + writing and output at most 2n+2. No new persistent accumulation. |
Evidence reused: exact-head CI run 34263119686 completed successfully; checkout logs verify the full reviewed SHA. UT and UT-coverage jobs succeeded, and the downloaded coverage artifact records execution of Quote, quotedBytesLength, writeQuotedBytes and QuoteString. The downloaded bvt-execution-pessimistic-attempt-1 report explicitly records func_string_quote.test: 24 total, 24 success, 0 failed/ignored/abnormal (0.183s). Shared build, static checks and both active BVT groups succeeded; skipped Darwin/upgrade jobs are not counted as validation. No local service or prepared-client test was run, and no repository code was changed.
| value, null := parameter.GetStrValue(row) | ||
| if null { | ||
| if err := rs.AppendBytes(nil, true); err != nil { | ||
| if err := rs.AppendBytes([]byte("NULL"), false); err != nil { |
There was a problem hiding this comment.
[P2] Include the four-character NULL result in the declared return-width bound
This new branch returns four characters, but quoteReturnType still uses only 2 * input.Width + 2. For the supported nullable VARCHAR(0)/VARBINARY(0) case it therefore advertises width 2 while QUOTE(s) on a NULL row produces NULL (length 4). TestExpandingReturnTypeBounds currently explicitly locks in the width-2 result. This also reaches persistent schema inference: CREATE TABLE src(s VARCHAR(0)); INSERT INTO src VALUES (NULL); CREATE TABLE dst AS SELECT QUOTE(s) AS q FROM src; feeds that width-2 expression type directly into genAsSelectCols (build_ddl.go:1387-1453), so the inferred target column cannot describe the newly valid result. This is a source-proven type/CTAS-schema mismatch; I have not run the SQL reproduction locally.
Please make the known return bound at least 4 for both text and binary domains (preserving unknown/large bounds), and update the boundary UT plus a nullable zero-width CTAS/BVT case. MySQL likewise uses max(4, 2 * max_char_length + 2) specifically for this NULL branch in Item_func_quote::resolve_type.
Follow-up: result-width boundaryThe review found that the original return-type bound could understate QUOTE(NULL): for a known zero-width VARCHAR/VARBINARY input, the runtime result is the four-byte string NULL. Commit 10d63e1:
Additional validation:
This is planner metadata only; the runtime QUOTE implementation and its performance characteristics are unchanged (the extra work is one bounded type check). |
## Summary HAKeeper can report a failed MORPC transport generation as `ErrBackendClosed` instead of EOF. The managed client previously reset that generation but returned the error directly, so a transient control-plane disconnect escaped as a SQL failure during `TestIssue26640CrossAccountRestoreRebindsPrivileges`. This change: - retries the transport-generation errors (`ErrBackendClosed`, connect/admission failures, connection reset) through the caller's existing deadline; - makes `managedHAKeeperClient.Close` terminal, prevents late failures from recreating a transport, and makes concurrent `Close` calls join the same cleanup result; - consolidates the retry regressions into deterministic table-driven tests, including deadline, business-error, in-flight-close, and concurrent-close cases. The retry is bounded by every public HAKeeper request context. An allocation whose response is lost may consume an ID range, as the existing EOF retry already did, but the server's monotonic allocator prevents duplicate IDs from being returned. ## Root cause and scope - #28443 failed before its restore/privilege assertions. The embedded LogService first reported checker/raft timing pressure, then MORPC returned `backend connection closed` while allocating an ID. The failure was a downstream control-plane transport error; the deeper first scheduler/WAL/IO fault is not proven by that job. - #28447 is a separate MORPC stream-sequence-gap failure. It was already fixed by merged #28358, which is in this branch's base. The exact regression test passes repeatedly on current main, so this PR intentionally does not duplicate that dispatch implementation. Fixes #28452 Related: #28443, #28447, #28313, #28358 ## Validation - `TestIssue26640CrossAccountRestoreRebindsPrivileges`: `-count=3`, passed. - `TestIssue28313EmptyRemoteDispatch`: `-count=5`, passed. - HAKeeper retry/close focused tests: normal and `-race -count=100`, passed. - `pkg/logservice`: normal and race package runs passed with the known unrelated flaky `TestNewServiceClosesStoreOnReplicaStartFailure` excluded; that test still fails independently with listener address collisions/store-close leakage. - `go vet ./pkg/logservice` with the repository CGo flags and `git diff --check`, passed. ## CI triage for run 34300098985 The source changes in this PR are limited to pkg/logservice. In the exact-head CI run: - Shared build, SCA, normal UT, Compose BVT, and Standalone BVT passed. - The UT coverage producer failed only at the unrelated existing test pkg/sql/compile/TestIssue27261StopSendingDuringParallelReaderBuildStaysGraceful, which returned context canceled; the producer report recorded no build failures and two failed events in pkg/sql/compile. - The downstream coverage merge failed because the required UT producer artifact was incomplete (prerequisites_ready=false); it did not calculate a coverage verdict. - The same TestIssue27261 test passed locally 10 times, and the PR retry/close focused tests passed locally 20 times normally and 100 times under -race; go vet and git diff --check passed. No unrelated compile/pipeline change is included to mask this flaky coverage-only failure. This PR was not rebased and the existing PR base was not changed.
## Summary Fixes matrixorigin#28203. Align `QUOTE()` with the MySQL result contract while preserving binary and invalid-UTF-8 payload bytes. ## Root cause The original implementation used MySQL-compatible escaping, but a later writer-based refactor changed the semantics in three ways: - SQL NULL was appended as a SQL NULL instead of the string `NULL`. - Apostrophes were doubled instead of being prefixed with a backslash. - Newline, carriage return, and tab were escaped even though MySQL retains those bytes. The refactor also counted the old escape set separately from the writer, so the size calculation and output rules could drift. ## Changes - Use one byte-oriented length calculation and writer for `Quote` and `QuoteString`. - Return the non-NULL string `NULL` for a NULL argument. - Escape only apostrophe, backslash, NUL, and Ctrl-Z with MySQL's rules. - Retain arbitrary non-escaped bytes, including binary data and invalid UTF-8. - Replace ambiguous control-byte BVT expectations with `HEX(QUOTE(...))` assertions. ## Correctness and unhappy paths - Outer select-list masked rows still produce SQL NULL; only an actual `QUOTE(NULL)` input produces the string `NULL`. - The writer capacity is derived from the same escape classification used by the writer, covering empty values, repeated escapes, control bytes, and binary payloads. - Existing result-size overflow behavior is unchanged; this PR does not broaden the function's accepted input or change planner nullability metadata. ## Validation - `GOWORK=off go test -mod=readonly -count=1 -timeout=8m ./pkg/sql/plan/function` - Focused race tests for QUOTE and string-domain behavior - Standalone MatrixOne black-box checks for NULL, apostrophe, backslash, LF, CR, TAB, NUL, and Ctrl-Z - `func_string_quote` BVT: 24/24 passed twice - `go vet` with `molint` - `golangci-lint` - `license-eye`: 5205 files checked, invalid 0 - `git diff --check` The standalone service was built from the latest `main` and the BVT used the fixed binary. No production concurrency, lifecycle, lock, or network behavior is changed. ## Follow-up: result-width boundary The review found that the original return-type bound could understate QUOTE(NULL): for a known zero-width VARCHAR/VARBINARY input, the runtime result is the four-byte string NULL. Commit 10d63e1: - enforces a minimum known result bound of 4 for QUOTE while preserving unknown/overflow bounds; - covers both VARCHAR(0) and VARBINARY(0) in the return-type unit test; - adds a real VARCHAR(0) DROP/CTAS boundary test and verifies the stored result length. Additional validation: - pkg/sql/plan/function UT: passed; - go vet and molint: passed; - targeted golangci-lint: 0 issues; - fixed-binary func_string_quote BVT: 30/30 passed. This is planner metadata only; the runtime QUOTE implementation and its performance characteristics are unchanged (the extra work is one bounded type check). --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…gin#28453) ## Summary HAKeeper can report a failed MORPC transport generation as `ErrBackendClosed` instead of EOF. The managed client previously reset that generation but returned the error directly, so a transient control-plane disconnect escaped as a SQL failure during `TestIssue26640CrossAccountRestoreRebindsPrivileges`. This change: - retries the transport-generation errors (`ErrBackendClosed`, connect/admission failures, connection reset) through the caller's existing deadline; - makes `managedHAKeeperClient.Close` terminal, prevents late failures from recreating a transport, and makes concurrent `Close` calls join the same cleanup result; - consolidates the retry regressions into deterministic table-driven tests, including deadline, business-error, in-flight-close, and concurrent-close cases. The retry is bounded by every public HAKeeper request context. An allocation whose response is lost may consume an ID range, as the existing EOF retry already did, but the server's monotonic allocator prevents duplicate IDs from being returned. ## Root cause and scope - matrixorigin#28443 failed before its restore/privilege assertions. The embedded LogService first reported checker/raft timing pressure, then MORPC returned `backend connection closed` while allocating an ID. The failure was a downstream control-plane transport error; the deeper first scheduler/WAL/IO fault is not proven by that job. - matrixorigin#28447 is a separate MORPC stream-sequence-gap failure. It was already fixed by merged matrixorigin#28358, which is in this branch's base. The exact regression test passes repeatedly on current main, so this PR intentionally does not duplicate that dispatch implementation. Fixes matrixorigin#28452 Related: matrixorigin#28443, matrixorigin#28447, matrixorigin#28313, matrixorigin#28358 ## Validation - `TestIssue26640CrossAccountRestoreRebindsPrivileges`: `-count=3`, passed. - `TestIssue28313EmptyRemoteDispatch`: `-count=5`, passed. - HAKeeper retry/close focused tests: normal and `-race -count=100`, passed. - `pkg/logservice`: normal and race package runs passed with the known unrelated flaky `TestNewServiceClosesStoreOnReplicaStartFailure` excluded; that test still fails independently with listener address collisions/store-close leakage. - `go vet ./pkg/logservice` with the repository CGo flags and `git diff --check`, passed. ## CI triage for run 34300098985 The source changes in this PR are limited to pkg/logservice. In the exact-head CI run: - Shared build, SCA, normal UT, Compose BVT, and Standalone BVT passed. - The UT coverage producer failed only at the unrelated existing test pkg/sql/compile/TestIssue27261StopSendingDuringParallelReaderBuildStaysGraceful, which returned context canceled; the producer report recorded no build failures and two failed events in pkg/sql/compile. - The downstream coverage merge failed because the required UT producer artifact was incomplete (prerequisites_ready=false); it did not calculate a coverage verdict. - The same TestIssue27261 test passed locally 10 times, and the PR retry/close focused tests passed locally 20 times normally and 100 times under -race; go vet and git diff --check passed. No unrelated compile/pipeline change is included to mask this flaky coverage-only failure. This PR was not rebased and the existing PR base was not changed.
## Summary Fixes matrixorigin#28203. Align `QUOTE()` with the MySQL result contract while preserving binary and invalid-UTF-8 payload bytes. ## Root cause The original implementation used MySQL-compatible escaping, but a later writer-based refactor changed the semantics in three ways: - SQL NULL was appended as a SQL NULL instead of the string `NULL`. - Apostrophes were doubled instead of being prefixed with a backslash. - Newline, carriage return, and tab were escaped even though MySQL retains those bytes. The refactor also counted the old escape set separately from the writer, so the size calculation and output rules could drift. ## Changes - Use one byte-oriented length calculation and writer for `Quote` and `QuoteString`. - Return the non-NULL string `NULL` for a NULL argument. - Escape only apostrophe, backslash, NUL, and Ctrl-Z with MySQL's rules. - Retain arbitrary non-escaped bytes, including binary data and invalid UTF-8. - Replace ambiguous control-byte BVT expectations with `HEX(QUOTE(...))` assertions. ## Correctness and unhappy paths - Outer select-list masked rows still produce SQL NULL; only an actual `QUOTE(NULL)` input produces the string `NULL`. - The writer capacity is derived from the same escape classification used by the writer, covering empty values, repeated escapes, control bytes, and binary payloads. - Existing result-size overflow behavior is unchanged; this PR does not broaden the function's accepted input or change planner nullability metadata. ## Validation - `GOWORK=off go test -mod=readonly -count=1 -timeout=8m ./pkg/sql/plan/function` - Focused race tests for QUOTE and string-domain behavior - Standalone MatrixOne black-box checks for NULL, apostrophe, backslash, LF, CR, TAB, NUL, and Ctrl-Z - `func_string_quote` BVT: 24/24 passed twice - `go vet` with `molint` - `golangci-lint` - `license-eye`: 5205 files checked, invalid 0 - `git diff --check` The standalone service was built from the latest `main` and the BVT used the fixed binary. No production concurrency, lifecycle, lock, or network behavior is changed. ## Follow-up: result-width boundary The review found that the original return-type bound could understate QUOTE(NULL): for a known zero-width VARCHAR/VARBINARY input, the runtime result is the four-byte string NULL. Commit 10d63e1: - enforces a minimum known result bound of 4 for QUOTE while preserving unknown/overflow bounds; - covers both VARCHAR(0) and VARBINARY(0) in the return-type unit test; - adds a real VARCHAR(0) DROP/CTAS boundary test and verifies the stored result length. Additional validation: - pkg/sql/plan/function UT: passed; - go vet and molint: passed; - targeted golangci-lint: 0 issues; - fixed-binary func_string_quote BVT: 30/30 passed. This is planner metadata only; the runtime QUOTE implementation and its performance characteristics are unchanged (the extra work is one bounded type check). --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…gin#28453) ## Summary HAKeeper can report a failed MORPC transport generation as `ErrBackendClosed` instead of EOF. The managed client previously reset that generation but returned the error directly, so a transient control-plane disconnect escaped as a SQL failure during `TestIssue26640CrossAccountRestoreRebindsPrivileges`. This change: - retries the transport-generation errors (`ErrBackendClosed`, connect/admission failures, connection reset) through the caller's existing deadline; - makes `managedHAKeeperClient.Close` terminal, prevents late failures from recreating a transport, and makes concurrent `Close` calls join the same cleanup result; - consolidates the retry regressions into deterministic table-driven tests, including deadline, business-error, in-flight-close, and concurrent-close cases. The retry is bounded by every public HAKeeper request context. An allocation whose response is lost may consume an ID range, as the existing EOF retry already did, but the server's monotonic allocator prevents duplicate IDs from being returned. ## Root cause and scope - matrixorigin#28443 failed before its restore/privilege assertions. The embedded LogService first reported checker/raft timing pressure, then MORPC returned `backend connection closed` while allocating an ID. The failure was a downstream control-plane transport error; the deeper first scheduler/WAL/IO fault is not proven by that job. - matrixorigin#28447 is a separate MORPC stream-sequence-gap failure. It was already fixed by merged matrixorigin#28358, which is in this branch's base. The exact regression test passes repeatedly on current main, so this PR intentionally does not duplicate that dispatch implementation. Fixes matrixorigin#28452 Related: matrixorigin#28443, matrixorigin#28447, matrixorigin#28313, matrixorigin#28358 ## Validation - `TestIssue26640CrossAccountRestoreRebindsPrivileges`: `-count=3`, passed. - `TestIssue28313EmptyRemoteDispatch`: `-count=5`, passed. - HAKeeper retry/close focused tests: normal and `-race -count=100`, passed. - `pkg/logservice`: normal and race package runs passed with the known unrelated flaky `TestNewServiceClosesStoreOnReplicaStartFailure` excluded; that test still fails independently with listener address collisions/store-close leakage. - `go vet ./pkg/logservice` with the repository CGo flags and `git diff --check`, passed. ## CI triage for run 34300098985 The source changes in this PR are limited to pkg/logservice. In the exact-head CI run: - Shared build, SCA, normal UT, Compose BVT, and Standalone BVT passed. - The UT coverage producer failed only at the unrelated existing test pkg/sql/compile/TestIssue27261StopSendingDuringParallelReaderBuildStaysGraceful, which returned context canceled; the producer report recorded no build failures and two failed events in pkg/sql/compile. - The downstream coverage merge failed because the required UT producer artifact was incomplete (prerequisites_ready=false); it did not calculate a coverage verdict. - The same TestIssue27261 test passed locally 10 times, and the PR retry/close focused tests passed locally 20 times normally and 100 times under -race; go vet and git diff --check passed. No unrelated compile/pipeline change is included to mask this flaky coverage-only failure. This PR was not rebased and the existing PR base was not changed.
## Summary Fixes matrixorigin#28203. Align `QUOTE()` with the MySQL result contract while preserving binary and invalid-UTF-8 payload bytes. ## Root cause The original implementation used MySQL-compatible escaping, but a later writer-based refactor changed the semantics in three ways: - SQL NULL was appended as a SQL NULL instead of the string `NULL`. - Apostrophes were doubled instead of being prefixed with a backslash. - Newline, carriage return, and tab were escaped even though MySQL retains those bytes. The refactor also counted the old escape set separately from the writer, so the size calculation and output rules could drift. ## Changes - Use one byte-oriented length calculation and writer for `Quote` and `QuoteString`. - Return the non-NULL string `NULL` for a NULL argument. - Escape only apostrophe, backslash, NUL, and Ctrl-Z with MySQL's rules. - Retain arbitrary non-escaped bytes, including binary data and invalid UTF-8. - Replace ambiguous control-byte BVT expectations with `HEX(QUOTE(...))` assertions. ## Correctness and unhappy paths - Outer select-list masked rows still produce SQL NULL; only an actual `QUOTE(NULL)` input produces the string `NULL`. - The writer capacity is derived from the same escape classification used by the writer, covering empty values, repeated escapes, control bytes, and binary payloads. - Existing result-size overflow behavior is unchanged; this PR does not broaden the function's accepted input or change planner nullability metadata. ## Validation - `GOWORK=off go test -mod=readonly -count=1 -timeout=8m ./pkg/sql/plan/function` - Focused race tests for QUOTE and string-domain behavior - Standalone MatrixOne black-box checks for NULL, apostrophe, backslash, LF, CR, TAB, NUL, and Ctrl-Z - `func_string_quote` BVT: 24/24 passed twice - `go vet` with `molint` - `golangci-lint` - `license-eye`: 5205 files checked, invalid 0 - `git diff --check` The standalone service was built from the latest `main` and the BVT used the fixed binary. No production concurrency, lifecycle, lock, or network behavior is changed. ## Follow-up: result-width boundary The review found that the original return-type bound could understate QUOTE(NULL): for a known zero-width VARCHAR/VARBINARY input, the runtime result is the four-byte string NULL. Commit 10d63e1: - enforces a minimum known result bound of 4 for QUOTE while preserving unknown/overflow bounds; - covers both VARCHAR(0) and VARBINARY(0) in the return-type unit test; - adds a real VARCHAR(0) DROP/CTAS boundary test and verifies the stored result length. Additional validation: - pkg/sql/plan/function UT: passed; - go vet and molint: passed; - targeted golangci-lint: 0 issues; - fixed-binary func_string_quote BVT: 30/30 passed. This is planner metadata only; the runtime QUOTE implementation and its performance characteristics are unchanged (the extra work is one bounded type check). --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…gin#28453) ## Summary HAKeeper can report a failed MORPC transport generation as `ErrBackendClosed` instead of EOF. The managed client previously reset that generation but returned the error directly, so a transient control-plane disconnect escaped as a SQL failure during `TestIssue26640CrossAccountRestoreRebindsPrivileges`. This change: - retries the transport-generation errors (`ErrBackendClosed`, connect/admission failures, connection reset) through the caller's existing deadline; - makes `managedHAKeeperClient.Close` terminal, prevents late failures from recreating a transport, and makes concurrent `Close` calls join the same cleanup result; - consolidates the retry regressions into deterministic table-driven tests, including deadline, business-error, in-flight-close, and concurrent-close cases. The retry is bounded by every public HAKeeper request context. An allocation whose response is lost may consume an ID range, as the existing EOF retry already did, but the server's monotonic allocator prevents duplicate IDs from being returned. ## Root cause and scope - matrixorigin#28443 failed before its restore/privilege assertions. The embedded LogService first reported checker/raft timing pressure, then MORPC returned `backend connection closed` while allocating an ID. The failure was a downstream control-plane transport error; the deeper first scheduler/WAL/IO fault is not proven by that job. - matrixorigin#28447 is a separate MORPC stream-sequence-gap failure. It was already fixed by merged matrixorigin#28358, which is in this branch's base. The exact regression test passes repeatedly on current main, so this PR intentionally does not duplicate that dispatch implementation. Fixes matrixorigin#28452 Related: matrixorigin#28443, matrixorigin#28447, matrixorigin#28313, matrixorigin#28358 ## Validation - `TestIssue26640CrossAccountRestoreRebindsPrivileges`: `-count=3`, passed. - `TestIssue28313EmptyRemoteDispatch`: `-count=5`, passed. - HAKeeper retry/close focused tests: normal and `-race -count=100`, passed. - `pkg/logservice`: normal and race package runs passed with the known unrelated flaky `TestNewServiceClosesStoreOnReplicaStartFailure` excluded; that test still fails independently with listener address collisions/store-close leakage. - `go vet ./pkg/logservice` with the repository CGo flags and `git diff --check`, passed. ## CI triage for run 34300098985 The source changes in this PR are limited to pkg/logservice. In the exact-head CI run: - Shared build, SCA, normal UT, Compose BVT, and Standalone BVT passed. - The UT coverage producer failed only at the unrelated existing test pkg/sql/compile/TestIssue27261StopSendingDuringParallelReaderBuildStaysGraceful, which returned context canceled; the producer report recorded no build failures and two failed events in pkg/sql/compile. - The downstream coverage merge failed because the required UT producer artifact was incomplete (prerequisites_ready=false); it did not calculate a coverage verdict. - The same TestIssue27261 test passed locally 10 times, and the PR retry/close focused tests passed locally 20 times normally and 100 times under -race; go vet and git diff --check passed. No unrelated compile/pipeline change is included to mask this flaky coverage-only failure. This PR was not rebased and the existing PR base was not changed.
Summary
Fixes #28203.
Align
QUOTE()with the MySQL result contract while preserving binary and invalid-UTF-8 payload bytes.Root cause
The original implementation used MySQL-compatible escaping, but a later writer-based refactor changed the semantics in three ways:
NULL.The refactor also counted the old escape set separately from the writer, so the size calculation and output rules could drift.
Changes
QuoteandQuoteString.NULLfor a NULL argument.HEX(QUOTE(...))assertions.Correctness and unhappy paths
QUOTE(NULL)input produces the stringNULL.Validation
GOWORK=off go test -mod=readonly -count=1 -timeout=8m ./pkg/sql/plan/functionfunc_string_quoteBVT: 24/24 passed twicego vetwithmolintgolangci-lintlicense-eye: 5205 files checked, invalid 0git diff --checkThe standalone service was built from the latest
mainand the BVT used the fixed binary. No production concurrency, lifecycle, lock, or network behavior is changed.Follow-up: result-width boundary
The review found that the original return-type bound could understate QUOTE(NULL): for a known zero-width VARCHAR/VARBINARY input, the runtime result is the four-byte string NULL.
Commit 10d63e1:
Additional validation:
This is planner metadata only; the runtime QUOTE implementation and its performance characteristics are unchanged (the extra work is one bounded type check).