0
0

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 1 year has passed since last update.

インスタンスストアにTEMPDBを配置してみた 4

Last updated at Posted at 2022-04-09

いざ実践

それではSQLServerを使ってのテストを実施してみます。

テスト手順

TEMPDBの場所を設定する(E:とD:で比較する)

locate_tempdb.sql
ALTER DATABASE [tempdb] MODIFY FILE (NAME = tempdev, FILENAME = 'E:\tempdb.mdf');
ALTER DATABASE [tempdb] MODIFY FILE (NAME = templog, FILENAME = 'E:\templog.ldf');
ALTER DATABASE [tempdb] MODIFY FILE (NAME = temp2, FILENAME = 'E:\temp2.ndf');
ALTER DATABASE [tempdb] MODIFY FILE (NAME = temp3, FILENAME = 'E:\temp3.ndf');
ALTER DATABASE [tempdb] MODIFY FILE (NAME = temp4, FILENAME = 'E:\temp4.ndf');

その後、SQLServerのサービスを再起動し、tempdbの場所変更を反映させる。
次に一時テーブルを作成し更新するSQLを実行

load_tempdb.sql
Declare @cd nvarchar(max) = REPLICATE('X', 4000);

Declare @t1 datetime2;
Declare @t2 datetime2;
Declare @t3 datetime2;
Declare @t4 datetime2;

Declare @c1 nvarchar(max) = Convert(nvarchar, RAND(0));
Declare @c2 nvarchar(max) = Convert(nvarchar, SYSDATETIME(), 121);
Declare @c3 nvarchar(max) = Convert(nvarchar,Convert(char(255), NEWID()));

Drop Table If Exists #test1
Create Table #test1(
	c0 bigint,
	c1 nvarchar(max),
	c2 nvarchar(max),
	c3 nvarchar(max),
	c4 nvarchar(max),
	c5 nvarchar(max),
	c6 nvarchar(max),
	c7 nvarchar(max),
	c8 nvarchar(max),
	c9 nvarchar(max)
);

Set @t1 = SYSDATETIME();

With 
N1(dummy) as (
Select 0 Union ALL Select 0), --2rows
N2(dummy) as (
Select 0 From N1 as T1 Cross Join N1 as T2), --4rows
N3(dummy) as (
Select 0 From N2 as T1 Cross Join N2 as T2), --16rows
N4(dummy) as (
Select 0 From N3 as T1 Cross Join N3 as T2), --256rows
N5(dummy) as (
Select 0 From N4 as T1 Cross Join N4 as T2), --65536rows
NX(id) as (
Select ROW_NUMBER() over (order by(Select Null)) From N5)

Insert into #test1
Select id, @cd, @cd, @cd, @cd, @cd, @cd, @cd, @cd, @cd
From NX;

Set @t2 = SYSDATETIME();

Update #test1
Set c1 = @c1, c2 = @c2, c3 = @c3
Where (c0 % 7) = 3

Set @t3 = SYSDATETIME();

Select *
From #test1

Set @t4 = SYSDATETIME();

Select 
	DATEDIFF(MILLISECOND, @t1, @t2) as t1,
	DATEDIFF(MILLISECOND, @t2, @t3) as t2,
	DATEDIFF(MILLISECOND, @t3, @t4) as t3,
	DATEDIFF(MILLISECOND, @t1, @t4) as t4

結果

tempdbの場所 t1 t2 t3 t4
D: 36570 172 25146 61888
E: 36029 172 25664 61865

ええっ、変わんないじゃん!

という訳で、続編に乞うご期待!
ちと頭を冷やして考えてみます。
TEMPDBの場所が変わっていることはエクスプローラで目視確認しているし、スクリプト実行中にtempdbのファイルサイズが増加していることも確認しているので、そこは問題ないはずですが...何か重大な見落としがあるのか???

原因

→ データ量が少なすぎてメモリの範囲内で処理が完結してしまうため差がつかないようです。データ量を増やしてリトライ中。

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?