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 3 years have passed since last update.

【Snowflake】テーブルにクラスタリングキーが設定されているか確認する方法

Posted at

Snowflakeでテーブルにクラスタリングキーが設定されているか確認する方法をググってもすぐにわからなかったのでメモ

方法

2つあります。

  1. SHOW TABLESで確認する方法
  2. INFORMATION_SCHMEスキーマのTABLESテーブルで確認する方法

1. SHOW TABLESで確認する方法

cluster_byカラムにクラスタリングキーが表示されます。
また、自動クラスタリングが有効になっているかどうかはautomatic_clusteringカラムで確認できます。

以下はクラスタリングキーが何も設定されておらず自動クラスタリングもOFFのテーブルの例です。

show tables like 'test';
+-------------------------------+------+----------------------+-------------+-------+---------+------------+------+-------+----------+----------------+----------------------+-----------------+---------------------+------------------------------+---------------------------+-------------+
| created_on                    | name | database_name        | schema_name | kind  | comment | cluster_by | rows | bytes | owner    | retention_time | automatic_clustering | change_tracking | search_optimization | search_optimization_progress | search_optimization_bytes | is_external |
|-------------------------------+------+----------------------+-------------+-------+---------+------------+------+-------+----------+----------------+----------------------+-----------------+---------------------+------------------------------+---------------------------+-------------|
| 2021-10-03 05:28:45.326 -0700 | TEST | HAGIWARA_TRAINING_DB | PUBLIC      | TABLE |         |            |    4 |  1536 | SYSADMIN | 1              | OFF                  | ON              | OFF                 |                         NULL |                      NULL | N           |
+-------------------------------+------+----------------------+-------------+-------+---------+------------+------+-------+----------+----------------+----------------------+-----------------+---------------------+------------------------------+---------------------------+-------------+
1 Row(s) produced. Time Elapsed: 0.159s

2. INFORMATION_SCHMEスキーマのTABLESテーブルで確認する方法

CLUSTERING_KEYカラムにクラスタリングキーが表示されます。
また、自動クラスタリングが有効になっているかどうかはAUTO_CLUSTERING_ONカラムで確認できます。

1と同じテーブルを確認すると以下のように表示されます。

select * from information_schema.tables where table_name = 'TEST';
+----------------------+--------------+------------+-------------+------------+--------------+----------------+-----------+-------+----------------+------------------------------+----------------------+---------------------------+--------------------------+------------------------+--------------------+----------+---------------+-------------------------------+-------------------------------+--------------------+---------+
| TABLE_CATALOG        | TABLE_SCHEMA | TABLE_NAME | TABLE_OWNER | TABLE_TYPE | IS_TRANSIENT | CLUSTERING_KEY | ROW_COUNT | BYTES | RETENTION_TIME | SELF_REFERENCING_COLUMN_NAME | REFERENCE_GENERATION | USER_DEFINED_TYPE_CATALOG | USER_DEFINED_TYPE_SCHEMA | USER_DEFINED_TYPE_NAME | IS_INSERTABLE_INTO | IS_TYPED | COMMIT_ACTION | CREATED                       | LAST_ALTERED                  | AUTO_CLUSTERING_ON | COMMENT |
|----------------------+--------------+------------+-------------+------------+--------------+----------------+-----------+-------+----------------+------------------------------+----------------------+---------------------------+--------------------------+------------------------+--------------------+----------+---------------+-------------------------------+-------------------------------+--------------------+---------|
| HAGIWARA_TRAINING_DB | PUBLIC       | TEST       | SYSADMIN    | BASE TABLE | NO           | NULL           |         4 |  1536 |              1 | NULL                         | NULL                 | NULL                      | NULL                     | NULL                   | YES                | YES      | NULL          | 2021-10-03 05:28:45.326 -0700 | 2021-10-03 05:33:37.198 -0700 | NO                 | NULL    |
+----------------------+--------------+------------+-------------+------------+--------------+----------------+-----------+-------+----------------+------------------------------+----------------------+---------------------------+--------------------------+------------------------+--------------------+----------+---------------+-------------------------------+-------------------------------+--------------------+---------+
1 Row(s) produced. Time Elapsed: 0.625s
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?