USE Database_Test
GO
DECLARE @Address TABLE
(
AddressID int,
City nvarchar(30),
StateProvinceID int,
AddressLine1 nvarchar(60),
INDEX cl_AddressID CLUSTERED (AddressID),
INDEX ix_StateProvinceID NONCLUSTERED (StateProvinceID)
)
One of things that surprised me was that Microsoft supports FILLFACTOR. However, it's not 100 per cent certain you can create every kind of index which you want. For example, you can not include columns or apply a filter to an inline index on the variable table. This is the opposite of the temporary table, when you can do that after creating the table. Or can you?
DECLARE @Inline_FillFactor TABLE
(
ID int PRIMARY KEY,
ColumnA nvarchar(30),
ColumnB nvarchar(3),
INDEX ix_Inline_FillFactor NONCLUSTERED(ColumnA) WITH(FILLFACTOR = 95)
);
Well...! This is a change for the variable table, so one question pops up:
IS A VARIABLE TABLE AS GOOD AS A TEMPORARY TABLE? One of the most important impacts to performance is
STATISTICS and
we are able to create inline indexes on the variable table so we're expecting it allows some populated statistics on the variable table.
GO
DECLARE @Address TABLE
(
AddressID int,
City nvarchar(30),
StateProvinceID int,
AddressLine1 nvarchar(60),
INDEX cl_AddressID CLUSTERED (AddressID),
INDEX ix_StateProvinceID NONCLUSTERED (StateProvinceID)
)
INSERT @Address(AddressID,City,StateProvinceID,AddressLine1)
SELECT AddressID,City,StateProvinceID,AddressLine1 FROM AdventureWork2012.[Person].[Address]
SET STATISTICS PROFILE ON
SELECT City, AddressLine1
FROM @Address
WHERE StateProvinceID = 79
SET STATISTICS PROFILE OFF
USE master;
GO
ALTER DATABASE Database_Test ADD FILEGROUP [MemoryOptmizedFileGroup] CONTAINS MEMORY_OPTIMIZED_DATA;
GO
ALTER DATABASE Database_Test ADD FILE(name='NewFileGroup1',filename='C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\NewFileGroup1')
TO FILEGROUP [MemoryOptmizedFileGroup]
GO
ALTER DATABASE Database_Test SET MEMORY_OPTIMIZED_ELEVATE_TO_SNAPSHOT ON;
We can start a memory optmizied variable table and the first step is to create a table type which is the same with variable table's definition:
USE Database_Test
GO
CREATE TYPE Address AS TABLE
(
AddressID int not null,
City nvarchar(30) not null,
StateProvinceID int not null,
AddressLine1 nvarchar(60),
INDEX ix_StateProvinceID NONCLUSTERED (StateProvinceID)
) WITH (MEMORY_OPTIMIZED =ON)
USE Database_Test
GO
DECLARE @Address Address;
INSERT @Address(AddressID,City,StateProvinceID,AddressLine1)
SELECT AddressID,City,StateProvinceID,AddressLine1 FROM [Person].[Address]
SET STATISTICS PROFILE ON
SELECT City, AddressLine1
FROM @Address
WHERE StateProvinceID = 79
SET STATISTICS PROFILE OFF
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)