Skip to content
This repository was archived by the owner on Jul 6, 2021. It is now read-only.

Commit c413519

Browse files
committed
fix: rows numbering fixed in H00X reports
1 parent 0c1b4b5 commit c413519

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

resources/checks/H001_invalid_indexes.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,17 @@ with fk_indexes as (
3838
'CREATE INDEX',
3939
'CREATE INDEX CONCURRENTLY'
4040
) as revert_code,
41-
case when fi.index_name is not null then true else false end as supports_fk
41+
(
42+
select count(1)
43+
from fk_indexes fi
44+
where
45+
fi.fk_table_ref = pct.relname
46+
and fi.opclasses like (array_to_string(pidx.indclass, ', ') || '%')
47+
) > 0 as supports_fk
4248
from pg_index pidx
4349
join pg_class as pci on pci.oid = pidx.indexrelid
4450
join pg_class as pct on pct.oid = pidx.indrelid
4551
left join pg_namespace pn on pn.oid = pct.relnamespace
46-
left join fk_indexes fi on
47-
fi.fk_table_ref = pct.relname
48-
and fi.opclasses like (array_to_string(pidx.indclass, ', ') || '%')
4952
where pidx.indisvalid = false
5053
), data_total as (
5154
select

resources/checks/H002_unused_indexes.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,14 @@ with fk_indexes as (
8585
formated_table_name,
8686
formated_relation_name,
8787
i.opclasses,
88-
case when fi.index_name is not null then true else false end as supports_fk
88+
(
89+
select count(1)
90+
from fk_indexes fi
91+
where fi.fk_table_ref = i.table_name
92+
and fi.schema_name = i.schema_name
93+
and fi.opclasses like (i.opclasses || '%')
94+
) > 0 as supports_fk
8995
from indexes i
90-
left join fk_indexes fi on
91-
fi.fk_table_ref = i.table_name
92-
and fi.schema_name = i.schema_name
93-
and fi.opclasses like (i.opclasses || '%')
9496
join table_scans ts on ts.relid = i.indrelid
9597
),
9698
-- Never used indexes

resources/checks/H004_redundant_indexes.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,14 @@ index_data as (
8383
), redundant_indexes_fk as (
8484
select
8585
ri.*,
86-
case when fi.index_name is not null then true else false end as supports_fk
86+
(
87+
select count(1)
88+
from fk_indexes fi
89+
where
90+
fi.fk_table_ref = ri.table_name
91+
and fi.opclasses like (ri.opclasses || '%')
92+
) > 0 as supports_fk
8793
from redundant_indexes ri
88-
left join fk_indexes fi on
89-
fi.fk_table_ref = ri.table_name
90-
and fi.opclasses like (ri.opclasses || '%')
9194
),
9295
-- Cut recursive links
9396
redundant_indexes_tmp_num as (

0 commit comments

Comments
 (0)