sql - 如何在 Amazon Redshift 中创建索引

标签 sql amazon-web-services indexing amazon-redshift

我正在尝试在 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/

相关文章:

mysql - 我试图从 LEFT JOIN 中只获取一行

linux - 停止和启动 EC2 实例后从/mnt 目录中删除的数据

amazon-web-services - 从 Putty 连接到 Amazon Linux EC2 AWS 镜像时出现 "Server refused our key"问题

matlab - 分配期间的索引

Python检查列表中是否存在刮取的元素

sql - JOIN 打破 WHERE 子查询

sql - 使用 PIVOT 的 NULL 字段

python - 通过整数索引选择和修改 Pandas 数据框中的切片

sql - 我应该在 SQL 连接/连接表中存储额外的数据吗?

amazon-web-services - API 网关集成请求 HTTP header 未将查询字符串映射到 header