Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
backend ruleP2stack specificStack: sql
sqlindexingmysqlperformanceschema
Don't add a redundant index that the engine already creates for foreign keys
MySQL/MariaDB auto-create an index for every foreign key, so adding an explicit index on the same column is redundant unless you need a different index type or composite ordering.
PR: vinify-database-migrator · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codejavascript
| 1 | // FK already creates a B-tree index on tasting_list_id on MySQL/MariaDB |
| 2 | await queryInterface.addIndex("junction", ["tasting_list_id"], { |
| 3 | name: "idx_junction_tasting_list_id", |
| 4 | }); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codejavascript
| 1 | // Rely on the auto-created FK index; only add an index when it differs |
| 2 | // (e.g. a composite index, or a non-default type the FK index doesn't cover) |
| 3 | await queryInterface.addIndex("junction", ["tasting_list_id", "created_at"]); |
Explanation (EN)
Objašnjenje (HR)