|
Создание индекса таблицы без её блокировки
|
|||
---|---|---|---|
#18+
Для тех, кто хочет размять мозги. Задали мне на собеседовании такой вопрос. MS SQL 2017. Есть таблица с овер-дохрена строчек. Проанализировали, что для ускорения нужен еще один индекс. Но во время создания индекса таблица заблокируется на слишком большое время. База 24*7. Как сделать создание индекса без отвала соединений клиентов (в это время кто-то что-то пишет или читает из таблицы)? Я раньше с таким не сталкивался, свой ответ быстро придумал. Но интересны ваши мысли. Ведь у вас будет время придумать более грамотный ответ. Заранее спасибо. ... |
|||
:
Нравится:
Не нравится:
|
|||
24.07.2020, 15:25 |
|
Создание индекса таблицы без её блокировки
|
|||
---|---|---|---|
#18+
Учись, студент ONLINE = { ON | OFF } ... |
|||
:
Нравится:
Не нравится:
|
|||
24.07.2020, 15:28 |
|
Создание индекса таблицы без её блокировки
|
|||
---|---|---|---|
#18+
ONLINE = { ON | OFF } Specifies whether underlying tables and associated indexes are available for queries and data modification during the index operation. The default is OFF. OFF Table locks are applied for the duration of the index operation. An offline index operation that creates, rebuilds, or drops a clustered index, or rebuilds or drops a nonclustered index, acquires a Schema modification (Sch-M) lock on the table. This prevents all user access to the underlying table for the duration of the operation. An offline index operation that creates a nonclustered index acquires a Shared (S) lock on the table. This prevents updates to the underlying table but allows read operations, such as SELECT statements. ON Long-term table locks are not held for the duration of the index operation. During the main phase of the index operation, only an Intent Share (IS) lock is held on the source table. This enables queries or updates to the underlying table and indexes to proceed. At the start of the operation, a Shared (S) lock is held on the source object for a very short period of time. At the end of the operation, for a short period of time, an S (Shared) lock is acquired on the source if a nonclustered index is being created; or an SCH-M (Schema Modification) lock is acquired when a clustered index is created or dropped online and when a clustered or nonclustered index is being rebuilt. ONLINE cannot be set to ON when an index is being created on a local temporary table. For more information, see Perform Index Operations Online . ... |
|||
:
Нравится:
Не нравится:
|
|||
24.07.2020, 18:57 |
|
Создание индекса таблицы без её блокировки
|
|||
---|---|---|---|
#18+
Это зависит от редакции сервера. Для редакций ниже, чем энтерпрайз - никак. Но если размер таблицы позволяет, то можно SORT_IN_TEMPDB = on сделать. Тогда блокироваться будет меньше, потому что быстрее посчитает. ... |
|||
:
Нравится:
Не нравится:
|
|||
25.07.2020, 07:47 |
|
|
start [/forum/topic.php?fid=46&tid=1685837]: |
0ms |
get settings: |
9ms |
get forum list: |
13ms |
check forum access: |
3ms |
check topic access: |
3ms |
track hit: |
73ms |
get topic data: |
12ms |
get forum data: |
3ms |
get page messages: |
44ms |
get tp. blocked users: |
1ms |
others: | 268ms |
total: | 429ms |
0 / 0 |