sortkeys

用量

view: my_view {
  derived_table: {
    sortkeys: ["date"]
    ...
  }
}
階層
sortkeys

- 或 -

sortkeys
預設值

接受
PDT 或匯總資料表中的一或多個資料欄名稱

特別規則
sortkeys 僅支援特定方言

定義

sortkeys 參數可讓您指定要套用一般排序鍵的持續性衍生資料表 (PDT) 或匯總資料表的一或多個資料欄。使用排序鍵指定 PDT 中最常排序的資料欄,加快資料查詢速度。

如需支援 sortkeys 的方言清單,請參閱「支援 sortkeys 的方言」一節。

您也可以改用 indexes 建立交錯排序鍵。這兩種方法無法同時使用,但至少要填寫一欄。

sortkeys 參數只能搭配持續性資料表使用,例如 PDT 和匯總資料表。如果衍生資料表沒有持續性策略,則不支援「sortkeys」。

此外,使用 create_processsql_create 定義的衍生資料表不支援 sortkeys 參數。

一般來說,排序鍵應套用至資料表中的日期或時間欄,也可能套用至經常做為篩選條件的資料欄。詳情請參閱 Amazon Redshift 說明文件

範例

這些範例假設您使用 Redshift 資料庫,因此可以使用 sortkeys 參數。

建立具有 date 排序鍵的customer_day_facts永久原生衍生資料表,並在觸發 datagroup order_datagroup 時重建:

view: customer_day_facts {
  derived_table: {
    explore_source: order {
      column: customer_id { field: order.customer_id }
      column: date { field: order.order_date }
      column: num_orders { field: order.customer_order_count }
    }
    datagroup_trigger: order_datagroup
    sortkeys: ["date"]
  }
}

建立以 SQL 查詢為基礎的customer_day_facts衍生資料表,並在 date 上設定排序鍵:

view: customer_day_facts {
  derived_table: {
    sql:
      SELECT
        customer_id,
        DATE(order_time) AS date,
        COUNT(*) AS num_orders
      FROM
        order
      GROUP BY
        customer_id ;;
    persist_for: "24 hours"
    sortkeys: ["date"]
  }
}

建立以 SQL 查詢為基礎的customer_day_facts衍生資料表,並在 datecustomer_id 上使用排序鍵:

view: customer_day_facts {
  derived_table: {
    sql:
      SELECT
        customer_id,
        DATE(order_time) AS date,
        COUNT(*) AS num_orders
      FROM
        order
      GROUP BY
        customer_id ;;
    persist_for: "24 hours"
    sortkeys: ["date", "customer_id"]
  }
}

支援 sortkeys 的方言

使用 sortkeys 的能力取決於 Looker 連線使用的資料庫方言。在最新版 Looker 中,下列方言支援 sortkeys

傳統 SQL 方言 (例如 MySQL 和 Postgres) 應使用 indexessortkeys 無法搭配這些資料庫使用。

方言 是否支援?
Actian Avalanche
Amazon Athena
Amazon Aurora MySQL
Amazon Redshift
Amazon Redshift 2.1+
Amazon Redshift Serverless 2.1+
Apache Druid
Apache Druid 0.13+
Apache Druid 0.18+
Apache Hive 2.3+
Apache Hive 3.1.2+
Apache Spark 3+
ClickHouse
Cloudera Impala 3.1+
Cloudera Impala 3.1+ with Native Driver
Cloudera Impala with Native Driver
DataVirtuality
Databricks
Denodo 7
Denodo 8 & 9
Dremio
Dremio 11+
Exasol
Google BigQuery Legacy SQL
Google BigQuery Standard SQL
Google Cloud PostgreSQL
Google Cloud SQL
Google Spanner
Greenplum
HyperSQL
IBM Netezza
MariaDB
Microsoft Azure PostgreSQL
Microsoft Azure SQL Database
Microsoft Azure Synapse Analytics
Microsoft SQL Server 2008+
Microsoft SQL Server 2012+
Microsoft SQL Server 2016
Microsoft SQL Server 2017+
MongoBI
MySQL
MySQL 8.0.12+
Oracle
Oracle ADWC
PostgreSQL 9.5+
PostgreSQL pre-9.5
PrestoDB
PrestoSQL
SAP HANA
SAP HANA 2+
SingleStore
SingleStore 7+
Snowflake
Teradata
Trino
Vector
Vertica