Skip to content

fix(sql): handle invalid DECIMAL casts and quoted ADD INDEX backfills - #31289

Merged
mergify[bot] merged 6 commits into
matrixorigin:mainfrom
aptend:fix/astra-30417-31080
Oct 26, 2026
Merged

mergify[bot] merged 6 commits into
matrixorigin:mainfrom
aptend:fix/astra-30417-31080

Conversation

@aptend

@aptend aptend commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #30417
issue #31080

What this PR does / why we need it:

#30417 — explicit CAST(text AS DECIMAL) lexical leniency, scoped to SELECT / loose / IGNORE

Previously an explicit CAST('<bad text>' AS DECIMAL) always failed with
20301 invalid input ... is invalid decimal string in every sql_mode and
statement kind, diverging from MySQL 8.0. The three precision paths
(strToDecimal64/128/256) now, for castModeExplicit lexical failures, return
the MySQL result: numeric prefix value (or 0 when none) plus warning 1292
Truncated incorrect DECIMAL value. Special numeric syntax (Inf/NaN/radix
hex) is outside this lexical-fallback change and retains its existing
behavior unchanged; this PR makes no general MySQL-parity claim for it.

Strict-DML boundary (verified against a dedicated mysql:8.0.46 oracle
container, full matrix in artifacts): MySQL escalates that truncation warning
to an error for non-IGNORE data-modifying statements under strict sql_mode.
The fallback therefore applies leniency only for SELECT and loose / IGNORE
sessions. Non-IGNORE INSERT/UPDATE under STRICT_TRANS_TABLES reuses the
existing diagnostic channel (proc.IsDMLStatement() && isStrictSqlMode(proc) && !statementIgnore(proc), same gate as diagnoseFloatText) and keeps
rejecting with 20301 — matching the pre-PR baseline verified on clean main
e033d4a (all five strict/loose DML forms previously failed with 20301). The
1292-vs-20301 error-code difference on that path pre-exists this PR.

Two pre-existing dtype/decimal.test cases
(10.0 + CAST('aaa' AS decimal(38,0)), CAST('' AS decimal(38,0))) carried
main's old 20301 golden and failed in CI after the leniency change; their
expected results are synchronized to the new behavior in this PR (together
with the func_cast golden updated earlier). This is an expectation sync, not a
behavior carve-out.

#31080 — escape backticks in generated index backfill SQL

ALTER TABLE \tick``table` ADD INDEXre-parses internally generated backfill/marker INSERT SQL fromgenInsertIndexTableSql*without escaping `` → , breaking quoted identifiers. Both with/without-pkey
branches and the master-index variant now escape; UT + BVT cover default and
COPY algorithms.

Validation

  • Typed UT: TestExplicitCastLexicalDecimalDiagnostics,
    TestExplicitCastLexicalStrictDMLEscalation (DECIMAL64/128/256 × strict
    select / strict insert / strict insert-ignore / strict update / generic DML
    / loose insert), TestGenInsertIndexTableSql_EscapesBacktickIdentifiers;
    owning package pkg/sql/plan/function sweep passed on the rebased lineage.
  • Public BVT, local single-CN launch; multi-CN pessimistic validation
    remains pending on the current HEAD's CI: func_cast.test 374/374, secondary_index_alter.sql 85/85,
    count_derived_sort.sql 36/36, dtype/decimal.test 690/690 after the golden
    sync — two consecutive rounds each, 0 failed, zero leftover databases.
  • Incremental static gate (static-check-selected on
    ./pkg/sql/compile ./pkg/sql/plan ./pkg/sql/plan/function ./pkg/tests/issues
    ./pkg/tests/sqlintegration): 0 issues; git diff --check clean.
  • Strict-CTAS probe: rejects with 20301 (inner write inherits strict context);
    loose CTAS warns and writes 0.00; strict INSERT...SELECT with bad rows
    filtered out writes valid rows/NULL without warnings.
  • CI status at HEAD dd079336ba is pending. The previous run's multi-CN
    BVT failure was the stale decimal.test golden fixed here (690/690 twice
    locally on final binary). The CI UT failure
    TestTemporaryTablePhysicalNameIsSessionScoped was selected locally with
    -run and -count=2 and both runs passed — the CI RC-mode retry failure
    was not reproduced locally. A same-fingerprint failure was also observed on
    another PR's run (fix(load): restore large CSV rows and preserve LOCAL upload errors #31300, error path ISCP ProcessInitSQL / alter reindex ft
    fulltext2 force_sync -> drop_at UPDATE -> txn need retry in rc mode), so it
    is recorded as a suspected shared baseline RC-retry, unverified against a
    clean-main reproduction; current run's verdict is pending CI.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify mergify Bot added the kind/bug Something isn't working label Oct 26, 2026
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Oct 26, 2026
@aptend
aptend force-pushed the fix/astra-30417-31080 branch from 5358887 to 015e89f Compare October 26, 2026 13:06
@aptend
aptend force-pushed the fix/astra-30417-31080 branch from 015e89f to e4afe4e Compare October 26, 2026 13:55
@mergify mergify Bot added the kind/test-ci label Oct 26, 2026
@matrix-meow matrix-meow added size/L Denotes a PR that changes [500,999] lines and removed size/M Denotes a PR that changes [100,499] lines labels Oct 26, 2026
@XuPeng-SH

XuPeng-SH commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: dd079336ba076895a3ffc1d93f0169f191143208

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: dd079336ba076895a3ffc1d93f0169f191143208

Assessment: approve

Reviewed the complete 14-file delta and affected callers. DECIMAL recovery reuses existing parsing, diagnostics and statement-context owners while preserving strict-DML rejection. Identifier escaping covers both index-backfill generators. Updated tests retain genuine failure and recovery oracles. No actionable defects remain; both frozen discussion items are informational.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

Validation:

  • Reused frozen exact-head successes for shared build, Ubuntu/x86 UT, Linux/arm64 SCA, UT coverage, Compose/Proxy BVT, multi-CN pessimistic BVT and CI Required.

  • Traced null/masked rows, prefix conversion and overflow, strict/loose/IGNORE context, folding protections, prepared recovery and backfill execution.

  • Local diff and Go-format checks passed; source remained unchanged. Receipt checks/1793031814546081392-5.json matches review-check.log.

  • Saved discussion-assessment.json, validation-audit.json and review-analysis.json under /home/xupeng/.local/state/mo-bot/jobs/c947778763b6d5c4e2519dea/attempt-1.

Limitations:

  • No local native tests or MySQL oracle were repeated. The frozen bundle contains CI outcomes but no raw per-case logs or retained author validation receipts.

  • Strict-DML error-code differences and special numeric syntax retain their documented prior behavior; broader MySQL parity is not claimed.

  • Valid cast paths are unchanged; lexical recovery adds parsing and warning work. Backfill escaping adds small per-statement scans. No performance measurements are claimed.

@mergify mergify Bot added the queued label Oct 26, 2026
@mergify

mergify Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-26 16:26 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-10-26 18:09 UTC · at dfaed071d0fc7941c3544fb57496bf14f1d704cb · squash

This pull request spent 1 hour 43 minutes 31 seconds in the queue, including 1 hour 9 seconds running CI.

Required conditions to merge

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working kind/test-ci size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants