2
4

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.

2016年7月時点で、Redshiftには論理パーティションの機能がありません。

それでは、pvログのようにデータ量が非常に大きいテーブルは、Redshiftではどのように扱えば良いのでしょうか?例えば、Hiveでは、月毎(日毎)にパーティションを作成しておき、月単位(日単位)でデータを分けておくというアプローチが一般的だと思います。が、論理パーティションの機能がないRedshiftでは、このアプローチを取ることができません。

答えは、ソートキーを正しく設定するです。特に、pvログのような時系列データの場合は、タイムスタンプ列をソートキーに設定します。例えば、タイムスタンプ列timeをソートキーに設定しておけば、

select
   *
from
   pv_log
where
   time >= timestamp '2016-04-01 00:00:00'
;

のように指定することで、Redshiftは2016年4月1日以降のデータだけをスキャンします。タイムスタンプ列timeにソートキーを設定していない場合、テーブルのフルスキャンが発生します。データ量が非常に大きい場合、クエリの結果が返ってくるのに非常に時間が掛かり、他のジョブにも悪影響を及ぼします。

また、Redshiftでは、ソートキーの設定状況は、

select
   *
from
   pg_table_def
where
   schemaname = 'hoge'
   and tablename = 'pv_log'
;

のようにSQLを実行すれば確認できます。pg_table_defの詳細は公式ページに載っています。

2
4
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
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?