列存储索引是否会影响内部联接所需的内存量?

时间:2017-03-30 14:07:55

标签: sql sql-server sql-server-2016 columnstore

我有一个超过700M行的表。我尝试了两种不同的索引选项:1)1个聚簇索引和1个非聚簇索引2)一个聚簇列存储索引。

我正在使用SQL Server 2016。

使用第一个选项时,我可以在大约30分钟内将此表与另一个表联系起来。

使用第二个选项,我在大约35分钟后收到内存不足错误。

这种内存不足错误是否可能与使用Column Store索引相关联?或者服务器是否只是忙碌?如果它是列存储索引的某些功能,是否有办法避免此错误?

此外,当通常的索引优先于列存储时,是否存在某些实例(当您的行数超过100,000,000时)?

编辑:

表格如下:

CREATE TABLE tab1 (
    column1 (bigint, not null),
    column2 (int, not null),
    column3 (bigint, not null),
    column4 (int, not null),
    column5 (datetime, not null),
    column6 (date, not null),
    column7 (datetime, not null),
    column8 (tinyint, not null),
    column9 (int, not null),
    column10 (datetime, not null),
    column11 (date, null)
)

没有定义任何键。

索引选项1:

create clustered index index1 on table1
    (column8, column1)

CREATE NONCLUSTERED INDEX index2 on table1(column4,column11)
    INCLUDE(
     column2
      ,column6
      ,column7
      )

索引选项2:

create clustered columnstore index colindex1 on table1

加入:

SELECT table1.column1
      ,table1.column2
      ,table1.column3
      ,table1.column4
      ,table1.column5
      ,table1.column6
      ,table1.column7
      ,table1.column8
      ,table1.column10
      ,table1.column11
      ,table2.column4
      ,table2.column5
      ,table2.column6
      ,table2.column7
      ,table2.column8
      ,table2.column9
      INTO newTable
      FROM table1
INNER JOIN table2
    ON (table1.column1 = table2.column1 and
        table1.column11 = table2.column2 and
        table1.column8 = table2.column3);

1 个答案:

答案 0 :(得分:0)

首先,尝试提出一个主键。如果您可以定义一组唯一的列,则没有任何内容可以进行索引。如果您不能这样做,请在column1, column8 and column11上创建聚簇索引(join子句中使用的所有列)。然后,如果您有其他select语句,请查看在连接和where子句中使用了哪些列,并且还可以为它们添加其他非聚簇索引。