How our plan share links fit a whole plan

The online query plan viewer packs the entire plan into the link: Brotli, base64url, after the #. Why we did it that way, the size limits, and how to build one.

By

Paste a plan into the online query plan viewer, press Copy share link, and you get a link with the whole plan inside it. Not a pointer to the plan. The plan itself, squashed down and tacked onto the end of the URL. Here's how that works, why I did it this slightly weird way instead of a nice short link, and where it stops working.

Why not just a short link

A short link means I keep a copy of your plan on a server, or at least the full link it points to, which is the same thing here. Plans are not harmless. They hold your SQL, your database, schema, table and index names, your predicates, and sometimes the actual parameter values. A SQL Server actual plan records both the value a parameter was compiled for and the value it ran with, which can be a customer's email sitting in a WHERE clause. If I store those, I need a retention policy, a deletion story, and a database that's worth breaking into. I don't want any of that, and you probably don't want me to have it.

So the plan goes after the #. Browsers don't send that part of the URL to the server when they request a page. sqlly.app serves the viewer, your browser keeps the plan, and the analysis runs entirely in your tab. No plan is uploaded, no plan is stored on my servers, and there's no central pile of execution plans for someone to break into.

What "the server never sees it" actually covers

That claim is narrower than it sounds, so here's exactly what it means. When you open a share link, the browser strips the fragment before it builds the request. HTTP defines the request target without it (RFC 9110). My server gets this and nothing more:

GET /tools/query-plan-viewer HTTP/2
Host: sqlly.app

So the plan isn't in my access logs, my CDN's logs, or anything in between. It doesn't leak through the Referer header either: browsers drop the fragment from referrers by spec, and on top of that sqlly.app sends Referrer-Policy: strict-origin-when-cross-origin, so other sites only ever see https://sqlly.app/.

The fragment isn't secret, though. It's just not sent. RFC 9110 says so itself: fragments stay visible to the browser and to "any extensions or scripts running as a result of the response." In practice that means:

  • Browser history, and any history sync to your other devices or your browser vendor's cloud.
  • Browser extensions that can read the pages you visit.
  • Scripts on the page. Lots of analytics and error-reporting tools record window.location.href, fragment included, and ship it to a third party.
  • Wherever you paste it. Slack, Teams, email and ticket systems store the whole link, and some fetch it to build a preview.
  • Redirects. If a page redirects, the browser carries the fragment over to the new address, which can hand it to a different site. The viewer's address doesn't redirect, but a link shortener you run it through will, and it stores the full link to do that.

The page-script one is the one I control, so I checked it rather than assume it. sqlly.app runs no analytics or error-reporting scripts at all. The viewer makes no network requests with your plan: the only things it fetches are its own code and the Brotli module, both from sqlly.app. And the site's Content Security Policy has connect-src 'self', so even if a script did try to send something elsewhere, the browser would block it. One thing to know: after you copy a link, the viewer also puts it in the address bar so a reload keeps your work, which means it lands in your history. Clear takes it back out of the address bar.

What's in the link

Four steps:

  1. The four input boxes (plan, table definitions, query text, plan after a change) and the format choice become a small JSON object.
  2. That JSON gets compressed with Brotli at quality 11, its slowest and smallest setting.
  3. The bytes get base64url-encoded: letters, digits, - and _, nothing a chat app or mail client will choke on.
  4. It all goes after #b=.
https://sqlly.app/tools/query-plan-viewer#b=W83QQUTVqEM4D2xb1PoCEjiT8h…

The letter before the = is a version tag. The first version of the viewer used #z= (deflate) and #j= (no compression at all), and those links still open. I'm not breaking a link somebody pasted into a ticket six months ago.

Why Brotli

The first version used deflate, because every modern browser has it built in through CompressionStream. It was free and it worked. Then I measured it against Brotli on the 209 real plans in the viewer's test corpus, across all eleven engines:

PlanInputDeflate linkBrotli link
PostgreSQL EXPLAIN ANALYZE, JSON119 KB6,286 chars3,331 chars
SQL Server actual plan, parallel32 KB4,915 chars4,076 chars
SQL Server actual plan, several statements30 KB5,470 chars4,520 chars
Trino EXPLAIN ANALYZE VERBOSE20 KB4,380 chars3,432 chars
All 209 plans, compressed bytes1.1 MB177 KB147 KB

Overall Brotli was 17% smaller. The median plan came out 13% smaller, PostgreSQL JSON up to 47%, and a couple of tiny plans came out the same. Plans are repetitive (the same element names, operator names and property names over and over), and Brotli looks much further back than deflate's 32 KB window. It also ships with a built-in dictionary of common text.

Is 13% worth it? For a lot of plans it makes no difference at all. But link limits are hard edges. Discord stops at 2,000 characters and email gets flaky past about 2,000, so 13% is often the difference between "fits" and "doesn't". With Brotli, 189 of the 209 plans fit in a single Discord message, against 182 with deflate. The longest link in the whole corpus is 4,520 characters.

What it costs

Here's the annoying part. Browsers decompress Brotli all day for downloads, but they don't let a page use it. So the viewer ships its own: the open-source brotli-wasm module, about 1 MB of WebAssembly. That's a lot of bytes to make a link shorter, so it only loads when you make or open a link, and it starts downloading as your pointer moves onto the button. If it can't load for some reason, the viewer falls back to deflate and you get a #z= link. A slightly longer link beats no link.

Quality 11 is also slow on purpose. For every plan in the corpus it took under 200 ms on my Mac, and it works out to about 1.4 seconds per megabyte of input. That's fine, because you pay it once. Everyone who opens the link decompresses it in a few milliseconds.

The part where a link tries to eat your browser

Compression has a classic trap: a tiny input can expand to something enormous. I made a 165-byte Brotli stream that unpacks to 100 MB of zeros. If the viewer just inflated whatever was in the URL, one crafted link in a chat channel could lock up the tab of everyone who clicked it.

So it doesn't. The viewer unpacks in 64 KB steps, counts as it goes, and gives up at 8 MB. That 165-byte link just doesn't open. The same 8 MB cap applies when you make a link, which also saves you from waiting ten seconds to compress something no browser would accept anyway.

Where it stops working

  • 8 MB of input (all four boxes together) is the most a link can carry. Past that the viewer says so and copies nothing.
  • 2 MB of link is the most Chrome and Edge will open, so the viewer won't make a longer one. Firefox stops at 1 MB; Safari has no fixed limit.
  • Chat apps are much stricter: Slack 40,000 characters, Teams about 28 KB, Discord 2,000 (4,000 with Nitro). After you copy a link, the viewer shows a check, a warning or a cross for each of them.
The online query plan viewer after Copy share link: a 4.8 KB link for a 31 KB plan, with check marks for Chrome, Edge, Firefox, Safari, Slack and Microsoft Teams, a cross for Discord and a warning for email
After you copy a link: how long it is, and where it will paste.

And the big one, which I want to be really clear about: the link is the plan. It's compressed, not encrypted. Anyone who gets the link can read everything in it. I never see it, but Slack does, your email provider does, your browser history does, and so does anything that syncs that history. There's no expiry and no revoke button, because there's no server to revoke it on. That's the trade for keeping it off my servers. Share the link the way you'd share the .sqlplan file.

Things you can do with it

  • Ask for help. Drop the link in a Slack thread or a GitHub issue instead of attaching a plan file that people have to download and open in something.
  • Before and after in one link. Put your rewritten query's plan in Plan after a change and the link carries both plus the comparison. Good for pull requests and postmortems.
  • Send the schema along. Paste the table definitions and the person opening the link gets the schema-aware advice too, without having to ask you for the DDL.
  • Make links from a script. The format is deliberately boring, so a test job or a monitoring check can capture a plan and post a link without any service in the middle:
import { readFileSync } from 'node:fs';
import { brotliCompressSync, constants } from 'node:zlib';

const snapshot = { v: 1, p: readFileSync('plan.json', 'utf8') };
const packed = brotliCompressSync(JSON.stringify(snapshot), {
  params: { [constants.BROTLI_PARAM_QUALITY]: 11 },
});
console.log('https://sqlly.app/tools/query-plan-viewer#b=' + packed.toString('base64url'));

That's it, the same thing the viewer does, and any standard Brotli encoder works. The share links docs list every field and have a shell version using jq and the brotli command.

Yes, the free viewer is partly there to get you to try SQLly, where the same plan engine captures plans straight from your connection. But the links work fine on their own. If one breaks on you, or a chat app I didn't list mangles it, tell me and I'll add it to the list.

References