-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add explanation about implicit indexes
- Loading branch information
Showing
3 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
Implicit indexes | ||
================ | ||
|
||
So-called implicit indexes are named as such because they are created | ||
without the user asking for it. Some RDBMS will do so when you create a | ||
foreign key: they will create an index on the referencing table, using | ||
the referencing columns. | ||
|
||
Here are some database platforms that are known to create indexes when | ||
creating a foreign key: | ||
|
||
- `MySQL <https://dev.mysql.com/doc/refman/8.0/en/create-table-foreign-keys.html>`_ | ||
- `MariaDB <https://mariadb.com/kb/en/foreign-keys>`_ | ||
|
||
|
||
Some other will not do so, on grands that such indexes are not always | ||
needed, and can be created in many different ways. They instead leave | ||
that responsibility to the user: | ||
|
||
- `PostgreSQL <https://stackoverflow.com/questions/970562/postgres-and-indexes-on-foreign-keys-and-primary-keys>`_ | ||
- `SQLite <https://sqlite.org/foreignkeys.html#fk_indexes>`_ | ||
- `SQL Server <https://stackoverflow.com/questions/836167/does-a-foreign-key-automatically-create-an-index>`_ | ||
|
||
In the case of these systems, the DBAL does the index creation for you | ||
and automatically picks an index name that obeys string length | ||
constraints of the platform you are using. That way, differences between | ||
platforms is reduced because you always end up with an index, be it | ||
created by the RDBMS or by the DBAL | ||
|
||
The rationale behind this is that these indexes improve performance, for | ||
instance for checking that a delete operation can be performed on a | ||
referenced table without violating the constraint in the referencing | ||
table. | ||
|
||
You can still explicitly create such indexes yourself, and the DBAL will | ||
notice when your index fulfills the indexing and constraint needs of the | ||
implicit index it would create, and will refrain from doing so. | ||
|
||
Some RDBMS such as MySQL do something similar and can also drop implicit | ||
indexes that are fulfilled by user-defined indexes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,5 @@ | |
reference/caching | ||
reference/known-vendor-issues | ||
reference/upgrading | ||
|
||
explanation/implicit-indexes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters