Skip to content

executor: return proper error for LOAD DATA with AUTO_RANDOM column - #65597

Merged
ti-chi-bot[bot] merged 3 commits into
pingcap:masterfrom
Milad93R:fix/load-data-auto-random-error-message
Mar 17, 2026
Merged

ti-chi-bot[bot] merged 3 commits into
pingcap:masterfrom
Milad93R:fix/load-data-auto-random-error-message

Conversation

@Milad93R

@Milad93R Milad93R commented Jan 15, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: close #65585

Problem Summary: When using LOAD DATA LOCAL INFILE on a table with AUTO_RANDOM column while allow_auto_random_explicit_insert is disabled, TiDB returns a runtime panic (index out of range [0] with length 0) instead of the expected error 8216.

What changed and how does it work?

Added a check in parserData2TableData() to detect ErrInvalidAutoRandom and return it as a real error instead of treating it as a warning. Previously, the error was converted to a warning in non-restrictive mode, and a nil row was returned, which later caused a panic when looking up the index.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Fix LOAD DATA LOCAL INFILE to return proper error 8216 when inserting explicit values into AUTO_RANDOM column with allow_auto_random_explicit_insert disabled, instead of a runtime panic.

Summary by CodeRabbit

  • Bug Fixes

    • LOAD DATA now correctly returns an error when explicit values are supplied for AUTO_RANDOM columns without permission, instead of falling back to a warning.
  • Tests

    • Added a test validating the AUTO_RANDOM explicit-insert error for LOAD DATA.
  • Chores

    • Updated test configuration to adjust sharding for the load-data test suite.

@ti-chi-bot ti-chi-bot Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/needs-tests-checked do-not-merge/needs-triage-completed contribution This PR is from a community contributor. needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 15, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jan 15, 2026

Copy link
Copy Markdown

Hi @Milad93R. Thanks for your PR.

I'm waiting for a pingcap member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ti-chi-bot ti-chi-bot Bot added the first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. label Jan 15, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jan 15, 2026

Copy link
Copy Markdown

Welcome @Milad93R!

It looks like this is your first PR to pingcap/tidb 🎉.

I'm the bot to help you request reviewers, add labels and more, See available commands.

We want to make sure your contribution gets all the attention it needs!



Thank you, and welcome to pingcap/tidb. 😃

@pingcap-cla-assistant

pingcap-cla-assistant Bot commented Jan 15, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@tiprow

tiprow Bot commented Jan 15, 2026

Copy link
Copy Markdown

Hi @Milad93R. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@lance6716

Copy link
Copy Markdown
Contributor

/ok-to-test

@ti-chi-bot ti-chi-bot Bot added ok-to-test Indicates a PR is ready to be tested. and removed needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. labels Jan 16, 2026
@codecov

codecov Bot commented Jan 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 77.1389%. Comparing base (8333420) to head (870e071).
⚠️ Report is 314 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #65597        +/-   ##
================================================
- Coverage   77.8487%   77.1389%   -0.7098%     
================================================
  Files          1978       1942        -36     
  Lines        542181     568618     +26437     
================================================
+ Hits         422081     438626     +16545     
- Misses       118441     129919     +11478     
+ Partials       1659         73      -1586     
Flag Coverage Δ
integration 40.9233% <0.0000%> (-7.2665%) ⬇️
unit 76.5665% <75.0000%> (+0.1072%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 56.7974% <ø> (ø)
parser ∅ <ø> (∅)
br 46.3736% <ø> (-14.7689%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@joechenrh

joechenrh commented Jan 16, 2026

Copy link
Copy Markdown
Contributor

IMPORT INTO can import the file successfully 🤔
Oh, it doesn't check allow_auto_random_explicit_insert

@joechenrh

Copy link
Copy Markdown
Contributor

/retest

@lance6716

Copy link
Copy Markdown
Contributor

CI failed:

Please run `make bazel_prepare` to update `.bazel` files, or just apply the following git diff (run `git apply -` and paste following contents with ctrl-D as ending):
diff --git a/pkg/executor/test/loaddatatest/BUILD.bazel b/pkg/executor/test/loaddatatest/BUILD.bazel
index 88853b38ca..a9a029c3ef 100644
--- a/pkg/executor/test/loaddatatest/BUILD.bazel
+++ b/pkg/executor/test/loaddatatest/BUILD.bazel
@@ -9,7 +9,7 @@ go_test(
     ],
     flaky = True,
     race = "on",
-    shard_count = 12,
+    shard_count = 13,
     deps = [
         "//pkg/config",
         "//pkg/executor",

Comment thread pkg/executor/load_data.go Outdated

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.

I found this issue is caused by this TODO which I left some years ago 😢

@joechenrh Do you think we should open another PR, to let caller skip nil row?

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.

I'm wondering when we will reach L591 after this PR. Maybe we should return newRow, nil for restrictive data interpretation error 🤔?

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.

newRow may still have mismatched length. Maybe a row of NULL?

Comment thread pkg/executor/test/loaddatatest/load_data_test.go Outdated
@ti-chi-bot ti-chi-bot Bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jan 16, 2026
@joechenrh joechenrh added the skip-issue-check Indicates that a PR no need to check linked issue. label Jan 16, 2026
When using LOAD DATA LOCAL INFILE on a table with AUTO_RANDOM column
while allow_auto_random_explicit_insert is disabled, return error 8216
(ErrInvalidAutoRandom) instead of a runtime panic.

Previously, when the AUTO_RANDOM validation failed, the error was
treated as a warning in non-restrictive mode, and a nil row was
returned. This nil row later caused a panic when looking up the
index with "runtime error: index out of range [0] with length 0".

This change ensures that ErrInvalidAutoRandom is always returned
as a real error, providing the user with a meaningful error message
instead of a cryptic runtime panic.

Issue Number: close pingcap#65585
@Milad93R
Milad93R force-pushed the fix/load-data-auto-random-error-message branch from 27ec5d9 to 8ac26dd Compare January 16, 2026 12:14
@Milad93R

Copy link
Copy Markdown
Contributor Author

C:/Program Files/Git/retest-required

@Milad93R

Copy link
Copy Markdown
Contributor Author

C:/Program Files/Git/test unit-test

@lance6716

Copy link
Copy Markdown
Contributor

/retest

@lance6716

Copy link
Copy Markdown
Contributor

/cc @kennytm @joechenrh

@ti-chi-bot
ti-chi-bot Bot requested review from joechenrh and kennytm January 17, 2026 12:28
Comment thread pkg/executor/load_data.go
// when looking up index. See https://github.com/pingcap/tidb/issues/65585
if dbterror.ErrInvalidAutoRandom.Equal(err) {
return nil, err
}

@kennytm kennytm Jan 17, 2026

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.

🤔 feels strange to only special case for the ErrInvalidAutoRandom

i think we should always return nil, err regardless of error type in strict mode, and discard the row in IGNORE mode

@joechenrh why is the current behavior like this 😕

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.

why is the current behavior like this

😵‍💫 I don't know about this part

Signed-off-by: Ruihao Chen <joechenrh@gmail.com>
@coderabbitai

coderabbitai Bot commented Mar 17, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4b995200-e7a1-48e0-a6de-8acc5b66cf4d

📥 Commits

Reviewing files that changed from the base of the PR and between 42d4cd2 and 870e071.

📒 Files selected for processing (2)
  • pkg/executor/load_data.go
  • pkg/executor/test/loaddatatest/BUILD.bazel

📝 Walkthrough

Walkthrough

Explicitly handle ErrInvalidAutoRandom during LOAD DATA parsing to return the proper error instead of falling through to warning/fallback logic. Adds a test asserting the error and updates the test BUILD file.

Changes

Cohort / File(s) Summary
Executor change
pkg/executor/load_data.go
Imported pkg/util/dbterror and changed parserData2TableData to special-case ErrInvalidAutoRandom: return nil, err immediately instead of the previous fallback/warning path that could lead to a panic.
Test added
pkg/executor/test/loaddatatest/load_data_test.go
Added TestLoadDataAutoRandomError which injects a custom LoadDataReader and asserts that LOAD DATA returns dbterror.ErrInvalidAutoRandom when explicit values are provided for an AUTO_RANDOM column while explicit insert is disabled.
Build/test config
pkg/executor/test/loaddatatest/BUILD.bazel
Updated shard_count from 12 to 13 and added //pkg/util/dbterror to deps for the test rule.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through code with nimble feet,
Found the auto-random snag and made it neat.
Now LOAD DATA speaks the error true,
Tests nod, builds updated too — hooray, woo-hoo! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: fixing LOAD DATA to return a proper error for AUTO_RANDOM columns, which directly addresses the core issue being solved.
Description check ✅ Passed The PR description includes all required template sections: issue number (close #65585), problem summary, what changed, test checklist with unit test marked, side effects assessed, and release note provided.
Linked Issues check ✅ Passed The PR fully addresses issue #65585 by adding a check in parserData2TableData() to detect ErrInvalidAutoRandom and return it as an error instead of a warning, preventing the runtime panic and returning the expected ERROR 8216.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the LOAD DATA AUTO_RANDOM error handling: modifications to load_data.go, test additions, and BUILD.bazel updates to support the new test are all in scope.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.11.3)

Command failed


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Signed-off-by: Ruihao Chen <joechenrh@gmail.com>
@ti-chi-bot

ti-chi-bot Bot commented Mar 17, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: joechenrh, lance6716

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [joechenrh,lance6716]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot Bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Mar 17, 2026
@ti-chi-bot

ti-chi-bot Bot commented Mar 17, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-01-16 07:10:56.964152266 +0000 UTC m=+132284.578109122: ☑️ agreed by lance6716.
  • 2026-03-17 06:23:42.266751376 +0000 UTC m=+251749.354408913: ☑️ agreed by joechenrh.

@tiprow

tiprow Bot commented Mar 17, 2026

Copy link
Copy Markdown

@Milad93R: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
tidb_parser_test 870e071 link true /test tidb_parser_test
fast_test_tiprow 870e071 link true /test fast_test_tiprow

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

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

Labels

approved contribution This PR is from a community contributor. first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. lgtm ok-to-test Indicates a PR is ready to be tested. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. skip-issue-check Indicates that a PR no need to check linked issue.

Projects

None yet

4 participants