Repository navigation
fix(function): complete binary string semantics - #28055
Conversation
# Conflicts: # pkg/bootstrap/versions/v4_0_6/upgrade_test.go # pkg/defines/const.go # test/distributed/cases/dml/show/show.result # test/distributed/cases/zz_accesscontrol/account_restricted.result
# Conflicts: # pkg/bootstrap/versions/v4_0_6/upgrade_test.go # pkg/defines/const.go # pkg/sql/compile/remoterun.go
# Conflicts: # pkg/defines/const.go # pkg/pb/pipeline/pipeline.pb.go # test/distributed/cases/database/system_table.result
# Conflicts: # pkg/defines/const.go # pkg/frontend/back_exec.go # pkg/frontend/compiler_context.go # pkg/frontend/computation_wrapper.go # pkg/frontend/computation_wrapper_test.go # pkg/frontend/mysql_cmd_executor.go # pkg/sql/colexec/evalExpression.go # pkg/sql/plan/function/func_builtin_regexp.go # pkg/sql/plan/function/func_unary.go # pkg/sql/plan/function/type_check.go # pkg/sql/plan/utils.go
# Conflicts: # pkg/defines/const.go # pkg/pb/pipeline/pipeline.pb.go
# Conflicts: # pkg/defines/const.go # pkg/pb/query/query.pb.go
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed head 080388b. Request changes for an unrelated protocol regression.
[P1] Preserve the already-shipped v53 ordered Top-N capability
pkg/sql/compile/compile.go:7344 changes supportsDistributedOrderedTop from MORPCVersion53 to MORPCVersion55, although pkg/defines/const.go still correctly assigns ordered-stream Top-N to v53 and only the new binary-string semantics to v55. This is not just a conservative planner fallback: the same helper is called by validateRemoteDistributedOrderedTopPipelineProtocol in remoterun.go. During an upgrade with negotiated v53/v54, an older coordinator can legitimately send an ordered Top-N pipeline, but a receiver containing this change now rejects it with the contradictory error "requires MORPC protocol version 53". New coordinators also lose the existing optimization at those versions.
Fix: restore this existing capability predicate to v53; keep the new binary-string/runtime-domain predicates independently gated at the new version. Add explicit v52/v53/v54/v55 sender and receiver tests: reject ordered Top-N at v52, accept at v53 and above, while rejecting the new binary-string protocol below its own gate. Do not test only MORPCLatestVersion: the existing compile matrix uses v52/latest and therefore misses this regression when latest advances.
Review scope/evidence: inspected the complete change map and function-semantics design, then followed protocol metadata validation/ownership and all callers of the changed Top-N capability. The failure above follows directly from the receiver predicate and the existing v53 wire contract; I did not run a fresh native two-CN reproduction or claim a complete approval of the large LIKE/NTT implementation. The binary metadata length/domain validation and separate fail-closed gates should be preserved. After fixing the capability regression, retain the PR's staged readiness holds and provide mixed-version receiver coverage before requesting re-review.
# Conflicts: # pkg/defines/const.go # pkg/frontend/computation_wrapper.go # pkg/frontend/computation_wrapper_test.go # pkg/frontend/types.go # pkg/pb/pipeline/pipeline.pb.go
# Conflicts: # pkg/frontend/computation_wrapper_test.go
Keep historical COLUMNS DDL and v46 gates; install new semantics only through v4.0.6. Reserve v57 for main's Arrow LOAD and gate binary-string/runtime-domain capabilities at v58. Restore empty DESC Comment fields and refresh bounded HEX result metadata.
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.
Deep review of exact head 90d773819692f16f61b08eabcecbafb53c565c16 (base 93e7a3c631e31e28b85714840279d7c20424693f).
Request changes: one confirmed P2 wrong-result blocker, detailed inline. The new domain-preserving resolver/executors are not closed over the existing exact BINARY/VARBINARY SUBSTRING overloads.
The previous requested-change blocker is closed: distributed ordered Top remains independently gated at v53; this feature uses v58. Reviewed the complete 81-file change map, approved design, function resolution and row-domain propagation, SQL/COM prepared values and transport/migration, sender/receiver capability checks, immutable historical catalog DDL versus appended v58 entries, LIKE direct/sparse/convolution paths and their accounting/cancellation, and UT/BVT changes. REGEXP full semantics remains explicitly owned by #27217; no claim that this PR implements it.
Validation: exact-head CI run 34314820610 succeeded, including UT and BVT jobs (upgrade was skipped, not counted as evidence). Independently rebuilt native dependencies in an isolated exact-head worktree and ran a new resolver-to-executor counterexample with .agents/skills/mo-dev/scripts/mo-cgo-test -p 4 -v -count=1 -timeout=120s -run '^TestAstraReviewSubstringAfterLeftTextOverride$' ./pkg/sql/plan/function: it failed deterministically, expected E5A5BD, actual BD. This was a typed executor test, not a claimed live SQL/BVT run. No other confirmed blockers from the reviewed scope; no production changes made.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep re-review of exact head c3d832e: the previous SUBSTRING wrong-result blocker is closed; no additional confirmed blocker found.
All four exact BINARY/VARBINARY registrations now dispatch to the existing domain-aware two-/three-argument executors. This preserves byte slicing for effective binary rows while honoring explicit Text overrides and propagating selected-result domains. Rechecked mixed vectors, NULL/masked rows, zero/negative/extreme offsets and lengths, result types, and the unchanged overflow-safe bounds helper. The binary fast path still slices bytes directly; this fix introduces no shared mutable state or new unbounded allocation path. REGEXP full semantics remains the explicitly separate scope of #27217.
Coverage/evidence: mapped all 82 current PR files against the prior complete review at 90d7738. Only four files differ, and all four were reviewed; prior design/protocol/planner/runtime-domain/LIKE/unhappy-path evidence is reused for unchanged code. Independently replayed the previously failing LEFT→SUBSTRING resolver/executor counterexample and the new TestSubstringExactBinaryRuntimeDomain matrix with repository-native CGo dependencies: both pass (including BINARY/VARBINARY × two/three arguments, mixed Text/Binary rows, NULL and selection masks). The three exercised implementation/test files match current-head Git blob hashes. This was the existing isolated native worktree with the exact four-line fix and exact new UT applied, not a claim of rebuilding the whole rebased head. Original counterexample now returns E5A5BD for the text row and BD for the binary row.
Exact-head CI run 34325129573 is successful for UT, coverage, shared build and compose/proxy BVT; the public SQL regression and expected output were also inspected. No fresh live SQL, mixed-version cluster run or performance benchmark was performed by this reviewer. No production workspace changes were made.
Merge Queue Status
This pull request spent 2 minutes 22 seconds in the queue, with no time running CI. Waiting for
All conditions
ReasonPull request #28055 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.
HintYou should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it. Tick the box to put this pull request back in the merge queue (same as
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #27216
What this PR does / why we need it:
CHARSET()andCOLLATION()from static expression types and aligns existing charset identities with protocol andinformation_schemametadata.mo/mainends at v47, and this complete capability uses the contiguousMORPCVersion48.Review follow-up
The seven review areas are addressed:
COLUMNSview andCHARACTER_SETSdata; corrected publicutf8.MAXLENto 3.LIKE ... ESCAPEby effective row domain: one arbitrary byte for binary rows and one valid rune for text rows.%...literalbyte-LIKE backtracking.Testing
The detailed follow-up sections below contain the latest validation and supersede this original test snapshot:
NATIVE_BUILD_JOBS=8 make buildpkg/bootstrap/versions/v4_0_6,pkg/frontend,pkg/sql/colexec,pkg/sql/compile,pkg/sql/plan,pkg/sql/plan/function,pkg/util/sysview, andpkg/vm/processgolangci-lintfor the owning packages with the repository CGo flags:0 issuesbinary_string_function_semantics.teston a freshly initialized instance, twice consecutively:49/49each rungit diff --checkand exact conflict-marker scanReviewer note: repository cleanup
This PR also deletes
CLAUDE_TODO_2026-08-29.mdandCLAUDE_TODO_2026-08-30.md. These internal planning files were accidentally committed by earlier work and are already present onmain; their deletion here is intentional repository cleanup and is unrelated to the binary-string behavior change. No production or test logic is removed by this cleanup.Second P1 review follow-up
EXECUTE ... USINGnow installsRuntimeStringDomainon typed non-NULL literals before the materialization fast-path returns. Bidirectional tests executeCHAR_LENGTH: static VARBINARY/runtime text returns 2, while static VARCHAR/runtime binary returns 4, with repeated materialization from the same prepared plan.T_blobon the first execution and remainsT_blobwhen the previous packet type and runtime compile cache are reused.POSITION,INTERNAL_CHAR_SIZE, andINTERNAL_COLUMN_CHARACTER_SET. All 28 changed Function IDs have table-driven tests through the realencodeRemoteScopesender and remotedecodeScopereceiver boundaries: v44 rejects and v45 accepts each ID.%followed by_runs and a literal segment, plus a fixed 16M-step budget for the remaining general backtracking fallback. The reported adversarial benchmark is now approximately 4.9/10.2/20.8 µs at n=2000/4000/8000 (about 2x per doubling, zero allocations), and an unoptimized fallback rejection case verifies the bound.0 issues), and two fresh-instance BVT runs (49/49each) pass.Third P1 review follow-up
O(valueBytes * ceil(patternTokens/64))time andO(distinctLiteralBytes * ceil(patternTokens/64))space.1, matching MySQL 8.4. A deterministic exhaustive test compares all shorta/bvalues anda/b/_/%patterns against an independent dynamic-programming oracle.pipelineContainsFunction, so steady-state peers do not reflectively scan the pipeline. A 1000-expression Projection benchmark is approximately27 ns/op, 0 B/op, 0 allocs/op, with a zero-allocation UT.0 issues), and two fresh-instance BVT runs (50/50each) pass.Fourth P1 review follow-up
%; anchored prefix/suffix segments are checked directly, and intermediate fixed-length segments use their longest literal run as abytes.Index/Two-Way search anchor while advancing a monotonic value cursor.0 B/opand0 allocs/opin the match phase.mo/main: owning function-package tests, build, focused lint (0 issues), 96.15% round-four changed-statement coverage (125/130), and two BVT runs (50/50each) pass.Repeated-anchor P1 follow-up
%a + _... + b%/ all-aregression test and a 2K–64K benchmark.0 B/opand0 allocs/op.make buildpasses, and the public BVT passes50/50on a fresh instance.Conflict resolution and CI follow-up
mo/main(bf63172c06) and resolved the two conflicts by preserving both the Parquet whole-file-fanout and binary-string sender/receiver protocol validators.MORPCVersion45is now owned by main's Parquet fanout, while concurrent PR fix: expose subscription tables in information schema #27942 reserves v46. This PR therefore moves the binary-string execution/migration/upgrade barrier toMORPCVersion47, with v46-reject/v47-accept coverage.ORDbytes, byte-oriented BLOB slicing (including preserved trailing bytes), andRPAD(..., '')returning NULL. Updated those three result files.pkg/sql/compile,pkg/frontend,pkg/bootstrap/versions/v4_0_6, andpkg/sql/plan/functiontests pass; focused lint reports 0 issues;make buildpasses. The exact charset (158/158), INSTR (91/91), binary-string (50/50) BVT files pass. The targettext_blobrow 86 also passes; three unrelated local external-file rows cannot run in this workstation launch because its external resource file resolves empty (the prior CI run populated it and only failed row 86).Fifth P1 review follow-up
This section supersedes the earlier protocol-version, binary-LIKE algorithm, and empty-pad statements above.
mo/main(494e6a7723). Main still ends at MORPC v45 and fix: expose subscription tables in information schema #27942 remains open, so this PR now publishes the complete binary-string capability as the contiguousMORPCVersion46; remote execution, migration, and catalog upgrades reject v45 and accept v46. There is no v47 declaration or dependency on unmerged work.LPAD/RPADbehavior for empty pads: expansion returns a non-NULL empty string, while a target no longer than the source still truncates normally. Text and binary executor UTs and BVT expectations cover both directions._segments use deterministic two-modulus NTT convolution in segment-sized candidate blocks. The modulus product exceeds the maximum mismatch polynomial for a 64 MiB segment, so this is exact rather than probabilistic. Failed blocks consume disjoint value ranges, giving the complete matcherO((value + pattern) log pattern)worst-case time for the supported BLOB range.0 B/opand0 allocs/opafter scratch warm-up. The existing repeated-anchor and late-alignment 2K–64K paths remain linear and allocation-free.pkg/sql/plan/function,pkg/sql/compile,pkg/frontend, andpkg/bootstrap/versions/v4_0_6; changed-statement coverage is 95.95% (142/148); focused lint reports 0 issues;make buildpasses; fresh-instance BVT passesbinary_string_function_semantics52/52 andfunction_instr91/91.Sixth review follow-up
min(anchorFrequency, candidateCount)and only selects convolution when that work exceeds64 * (valueLength + segmentLength). A one-alignment segment therefore always stays on the direct path, independent of segment size.0 B/op,0 allocs/op, and zero NTT scratch. The equal-frequency multi-candidate benchmark still selects convolution and retains itsn log nscaling.p*x*(p-x)^2, whose maximum per-byte term is 636,284,160. The 64-MiB aggregate bound remains below the two-modulus product. The dual-modulus test now uses[244 x 8, 157]versus[56 x 8, 78], asserts a zero first residue and nonzero second residue, and verifies rejection by the second modulus.mo/main(149219181f). Full function-package tests,make build, focused lint (0 issues), 78.26% follow-up changed-statement coverage (36/46), and BVT (53/53binary-string semantics;91/91INSTR) pass.Seventh review follow-up
This section supersedes the Sixth follow-up for multi-segment direct verification and empty-pad character limits.
64 * (valueLength + patternLength)direct-verification budget for the complete match. Every actually inspected constraint consumes it; it is never reset per%segment. If it is exhausted, matching resumes from the current unresolved candidate with the exact two-modulus convolution path rather than returning an error._runs for every candidate. For a multi-candidate segment whose literal density is at most 1/8, reusable process-MPool scratch stores only literal offsets, so direct verification checks exactly those constraints. Single-candidate segments retain the zero-scratch direct path. MPool admission-failure and no-leak tests cover this new scratch.context.Canceledwithout timing or sleep dependencies.0 B/opand0 allocs/opafter warm-up and no NTT scratch. A MaxBlobLen arithmetic guard proves that the original per-segment work exceeds the match-wide budget, while a forced-budget test verifies exact fallback from an unresolved candidate. Dense equal-frequency cases still use convolution and retainn log nscaling.mo/main(922e792ebf); fix: expose subscription tables in information schema #27942 remains open and MORPC v46 remains contiguous. Post-merge full function-package tests andmake buildpass. Focused lint reports0 issues, follow-up changed-statement coverage is 87.18% (102/117), and fresh-instancebinary_string_function_semanticsBVT passes 54/54.Eighth follow-up: latest-main conflict resolution
This section supersedes all earlier protocol-version statements.
mo/main(e7bb057223) and resolved all four textual conflicts. Main's subscription-awareTABLES/COLUMNSdefinitions and this PR's charset/collation mappings are both preserved in the combined view SQL and BVT expectations.MORPCVersion48. Remote sender/receiver validation and user-variable migration reject v47 and accept v48.InformationSchemaColumnsDDLnow requires v48, whileTABLESremains at main's v46. This prevents older v46/v47 CNs from materializing a combinedCOLUMNSview whose internal functions require the binary-string capability.SHOW CREATE information_schema.columnsoutput retains subscription metadata and all existingutf8,utf8mb4, andbinarymappings. The conflict rows use the verified combined DDL metadata length of 10,118.pkg/sql/compile,pkg/frontend,pkg/sql/plan/function, and the affected v1.2.0/v2.0.0/v2.0.2/v2.1.0/v4.0.0/v4.0.5/v4.0.6 bootstrap packages. Focused lint reports0 issues;make build, the binary-string BVT (54/54), andaccount_restricted(125/125 executed cases) pass.Ninth review follow-up
maxBytes / charsetWidthas an absolute target-character limit. Truncation is admitted from the actual retained prefix bytes. Expansion is checked overflow-safely assourceBytes + missingRunes * charsetMaxWidthbefore the empty-pad result is selected. Tests cover utf8mb4 source-length-sensitive target 16,777,217, truncation from 17,000,000 characters, and the utf8mb3 22,369,622 boundary.bytes.Indexcall, so cancellation that occurs during either a successful or unsuccessful scan is returned ascontext.Canceled. Deterministic tests cover both outcomes.0 issues;make buildand the binary-string BVT (55/55) pass. The multi-segment benchmark remains allocation-free at approximately 0.33/1.30/5.12/15.34 ms for the existing four scales.Tenth review follow-up
utf8/utf8_binpresentation. The v48 definition still maps identity 3 toutf8mb4/utf8mb4_general_ci. Protocol-tier tests validate both compatibility definitions and parse every generated initialization statement.[oldCursor, newCursor)range. The frequency table therefore remains exact for each subsequent segment; every value byte is decremented at most once, and the new linear loop retains periodic cancellation checks.false, nilwithout sparse/convolution scratch allocation or leakage.compiled.matchregression verifies that every segment remains below its local convolution threshold, then exhausts the shared match-wide direct budget and observes convolution scratch. This closes the previous test gap where fallback was only forced through a manually zeroed budget.0 issues;make buildand the binary-string BVT (55/55) pass. Existing direct and equal-frequency benchmark scales remain at0 B/op, 0 allocs/op.Eleventh review follow-up
%when another segment remains, removing the extra full scan from the single-long-segment hot path.%a%b%, so cancellation is exercised during frequency maintenance that is required for the next segment rather than during an otherwise unnecessary final-segment scan.mo/mainand resolved conflicts while preserving binary-string MORPC v48 plus the newer v49 grouping-set capability, all remote validators, and the combined upgrade-test expectations.Twelfth review follow-up
MORPCLatestVersionis v50.mo/main@109bf926fwhile preserving the main branch's v48/v49 capability assignments.0 issues;make buildand binary-string BVT55/55pass.Thirteenth review follow-up
PrepareParamInfo.runtime_string_domains(protobuf field 8) and regeneratedpipeline.pb.go.remoterunServernow preserve explicitInherit,Text, andBinaryruntime domains. NULL rows remainInheritand are safely ignored by the vector domain setter.informationSchemaColumnsV48DDLtoinformationSchemaColumnsV50DDL.0 issues;make buildand binary-string BVT55/55pass.Conflict resolution follow-up
mo/mainthrougha6ee717132and resolved all conflicts.MORPCLatestVersionis v52.21ba69fb8f; working tree is clean.