Skip to content

Conversation

@vadimonus
Copy link
Contributor

@vadimonus vadimonus commented Aug 11, 2025

By default Postgresql and SqlServer create index using write lock (exclusive lock) on table. This makes application unusable durng migration, if index creation is long (big table), leading to downtime wich is not suitable in production.

Currentrly creating indexex concurrently is possible only with DB::statement method. This PR adds ability to use it online() method in index definition.

Tried different names for IndexDefinition method (withoutLock, noLock, concurrently). Selected "online", as it's most widely used terminology. See https://mariadb.com/docs/server/server-usage/storage-engines/innodb/innodb-online-ddl/innodb-online-ddl-overview , https://learn.microsoft.com/en-us/sql/relational-databases/indexes/perform-index-operations-online?view=sql-server-ver16 .

Currently postgresql uses add constraint command for unique indexes, which does not support Concurently option. For such case two commands are used (create index and add constraint), as described in https://www.postgresql.org/docs/17/sql-altertable.html#SQL-ALTERTABLE-DESC-ADD-TABLE-CONSTRAINT-USING-INDEX

@github-actions
Copy link

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@vadimonus vadimonus changed the title [12.x] Online (concurrently) index creation for PoslgreSQL and SqlServer [12.x] Online (concurrently) index creation for PostgreSQL and SqlServer Aug 11, 2025
@vadimonus vadimonus marked this pull request as ready for review August 11, 2025 19:51
@taylorotwell taylorotwell merged commit 6e3cd5d into laravel:12.x Aug 12, 2025
9 of 60 checks passed
@vadimonus vadimonus deleted the online-indexes branch November 8, 2025 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants