Skip to content

[P0][bug] executeExplain/executeExplainAnalyze use raw EXPLAIN ${sql} string concat — trailing ; fails for EXPLAIN ANALYZE; multi-statement fails outright #418

Closed

Description

@EVWorth

Context

EXPLAIN / EXPLAIN ANALYZE in SQLPilot is implemented via string concatenation in resultStore.

Problem

src/stores/resultStore.ts:103-117 (executeExplain) and 119-136 (executeExplainAnalyze) use raw EXPLAIN ${sql} string concat. Editor F34 noted: if sql ends with ;, the result is EXPLAIN SELECT 1;; (double semicolon). EXPLAIN tolerates this; EXPLAIN ANALYZE raises ERROR 1064 (42000): You have an error in your SQL syntax…near 'EXPLAIN ANALYZE SELECT 1;;'. The QueryToolbar passes editor.getValue() which includes the trailing ; per convention. EXPLAIN ANALYZE fails silently with a confusing error. Additionally, a multi-statement SQL SELECT 1; SELECT 2; gets prefixed with EXPLAIN and submitted as one — MySQL returns ERROR 1064 for multi-statement EXPLAIN.

Files

  • src/stores/resultStore.ts:103-117
  • src/stores/resultStore.ts:119-136

Repro

  1. Open query tab, type SELECT 1; (with trailing semicolon)
  2. Click Explain → EXPLAIN ANALYZE
  3. MySQL returns error 1064 — confusing for the user

Expected

EXPLAIN ANALYZE SELECT 1; (trailing ;) executes successfully. Multi-statement SELECT 1; SELECT 2; shows "EXPLAIN supports a single statement".

Proposed fix

(1) const trimmed = sql.replace(/;\s*$/, '') before string concat. (2) Reject multi-statement SQL with a clear error: "EXPLAIN supports a single statement — split your script and re-run". Scope: S.

Acceptance

EXPLAIN ANALYZE SELECT 1; (trailing ;) executes successfully. Multi-statement SELECT 1; SELECT 2; shows "EXPLAIN supports a single statement".

Needs human verify

yes

Doc drift

no

Activity

  1. added
    audit
    severity/p0
    kind/bug
    area/explain
    on Jul 31, 2026
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/explainauditkind/bugseverity/p0

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions