Repository navigation
fix: close MySQL type compatibility gaps for YEAR/DECIMAL256/SET on 3.0-dev - #24342
Conversation
….0-dev PR matrixorigin#24204 added plan/type-level support for these MySQL-compatible types but did not touch the vector container or the INSERT/UPDATE binding and frontend codec paths, so INSERT into YEAR / DECIMAL256 panicked in GetUnionAllFunction and INSERT into SET fell into a raw varchar -> uint64 cast. - vector.go: add T_year / T_decimal256 branches to GetAny, Shrink, ShrinkByMask, Shuffle, GetUnionAllFunction, GetConstSetFunction, String, RowToString, AppendAny, GetMinMaxValue, InplaceSortAndCompact, InplaceSort; include T_geometry in the varlena-group switches. - types: widen DecimalWithFormat to include Decimal256; add EncodeMoYear/DecodeMoYear and EncodeDecimal256/DecodeDecimal256. - plan: route SET columns through funcCastForSetType in bind_insert, build_constraint_util, bind_update, build_update (enum already handled). - function: add operatorUnaryMinusDecimal256 and overloadId=8 so negative DECIMAL(65,*) literals bind. - frontend: map T_year -> MYSQL_TYPE_YEAR, T_decimal256 -> MYSQL_TYPE_DECIMAL, T_geometry -> MYSQL_TYPE_GEOMETRY in convertEngineTypeToMysqlType; extend extractRowFromVector / extractRowFromVector2 / ColumnSlices.{convertVectorToSlice,GetInt64,GetUint64,GetDecimal} for the three types; add arrMoYear / arrDecimal256 slices. - bvt: add year_insert.sql / decimal256_insert.sql / set_insert.sql under test/distributed/cases/dtype/. - tests: add TestGetUnionAllFunctionSupportsYearAndDecimal256 in vector_test.go. Verified on single-node mo-service with the three reproducers from issue matrixorigin#24184. Co-Authored-By: Claude Opus 4.7 <[email protected]>
ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one. |
Flushing a block containing YEAR or DECIMAL(65,*) panicked inside flushObjTask because the TAE compute/index layer was still missing branches for T_year and T_decimal256: - compute.Compare / CompareGeneric panicked with "unsupported type: YEAR" - index.BatchUpdateZM handed a 64-byte Decimal256 min/max into the fixed 32-byte ZM payload, tripping "index out of range" inside compute.Compare Changes: - compute/compare.go: add T_year case to Compare and CompareGeneric so TAE can order YEAR values. - index/zm.go: add T_year decoder and range-search branches; skip ZM maintenance entirely for T_decimal256 (values exceed the fixed ZM budget) in UpdateZM and BatchUpdateZM, matching main's approach. - Adjust decimal256_insert BVT to avoid the INT64->DECIMAL256 cast gap (out of scope for this PR). - Add the mo-tester-generated .result files for the three new BVT cases; all three now validate at 100% success rate with `./run.sh -p <file> -g -n`. Co-Authored-By: Claude Opus 4.7 <[email protected]>
…iden Address XuPeng-SH's review comments on PR matrixorigin#24342. 1. BuildZM(T_decimal256, v) now skips doInit the same way UpdateZM / BatchUpdateZM do. Without the guard, the 32-byte payload would overwrite the length byte at offset 30 inside the 64-byte ZM buffer on the next caller; today all public paths go through IsInited() first so the hazard is latent, but the guard closes the class. Test in zm_test.go asserts BuildZM returns a typed-but-uninited ZM for decimal256. 2. year_insert.sql now carries an explicit note that 3.0-dev renders YEAR as `YYYY-01-01` because pkg/defines/type.go has no MYSQL_TYPE_YEAR branch in GetLength. This tells future contributors who fix the protocol metadata to update the .result baseline instead of assuming they broke something. 3. year_insert.sql adds an ORDER BY birth_year DESC assertion to exercise the T_year arm in the vector sort path and the compute Compare path — widens the BVT beyond the original panic-only check. (WHERE-on-YEAR deliberately omitted: 3.0-dev has no operator overload for T_year vs integer literals; tracked separately from this PR's panic-fix scope.) 4. decimal256_insert.sql adds `SELECT -large_val` to exercise the new operatorUnaryMinusDecimal256 overload in the executor (the INSERT literal path only exercised the planner side). 5. Geometry INSERT/UPDATE subtype validation was flagged as a gap. Not in scope here; filed as follow-up issue matrixorigin#24350. Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Thanks @XuPeng-SH for the thorough walk-through. Addressed in the follow-up commit 🔴 Blocking (both resolved)1. BVT baselines encoding known-broken behavior
2. Added to 🟡 Geometry INSERT/UPDATEFiled as follow-up issue #24350 (linked from this PR). Agreed with you that registering a no-op 🟢 Nits
Please re-review when you have a moment. |
…al256 ZM
The previous ZM-skip approach for T_decimal256 left Contains,
ContainsKey, FastContainsAny, and FastIntersect returning false on
uninited ZMs, which meant:
1. MutIndex.GetActiveRow and MutIndex.Dedup treat "unknown range" as
"definitely absent" — silently skipping ART lookup and allowing
duplicates.
2. FastIntersect on an uninited decimal256 ZM feeds zero-length
GetMinBuf/GetMaxBuf to compute.Compare which dereferences &a[0]
on an empty slice → panic on any runtime_filter or scan path that
hits an uninited decimal256 ZM.
Fix: for T_decimal256 specifically, Contains / ContainsKey /
FastContainsAny now return true ("unknown → assume present") so
callers fall through to ART. FastIntersect does the same ("unknown →
assume overlap") to avoid both false-negative pruning and the empty-
slice dereference in compute.Compare.
For all other types, uninited ZM behaviour is unchanged (false = "no
data seen, nothing to match").
Also:
- func_testcase.go: add T_year result comparison branch so future
YEAR function tests don't panic in the test framework.
- defines/type.go: add MYSQL_TYPE_YEAR → 4 in GetLength so the
MySQL wire column metadata reports 4 (matching MySQL's display
width for YEAR) instead of 0xFFFFFFFF.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
The SET dispatch was removed in d1f2e30 on the grounds that it only works for literal VALUES, not expressions or subqueries. But the original matrixorigin#24184 Case 3 reproducer IS a literal INSERT: INSERT INTO t_set VALUES (1, 'read,write', 'red'); Without the dispatch, that statement hits the generic varchar->uint64 cast and reports ERROR 20203. The literal-only path is a valid partial fix — it resolves the reported bug. Expression/subquery/SELECT-format gaps are pre-existing 3.0-dev limitations to be addressed in a follow-up that ports cast_set_value_to_index from main. Restored files (identical to commit 15c762e): - pkg/sql/plan/bind_insert.go: route isSetPlanType through funcCastForSetType in both initInsertReplaceStmt and buildValueScan. - pkg/sql/plan/build_constraint_util.go: same for the constraint-util buildValueScan path. - pkg/sql/plan/bind_update.go: wrap SET column projections via funcCastForSetType. - pkg/sql/plan/build_update.go: same for rewriteUpdateQueryLastNode. BVT: - test/distributed/cases/dtype/set_insert.sql + .result re-added with a header comment explaining that SELECT returns raw bitmask integers (not member names) on 3.0-dev, and that this .result should be updated when the runtime cast_set_index_to_value is backported. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Refreshed after GetLength fix (MYSQL_TYPE_YEAR → 4) so the column metadata in the .result matches. Also picks up the ORDER BY birth_year DESC assertion added in commit 59ac41d. Co-Authored-By: Claude Opus 4.6 <[email protected]>
1. AnyLTByValue / AnyGTByValue / AnyGEByValue / AnyLEByValue in
zm.go returned false for uninited ZMs, which caused scan-time
range pruning to falsely eliminate blocks containing Decimal256
data. Now returns true for T_decimal256 ("unknown range → don't
prune"), matching the Contains/ContainsKey/FastIntersect treatment.
2. EncodeValue in encoding.go had no T_decimal256 / T_year branch,
so any generic lookup/dedup path calling types.EncodeValue would
panic. Added both.
3. year_insert.sql header comment updated — the GetLength fix already
landed; the remaining YYYY-01-01 rendering is a JDBC client
artifact, not a missing server branch.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
… path funcCastForSetType previously only handled constant literals — any non-literal expression (column ref, function call, INSERT...SELECT, CASE, concat(...)) was silently returned unchanged, falling through to the generic varchar->uint64 cast that produced ERROR 20203. Fix: - Port CastSetIndexToValue, CastSetValueToIndex, CastSetIndexValueToIndex runtime functions from main (pkg/sql/plan/function/func_mo.go). - Register them as cast_index_to_set_value (ID 355), cast_set_value_to_index (ID 356), cast_set_index_value_to_index (ID 357) in function_id.go and list_builtIn.go. - Add constant names moSetCast*Fun to tools.go. - funcCastForSetType (make.go) now wraps non-literal expressions with BindFuncExprImplByPlanExpr → the runtime function handles member resolution at execution time, not just at plan time. - Null literals still pass through unchanged (avoid wrapping NULL in a function call that would discard the NULL semantic). - Expressions already typed as the target SET (same Enumvalues) short- circuit without re-wrapping. This means INSERT...SELECT, UPDATE SET s = concat(...), VALUES(expr) all correctly resolve SET member names at runtime via the registered cast_set_value_to_index function. Co-Authored-By: Claude Opus 4.6 <[email protected]>
1. year_insert.result: revert to tab-separated no-metadata format matching CI's mo-tester version (local mo-tester had been updated to emit column metadata prefixes that CI doesn't expect). 2. zm.go AnyIn: add T_year branch so YEAR columns get proper zonemap range pruning during sorted-vector IN lookups instead of falling through to the conservative "assume overlap" default. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…cCastForSetType Coverage check failed at 60% (need 75%). Main gaps were: - func_mo.go (0%): CastSetValueToIndex/CastSetIndexToValue/ CastSetIndexValueToIndex had no direct UT - make.go (29%): the new non-literal runtime-wrap path in funcCastForSetType was untested - list_builtIn.go (0%): registration not exercised Add: - Test_CastSetFunctions in operatorSet_test.go: directly exercises all three CastSet* functions with string/uint64 inputs and null handling. This touches func_mo.go + list_builtIn.go registration paths. - TestFuncCastForSetType_NonLiteral in build_util_test.go: verifies funcCastForSetType wraps varchar col-refs with cast_set_value_to_index and integer col-refs with cast_set_index_value_to_index; also tests the same-type short-circuit path. Covers the make.go runtime-wrap code added in this PR. Co-Authored-By: Claude Opus 4.6 <[email protected]>
XuPeng-SH
left a comment
There was a problem hiding this comment.
LGTM on the current head (a2c66f8). Both blocking items from my earlier review are addressed:
-
BVT
.resultbaseline comments —set_insert.sqlhas the raw-bitmask rendering note (lines 6-10);year_insert.sqlhas the JDBCYYYY-01-01rendering note (lines 6-11). Future contributors will know the baselines are intentionally encoding known-limited behavior. -
BuildZMguard for Decimal256 —zm.go:67-72early-returns an uninitialized ZM whent == T_decimal256, matching the skip inUpdateZM/BatchUpdateZM. Additional defensive guards added throughout the ZM public surface (lines 292, 335, 338, 351, 364, 377, 541, 554, 611) — comprehensive.
Also note the scope evolved since my review: the latest commits (a95cb178, 01eab019, a2c66f89) port the SET runtime cast functions from main and add non-literal SET expression coverage. This goes beyond the original "panic fixes only" scope and delivers the runtime CastSetValueToIndex/CastSetIndexToValue overloads that were previously deferred. Good — it means SET INSERT/UPDATE with expressions now works too.
CI all green (Upgrade/Coverage still pending). Merge after those clear.
- encoding_test.go: roundtrip test for EncodeDecimal256/DecodeDecimal256 and EncodeMoYear/DecodeMoYear (covers the 1 uncovered line in encoding.go). - zm_test.go: TestZMYearAnyIn exercises the new T_year branch in AnyIn with both in-range and out-of-range vectors. - operatorSet_test.go: add null-input cases to CastSetIndexToValue and CastSetValueToIndex so the null-handling branches in func_mo.go get covered. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Add Test_YearAndDecimal256_FuncTestcaseCompare that uses an inline identity function returning T_year results. This exercises the T_year branch in func_testcase.go's result comparison switch that previously showed 0% coverage because no existing test produced a T_year output vector. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Integrate upstream geometry subtype validation (a126714) with our SET/YEAR/DECIMAL256 type support. Conflicts resolved by adding `case isGeometryPlanType` branches to the existing switch/case pattern. CAST_GEOMETRY_TO_SUBTYPE assigned function ID 358 (after SET IDs 355-357), FUNCTION_END_NUMBER bumped to 359. Also add TestZMDecimal256Pruning and TestZMYearSubVecIn to cover the remaining diff lines in zm.go that caused the CI coverage check to fail (62.5% < 75% threshold). Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Merge Queue Status
This pull request spent 54 minutes 1 second in the queue, including 53 minutes 29 seconds running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #24184
What this PR does / why we need it:
PR #24204 added plan/type-level support for YEAR / DECIMAL256 / SET on
3.0-dev, but did not touch the vector container, the TAE compute/index layer, or the frontend codec paths. Heni02's latest comment on #24184 reproduces three failures caused by those gaps:INSERT INTO t_year VALUES (1, 2024, 2023);→ PANICunexpect type YEAR for function vector.GetUnionFunctionINSERT INTO t_decimal VALUES (1, 12345...1234567890);→ PANICunexpect type DECIMAL256 for function vector.GetUnionFunctionINSERT INTO t_set VALUES (1, 'read,write', 'red');→ERROR 20203: invalid argument cast to uint64Scope of this PR
Panic / cast-error fixes only. No new SET DML semantics, no new SET SELECT formatting. The original #24184 reproducers stop crashing; they do not necessarily produce MySQL-equivalent output for SET (that requires the
cast_set_value_to_index/cast_set_index_to_valueruntime functions that exist onmainbut not on3.0-dev— tracked as a follow-up).Fix
pkg/container/vector/vector.go: add T_year / T_decimal256 arms to every per-type switch that previously panicked (GetAny,Shrink,ShrinkByMask,Shuffle,GetUnionAllFunction,GetConstSetFunction,String,RowToString,AppendAny,GetMinMaxValue,InplaceSortAndCompact,InplaceSort). Also include T_geometry in the varlena-group switches so the existing geometry DDL/SHOW support actually matches an executor branch.pkg/container/types: widenDecimalWithFormatto includeDecimal256; addEncodeMoYear/DecodeMoYearandEncodeDecimal256/DecodeDecimal256.pkg/sql/plan/function: addoperatorUnaryMinusDecimal256(overload 8) so negative DECIMAL(65,*) literals bind.pkg/frontend/mysql_cmd_executor.go: map T_year →MYSQL_TYPE_YEAR, T_decimal256 →MYSQL_TYPE_DECIMAL, T_geometry →MYSQL_TYPE_GEOMETRY.pkg/frontend/output.go: extendextractRowFromVector/extractRowFromVector2andColumnSlices.{convertVectorToSlice, GetInt64, GetUint64, GetDecimal}; addarrMoYear/arrDecimal256slices.pkg/vm/engine/tae/compute/compare.go: add T_year arm toCompare/CompareGenericso TAE can order YEAR values during flush.pkg/vm/engine/tae/index/zm.go: add T_year decoder + range-search branches; skip ZM maintenance for T_decimal256 inUpdateZM/BatchUpdateZM(matches main — the fixed ZM buffer is 32B while Decimal256 is 64B).What this PR explicitly does NOT do
funcCastForSetTypeis literal-only. The earlier version of this PR added a bind-time dispatch for SET columns, but it only worked for literal VALUES;INSERT ... SELECT,UPDATE s = concat(...),VALUES (concat(...))all still fall through tocast(varchar -> uint64). That dispatch has been reverted to avoid shipping a half-fix.cast_set_index_to_valuefunction (exists on main, not on 3.0-dev) and thebase_bindercolumn-ref auto-wrap that uses it.types.CompareDecimal256ignores scale; this is the case onmaintoo — it is not a 3.0-dev regression and warrants a standalone feature PR.GetLengthprotocol metadata.pkg/defines/type.go:GetLengthhas noMYSQL_TYPE_YEARcase and falls back tomath.MaxUint32. Same on main — pre-existing bug, tracked separately.funcCastForGeometryType; INSERT stores WKT as varchar without subtype checks. Unchanged by this PR.PR Test Plan
makemake static-check— 0 issuesgo test ./pkg/container/vector -count=1go test ./pkg/container/types -count=1go test ./pkg/sql/plan/... -count=1go test ./pkg/frontend -count=1go test ./pkg/vm/engine/tae/compute ./pkg/vm/engine/tae/index -count=1cast to uint64error; INSERT/UPDATE/DELETE/SELECT all complete for YEAR (incl. 2-digit year, boundary values 1901/2155), DECIMAL(65,10) (incl. negative values), and SET (values land as bitmap; full MySQL SET semantics tracked as follow-up).test/distributed/cases/dtype/year_insert.sqlanddecimal256_insert.sql. The YEAR case now usesCAST(y AS UNSIGNED)assertions to lock down numeric semantics instead of relying on the JDBC-sideYYYY-01-01rendering.🤖 Generated with Claude Code