Skip to content
sqlsage=#\d docs.examplesoffline-first · v0.2.1

Bundled Examples ​

SQLSage ships a demonstration catalog and twelve realistic queries. They cover the correctness and performance problems the tool is designed to catch, and none of them touch your data:

bash
sqlsage list
sqlsage analyze --corpus q05 --format text
IDTitleThe problem it shows
q01-nonsargable-dateMonthly revenue via date_trunc on the filtered columnAn index the planner cannot use.
q02-leading-wildcard-orCustomer search with leading wildcard and OR across columnsNon-sargable LIKE and OR.
q03-correlated-scalar-subqueryPer-customer order counts via correlated scalar subqueriesCorrelated work.
q04-deep-offset-paginationDeep OFFSET pagination over the orders feedThe cost of skipping rows.
q05-not-in-nullableCustomers with no events, via NOT IN on a nullable columnA query that returns the wrong answer.
q06-fanout-double-countRevenue per customer joined through order_itemsJoin fan-out double counting.
q07-left-join-demotedCustomers and their complete orders, filtered in WHEREDemotion of an outer join.
q08-distinct-hides-fanoutDISTINCT used to undo a join fan-outFan-out hidden behind DISTINCT.
q09-cast-on-columnDaily order counts with a cast applied to the indexed columnA cast that defeats the index.
q10-having-instead-of-whereAggregate with a row filter placed in HAVINGRow filter misplaced in HAVING.
q11-top-n-per-groupMost recent order per customer via a correlated max()Per-group top-N.
q12-jsonb-and-unbounded-sortEvent funnel filtered on a jsonb attributejsonb filtering and a full sort.

Start with the wrong answer ​

q05 is the demo query — a nullable NOT IN that can silently return zero rows instead of 196,000:

bash
sqlsage analyze --corpus q05 --format text
text
WRONG RESULTS
This query returns wrong answers today. Fix that before you spend a minute on
its speed.

It is the best first example because it shows the product's strongest claim: SQLSage tells you a query is wrong before it tells you it is slow.

Run them all ​

bash
for q in $(sqlsage list | awk '{print $1}'); do
  echo "== $q =="
  sqlsage analyze --corpus "$q" --format markdown
done

Each example is also a regression case: the analysis runs in CI on every commit, and the --check IR assertions pin the project's real regression history.

MIT licensed · Analyzes PostgreSQL SELECT statements with an honest evidence model.