Skip to content

Instantly share code, notes, and snippets.

@mhicauber
mhicauber / pgsql-find-create-missing-indexes.sql
Created July 17, 2023 10:41 — forked from jonasraoni/pgsql-find-create-missing-indexes.sql
PostgreSQL SELECT statement to find/create foreign keys that are missing indexes
-- find missing indexes
SELECT
conrelid::regclass, conname, reltuples::bigint
FROM
pg_constraint
JOIN pg_class
ON conrelid = pg_class.oid
WHERE
contype = 'f'
AND NOT EXISTS (
@mhicauber
mhicauber / pgsql-find-create-missing-indexes.sql
Created July 17, 2023 10:41 — forked from jonasraoni/pgsql-find-create-missing-indexes.sql
PostgreSQL SELECT statement to find/create foreign keys that are missing indexes
-- find missing indexes
SELECT
conrelid::regclass, conname, reltuples::bigint
FROM
pg_constraint
JOIN pg_class
ON conrelid = pg_class.oid
WHERE
contype = 'f'
AND NOT EXISTS (