lib/pghero/methods/indexes.rb in pghero-1.6.3 vs lib/pghero/methods/indexes.rb in pghero-1.6.4

- old
+ new

@@ -112,26 +112,29 @@ # TODO parse array properly # http://stackoverflow.com/questions/2204058/list-columns-with-indexes-in-postgresql def indexes select_all(<<-SQL SELECT + schemaname AS schema, t.relname AS table, ix.relname AS name, - regexp_replace(pg_get_indexdef(indexrelid), '^[^\\(]*\\((.*)\\)$', '\\1') AS columns, - regexp_replace(pg_get_indexdef(indexrelid), '.* USING ([^ ]*) \\(.*', '\\1') AS using, + regexp_replace(pg_get_indexdef(i.indexrelid), '^[^\\(]*\\((.*)\\)$', '\\1') AS columns, + regexp_replace(pg_get_indexdef(i.indexrelid), '.* USING ([^ ]*) \\(.*', '\\1') AS using, indisunique AS unique, indisprimary AS primary, indisvalid AS valid, indexprs::text, indpred::text, - pg_get_indexdef(indexrelid) AS definition + pg_get_indexdef(i.indexrelid) AS definition FROM pg_index i INNER JOIN pg_class t ON t.oid = i.indrelid INNER JOIN pg_class ix ON ix.oid = i.indexrelid + LEFT JOIN + pg_stat_user_indexes ui ON ui.indexrelid = i.indexrelid ORDER BY 1, 2 SQL ).map { |v| v["columns"] = v["columns"].sub(") WHERE (", " WHERE ").split(", ").map { |c| unquote(c) }; v } end @@ -139,10 +142,10 @@ def duplicate_indexes indexes = [] indexes_by_table = self.indexes.group_by { |i| i["table"] } indexes_by_table.values.flatten.select { |i| PgHero.falsey?(i["primary"]) && PgHero.falsey?(i["unique"]) && !i["indexprs"] && !i["indpred"] && PgHero.truthy?(i["valid"]) }.each do |index| - covering_index = indexes_by_table[index["table"]].find { |i| index_covers?(i["columns"], index["columns"]) && i["using"] == index["using"] && i["name"] != index["name"] && !i["indexprs"] && !i["indpred"] && PgHero.truthy?(i["valid"]) } + covering_index = indexes_by_table[index["table"]].find { |i| index_covers?(i["columns"], index["columns"]) && i["using"] == index["using"] && i["name"] != index["name"] && i["schema"] == index["schema"] && !i["indexprs"] && !i["indpred"] && PgHero.truthy?(i["valid"]) } if covering_index && (covering_index["columns"] != index["columns"] || index["name"] > covering_index["name"]) indexes << {"unneeded_index" => index, "covering_index" => covering_index} end end