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
Copy file name to clipboardExpand all lines: sql/i2_redundant_indexes.sql
+13-8Lines changed: 13 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -8,11 +8,11 @@
8
8
-- `CREATE INDEX`, put them to revert/rollback migration script.
9
9
10
10
-- It is also a good idea to manually double check all indexes being dropped.
11
-
-- WARNING here: when you are dropping an index B which is redundant to some index A,
11
+
-- WARNING here: when you are dropping an index B which is redundant to some index A,
12
12
-- check that you don't drop the A itself at the same time (it can be in "unused").
13
13
-- So if B is "redundant" to A and A is "unused", the script will suggest
14
14
-- dropping both. If so, it is probably better to drop B and leave A.
15
-
-- -- in this case there is a chance that A will be used. If it will still be unused,
15
+
-- -- in this case there is a chance that A will be used. If it will still be unused,
16
16
-- you will drop it during the next cleanup routine procedure.
17
17
18
18
-- This query doesn't need any additional extensions to be installed
@@ -22,7 +22,7 @@
22
22
-- It also does't do anything except reading system catalogs and
23
23
-- printing NOTICEs, so you can easily run it on your
24
24
-- production *master* database.
25
-
-- (Keep in mind, that on replicas, the whole picture of index usage
25
+
-- (Keep in mind, that on replicas, the whole picture of index usage
26
26
-- is usually very different from master).
27
27
28
28
-- TODO: take into account type of index and opclass
@@ -66,9 +66,9 @@ with unused as (
66
66
join index_data as i2 oni1.indrelid=i2.indrelidandi1.indexrelid<>i2.indexrelid
67
67
where
68
68
(regexp_replace(i1.indpred, 'location \d+', 'location', 'g') IS NOT DISTINCT FROM regexp_replace(i2.indpred, 'location \d+', 'location', 'g'))
69
-
and (regexp_replace(i1.indexprs, 'location \d+', 'location', 'g') IS NOT DISTINCT FROM regexp_replace(i2.indexprs, 'location \d+', 'location', 'g'))
69
+
and (regexp_replace(i1.indexprs, 'location \d+', 'location', 'g') IS NOT DISTINCT FROM regexp_replace(i2.indexprs, 'location \d+', 'location', 'g'))
70
70
and ((i1.nkeys>i2.nkeysand not i2.indisunique) OR (i1.nkeys=i2.nkeysand ((i1.indisuniqueandi2.indisuniqueand (i1.indexrelid>i2.indexrelid)) or (not i1.indisuniqueand not i2.indisuniqueand (i1.indexrelid>i2.indexrelid)) or (i1.indisuniqueand not i2.indisunique))))
0 commit comments