@@ -181,6 +181,50 @@ Example:
181181 }
182182
183183
184+ .. _ref_datamodel_indexes_concurrent :
185+
186+ Concurrent index building
187+ =========================
188+
189+ When creating an index, the object type will be locked for writes. This means
190+ that until the index is created, all ``insert ``, ``update `` and ``delete ``
191+ queries will be put on hold.
192+ On types containing many objects, this can span minutes or even hours.
193+
194+ Instead, index building can be deferred from migration application to a later
195+ time. To do this, set ``build_concurrently `` index property to ``true ``:
196+
197+ .. code-block :: sdl
198+
199+ type User {
200+ name: str;
201+ index on (.name) {
202+ build_concurrently := true;
203+ };
204+ }
205+
206+ When this schema in applied to an instance, the index will be created, but it
207+ will not yet be active. The migration will not attempt to read any objects to
208+ build the index.
209+
210+ As the last step of :gelcmd: `migration apply ` (and :gelcmd: `migrate `), index
211+ will actually be built. During this time, the object type will not be locked
212+ for reads or writes.
213+
214+ This means that migration will lock for significantly less time and allow index
215+ the be created while new writes are applied to the database.
216+
217+ To apply migrations, but not build indexes at all, use
218+ :gelcmd: `migration apply --no-index-build ` flag.
219+ This allows index building to be triggered at a later time,
220+ by using :gelcmd: `migration apply ` again.
221+
222+ Until the index is created, it will not be used to speed up queries.
223+
224+ For tradeoffs of concurrent index building, refer to
225+ `PostgreSQL documentation <https://www.postgresql.org/docs/current/sql-createindex.html#SQL-CREATEINDEX-CONCURRENTLY >`_.
226+
227+
184228Annotate an index
185229=================
186230
@@ -232,6 +276,11 @@ Syntax
232276 Allows setting index :ref: `annotation <ref_eql_sdl_annotations >` to a given
233277 value.
234278
279+ - :sdl:synopsis: `build_concurrently := <bool> `
280+
281+ Allows index to be built
282+ :ref: `after migration is applied <ref_datamodel_indexes_concurrent >`
283+ to the instance.
235284
236285.. _ref_eql_ddl_indexes :
237286
@@ -269,6 +318,12 @@ Creates a new index for a given object type or link using *index-expr*.
269318 Assign an annotation to this index.
270319 See :eql:stmt: `create annotation ` for details.
271320
321+ - :eql:synopsis: `set build_concurrently := <bool> `
322+
323+ Allows index to be built
324+ :ref: `after migration is applied <ref_datamodel_indexes_concurrent >`
325+ to the instance.
326+
272327Example:
273328
274329.. code-block :: edgeql
0 commit comments