You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Visual Explain enables ANALYZE by default for REPLACE, MERGE and data-modifying CTEs #884
Visual Explain turns Analyze on by default unless the statement is detected as data-modifying. With ANALYZE the statement is really executed. The detection only looks at the first keyword:
So these are treated as read-only, get ANALYZE enabled with no warning, and are executed when the plan is fetched:
REPLACE INTO … (MySQL/MariaDB/SQLite)
MERGE INTO … (PostgreSQL 15+, SQL Server)
data-modifying CTEs such as WITH d AS (DELETE FROM t RETURNING *) SELECT * FROM d
statements preceded by a comment (-- note\nDELETE …)
MERGE is explainable per src/utils/sqlSplitter/classify.ts, so it does reach Visual Explain.
To Reproduce
Open a PostgreSQL connection with a scratch table t.
Select WITH d AS (DELETE FROM t RETURNING *) SELECT * FROM d and open Visual Explain.
Analyze is ticked and there's no data-modification warning; the rows are deleted.
Expected behavior
Any statement that can modify data defaults to Analyze off and shows the existing warning.
Where to start
src/utils/sql.tsisDataModifyingQuery: strip leading comments, add REPLACE, MERGE, UPSERT, CREATE, GRANT/REVOKE, CALL/EXEC, and for WITH look for INSERT|UPDATE|DELETE|MERGE outside string literals. The tokenizer in src/utils/sqlSplitter/ may help.
Activity
fix(explain): default Analyze off for every data-modifying statement