Skip to content

[P2][bug] The row limit is appended to EXPLAIN and SHOW, rewriting the statement it is meant to bound #520

Closed

Description

@EVWorth

Context

execute_owned applies the user's max-row setting by appending LIMIT n to statements it considers row-returning.

Problem

src-tauri/crates/mas-core/src/query/executor.rs:110-131 matches on SELECT, SHOW, DESCRIBE and EXPLAIN, then appends LIMIT n to any of them that has no LIMIT of its own. That is wrong for three of the four:

  • EXPLAIN — EXPLAIN SELECT * FROM users becomes EXPLAIN SELECT * FROM users LIMIT 1000. The LIMIT binds to the inner statement, so the plan reported is the plan for a different query than the user asked about. EXPLAIN ANALYZE would additionally execute the modified statement.
  • SHOW — most SHOW forms accept LIMIT, but SHOW CREATE TABLE t LIMIT 1000 is a syntax error.
  • DESCRIBE — DESCRIBE users LIMIT 1000 is a syntax error.

Currently dormant

EXPLAIN is not reachable today: since #512, explain goes through the explain_query command, which calls execute_owned with limit: None precisely so the statement is not rewritten. The SHOW/DESCRIBE paths depend on whether any caller passes a limit alongside them — resultStore.doExecuteQuery passes the configured row limit for whatever the user typed, so a user running DESCRIBE users in the editor with the row limit enabled is the reachable case.

Filing it because the guard is a call-site convention rather than anything the executor enforces, and the next caller that passes a limit re-opens it.

Repro

  1. Settings → enable the result row limit
  2. Run DESCRIBE users in a query tab
  3. The executor sends DESCRIBE users LIMIT 1000

Expected

The row limit applies only to statements where LIMIT means what the setting intends — SELECT, and TABLE/VALUES/WITH ... SELECT. EXPLAIN, SHOW and DESCRIBE are passed through untouched.

Proposed fix

Reuse query::statement::effective_verb (added in #512, and already used by returns_rows) rather than a second prefix list — the two lists answering different questions about the same statement is what let this drift. Truncation for the statements a LIMIT cannot bound should be handled by the existing row cap on the result, not by rewriting the SQL.

Add cases to the executor's unit tests for EXPLAIN/SHOW CREATE/DESCRIBE with a limit set. Scope: S.

Needs human verify

no — DESCRIBE users LIMIT 1000 is a syntax error on any MySQL.

Activity

  1. added
    kind/bug
    area/results
    on Aug 29, 2026
  2. EVWorth commented on Aug 29, 2026

    @EVWorth
    OwnerAuthor

    Verified against the MySQL 8 test container rather than assumed:

    mysql> DESCRIBE users LIMIT 1000;
    ERROR 1064 (42000): ... near 'LIMIT 1000' at line 1
    
    mysql> SHOW CREATE TABLE users LIMIT 1000;
    ERROR 1064 (42000): ... near 'LIMIT 1000' at line 1
    
    mysql> EXPLAIN SELECT * FROM users LIMIT 1000;
    -- succeeds, but the LIMIT binds to the inner SELECT, so the plan
    -- described is for a different query than the user asked about
    

    So SHOW CREATE and DESCRIBE fail outright, and EXPLAIN fails silently by answering a question that was not asked — the worse of the two.

  3. added a commit that references this issue on Sep 8, 2026
    4439ef9
  4. added 3 commits that reference this issue on Sep 8, 2026
    932ec3b
    f48850e
    df60343
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/resultskind/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions