我正在尝试在 Amazon Redshift 中创建索引,但收到错误
create index on session_log(UserId);
UserId
是一个整数字段。
最佳答案
如果您尝试在 Redshift 表上创建索引(带有名称):
create index IX1 on "SomeTable"("UserId");
你会收到错误
An error occurred when executing the SQL command: create index IX1 on "SomeTable"("UserId") ERROR: SQL command "create index IX1 on "SomeTable"("UserId")" not supported on Redshift tables.
这是因为,像其他 data warehouses , Redshift 使用 columnar storage ,因此,其他 RDBMS 中使用的许多索引技术(如添加非聚集索引)不适用。
但是,您可以选择提供单个 sort key每个表,您还可以使用 distribution key 影响性能用于分片您的数据,并选择合适的 compression encodings以最小化存储和 I/O 开销。
例如,在您的情况下,您可以选择使用
UserId
作为排序键:create table if not exists "SomeTable"
(
"UserId" int,
"Name" text
)
sortkey("UserId");
您可能想阅读一些引物 like these
关于sql - 如何在 Amazon Redshift 中创建索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32088161/