env: Windows Server 2016
SQL Server 2016 SP2
We introduced the use of Alter database 1117 Flag enable the trace " SQL Server 1117 with the ALTER enable the trace Flag Database ", this time to introduce this time to introduce the use of "Alter database" Enable trace flag 1118
Trace flag:1118
Most of the pages on a single server configuration is removed, in order to reduce competition SGAM pages. When creating a new object, by default, the first eight will be configured from different ranges (mixed range). After more pages if needed, will be configured from the same range (unified range). SGAM pages can be used to track these mixed range, so If there is more mixed configuration page, it will quickly become a bottleneck. This tracking will flag when creating a new object, configure all eight pages from the same range, and then will be reduced to the minimum requirements for scanning SGAM pages. For more information, see this Microsoft support article (machine translation).
Note: Starting with SQL Server 2016 (13.x), this behavior by the ALTER DATABASE SET MIXED_PAGE_ALLOCATION option of control, tracking flag 1118 has no effect. For more information, see ALTER DATABASE SET Options (Transact-SQL).
Scope: global only
1. Create a test DB
command:
CREATE DATABASE [TBTEST02]
CONTAINMENT = NONE
ON PRIMARY
( NAME = N'TBTEST01', FILENAME = N'E:\SQLData\TBTEST02.mdf' , SIZE = 8192KB , FILEGROWTH = 65536KB )
LOG ON
( NAME = N'TBTEST01_log', FILENAME = N'E:\SQLLog\TBTEST02_log.ldf' , SIZE = 8192KB , FILEGROWTH = 65536KB )
GO
2. Check whether the test DB trace flag 1117 is enabled by default
command:
SELECT
[NAME],
is_mixed_page_allocation_on
FROM SYS.databases
WHERE [name] ='TBTEST02'
After the query can be found in " is_mixed_page_allocation_on " 0
3. Check the test DB and tempdb again
command:
SELECT
[NAME],
is_mixed_page_allocation_on
FROM SYS.databases
WHERE [name] IN ('TBTEST02','tempdb')
After the query can be found in " is_mixed_page_allocation_on " 0
4. Create a test table and create a test data
command:
USE [TBTEST02]
GO
CREATE TABLE test01
(
Name CHAR(8000)
) ON [PRIMARY]
GO
USE [TBTEST02]
GO
INSERT INTO [TBTEST02].dbo.test01 VALUES ('Larry222222222222')
GO 20
extent 5. Check test distribution DB
command:
USE [TBTEST02]
GO
SELECT
DB_NAME(database_id) as DBName,
OBJECT_NAME(object_id) as ObjectName,
extent_page_id, page_type_desc
FROM sys.dm_db_database_page_allocations(DB_ID('TBTEST02'),
OBJECT_ID('test01'),NULL,NULL,'DETAILED')
--WHERE OBJECT_NAME(object_id) = 'test02'
go
extent_page_id : 320
All 8kb pages placed in the same extent
extent_page_id : 328
extent been filled, the next extent configured
extent_page_id : 336
extent not fill, the next extent not configured
6. Establish new test DB
command:
CREATE DATABASE [TBTEST03]
CONTAINMENT = NONE
ON PRIMARY
( NAME = N'TBTEST03', FILENAME = N'E:\SQLData\TBTEST03.mdf' , SIZE = 8192KB , FILEGROWTH = 65536KB )
LOG ON
( NAME = N'TBTEST03_log', FILENAME = N'E:\SQLLog\TBTEST03_log.ldf' , SIZE = 8192KB , FILEGROWTH = 65536KB )
GO
7. Create a test table
command:
USE [TBTEST02]
GO
CREATE TABLE test01
(
Name CHAR(8000)
) ON [PRIMARY]
8. Use "Alter databaase" function to enable trace flag 1117
command:
ALTER DATABASE [TBTEST03] SET MIXED_PAGE_ALLOCATION ON
9. increase the test data
command:
USE [TBTEST03]
GO
INSERT INTO [TBTEST03].dbo.test01 VALUES ('Larry222222222222')
GO 20
extent 10. Check test distribution DB
command:
USE [TBTEST03]
GO
SELECT
DB_NAME(database_id) as DBName,
OBJECT_NAME(object_id) as ObjectName,
extent_page_id,
page_type_desc,
is_mixed_page_allocation
FROM sys.dm_db_database_page_allocations(DB_ID('TBTEST03'),
OBJECT_ID('test01'),NULL,NULL,'DETAILED')
--WHERE OBJECT_NAME(object_id) = 'test02'
go
extent_page_id : 336
All 8kb pages placed in the same extent
extent_page_id : 344
extent been filled, the next extent configured
extent_page_id : 352
extent not fill, the next extent not configured
11. Enable trace flag 1118 in TempDB
command:
USE [master]
GO
ALTER DATABASE [Tempdb] SET MIXED_PAGE_ALLOCATION ON
GO
This is a rather unfortunate place !!!!