Skip to content

MySQL: Fix FLUSH TABLES consuming semicolon delimiter - #2789

Closed
slopgobblercobbler wants to merge 1 commit into
apache:mainfrom
slopgobblercobbler:fix/mysql-flush-tables-semicolon
Closed

slopgobblercobbler wants to merge 1 commit into
apache:mainfrom
slopgobblercobbler:fix/mysql-flush-tables-semicolon

Conversation

@slopgobblercobbler

Copy link
Copy Markdown

Dialects: mysql, generic

Description

Fixes #2764.

In parse_flush, the FLUSH TABLES loop previously consumed tokens unconditionally via self.next_token(). On the break condition (such as reaching a semicolon or EOF), the token was not restored with prev_token(). Consequently, when FLUSH TABLES; was immediately followed by another statement in a multi-statement query, the semicolon delimiter had already been consumed and was lost to the outer parser, resulting in Expected: end of statement, found: <TOKEN>.

This PR switches the TABLES loop to inspect tokens via self.peek_token(), advancing only when matching valid options (WITH or FOR), so statement delimiters and EOF are preserved cleanly.

Tests

  • Added parse_flush_tables_followed_by_statement in tests/sqlparser_mysql.rs covering:
    • FLUSH TABLES; SELECT 1
    • FLUSH TABLES t1, t2; SELECT 1
    • FLUSH TABLES WITH READ LOCK; SELECT 1
    • FLUSH TABLES t1, t2 WITH READ LOCK; SELECT 1
    • FLUSH TABLES t1, t2 FOR EXPORT; SELECT 1
  • Verified all MySQL and library unit tests pass locally (cargo test --all-features).
  • Verified cargo clippy --all-features -- -D warnings and cargo fmt --check are clean.

In `parse_flush`, parsing `FLUSH TABLES` consumed the next token inside a loop
using `self.next_token()`. When breaking out of the loop at the end of the
table/options list, the following token (such as a semicolon delimiter) was
already consumed and not restored, causing subsequent statements to fail parsing
with `Expected: end of statement, found: <TOKEN>`.

Use `self.peek_token()` instead of unconditionally consuming tokens in the
`TABLES` loop, advancing only on matched options and allowing delimiters and
EOF to be preserved for statement separation.

Closes apache#2764.
@github-actions github-actions Bot added the MySQL label Oct 31, 2026
@LucaCappelletti94 LucaCappelletti94 added the Prolific Author author opened PRs or issues in more than 20 repositories in the last 30 days label Nov 1, 2026
@alamb

alamb commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Thank you for the contribution. The change may well be correct, but I am closing this PR under the DataFusion AI policy, which also applies to sqlparser-rs: https://datafusion.apache.org/contributor-guide/ai-policy.html#what-is-an-ai-dump-and-why-it-is-not-helpful

Maintainer review time is the scarcest resource in this project. This account has recently opened many AI-generated PRs across many repositories. That suggests the changes aren't coming from someone who uses sqlparser-rs, and that no human will be around to discuss review feedback and maintain the code. Reviewing PRs like this costs us more time than it saves.

If you do use sqlparser-rs and this fix matters to you, please pick the one change you care most about. Then open a focused PR with a short description in your own words, one you have reviewed and understand, and we'd be happy to help with review.

@alamb alamb closed this Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

MySQL Prolific Author author opened PRs or issues in more than 20 repositories in the last 30 days

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MySQL: FLUSH TABLES consumes the ;, so the next statement is rejected

3 participants