Skip to content

Improved polymorphic and STI index suggestions #109

@Epigene

Description

@Epigene

Hi!

I am using v2.1.8 and polymorphic indexes are still suggested despite them already being present in different order, see #107

Furthermore, I believe the suggestion should be in the format [:poly_type, :poly_id]. This is somewhat of a controversial topic, but the reasoning for putting the type first is that it is more useful:

Pros:

  • Index can be used for searches only by type (in case we want a count of how many records by types there are)

Cons:

  • Index can not be used to search by just :poly_id, but this should be a non-problem since it can be argued that searching by just polymorphic ID does not guarantee that the correct record is selected.

Additionally, there are false positives when using Rails' STI pattern. If a table has a :type column loldba proposes an [:id, :type] index, which is redundant, especially if an index on just :type is present (and :id is indexed by default).

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions