当我从一个带有身份、主键和排序键的表中选择到另一个带有自己的一组身份、主键和排序键的表时,我最初遇到了这个问题。它没有尊重定义的 (1,1) 身份,而是执行 (1,8)(有时为 3,8)。我想可能是因为原始表已排序?为了弄清楚发生了什么,我做了一个更简单的查询和数据,并在多个红移集群中找到了一个可重现的示例。拿这个测试例子:
drop table if exists test;
create temp table test (id int identity(1,1) not null
, value varchar(16)
, primary key (id))
diststyle all
sortkey (id);
insert into test (value) select 'a';
insert into test (value) select 'b';
insert into test (value) select 'c' union select 'd';
insert into test (value) values ('e'), ('f'), ('g');
select * from test;
Run Code Online (Sandbox Code Playgroud)
我得到的输出是:
id value
1 a
2 b
9 c
10 d
3 e
4 f
5 g …Run Code Online (Sandbox Code Playgroud)