Internal Query Processor Error with ColumnStore Indexes

, 2016-12-29

As I was doing some testing for upgrading our data warehouse to SQL Server 2016, I found something interesting to share. I have a few tables that have columnstore indexes in them, in addition to a clustered btree index. On SQL Server 2016, I tried to drop and recreate the columnstore index and would get an error that the optimizer could not create the execution plan. I thought it was initially due to memory constraints, so I tried increasing the memory on the server, but still continued to have the same problem.

I finally narrowed the issue down to this: the key on which I was creating the btree clustered index had a computed column in it. When I got rid of this, I was able to create both the columnstore index as well as the clustered btree index without any issues. I can, of course, choose my clustered index to be the columnstore index on 2016 also. If I want the computed column to stay as part of the key, the solution would be to create the clustered index as columnstore, and then go with a non clustered btree index if necessary.

The steps to recreate the error as below.

CREATE TABLE [dbo].[BillDate](
       [DateID]  AS (isnull((datepart(year,[date])*(10000)+datepart(month,[date])*(100))+datepart(day,[date]),(-1))) PERSISTED NOT NULL,
       [Date] [date] NULL,
       [DayOfWeekNumber] [int] NULL,
       [DayOfWeekName] [varchar](20) NULL
CONSTRAINT [PK_Date] PRIMARY KEY NONCLUSTERED
(
       [DateID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE NONCLUSTERED COLUMNSTORE INDEX [NCCS_Billdate] ON [dbo].[Billdate]
(
       [Date],
       [DayOfWeekNumber],
       [DayOfWeekName]
)WITH (DROP_EXISTING = OFF, COMPRESSION_DELAY = 0) ON [PRIMARY]
CREATE CLUSTERED INDEX [pk_Billdate] ON BillDate(DateID)

Steps 2 or 3, may be reversed and either way – the last step gives an error as below:

This problem can be solved by

1. Not using a computed field in primary key of btree clustered index or columnstore index (Columnstore indexes cannot include computed columns anyway).

OR

2. Creating the btree clustered index using computed column and any other columns, avoiding columnstore indexes entirely.

OR

3. Creating nonclustered columnstore index without including computed column and a nonclustered btree index on computed column.

Rate

5 (5)

Share

Share

Rate

5 (5)

Related content

Boost Your Performance - Bad Index Detection

SQL Server depends heavily on good indexing to perform well. The optimizer requires relevant and intelligent indexing in order to do its job well. Author Andre Vigneau brings us a script that he uses to detect possible index problems in the database design as well as a number of hints to ensure that your database is performing optimally.

5 (1)

2004-12-08

15,534 reads