lib/pghero/methods/indexes.rb in pghero-1.5.3 vs lib/pghero/methods/indexes.rb in pghero-1.6.0
- old
+ new
@@ -140,10 +140,10 @@
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"]) }
- if covering_index
+ if covering_index && (covering_index["columns"] != index["columns"] || index["name"] > covering_index["name"])
indexes << {"unneeded_index" => index, "covering_index" => covering_index}
end
end
indexes.sort_by { |i| ui = i["unneeded_index"]; [ui["table"], ui["columns"]] }