Skip to content

fix: support insert ignore with on duplicate key update - #28482

Merged
mergify[bot] merged 10 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/issue-28159-insert-ignore-odku
Sep 16, 2026
Merged

mergify[bot] merged 10 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/issue-28159-insert-ignore-odku

Conversation

@VioletQwQ-0

@VioletQwQ-0 VioletQwQ-0 commented Sep 9, 2026 •

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • BUG

Which issue(s) this PR fixes:

Issue #28159 (bounded first-stage compatibility; issue remains open)

What this PR does / why we need it:

Adds the first-stage INSERT IGNORE ... ON DUPLICATE KEY UPDATE compatibility path within the existing ODKU domain.

  • Gives tree.Insert an independent Ignore policy and keeps executable ODKU assignments ordered, including repeated targets.
  • Accepts and canonicalizes combined syntax and the legacy ON DUPLICATE KEY IGNORE spelling.
  • Routes UPDATE, IGNORE, and FAIL actions explicitly; preserves generated-column/key-update rejection, affected-row accounting, index maintenance, transaction errors, prepared binding, runtime diagnostics, and remote statement-ignore propagation.
  • Applies the existing assignment conversion policy to both candidate values and ODKU assignments, including visible CHAR/VARCHAR truncation warnings.
  • Keeps unsupported key changes and CHECK/FK/storage/transaction failures as statement failures. Full row-level IGNORE rollback/skip compatibility is out of scope.
  • Safely scans discarded no-key ODKU RHS expressions without invoking incomplete parser visitors. This preserves prepared markers in arithmetic, user-variable, and nested scalar-subquery forms while avoiding panics for expressions that the fallback does not execute.
  • Traverses Expr_Sub children and referenced subquery roots during prepared-plan reset and normalization, so inner parameters are retained with the correct execution-time ordinal.
  • Routes string-assignment truncation warnings through the generation-scoped proc.GetWarningSink() and covers sink-only execution plus warning-attempt discard behavior.

Validation on current head 8ad9942cffdadc31723097d8ae4cdf87fa112bb1

  • Previous validation was bound to superseded head 10741bbe1c4bb0c8ece37359a9045a0a4c025553 and is not reused as current-head evidence.
  • Rebased 222b92ea773feb1985f84edaebb59de60608bbea onto main@b347a62a30719cf3f2c8ca5a2da0dcfb11639f8; git diff --check and the parser tree focused tests — PASS.
  • Range-diff preserved the eight PR commits; no business-logic changes were introduced by the synchronization.
  • The owning worktree is clean. Frontend focused tests remain BLOCKED_ENVIRONMENT because the local docfilter CGo symbols/native bundle are unavailable.
  • Fresh exact-head CI was triggered by the push and is pending; the PR remains CHANGES_REQUESTED and requires reviewer re-review.

The prepared regressions cover ordinary and INSERT IGNORE no-key ODKU, user variables, literal scalar subqueries, scalar subqueries containing parameters, referenced-root traversal, and one-based ordinal normalization. The warning regressions prove sink-only routing and that a discarded attempt does not publish its warning to the session.

Fresh exact-head CI, distributed BVT, and QA remain required; no blind CI rerun was forced.

@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 →

@iamlinjunhong iamlinjunhong 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.

Findings

  • [P1] pkg/sql/plan/build_constraint_util.go:2173 — retain parameters inside discarded scalar subqueries.
    Trigger: a prepared statement on a table without a real primary/unique key, for example PREPARE s FROM 'INSERT INTO insert_fk_no_key_c VALUES (?, ?) ON DUPLICATE KEY UPDATE pid = (SELECT ?)', including the INSERT IGNORE form. The new reflective scan correctly detects the marker and this code binds/appends the RHS to VALUE_SCAN.OnUpdateExprs, but the final parameter walk does not recurse through that bound scalar subquery. NewVisitPlan reaches OnUpdateExprs, while GetParamRule.applyExpr in pkg/sql/plan/visit_plan_rule.go:195-223 has no Expr_Sub case and therefore does not visit SubqueryRef.Child. ResetPreparePlan consequently collects only the two VALUES markers; the added scalar subquery parameter controls expect three and the statement cannot bind its third parameter. Explicitly retain/collect every marker in the discarded RHS (or keep the bound subquery expression graph reachable), and make both ordinary and IGNORE controls pass.

  • [P1] pkg/sql/plan/function/func_cast.go:6772 — route truncation warnings through proc.GetWarningSink().
    Compile.Run installs a generation-scoped collector in Process.WarningSink (pkg/sql/compile/compile2.go:388-392, pkg/sql/compile/warning_attempt.go:40-48), but this helper reads GetSession() directly. A warning emitted by an attempt that is later discarded/retried therefore bypasses the collector and can leak or be duplicated in the frontend; a process carrying only a captured WarningSink also loses the warning. The adjacent numeric conversion warnings already use GetWarningSink(). Route this helper through that sink and add coverage for the sink-only and discarded-attempt cases.

The previous P2 Expr.Accept panic is fixed in 669951a37ec7c6a90530516bde35b9a7978e8d90, and the author explicitly replied to that earlier finding. These two current-head P1 blockers remain unresolved, so this review requests changes.

Validation: reviewed the complete current-head diff and the relevant planner, parameter-reset, warning-lifecycle, and runtime call chains. git diff --check passes. The focused native-CGo test was blocked before execution in this isolated environment by missing native headers/libraries; no local test pass is claimed.

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Current-head CI diagnosis for dffb56cbe21b9b075c2800ebaba7b4ac06e8fde0:

  • UT Coverage on Ubuntu/x86 timed out during Checkout MatrixOne source after 5 minutes.
  • The cleanup path then could not find .ci-workflow/scripts/summarize_coverage_ut.py, which is consistent with the checkout not completing.
  • No coverage or test execution reached the source under test; this is classified as a CI runner/setup failure, not a code coverage failure.

No rerun was started while the workflow still had other jobs in progress. The failed job should be rechecked from this exact head after the run reaches a terminal state.

@aptend aptend 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.

Re-review completed at exact head dffb56cbe21b9b075c2800ebaba7b4ac06e8fde0.

I read the complete review/comment/thread history and checked the delta since my previous reviewed head 669951a37ec7c6a90530516bde35b9a7978e8d90 together with the full PR diff. Both previously blocking issues are closed in the implementation: discarded no-key ODKU expressions still participate in parameter discovery/reindexing, including Expr_Sub operands and referenced subquery roots; and assignment-width warnings now flow through the execution attempt’s WarningSink, so discarded attempts do not leak diagnostics. I also rechecked the independent IGNORE/ODKU AST representation, parser round-trips, planner routing, ordered repeated assignments, no-key fallback, auto-increment provenance, and the stated failure-scope boundary.

Validation on the exact head:

  • git diff --check; forced MySQL parser regeneration remained clean.
  • Full package tests: ./pkg/sql/parsers/dialect/mysql, ./pkg/sql/plan, ./pkg/sql/plan/function, ./pkg/frontend, and ./pkg/sql/compile.
  • Focused race tests for prepared/subquery parameter handling and attempt-scoped warning behavior in plan, function, and compile packages.

The current GitHub coverage failure is an infrastructure checkout timeout before repository code ran. No blocking code issue found.

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Current-head CI diagnosis for dffb56cbe21b9b075c2800ebaba7b4ac06e8fde0 (run 34576837685):

  • UT Coverage on Ubuntu/x86 timed out during Checkout MatrixOne source after 5 minutes.
  • The cleanup path then could not find .ci-workflow/scripts/summarize_coverage_ut.py, which is consistent with the checkout not completing.
  • No coverage or test execution reached the source under test; this is classified as a CI runner/setup failure, not a code coverage failure.

No blind rerun is warranted for this completed runner/setup failure.

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

This update synchronizes the PR branch with upstream/main through a72a224ce85fd13aa919fb56dab58b8c60b366dc and pushes exact head 10741bbe1c4bb0c8ece37359a9045a0a4c025553.

The current head:

  • keeps INSERT IGNORE independent from the executable, ordered ODKU assignment list;
  • retains prepared parameters from discarded no-key ODKU RHS expressions, including referenced scalar-subquery roots;
  • routes assignment truncation warnings through the execution-attempt sink; and
  • preserves IGNORE semantics for strict-write GROUP_CONCAT when executable ODKU is present, with a dedicated regression case.

Validation on the current head: full controlled native-bundle tests pass for the MySQL parser, plan/function, plan, compile, and frontend packages; semantic preflight schema v7 passes with the exact diff hash recorded in the PR body; and git diff --check upstream/main...HEAD passes. The owning worktree lacks its standard native CGo bundle, so the local package tests used the existing native bundle from the prepared environment. Fresh exact-head CI, distributed BVT, and QA remain pending.

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Re-review request for current head 222b92ea773feb1985f84edaebb59de60608bbea against main@2ea4ec2e6ef4b20321a235ef416228506813e39b.

The two current-head P1 findings from the prior review are addressed:

  • The no-key prepared fallback now binds the complete ODKU RHS, and prepared-plan parameter traversal recurses through Expr_Sub / SubqueryRef.Child, retaining markers inside scalar subqueries in lexical order for both ordinary and INSERT IGNORE forms.
  • String-assignment truncation diagnostics now use proc.GetWarningSink(), so generation-scoped retry/discard handling owns the warning and a discarded attempt cannot publish it to the session.

The current exact-head semantic preflight is regenerated and validated PASS (schema v7, diff hash 55344822fad439ef345a968e40827d9fa57905cb5591958b964e7583449d2dba). git diff --check passes. The focused pkg/sql/plan/function cast/width/warning tests pass. The corresponding pkg/sql/plan and pkg/sql/compile test binaries are blocked in this environment by missing docfilter CGo symbols; no PASS is claimed for those packages. Fresh CI/BVT/QA evidence remains required.

Please re-review the repaired P1 findings at this exact head. The PR remains CHANGES_REQUESTED until formal review and the remaining CI/BVT/QA gates complete.

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Current exact-head CI review (222b92ea773feb1985f84edaebb59de60608bbea on main@2ea4ec2e6ef4b20321a235ef416228506813e39b).

Ubuntu UT job 104231896590 ran for about 71 minutes and ended with Error 124 before completion. The last observed tests were pkg/sql/plan.TestIcebergMergeMatchedUpdateAndNotMatchedInsertBuildsDMLWriteIntent and pkg/vm/engine/tae/db/test.TestCommitS3Blocks; no assertion failure, panic, OOM, or PR-specific SQL failure was reported. CI Required job 104258708175 is the derived matrixone-ci failure. UT Coverage, BVT, and Coverage merge were successful.

I classify the current block as BLOCKED_ENVIRONMENT / UT execution deadline, not a confirmed product regression. I will perform one failed-job rerun for this exact head; if it hits the same deadline, the remaining action is runner capacity/timeout recovery rather than a code change.

@iamlinjunhong iamlinjunhong 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.

按当前 head 8ad9942 完成复审,未发现可确认的 P0/P1/P2/P3 问题,提交 APPROVE。\n\n重点复核:\n- parser/AST 将 INSERT IGNORE 与有序 ODKU assignment 独立保存,并核对了各调用方的 getter 迁移;\n- no-key prepared fallback 在 pkg/sql/plan/build_constraint_util.go:2188-2211 绑定完整 ODKU RHS,保留嵌套表达式中的全部参数;\n- pkg/sql/plan/visit_plan_rule.go:195-225, 319-323, 351-359 及相关 root BFS 覆盖 Expr_Sub.Child 和引用的子查询计划;\n- pkg/sql/plan/function/func_cast.go:7015-7037, 8974-9009 使用 attempt-scoped warning sink 处理 assignment 截断告警;\n- 已复核上轮两个 P1 的作者回复及当前修复,未发现残留阻塞。

@mergify

mergify Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-16 01:06 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-09-16 02:02 UTC · at 091825aac2c8785d912f8d3eceb0e38de320e57a · squash

This pull request spent 56 minutes 40 seconds in the queue, including 49 minutes 19 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 size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants