|
|
|
Вот такой глупый вопрос:
|
|||
|---|---|---|---|
|
#18+
Восстанавливаю базу на соседней машине (ее «родной» размер» 2.4 гига.), потом – 1. dbcc checkdb 2. делаю DBCC DBREINDEX (ее размер увеличивается до 3 гиг.) - 2 раза 3. делаю sp_updatestats 4. потом делаю DBCC SHRINKDATABASE ее размер становится 1.4 гига Хотелось бы узнать, за счет чего уменьшается ее размер на 1 гиг? Нужно ли это для ее оптимизации? Правильна ли последовательность действий? ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 02.12.2002, 23:49:57 |
|
||
|
Вот такой глупый вопрос:
|
|||
|---|---|---|---|
|
#18+
Rebuilding a clustered index by deleting the old index and then re-creating the same index again is expensive because all the secondary indexes use the clustering key to point to the data rows. If you simply delete the clustered index and re-create it, you cause all the nonclustered indexes to be deleted and re-created twice. This occurs once when you delete the clustered index, and a second time when you re-create it. You avoid this expense by re-creating the index in one step. Re-creating the index in a single step tells SQL Server that you are reorganizing an existing index and avoids the unnecessary work of deleting and re-creating nonclustered indexes. This method also has the significant advantage of using the sorted order of the data in the existing index, thus avoiding the need to sort the data again. This is useful for both clustered and nonclustered indexes, and significantly reduces the cost of rebuilding an index. Additionally, SQL Server allows you to rebuild (in one step) one or more indexes on a table by using the DBCC DBREINDEX statement, without having to rebuild each index separately. DBCC DBREINDEX is also useful to rebuild indexes enforcing PRIMARY KEY or UNIQUE constraints without having to delete and re-create the constraints (because an index created to enforce a PRIMARY KEY or UNIQUE constraint cannot be deleted without deleting the constraint first). For example, you may want to rebuild an index on a PRIMARY KEY constraint to reestablish a given fill factor for the index. DBCC INDEXDEFRAG can defragment clustered and nonclustered indexes on tables and views. DBCC INDEXDEFRAG defragments the leaf level of an index so that the physical order of the pages matches the left-to-right logical order of the leaf nodes, thus improving index-scanning performance. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 03.12.2002, 13:06:11 |
|
||
|
Вот такой глупый вопрос:
|
|||
|---|---|---|---|
|
#18+
Александр Гладченко абсолютно прав, говоря об отличиях переиндексирования и дефрагментирования. Однако у них есть одна общая неприятная деталь: они аллоцируют под себя доп.пр-во, к-е затем забывают отдавать. Рассмотрим простейший пример: use Northwind exec sp_spaceused 'Order Details', 'true' У меня получилось 72 KB под данные, 200 KB под индексы и 0 неиспользованного пространства. Поскольку таблица имеет кластерный индекс, под данными здесь понимаются его листовые страницы: то, что в выдаче dbcc tab обозначается типом 0 (при IndexID = 1). Cделаем dbcc dbreindex('Northwind.dbo.[Order Details]') или dbcc indexdefrag(0, 'Order Details', 1) - без разницы. Теперь exec sp_spaceused 'Order Details', 'true' по прежнему говорит про 9 страниц данных и 25 индексных, а вот в unused space появилось 48 КВ, что увеличило общий размер таблицы до 320 КВ. Сначала я подумал, что первоначально у индекса был филлфактор, который реиндекс восстановил, от чего таблица слегка раздулась. Но филлфактор только раздвигает индексные записи по страницам, они не перестают от этого числиться как used. dbcc extentinfo показывавает следующую вещь: 1 208 8 8 325576198 1 0x4040404040404040 1 368 2 8 325576198 1 0x4040000000000000 1 361 1 1 325576198 2 0x6000000000000000 ... Из 2-й строчки видно, что эти непонятные 48 КВ кучно лежат во втором экстенте кластерного индекса. Кроме reindex / defrag подозреваемых, как мы видим, нет. Зачем они их резервируют и почему не отдают взад, я не знаю. Во всяком случае dbcc shrinkdatabase('Northwind'), когда проходит по таблице, видит, что pg_alloc < ext_size и выкидывает их нафиг. Поэтому я думаю, что посл-ть Ваших действий абсолютно правильная: реиндекс перестроил листики по порядку, уменьшив кол-во перепрыжек с экстента на экстент, а шринк за ним подчистил. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 04.12.2002, 12:03:34 |
|
||
|
Вот такой глупый вопрос:
|
|||
|---|---|---|---|
|
#18+
Cделаем dbcc dbreindex('Northwind.dbo.[Order Details]') или dbcc indexdefrag(0, 'Order Details', 1) - без разницы Все-таки разница есть или ее нет? Зачем переиндексировать таблицу я понимаю - чтобы при вставке записи в таблицу с кластерным индексом была бы меньше вероятность того, что нужная страница данных полностью заполнена и приходится ее разбивать чтобы вставить запись. Но зачем дефрагментировать индекс? После дефрагментации индекс имеет филфактор? Включает ли DBCC INDEXDEFRAG в себя DBCC DBREINDEX? Или наоборот DBCC DBREINDEX включает в себя DBCC INDEXDEFRAG? Или это вообще никак не связанные действия? ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 04.12.2002, 12:52:57 |
|
||
|
Вот такой глупый вопрос:
|
|||
|---|---|---|---|
|
#18+
Без разницы в том плане, что и после того, и после другого появились 6 зарезервированных, но не задействованных страниц. После дефрагментации индекс, конечно, имеет fillfactor, как и после переиндексации. Из BOL: DBCC INDEXDEFRAG also compacts the pages of an index, taking into account the FILLFACTOR specified when the index was created. Any empty pages created as a result of this compaction will be removed. Просто в моем примере с Northwind пустых страниц и мусора, неизбежного в случае интенсивной работы с серьезной базой, просто не было. Что касается их разницы, то опять же цитата из BOL: Unlike DBCC DBREINDEX or any general index build, DBCC INDEXDEFRAG is an online operation, so it does not hold long-term locks that can block running queries or updates. Depending on the amount of fragmentation, DBCC INDEXDEFRAG can be considerably faster than running DBCC DBREINDEX because a relatively unfragmented index can be defragmented much faster than a new index can be built. Another advantage is that with DBCC INDEXDEFRAG, the index is always available, unlike DBREINDEX . A large amount of fragmentation can cause DBCC INDEXDEFRAG to run considerably longer than DBCC DBREINDEX, which may or may not outweigh the benefit of the command's online capabilities. DBCC INDEXDEFRAG will not help if two indexes are interleaved on the disk because INDEXDEFRAG shuffles the pages in place. To improve the clustering of pages, rebuild the index. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 04.12.2002, 13:41:31 |
|
||
|
|

start [/forum/topic.php?fid=46&fpage=3365&tid=1818312]: |
0ms |
get settings: |
8ms |
get forum list: |
10ms |
check forum access: |
2ms |
check topic access: |
2ms |
track hit: |
28ms |
get topic data: |
6ms |
get forum data: |
2ms |
get page messages: |
49ms |
get tp. blocked users: |
1ms |
| others: | 210ms |
| total: | 318ms |

| 0 / 0 |
