MaxCompute の処理効率を向上させるために、テーブルの作成時にパーティションを定義できます。 具体的には、テーブル内の複数フィールドをパーティションとして指定できます。 機能的観点からみると、パーティションは、ファイルシステム下のディレクトリに相当します。

MaxCompute では、各フィールドを個別のパーティションとして指定できます。 あるいは、複数のフィールドを 1 つのパーティションとして指定することもできます。これにより、複数階層のディレクトリと同様の機能を備えます。

データを使用するときにアクセスするパーティションを指定すると、対応するパーティションのみが読み取られるため、テーブル全体のスキャンが回避され、処理効率が向上し、コストの削減が実現します。

パーティションタイプ

MaxCompute 2.0 では、サポート対象のパーティションタイプが増え、現在 tinyint 型、smallint 型、Int型、bigint 型、varchar 型、および string 型のパーティションに対応しています。
MaxCompute 2.0 より前のバージョンは、STRING 型のパーティションにのみ対応しています。 bigint 型のパーティションを指定できますが、これまでの背景から、テーブルのスキーマ表現をbigint 型として指定する場合を除き、その他のケースでは、実際には string 型として扱われます。 例:
create table parttest (a bigint) partitioned by (pt bigint);
insert into parttest partition(pt) select 1, 2 from dual;
insert into parttest partition(pt) select 1, 10 from dual;
select * from parttest where pt >= '2';

上記 SQL 文を実行すると、戻ってくる結果は、1 行のみです。10 は STRING 型として扱われ、2 と比較されたので、結果は返されません。

制限事項

パーティションを使用する際、次の制限事項が適用されます。
  • 1 つのテーブルの最大パーティション階層数は 6 です。
  • 1 つのテーブルの最大パーティション数は 60,000 です。
  • 1 つのクエリの最大クエリパーティション数は 10,000 です。
例:
-- create a two-level partition table with the date as the level one partition and the region as the level two partition
create table src (key string, value bigint) partitioned by (pt string,region string);
クエリの実行時、WHERE 条件フィルタで、パーティション列をフィルタ条件として使用できます。
select * from src where pt='20170601' and region='hangzhou';  -- This example is the correct method of using WHERE conditional filter. When MaxCompute generates a query plan, only data of the region 'hangzhou' under the '20170601' partition is accessed.
select * from src where pt = 20170601;   -- This example is an incorrect method of using the WHERE conditional filter. In this example, the effectiveness of the partition filter cannot be guaranteed. pt is a STRING type. When the STRING type is compared with BIGINT type (20170601), MaxCompute converts both to DOUBLE type, and loss of precision occurs.

パーティションに対する一部の SQL 操作は効率的ではなく、課金料金が高くなることがあります。「動的パーティションの使用 (using dynamic partition)」が例として挙げられます。

MaxCompute の一部の操作コマンドは、パーティションテーブルを処理する場合と非パーティションテーブルを処理する場合とで構文が異なります。詳細は、「DDL 文 (DDL statement)」および「動的パーティションの使用 (using dynamic partitioning) 」をご参照ください。