Schema-aware advice

funcional

Advice checked against your tables and indexes, and the seven checks only the schema can answer.

A plan says what the database did, but not what it could have done. It does not list the indexes the optimizer passed over, the declared types of the columns it compared, or which columns are nullable. Given your table definitions, SQLly checks its advice against them and adds seven checks that only the schema can answer.

Where the table definitions come from

DóndeHow
Aplicación SQLlyAutomatic. When the plan was captured on a connection whose tables SQLly already knows (the same table, column, key and index snapshot IntelliSense uses), the findings use it. No extra query runs, and findings that relied on it say so.
Online viewerPaste the CREATE TABLE y CREATE INDEX statements into the Table definitions tab. See below.

Pasting table definitions

SQLly
Table definitions tab in the online query plan viewerTable definitions tab in the online query plan viewer
The online viewer's input: the Plan, Table definitions, Query text and Plan after a change tabs, with a note under them saying how many tables, indexes and columns were read from the definitions.

The reader takes the DDL your database or migration tool already produces:

  • CREATE TABLE with columns, types, nullability, collations, identity and computed columns, primary keys and foreign keys.
  • CREATE INDEX (unique, clustered, filtered or partial, with included columns and the index method) and ALTER TABLE … ADD constraints.
  • Statements separated by ; or SQL Server's GO.
  • A row count per table, written as a line such as orders: 1.2M, for checks that depend on table size.

Under the box, a note confirms what was read: “read 4 tables, 7 indexes, 19 columns as PostgreSQL”. Only the tables in the plan are used. ignored. Write the definitions in the same engine's dialect as the plan.

How the schema changes the advice

  • No suggestion for an index you already have. If the index exists, the finding asks why it was not used instead.
  • Extend instead of duplicate. When an existing index almost fits, the suggestion extends it (on SQL Server with DROP_EXISTING = ON) rather than adding a near-copy.
  • Real column types are used to explain implicit conversions and to write correctly typed fixes.

Checks that need the schema

ComprobarEjemplo
Index not used“orders has the index orders_status_idx on status, but the plan scans the table”, with the likely reason: the column is text and the query compares it with a number, or the optimizer expected far more matching rows than it got.
Foreign key with no index“orders.customer_id is a foreign key to customers with no index, and this plan joins on it by scanning orders”, with the CREATE INDEX that fixes it.
Join on mismatched columnsA join comparing columns of different types or different collations, which can stop an index being used.
NOT IN over a nullable columnA NOT IN against a column the schema declares nullable: slower, and it returns no rows at all if a NULL ever appears. NOT EXISTS is the usual fix.
Heap or no primary keyA large table with no clustered index (a heap) on SQL Server, or no primary key elsewhere.
Very wide indexAn index in the plan with many key columns, or one that stores most of the table's columns.
Definitions out of dateThe plan mentions tables or indexes that the definitions do not have, so the definitions are probably from another version of the database.

Query text helps too. MySQL, MariaDB and SQLite plans print the query's aliases instead of table names; paste the query into the online viewer's Query text tab (the app has it already) and the real table names are shown.