Skip to content

About

Draws the joins of a SQL query as an interactive graph, linked both ways to the code. One HTML file, runs in the browser.

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

15 Commits

Folders and files

Repository files navigation

Arpe - SQL Visualizer

A single-file web page by arpe.io that draws the join structure of a SQL SELECT query as an interactive graph, linked both ways to the query text.

Try it online: https://arpe-io.github.io/SQL-Visualizer/ (served by GitHub Pages from the main branch).

Everything runs in the browser. The query is parsed locally by a hand-written parser embedded in the page; there are no external libraries, no web fonts and no network requests. Open index.html from disk and it works offline.

Features

  • Dialects — the Dialect chip in the header opens a panel of SQL dialects that can be hidden again. Five are read: T-SQL (SQL Server, Azure SQL, Fabric, Synapse; the default), PostgreSQL (also Redshift, Greenplum), Oracle, MySQL / MariaDB and DuckDB. Snowflake, Databricks SQL, BigQuery, Db2, SAP HANA, Teradata and ClickHouse are listed as planned. Each tab keeps its own dialect (saved with it); a new tab takes the last one chosen. When a query can't be read and shows clear signs of another dialect that does read it (backticks, (+), ::, LIMIT, QUALIFY…), the page offers to switch; it never switches by itself. See docs/dialects-plan.md.

  • Help — the Help button (or F1) shows what the tool does, the demo video (fetched only then), the version, the author and links to LinkedIn, the source code and the issues.

  • Full screen — a Full screen button in the header when the page is opened on its own (a page that embeds it in a frame offers its own button).

  • Live graph — edit or paste a query and the graph is rebuilt as you type (250 ms debounce). If the query can't be read yet, the last good graph is kept and the error is underlined in the code.

  • Two-way linking — click a table or a join to highlight its code (declaration, ON clause, selected columns); click in the code to find the matching table or join in the graph.

  • CTEs — click a CTE name where it is defined (or its label in the graph) to select the whole CTE: its zone and label stand out in the graph, its name and every place that reads it are highlighted in the code, and the panel lists the tables it is built from and where it is read.

  • Highlight ruler — a strip next to the editor scrollbar shows where highlighted lines are; ↑ / ↓ jump between them.

  • Two views

    • Condensed: the main join chain runs vertically, side tables branch to the right, and three or more identical sibling branches are folded into one stacked box (e.g. key/value property joins).
    • Extended: layered graph with three-line nodes and join-type badges. The ← → ↓ ↑ buttons turn the flow.
    • Each tab keeps its own view and flow direction (saved with it, in the browser and in files); a new tab takes the last ones chosen. The automatic layout keeps each nested query (CTE, subquery, derived table, UNION branch) in its own frame, orders each layer to reduce crossings, routes long edges between the tables and spreads a wide fan (a star schema) over two or three staggered layers.
  • Expand / collapse any branch, Expand all / Collapse all.

  • Move tables by hand (Shift-drag moves the whole branch); positions are kept per tab, per view and per flow direction, Reset positions restores the automatic layout. A table dragged back within 10 px of its automatic place snaps to it and is no longer counted as moved, so its edges are the automatic ones again; a moved table keeps the automatic lanes of its edges when they still cross nothing. Edges go around the tables they would otherwise cross, and the edges of a table moved by hand also avoid crossing other edges when a reasonable detour exists (a crossing costs about 220 px of detour, a table 1000). While a table is dragged its edges are hidden and nothing is computed; when it is dropped every edge is routed again (150 ms budget, then refined 20 ms at a time without blocking the page). Those edges also go round the frame labels.

  • Auto-fit keeps the whole graph in view; zooming or panning turns it off.

  • Tabs — several queries side by side, rename with double-click / ✎ / F2, close with undo.

  • Undo / redo per tab (Ctrl+Z, Ctrl+Shift+Z / Ctrl+Y), including Format / Clear.

  • Samples — six queries, written for each of the five dialects:

    • CTE: three chained CTEs;
    • TPC-H Q8: eight tables joined in WHERE, and a derived table;
    • TPC-DS Q72: eleven tables, inner and outer joins;
    • EF Core: a query as Entity Framework Core writes it, with derived tables and subqueries (SQL Server, Npgsql, Oracle and Pomelo MySQL providers; DuckDB has no EF Core provider in common use, so its version is the PostgreSQL text with DuckDB parameters);
    • DSS: a 22-table data-warehouse query from a reporting tool (for Oracle, written the way such tools write it there: joins in WHERE, the outer one with (+));
    • INDUS: 41 tables with nested joins and key/value properties.

    A first visit opens the T-SQL set. The Samples menu shows the set of the current tab's dialect; the chips at its top show another one. Queries with ten tables or fewer open top to bottom, the larger ones right to left.

  • Save / open — save all tabs or only the current one to a .json file (queries, names, folded branches, moved tables); open it again later, or open a .sql file as a new tab.

  • Formatter — re-indents the query, including nested joins with deferred ON clauses; it never changes a token.

  • Phones — the panes stack, and a rail on the left edge scrolls the page (the graph keeps its own touches for panning): tap Graph or SQL to jump to it, or drag along the rail.

  • Insights — nested joins, RIGHT JOINs, tables joined only to filter (duplicate risk), repeated key/value joins (pivot candidates), WHERE filters that turn an outer join into an inner join, Cartesian products, unknown aliases.

What the parser understands

T-SQL

INNER / LEFT / RIGHT / FULL [OUTER] JOIN, join hints (LOOP, HASH, MERGE, REMOTE), nested joins whose ON clause comes after the nested block, CROSS JOIN, CROSS / OUTER APPLY, old-style comma joins (linked through WHERE), IN / EXISTS / ANY / ALL / scalar subqueries, derived tables, VALUES lists, CTEs (WITH), UNION / EXCEPT / INTERSECT branches, table hints (WITH (NOLOCK), (NOLOCK)), TABLESAMPLE, FOR SYSTEM_TIME, PIVOT / UNPIVOT, TOP, bracketed and quoted identifiers, N'…' strings and comments.

PostgreSQL, Oracle, MySQL / MariaDB, DuckDB

All four: USING (…) (the left table holding the columns is not written: the one named after them, customers for customer_id, else one whose column of that name is written elsewhere, else the first table), NATURAL JOIN (with an insight: the keys are implicit), LATERAL subqueries and functions (drawn like APPLY; a function in FROM that reads a table on its left, such as unnest(t.tags), is LATERAL too), WITH RECURSIVE, FETCH FIRST, FOR UPDATE, and their own reserved words, so that LIMIT is not taken for an alias.

  • PostgreSQL: LIMIT / OFFSET, :: casts, JSON and array operators (->>, #>, @>…), $1 parameters, $$…$$ and $tag$…$tag$ strings, E'…' strings, DISTINCT ON, FROM ONLY, WITH ORDINALITY, TABLESAMPLE, column aliases AS t(a, b), AS [NOT] MATERIALIZED, WINDOW.
  • Oracle: outer joins written with (+) in WHERE (drawn as outer joins, the (+) side optional, with an insight suggesting the ANSI form), START WITH / CONNECT BY / ORDER SIBLINGS BY, MINUS, CROSS / OUTER APPLY, q'[…]' strings, :name binds, table@dblink, AS OF / VERSIONS BETWEEN flashback, SAMPLE, PARTITION (…), PIVOT / UNPIVOT, ROWNUM.
  • MySQL / MariaDB: `name` identifiers, "…" strings and backslash escapes, # comments (-- only followed by a space), LIMIT offset, count, STRAIGHT_JOIN, JOIN / INNER JOIN / CROSS JOIN with or without ON (read left to right, as MySQL does), USE / FORCE / IGNORE INDEX, PARTITION (…), JSON_TABLE, @variables, SQL_CALC_FOUND_ROWS and the other SELECT modifiers, WITH ROLLUP, LOCK IN SHARE MODE.
  • DuckDB: FROM first (FROM t SELECT …, or FROM t alone), files read by name (FROM 'sales.parquet'), ASOF [LEFT] JOIN, SEMI / ANTI JOIN (drawn in the subquery style: the table only filters), POSITIONAL JOIN, QUALIFY, USING SAMPLE, UNION [ALL] BY NAME, * EXCLUDE (…), lists, structs, $1 parameters.

Limitations

Only the first SELECT statement of the text is drawn; anything before it (for example CREATE VIEW … AS) is skipped. There is no schema: a column written without its table (WHERE a_id = id) is linked to a table only when the query reads a single one.

Usage

Open the online version, or open index.html in a recent browser (Chrome, Edge, Firefox, Safari). Tabs, the current view and the panel layout are remembered in the browser's local storage.

Development

The page is deliberately one self-contained file. The parser, analyser and formatter are pure functions (no DOM access) located between the /*PARSER-START*/ and /*PARSER-END*/ markers in index.html; the tests extract that block and run it under Node.js.

node --test

Requires Node.js 18 or later; no dependencies to install. tests/parser.test.mjs covers T-SQL and the formatter; tests/dialects/<id>.test.mjs covers one dialect each: a test per construct, and the 22 TPC-H queries in that dialect's syntax (tests/dialects/tpch.mjs). Every pure function takes the dialect profile as its last argument (analyse(sql, dialectOf('postgres'))) and reads T-SQL without one.

Embedding in the blogs

The blogs show the GitHub Pages version, https://arpe-io.github.io/SQL-Visualizer/, in a frame with a full-screen button around it. A change pushed to main reaches the articles once Pages has rebuilt (about a minute, plus up to 10 minutes of browser cache): nothing to copy, no site to redeploy. Since every push to main goes live there, prefer a pull request for any change that is not trivial.

Site Frame wrapper Article
blog.arpe.io (Docusaurus) src/components/ToolEmbed blog/tools/2026-12-04-arpe-sql-visualizer/index.md
architecture-performance.fr (Next.js) src/components/ToolEmbed.tsx, and https://arpe-io.github.io/SQL-Visualizer/ (this path only) in frame-src (next.config.ts) content/blog/20261204_arpe-sql-visualizer/index.md

The page still sends nothing: it only runs in the visitor's browser. Browsers keep the storage of a framed page apart for each site that embeds it, so the tabs a visitor keeps on one blog are not those of the other blog or of the GitHub Pages page.

Changing the samples

The samples are one file per dialect, Demo/samples/<dialect>.json, each a file saved with Save…. To change a set:

  1. Open it with Samples → All … samples.
  2. Arrange it: tabs, view, flow direction, folded branches, moved tables.
  3. Save all tabs with Save… over the file. Keep only the tabs of that set.
  4. Run node Demo/embed-samples.mjs. It copies every file into its <script type="application/json" id="demo-<dialect>"> block of index.html.

tests/samples.test.mjs checks four things:

  • the copies match the files;
  • each set holds the six sources, read without notes or false alarms;
  • each sample's orientation follows its number of tables;
  • each source draws the same tables in every dialect.

Demo video

Demo/video records a desktop demo (1920 × 1080, H.264 MP4, about 110 s) of the CTE and DSS samples: selections in the graph and in the query (tables, joins, CTE names, aliases, columns), the details panel, a table moved by hand, and the samples of another dialect. It needs Node 22+ and Microsoft Edge (another Chromium browser: set BROWSER to its path). Nothing is installed.

node Demo/video/record.mjs    # drives the page headless with real mouse events, keeps the frames
node Demo/video/encode.mjs    # WebCodecs H.264 in the browser → Demo/video/out/sql-visualizer-demo.mp4

The captions, the steps and their timing are in record.mjs. Frames are taken as PNG: the JPEG screencast of Chromium is narrower than the page. Demo/video/out is not tracked by git.

The Help dialog plays Demo/video/sql-visualizer-demo.mp4, tracked in the repository and served by GitHub Pages next to the page. After recording again, copy Demo/video/out/sql-visualizer-demo.mp4 over it, and update the length written in the dialog.

Version

APP_VERSION in index.html is shown in the Help dialog. Raise it with each change that reaches main.

License

MIT, © Architecture & Performance (A&P), with one added condition: any copy or modified version, and any product, page or service that includes this tool, must show the credit arpe.io with a working link to https://arpe.io in its interface, where users can see it, as this page does (next to the logo, or in the help or "about" screen). Embedding the GitHub Pages page in a frame meets it, since the page shows the credit itself.

Repository layout

index.html                 the application (HTML + CSS + JS, no dependencies)
LICENSE                    MIT, with an attribution condition (credit and link to arpe.io)
docs/dialects-plan.md      plan and status of the SQL dialects
Demo/samples/<dialect>.json  the built-in samples, saved with Save…; index.html embeds a copy of each
Demo/embed-samples.mjs     copies the sample files into index.html
Demo/video/                scripts that record and encode the demo video, and the video the Help dialog plays
tests/parser.test.mjs      parser / analyser / formatter tests, T-SQL (node:test)
tests/samples.test.mjs     the built-in samples, in every dialect
tests/dialects/            one test file per other dialect, and the TPC-H corpus

About

Draws the joins of a SQL query as an interactive graph, linked both ways to the code. One HTML file, runs in the browser.

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages