Redshift Temp Table 身份列

Redshift Temp Table Identity column

我的存储过程包括以下代码:

CREATE TEMPORARY TABLE #lala
(
     idx int IDENTITY(1,1), 
     tablename nvarchar(128)
);
  
INSERT INTO #lala(tablename)
    SELECT LEFT(tablename, LEN(tablename) - 3)
    FROM SVV_EXTERNAL_TABLES 
    WHERE schemaname = 'spectrum' 
      AND tablename LIKE '%_v2';

然后我这样称呼它:

BEGIN;
CALL myschema.make_union_views('spectrum_views','spectrum','mycursor');
FETCH ALL FROM mycursor;
COMMIT;

一开始是运行成功的

然后就开始崩溃了,调试,我列出了'#lala

的内容

我很困惑这是怎么发生的 - [idx] 列不是连续的?

希望有人能阐明可能发生的事情?

这是设计使然。 Redshift 是一个集群,因此集群各部分之间的通信非常昂贵。 Redshift 确保标识列的唯一性但不是顺序性。根据 CREATE TABLE 文档 (https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_TABLE_NEW.html):

When you load the table using an INSERT INTO [tablename] SELECT * FROM or COPY statement, the data is loaded in parallel and distributed to the node slices. To be sure that the identity values are unique, Amazon Redshift skips a number of values when creating the identity values.