session: drain result sets in --initialize-sql-file before closing#66295
session: drain result sets in --initialize-sql-file before closing#66295ljluestc wants to merge 1 commit intopingcap:masterfrom
Conversation
When doBootstrapSQLFile executes SQL from --initialize-sql-file, SELECT statements that call functions with side effects (e.g. audit_log_create_filter) must have their result sets fully drained. Previously, the result set was closed without iterating through the rows. Since TiDB evaluates expressions lazily during row iteration, side-effect functions were never executed. Drain result sets by calling rs.Next() in a loop before rs.Close(), so that all row-level expression evaluation completes. Fixes pingcap#63450
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @ljluestc. 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 Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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. |
|
|
|
Hi @ljluestc. Thanks for your PR. PRs from untrusted users cannot be marked as trusted with I understand the commands that are listed here. DetailsInstructions 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. |
What problem does this PR solve?
Issue Number: close #63450
Problem Summary:
When bootstrapping TiDB with
--initialize-sql-file,SELECTstatements that call functions with side effects do not work. For example:After bootstrap,
SELECT * FROM mysql.audit_log_filtersreturns an empty result. The workaround is to useDOinstead ofSELECT, butSELECTshould also work.Root cause: In
doBootstrapSQLFile(pkg/session/bootstrap.go), result sets fromSELECTstatements were closed viars.Close()without being drained. TiDB evaluates expressions lazily during row iteration (rs.Next()). When aSELECTcalls a function with side effects, the function body is only executed when rows are fetched. SinceClose()was called without anyNext()calls, the function was never evaluated and its side effects never occurred.What changed and how does it work?
pkg/session/bootstrap.go— IndoBootstrapSQLFile, replace the immediaters.Close()with a drain loop that callsrs.Next()until all rows are consumed before closing. This ensures all row-level expression evaluation (including side-effect functions) completes.Before (broken):
After (fixed):
pkg/session/test/session_test.go— AddTestInitSQLFileSelectDrainregression test that bootstraps with an init SQL file containing mixed DDL,SELECT, and DML statements, verifying all statements execute correctly after theSELECTresult sets are drained.Check List
Tests
Unit test (all PASS):
No integration tests exist for
--initialize-sql-file(checkedtests/integrationtest/andtests/— no matches).Manual test (enterprise build):
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.