0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

列ストアインデックスを貼るとInsertはどれくらい遅くなる?

Last updated at Posted at 2019-11-23

そもそも列ストアインデックスって?

テーブル作成

列が50個のテーブルを2つ用意

CREATE TABLE [TableName]
	(
	c000 char(20) NULL,
	c001 char(20) NULL,
                        
	c049 char(20) NULL
	)  ON [PRIMARY]

一方のテーブルには全項目を対象にした列ストアインデックスを作成

CREATE NONCLUSTERED COLUMNSTORE INDEX NonClusteredColumnStoreIndex ON dbo.TEST_withCSIndex
	(
	c000,
	c001,
      
	c049
	)

ダミーデータをInsert

1000 万件 Insert するよ
これが早い( http://geekswithblogs.net/nestor/archive/2007/08/23/114925.aspx

SET STATISTICS TIME ON

Declare @p_NumberOfRows Bigint 
Select @p_NumberOfRows=10000000; 
With Base As
  (
    Select 1 as n
    Union All
    Select n+1 From Base Where n < Ceiling(SQRT(@p_NumberOfRows))
  ),
  Expand As
  (
    Select 1 as C From Base as B1, Base as B2
  ),
  Nums As
  (
    Select Row_Number() OVER(ORDER BY C) As n From Expand
  )
INSERT INTO [TableName]
  Select 
    -- 列の数分
	'DATA' + right('0000000000' + convert(varchar, n), 10),
	'DATA' + right('0000000000' + convert(varchar, n), 10),
                                            
	'DATA' + right('0000000000' + convert(varchar, n), 10)
    from Nums  Where n<=@p_NumberOfRows
OPTION (MaxRecursion 0); 

結果(no インデックス)

        ︙
 SQL Server 実行時間: 
、CPU 時間 = 150328 ミリ秒、経過時間 = 200014 ミリ秒。

(10000000 行処理されました)

結果(with インデックス)

        ︙
 SQL Server 実行時間: 
、CPU 時間 = 295593 ミリ秒、経過時間 = 473816 ミリ秒。

(10000000 行処理されました)

まとめ

約2倍になってますね
(実際のテーブルではここまでシンプルでないため、一概には言えませんが...)

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?