logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

unindexed_fk.sql (1136B)


  1. -- Unindexed FK -- Missing indexes - For CI
  2. WITH y AS (
  3. SELECT
  4. pg_catalog.format('%I', c1.relname) AS referencing_tbl,
  5. pg_catalog.quote_ident(a1.attname) AS referencing_column,
  6. (SELECT pg_get_expr(indpred, indrelid) FROM pg_catalog.pg_index WHERE indrelid = t.conrelid AND indkey[0] = t.conkey[1] AND indpred IS NOT NULL LIMIT 1) partial_statement
  7. FROM pg_catalog.pg_constraint t
  8. JOIN pg_catalog.pg_attribute a1 ON a1.attrelid = t.conrelid AND a1.attnum = t.conkey[1]
  9. JOIN pg_catalog.pg_class c1 ON c1.oid = t.conrelid
  10. JOIN pg_catalog.pg_namespace n1 ON n1.oid = c1.relnamespace
  11. JOIN pg_catalog.pg_class c2 ON c2.oid = t.confrelid
  12. JOIN pg_catalog.pg_namespace n2 ON n2.oid = c2.relnamespace
  13. JOIN pg_catalog.pg_attribute a2 ON a2.attrelid = t.confrelid AND a2.attnum = t.confkey[1]
  14. WHERE t.contype = 'f'
  15. AND NOT EXISTS (
  16. SELECT 1
  17. FROM pg_catalog.pg_index i
  18. WHERE i.indrelid = t.conrelid
  19. AND i.indkey[0] = t.conkey[1]
  20. AND indpred IS NULL
  21. )
  22. )
  23. SELECT referencing_tbl || '.' || referencing_column as "column"
  24. FROM y
  25. WHERE (partial_statement IS NULL OR partial_statement <> ('(' || referencing_column || ' IS NOT NULL)'))
  26. ORDER BY 1;