forked from GNUsocial/gnu-social
[DATABASE] Add explicit indices for all foreign keys
This adds a requirement for all definitions that have foreign keys to also require indices for all source (local) attributes mentioned in foreign keys. MariaDB/MySQL creates indices for source attributes automatically, so this serves as a way to get rid of those automatic indices and create clean explicit ones instead. In PostgreSQL, most of the time, indices on the source are necessary to decrease performance penalty of foreign keys (like in MariaDB), but they aren't created automatically, so this serves to remove that difference between PostgreSQL and MariaDB.
This commit is contained in:
@@ -259,12 +259,9 @@ class MysqlSchema extends Schema
|
||||
<<<END
|
||||
SELECT INDEX_NAME AS `key_name`, INDEX_TYPE AS `key_type`, COLUMN_NAME AS `col`
|
||||
FROM INFORMATION_SCHEMA.STATISTICS
|
||||
WHERE TABLE_SCHEMA = '{$schema}' AND TABLE_NAME = '{$table}'
|
||||
WHERE TABLE_SCHEMA = '{$schema}'
|
||||
AND TABLE_NAME = '{$table}'
|
||||
AND NON_UNIQUE IS TRUE
|
||||
AND INDEX_NAME NOT IN (
|
||||
SELECT CONSTRAINT_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
|
||||
WHERE REFERENCED_TABLE_NAME IS NOT NULL
|
||||
)
|
||||
ORDER BY SEQ_IN_INDEX;
|
||||
END
|
||||
);
|
||||
|
Reference in New Issue
Block a user