You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SCHEMA003 fires on PRIMARY KEY columns (false positive) #146
SCHEMA003 ("ORDER BY column could benefit from index") fires on a column that is the table's PRIMARY KEY. The primary key already provides a B-tree index, and Postgres satisfies ORDER BY id DESC with a backward index scan, so the suggestion CREATE INDEX idx_id ON table(id) is redundant.
Reproduction
schema.sql:
CREATETABLEcampaigns (
id SERIALPRIMARY KEY,
name VARCHAR(255) NOT NULL
);
queries.sql:
SELECT id, name FROM campaigns ORDER BY id DESCLIMIT100;
Actual: [INFO] SCHEMA003: ORDER BY column 'id' could benefit from index
Expected: no finding — id is the primary key.
Suspected cause
The schema parser appears to collect only explicit CREATE INDEX statements as indexed columns and does not register PRIMARY KEY (and likely UNIQUE) constraints as indexes.
Suggested fix
Register PRIMARY KEY and UNIQUE columns as indexed (single-column) when building the schema index map, and skip SCHEMA003/SCHEMA001/SCHEMA004 findings for columns already covered by a unique/PK index prefix.
Activity