|
| 1 | +Implicit indexes |
| 2 | +================ |
| 3 | + |
| 4 | +So-called implicit indexes are named as such because they are created |
| 5 | +without the user asking for it. Some RDBMS will do so when you create a |
| 6 | +foreign key: they will create an index on the referencing table, using |
| 7 | +the referencing columns. |
| 8 | + |
| 9 | +Here are some RDBMS that are known to create indexes when creating a |
| 10 | +foreign key: |
| 11 | + |
| 12 | +- `MySQL <https://dev.mysql.com/doc/refman/8.0/en/create-table-foreign-keys.html>`_ |
| 13 | +- `MariaDB <https://mariadb.com/kb/en/foreign-keys>`_ |
| 14 | + |
| 15 | + |
| 16 | +Some other will not do so, on grands that such indexes are not always |
| 17 | +needed, and can be created in many different ways. They instead leave |
| 18 | +that responsability to the user: |
| 19 | + |
| 20 | +- `PostgreSQL <https://stackoverflow.com/questions/970562/postgres-and-indexes-on-foreign-keys-and-primary-keys>`_ |
| 21 | +- `SQLite <https://sqlite.org/foreignkeys.html#fk_indexes>`_ |
| 22 | +- `SQL Server <https://stackoverflow.com/questions/836167/does-a-foreign-key-automatically-create-an-index>`_ |
| 23 | + |
| 24 | +In the case of these systems, the DBAL does the index creation for you |
| 25 | +and automatically picks an index name that obeys string length |
| 26 | +constraints of the platform you are using. That way, differences between |
| 27 | +platforms is reduce because you always end up with an index, be it |
| 28 | +created by the RDBMS or by the DBAL |
| 29 | + |
| 30 | +The rationale behind this is that these indexes improve performance, for |
| 31 | +instance for checking that a delete operation can be performed on a |
| 32 | +referenced table without violating the constraint in the referencing |
| 33 | +table. |
| 34 | + |
| 35 | +You can still explicitly create such indexes yourself, and the DBAL will |
| 36 | +notice when your index fulfills the indexing and constraint needs of the |
| 37 | +implicit index it would create, and will refrain from doing so. |
| 38 | + |
| 39 | +Some RDBMS such as MySQL do something similar and can also drop implicit |
| 40 | +indexes that are fulfilled by user-defined indexes. |
0 commit comments