dsh-sql-tuner
jrc521/dsh-sql-tuner
Adds a panel that explains a SQL query against a pasted schema, ranks optimization advice, and produces index DDL, SQL rewrites and an execution plan checklist.
설치
dsh plugin --profile web add github:jrc521/dsh-sql-tunerREADME
SQL tuner
A DeepSeek Harness panel for reading and tuning SQL without touching a database.
Open SQL 调优 / SQL tuner from the left sidebar. The panel is split in two: the schema (and therefore index, partition, foreign-key and row-count context) on the left, the SQL under review on the right. Results refresh as you type.
What it does
Explanation — statement type, tables with aliases and row counts, join order, the projection, every predicate with an indexable / not indexable marker, grouping, ordering, paging, subqueries and set operations, followed by the logical execution order and an estimated access method per table.
Advice — rules run against your schema, each finding carrying a severity, the line it comes from, the concrete symptom, why it is slow, and how to fix it. About thirty checks including: function wrapped around an indexed column, leading-wildcard LIKE, implicit type conversion, NOT IN with a subquery, OR predicates, missing or non-covering indexes, range-before-equality index ordering, deep OFFSET paging, sorts that cannot use an index, correlated subqueries, cartesian products, LEFT JOIN degraded by WHERE, UPDATE/DELETE without WHERE, missing partition pruning, unindexed foreign keys.
Execution — ready-to-run index DDL for 14 dialects (CREATE INDEX CONCURRENTLY for PostgreSQL, ONLINE for Oracle, WITH (ONLINE = ON) for SQL Server, bitmap / minmax / inverted index notes for columnar engines), SQL rewrites (date ranges instead of functions on columns, keyset paging, NOT EXISTS, explicit projections, UNION ALL), a plan checklist for the chosen engine, and the session or optimizer settings commonly needed to verify the fix.
Input
- Schema — paste
CREATE TABLE/CREATE INDEX/ALTER TABLE ... ADD INDEX, or a plain data dictionary. Primary keys, foreign keys, partition keys, indexes and comments are detected. Row counts can be set per table in the parsed cards, or declared inline with-- rows: 12m(-- rows: 1200万also works). Extra indexes can be typed per table when they live outside the DDL. - SQL — type it, paste it, import a
.sql/.txtfile, or drop the file on the editor. Multiple statements separated by semicolons are analyzed individually (up to 8).
Interaction notes
- Results refresh as you type (260 ms debounce);
Ctrl+Enterre-runs the analysis immediately and confirms with a toast plus aHH:MM:SSstamp in the editor footer. - Each advice card carries an
L<n>chip; clicking it selects that line in the editor. 样例 / 清空ask for confirmation when the editor already holds content, and the toast reports what changed.- Copy buttons fall back to a selection based
execCommand('copy')when the clipboard API is denied. - Text stays in
localStorageunderdsh-sql-tuner.v1; the chip shows extra columns beyond the first 40 by count.
Limitations
- Analysis is rule-based and local. Row counts and scan estimates are heuristics derived from what you paste, not real
EXPLAINoutput — always confirm the final plan in the database. - It never connects to a database, never uploads SQL or schema, and makes no model request. State stays in the browser's
localStorage. - The parser understands common
SELECT/INSERT/UPDATE/DELETE/MERGEshapes including CTEs and subqueries; dialect-specific syntax outside those shapes may be parsed conservatively or skipped. - "Send to agent" only copies a formatted prompt and opens the conversation panel — it does not send anything by itself.
Files
engine.js— the analyzer; a pure function library with no I/O, shared by the Node tests and the browser bundle.src/client-src.js— the panel UI (React, no JSX) plus both locales.client.js— generated byscripts/build-client.mjs(inlines the engine into thewindow.__ModuleLoader__factory).test/engine.test.mjs— 62 assertions over parsing, rules, rewrites and every dialect.test/client.smoke.mjs— 48 assertions that load the built bundle with a tiny hooks runtime and render the whole panel in both languages.scripts/check-dict.mjs— asserts zh/en key parity and that every advice, explanation, plan and rewrite key used by the code exists.