Usage
derived_table: {
sortkeys: ["date"]
…
}
}
Hierarchysortkeys - or - sortkeys |
Default ValueNoneAcceptsThe names of one or more columns in a PDT or an aggregate tableSpecial Rulessortkeys is supported only on specific dialects
|
Definition
The sortkeys
parameter lets you specify one or more columns of a persistent derived table (PDT) or an aggregate table on which to apply a regular sort key.
See the Dialect support for
sortkeys
section below for the list of dialects that supportsortkeys
.
You can also create an interleaved sort key by using indexes
instead. You cannot use both at the same time, but at least one is required.
The
sortkeys
parameter works only with tables that are persistent, such as PDTs and aggregate tables.sortkeys
is not supported for derived tables without a persistence strategy.In addition, the
sortkeys
parameter is not supported for derived tables that are defined usingcreate_process
orsql_create
.
Generally speaking, a sort key should be applied to date or time columns in the table, and possibly to columns that will be used frequently as filters. More information can be found in the Amazon Redshift documentation.
Examples
These examples assume that you are working with a Redshift database so that you can use the sortkeys
parameter.
Create a customer_day_facts
persistent native derived table that has a sortkey on date
and rebuilds when the datagroup order_datagroup
is triggered:
Create a customer_day_facts
derived table that is based on a SQL query and has a sortkey on date
:
Create a customer_day_facts
derived table that is based on a SQL query with a sortkey on date
and customer_id
:
Dialect support for sortkeys
The ability to use sortkeys
depends on the database dialect your Looker connection is using. In Looker 22.6, the following dialects support sortkeys
:
Traditional SQL dialects (such as MySQL and Postgres) should use
indexes
;sortkeys
will not work with these databases.