How to add a sort key to an existing table in AWS Redshift

后端 未结 7 803
孤街浪徒
孤街浪徒 2021-01-01 09:24

In AWS Redshift, I want to add a sort key to a table that is already created. Is there any command which can add a column and use it as sort key?

相关标签:
7条回答
  • 2021-01-01 10:23

    it is now possible to alter a sort kay:

    Amazon Redshift now supports changing table sort keys dynamically

    Amazon Redshift now enables users to add and change sort keys of existing Redshift tables without having to re-create the table. The new capability simplifies user experience in maintaining the optimal sort order in Redshift to achieve high performance as their query patterns evolve and do it without interrupting the access to the tables.
    
    Customers when creating Redshift tables can optionally specify one or more table columns as sort keys. The sort keys are used to maintain the sort order of the Redshift tables and allows the query engine to achieve high performance by reducing the amount of data to read from disk and to save on storage with better compression. Currently Redshift customers who desire to change the sort keys after the initial table creation will need to re-create the table with new sort key definitions.
    
    With the new ALTER SORT KEY command, users can dynamically change the Redshift table sort keys as needed. Redshift will take care of adjusting data layout behind the scenes and table remains available for users to query. Users can modify sort keys for a given table as many times as needed and they can alter sort keys for multiple tables simultaneously.
    
    For more information ALTER SORT KEY, please refer to the documentation.
    

    documentation

    as for the documentation itself:

    ALTER DISTKEY column_name or ALTER DISTSTYLE KEY DISTKEY column_name A clause that changes the column used as the distribution key of a table. Consider the following:

    VACUUM and ALTER DISTKEY cannot run concurrently on the same table.
    
    If VACUUM is already running, then ALTER DISTKEY returns an error.
    
    If ALTER DISTKEY is running, then background vacuum doesn't start on a table.
    
    If ALTER DISTKEY is running, then foreground vacuum returns an error.
    
    You can only run one ALTER DISTKEY command on a table at a time.
    
    The ALTER DISTKEY command is not supported for tables with interleaved sort keys.
    
    When specifying DISTSTYLE KEY, the data is distributed by the values in the DISTKEY column. For more information about DISTSTYLE, see CREATE TABLE.
    

    ALTER [COMPOUND] SORTKEY ( column_name [,...] ) A clause that changes or adds the sort key used for a table. Consider the following:

    You can define a maximum of 400 columns for a sort key per table.
    
    You can only alter a compound sort key. You can't alter an interleaved sort key.
    
    When data is loaded into a table, the data is loaded in the order of the sort key. When you alter the sort key, Amazon Redshift reorders the data. For more information about SORTKEY, see CREATE TABLE.
    
    0 讨论(0)
提交回复
热议问题