UJP - 技術情報

Life is fun and easy!

不正IP報告数

Okan Sensor
 
メイン
ログイン
ブログ カテゴリ一覧

     

Sybaseでテーブルの利用容量を見積もる 〜sp_estspace〜

Sybaseでテーブルの利用容量を見積もる

〜sp_estspace〜


0.更新履歴

  • 2001.10.25 新規作成

1.はじめに

 このドキュメントでは,作成したSybaseのディスク容量を見積もるため,作成したテーブルにデータがn件登録されたときの容量の推定値を表示させるsp_estspaceの使い方について説明する.

 「推定値」となって正確な数値が出ないのは,VARCHAR型などが含まれる場合である.

2.前提事項

 sp_estspaceでは,現在作成されているテーブル定義を元に計測するため,はじめにcreate tableが完了していなければならない.

3.テーブルの推定使用容量を算出させる

  • 次に酔うな,テーブルtest1を作成する.
    • 3つあるフィールドがすべてchar(10)で統一されている.

1> create table test1
2> (
3> aaa char(10),
4> bbb char(10),
5> ccc char(10)
6> )
7> go
1>

  • sp_estspaceを使い,test1テーブルにデータが1件挿入された時に消費される容量を計測する.

1> sp_estspace test1,1
2> go
test1 has no indexes
 name                           type         idx_level Pages
         Kbytes
 ------------------------------ ------------ --------- ------------
        ------------
 test1                          data                 0            8
                   16
(1 row affected)
 Total_Mbytes
 -----------------
              0.02
(return status = 0)
1>

  • test1テーブルが1レコードあれば,8ページ(1ページ2KB)で16KB消費する.
  • 次は,test1テーブルに444件データがあると想定した場合の計測結果を表示する.

1> sp_estspace test1,444
2> go
test1 has no indexes
 name                           type         idx_level Pages
         Kbytes
 ------------------------------ ------------ --------- ------------
        ------------
 test1                          data                 0            8
                   17
(1 row affected)
 Total_Mbytes
 -----------------
              0.02
(return status = 0)
1>

  • この場合も8ページのままなのなので,test1テーブルの場合は,1行でも120行でもとられる領域(ディスクスペース)は同じ物となる.
  • 次はtest1テーブルに445件データがあると想定した場合の計測結果を表示する.

1> sp_estspace test1,445
2> go
test1 has no indexes
 name                           type         idx_level Pages
         Kbytes
 ------------------------------ ------------ --------- ------------
        ------------
 test1                          data                 0            9
                   17
(1 row affected)
 Total_Mbytes
 -----------------
              0.02
(return status = 0)
1>

  • ここで9ページ必要となっているので,445件目からは,別のページが必要ということがわかる.
  • 次に9000件のデータがあると想定して計測してみる.

1> sp_estspace test1,9000
2> go
test1 has no indexes
 name                           type         idx_level Pages
         Kbytes
 ------------------------------ ------------ --------- ------------
        ------------
 test1                          data                 0          153
                  306
(1 row affected)
 Total_Mbytes
 -----------------
              0.30
(return status = 0)
1>

  • 9000件だと,約0.3MB使用することがわかる.

4.インデックスをつけた場合の推定使用容量を算出させる

  • 先ほど作成したテーブルに,インデックスをつけてみる.

1> create index idx_test1_aaa on test1(aaa)
2> go
1>

  • sp_estspaceでtest1テーブルを計測してみる.

1> sp_estspace test1,444
2> go
 name                           type         idx_level Pages
         Kbytes
 ------------------------------ ------------ --------- ------------
        ------------
 test1                          data                 0            8
                   17
 idx_test1_aaa                  nonclustered         0            5
                    8
 idx_test1_aaa                  nonclustered         1            1
                    2
(1 row affected)
 Total_Mbytes
 -----------------
              0.03
 name                           type         total_pages  time_mins
 ------------------------------ ------------ ------------ ------------
 idx_test1_aaa                  nonclustered            6            0
(return status = 0)
1>

  • インデックス領域として,6ページ(5ページ+1ページ)が付加されている.
  • この場合,データ(8ページ)+インデックス(6ページ)=14ページなので,14×2KB=28KBのディスクスペースが使われる.
  • もう1つインデックスを作成して,計測してみる.

1> create index idx_test1_bbb on test1(bbb)
2> go
1> sp_estspace test1,444
2> go
 name                           type         idx_level Pages
         Kbytes
 ------------------------------ ------------ --------- ------------
        ------------
 test1                          data                 0            8
                   17
 idx_test1_aaa                  nonclustered         0            5
                    8
 idx_test1_aaa                  nonclustered         1            1
                    2
 idx_test1_bbb                  nonclustered         0            5
                    8
 idx_test1_bbb                  nonclustered         1            1
                    2
(1 row affected)
 Total_Mbytes
 -----------------
              0.04
 name                           type         total_pages  time_mins
 ------------------------------ ------------ ------------ ------------
 idx_test1_aaa                  nonclustered            6            0
 idx_test1_bbb                  nonclustered            6            0
(return status = 0)
1>

  • さらに6ページ追加されたことがわかる.
  • この場合,データ(8ページ)+インデックス(12ページ)=20ページなので,20×2KB=40KBのディスクスペースが使われる.
  • クラスタードインデックスを追加してみる.

1> create clustered index idx_test1_ccc on test1(ccc)
2> go
ノンクラスタード・インデックス (インデックス id = 2) は再構築中です。

ノンクラスタード・インデックス (インデックス id = 3) は再構築中です。
1> sp_estspace test1,444
2> go
 name                           type         idx_level Pages
         Kbytes
 ------------------------------ ------------ --------- ------------
        ------------
 test1                          data                 0            8
                   17
 idx_test1_ccc                  clustered            0            1
                    2
 idx_test1_ccc                  clustered            1            1
                    2
 idx_test1_aaa                  nonclustered         0            5
                    8
 idx_test1_aaa                  nonclustered         1            1
                    2
 idx_test1_bbb                  nonclustered         0            5
                    8
 idx_test1_bbb                  nonclustered         1            1
                    2
(1 row affected)
 Total_Mbytes
 -----------------
              0.04
 name                           type         total_pages  time_mins
 ------------------------------ ------------ ------------ ------------
 idx_test1_ccc                  clustered              11            0
 idx_test1_aaa                  nonclustered            6            0
 idx_test1_bbb                  nonclustered            6            0
(return status = 0)
1>

  • クラスタードインデックスでは,11ページ取られることがわかる.
  • この場合,データ(8ページ)+インデックス(24ページ)=32ページなので,32×2KB=64KBのディスクスペースが使われる.
  • 次に,nonclusteredインデックスを2つ消して,計測してみる.

1> drop index test1.idx_test1_aaa
2> go
1> drop index test1.idx_test1_bbb
2> go
1> sp_estspace test1,444
2> go
 name                           type         idx_level Pages
         Kbytes
 ------------------------------ ------------ --------- ------------
        ------------
 test1                          data                 0            8
                   17
 idx_test1_ccc                  clustered            0            1
                    2
 idx_test1_ccc                  clustered            1            1
                    2
(1 row affected)
 Total_Mbytes
 -----------------
              0.02
 name                           type         total_pages  time_mins
 ------------------------------ ------------ ------------ ------------
 idx_test1_ccc                  clustered              11            0
(return status = 0)
1>

  • この場合,データ8

5.test/imageフィールドを含む列がある場合の計測

  • textフィールドを含んだテーブルを作成してみる.

1> create table test2
2> (
3> aaa char(10),
4> bbb text
5> )
6> go
1>

  • sp_estspaceで計測してみると次のようになる.

1> sp_estspace test2,1
2> go
Msg 18054, Level 16, State 1:
Procedure 'sp_estspace', Line 211:
テーブルに、text/image型のカラムがあります。引数リスト
で、これらのカラムに対する各ローの全体の長さを指定しな
ければなりません。
(return status = 1)
1>

  • sp_estspacetextbin_lenフィールドを指定して実行してみる.

1> sp_estspace test2,1,null,null,100
2> go
test2 has no indexes
 name                           type         idx_level Pages
         Kbytes
 ------------------------------ ------------ --------- ------------
        ------------
 test2                          data                 0            8
                   16
 test2                          text/image           0            1
                    2

(1 row affected)
 Total_Mbytes
 -----------------
              0.02
(return status = 0)
1>

  • textフィールドに100バイトも文字が入ることを想定している.
  • textフィールドは,確実に1ページ別枠で取られる事になっている.
  • test2テーブルにtextフィールドをもう1つ追加してみる.

1> alter table test2 add ccc text null
2> go
1> sp_help test2
2> go
 Name                           Owner
         Type
 ------------------------------ ------------------------------
        ----------------------
 test2                          dbo
         ユーザ・テーブル
(1 row affected)
 Data_located_on_segment        When_created
 ------------------------------ --------------------------
 default                                          01/10/25
 Column_name     Type            Length Prec Scale Nulls Default_name
         Rule_name       Identity
 --------------- --------------- ------ ---- ----- ----- ---------------
        --------------- --------
 aaa             char                10 NULL  NULL     0 NULL
         NULL                   0
 bbb             text                16 NULL  NULL     0 NULL
         NULL                   0
 ccc             text                16 NULL  NULL     1 NULL
         NULL                   0
オブジェクトにはインデックスがありません。

このオブジェクトに定義されたキーはありません。

オブジェクトは分割されていません。

Allpages のロック・スキーム
属性 'exp_row_size' は allpages
ロック・スキームのあるテーブルには適用できません。

 exp_row_size reservepagegap fillfactor max_rows_per_page
 ------------ -------------- ---------- -----------------
            0              0          0                 0
(return status = 0)
1>

  • もう一度sp_estspaceを実行してみる.

1> sp_estspace test2,1,null,null,100
2> go
test2 has no indexes
 name                           type         idx_level Pages
         Kbytes
 ------------------------------ ------------ --------- ------------
        ------------
 test2                          data                 0            8
                   16
 test2                          text/image           0            1
                    2
(1 row affected)
 Total_Mbytes
 -----------------
              0.02
(return status = 0)
1>



広告スペース
Google