まとめ
- 「SVV_TABLE_INFO.TBL_ROWS」 で削除対象としてマークされた行も含めた行数を確認できる
- 「SVV_TABLE_INFO.TBL_ROWS」 - 「select count(*) from テーブル名」が削除済としてマークされた行数
- STV_TBL_PERM、SVV_DISKUSAGE も同様に削除済としてマークされた行数を含んだ行数を返す
- VACCUME すると削除された行が解放され、「SVV_TABLE_INFO.TBL_ROWS」と「select count(*) from テーブル名」が一致する
データロード後
- テーブルを作成する
CREATE TABLE customer ( c_custkey integer not null, c_name varchar(25) not null, c_address varchar(25) not null, c_city varchar(10) not null, c_nation varchar(15) not null, c_region varchar(12) not null, c_phone varchar(15) not null, c_mktsegment varchar(10) not null) diststyle all;
- ロードする
mydb=# copy customer from 's3://awssampledbuswest2/ssbgz/customer' credentials 'aws_access_key_id=<Your-Access-Key-ID>;aws_secret_access_key=<Your-Secret-Access-Key>' gzip compupdate off region 'us-west-2'; INFO: Load into table 'customer' completed, 3000000 record(s) loaded successfully. COPY
- テーブルの情報を確認する
mydb=# \i table_info.sql schema | table | tableid | distkey | skew | sortkey | #sks | rows | mbytes | enc | pct_enc | pct_of_total | pct_stats_off | pct_unsorted --------+-----------+---------+-----------+--------+---------+------+-----------+--------+-----+-----------------------+--------------+---------------+-------------- public | customer | 139204 | EVEN | 1.0000 | | 0 | 3000000 | 188 | Y | 52.941176470588235200 | 0.04 | 0.00 | (1 rows)
- テーブルの行数を確認する
mydb=# select count(*) from customer; count --------- 3000000 (1 row) mydb=# select * from SVV_TABLE_INFO where "table" = 'customer'; database | schema | table_id | table | encoded | diststyle | sortkey1 | max_varchar | sortkey1_enc | sortkey_num | size | pct_used | empty | unsorted | stats_off | tbl_rows | skew_sortkey1 | skew_rows ----------+--------+----------+----------+---------+-----------+----------+-------------+--------------+-------------+------+----------+-------+----------+-----------+----------+---------------+----------- mydb | public | 139204 | customer | Y | EVEN | | 25 | | 0 | 188 | 0.0492 | 0 | | 0.00 | 3000000 | | (1 row)
- スライス毎の行数を確認する
mydb=# select * from stv_tbl_perm where name = 'customer' order by slice; slice | id | name | rows | sorted_rows | temp | db_id | insert_pristine | delete_pristine | backup -------+--------+--------------------------------------------------------------------------+---------+-------------+------+--------+-----------------+-----------------+-------- 0 | 139204 | customer | 1500000 | 0 | 0 | 100153 | 0 | 1 | 1 1 | 139204 | customer | 1500000 | 0 | 0 | 100153 | 0 | 1 | 1 6411 | 139204 | customer | 0 | 0 | 0 | 100153 | 3 | 0 | 1 (3 rows)
- スライス毎のブロック数を確認する
mydb=# select name, slice, count(*) as mb from svv_diskusage where name = 'customer' group by name, slice; name | slice | mb --------------------------------------------------------------------------+-------+---- customer | 1 | 94 customer | 0 | 94 (2 rows)
DELETE後
- 削除する
mydb=# delete from customer; DELETE 3000000 mydb=# commit; COMMIT
- テーブルの件数を確認する
mydb=# select count(*) from customer; count ------- 0 (1 row) mydb=# select * from SVV_TABLE_INFO where "table" = 'customer'; database | schema | table_id | table | encoded | diststyle | sortkey1 | max_varchar | sortkey1_enc | sortkey_num | size | pct_used | empty | unsorted | stats_off | tbl_rows | skew_sortkey1 | skew_rows ----------+--------+----------+----------+---------+-----------+----------+-------------+--------------+-------------+------+----------+-------+----------+-----------+----------+---------------+----------- mydb | public | 139204 | customer | Y | EVEN | | 25 | | 0 | 188 | 0.0492 | 0 | | 0.00 | 3000000 | | (1 row)
- スライス毎の行数を確認する
mydb=# select * from stv_tbl_perm where name = 'customer' order by slice; slice | id | name | rows | sorted_rows | temp | db_id | insert_pristine | delete_pristine | backup -------+--------+--------------------------------------------------------------------------+---------+-------------+------+--------+-----------------+-----------------+-------- 0 | 139204 | customer | 1500000 | 0 | 0 | 100153 | 0 | 1 | 1 1 | 139204 | customer | 1500000 | 0 | 0 | 100153 | 0 | 1 | 1 6411 | 139204 | customer | 0 | 0 | 0 | 100153 | 3 | 0 | 1 (3 rows)
- スライス毎のブロック数を確認する
mydb=# select name, slice, count(*) as mb from svv_diskusage where name = 'customer' group by name, slice; name | slice | mb --------------------------------------------------------------------------+-------+---- customer | 1 | 94 customer | 0 | 94 (2 rows)
ANALYZE後
- ANALYZE する
mydb=# set analyze_threshold_percent to 0; SET mydb=# analyze customer all columns; ANALYZE
- テーブルの件数を確認する
mydb=# select count(*) from customer; count ------- 0 (1 row) mydb=# select * from SVV_TABLE_INFO where "table" = 'customer'; database | schema | table_id | table | encoded | diststyle | sortkey1 | max_varchar | sortkey1_enc | sortkey_num | size | pct_used | empty | unsorted | stats_off | tbl_rows | skew_sortkey1 | skew_rows ----------+--------+----------+----------+---------+-----------+----------+-------------+--------------+-------------+------+----------+-------+----------+-----------+----------+---------------+----------- mydb | public | 139204 | customer | Y | EVEN | | 25 | | 0 | 188 | 0.0492 | 0 | | 0.00 | 3000000 | | (1 row)
- スライス毎の行数を確認する
mydb=# select name, slice, sum(rows) from stv_tbl_perm where name = 'customer' group by name, slice; name | slice | sum --------------------------------------------------------------------------+-------+--------- customer | 6411 | 0 customer | 0 | 1500000 customer | 1 | 1500000 (3 rows)
- スライス毎のブロック数を確認する
mydb=# select name, slice, count(*) as mb from svv_diskusage where name = 'customer' group by name, slice; name | slice | mb --------------------------------------------------------------------------+-------+---- customer | 1 | 94 customer | 0 | 94 (2 rows)
VACUUM後
- VACUUM する
mydb=# vacuum full customer; VACUUM
- テーブルの件数を確認する
mydb=# select count(*) from customer; count ------- 0 (1 row) mydb=# select * from SVV_TABLE_INFO where "table" = 'customer'; database | schema | table_id | table | encoded | diststyle | sortkey1 | max_varchar | sortkey1_enc | sortkey_num | size | pct_used | empty | unsorted | stats_off | tbl_rows | skew_sortkey1 | skew_rows ----------+--------+----------+----------+---------+-----------+----------+-------------+--------------+-------------+------+----------+-------+----------+-----------+----------+---------------+----------- mydb | public | 139204 | customer | Y | EVEN | | 25 | | 0 | 22 | 0.0057 | 0 | | | 0 | | (1 row)
- スライス毎の行数を確認する
mydb=# select * from stv_tbl_perm where name = 'customer' order by slice; slice | id | name | rows | sorted_rows | temp | db_id | insert_pristine | delete_pristine | backup -------+--------+--------------------------------------------------------------------------+------+-------------+------+--------+-----------------+-----------------+-------- 0 | 139204 | customer | 0 | 0 | 0 | 100153 | 0 | 1 | 1 1 | 139204 | customer | 0 | 0 | 0 | 100153 | 0 | 1 | 1 6411 | 139204 | customer | 0 | 0 | 0 | 100153 | 3 | 0 | 1 (3 rows)
- スライス毎のブロック数を確認する
mydb=# select name, slice, count(*) as mb from svv_diskusage where name = 'customer' group by name, slice; name | slice | mb --------------------------------------------------------------------------+-------+---- customer | 1 | 11 customer | 0 | 11 (2 rows)
参考
SVV_TABLE_INFO
データベースのテーブルに関する概要情報を表示します。ビューではシステムテーブルが絞り込まれ、ユーザー定義テーブルのみが表示されます。
SVV_TABLE_INFO ビューを使用して、クエリのパフォーマンスに影響する可能性のあるテーブル設計の問題を診断し、対応できます。これには、圧縮エンコード、分散キー、ソートスタイル、データ分散スキュー、テーブルサイズ、および統計情報が含まれます。SVV_TABLE_INFO ビューは、空のテーブルの情報を返しません。
SVV_TABLE_INFO ビューには、STV_BLOCKLIST、STV_PARTITIONS、STV_TBL_PERM、および STV_SLICES システムテーブルと、PG_DATABASE、PG_ATTRIBUTE、PG_CLASS、PG_NAMESPACE、および PG_TYPE カタログテーブルからの概要情報が表示されます。テーブルの列
SVV_TABLE_INFO - Amazon Redshift
列名 データ型 説明 tbl_rows numeric(38,0) テーブル内の合計行数。この値には、削除対象としてマークされ、まだバキューム処理されていない列が含まれます。
STV_TBL_PERM
STV_TBL_PERM テーブルには、現在のセッション用にユーザーが作成した一時テーブルを含め、Amazon Redshift の永続テーブルに関する情報が表示されます。STV_TBL_PERM には、すべてのデータベース内のすべてのテーブルに関する情報が含まれます。
このテーブルは、クエリの処理中にシステムが作成する一時的なデータベーステーブルの情報を表示する STV_TBL_TRANS とは異なります。
テーブルの列STV_TBL_PERM - Amazon Redshift
列名 データ型 説明 slice integer テーブルに割り当てられたノードスライス。 name character(72) テーブル名。 rows bigint スライス内のデータ行数。 sorted_rows bigint ディスク上でソート済みの、スライス内の行数。この数が ROWS の数と異なる場合は、テーブルに vacuum を実行して行をソートし直してください。
SVV_DISKUSAGE
Amazon Redshift は STV_TBL_PERM テーブルと STV_BLOCKLIST テーブルを結合して、SVV_DISKUSAGE システムビューを作成します。SVV_DISKUSAGE ビューにはデータベースのテーブルに対するデータ割り当てに関する情報が含まれます。
次の例で示されているように集計クエリを SVV_DISKUSAGE と一緒に使用すると、データベースあたり、テーブルあたり、スライスあたり、列あたりに割り当てられたディスクブロックの数が算出されます。各データブロックのサイズは 1 MB です。または STV_PARTITIONS を使用して、ディスク利用に関する概要を見ることができます。
テーブルの列
列名 データ型 説明 db_id integer データベース ID。 name character(72) テーブル名。 slice integer テーブルに割り当てられたデータスライス。 SVV_DISKUSAGE には割り当て済みディスクブロックにつき 1 つの行が含まれるため、すべての行を選択するクエリを実行すると非常に多数の行が返される可能性があります。SVV_DISKUSAGE を使用した集計クエリのみを使用することをお勧めします。
SVV_DISKUSAGE - Amazon Redshift