Skip to content

Commit f83c71a

Browse files
authored
Merge pull request #2398 from BYHAM/patch-321
Create classifier, format code
2 parents 7c0dece + cd42ee7 commit f83c71a

File tree

1 file changed

+49
-45
lines changed

1 file changed

+49
-45
lines changed

docs/relational-databases/resource-governor/create-and-test-a-classifier-user-defined-function.md

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Create and Test a Classifier User-Defined Function | Microsoft Docs"
33
ms.custom: ""
4-
ms.date: "03/16/2017"
4+
ms.date: "07/11/2017"
55
ms.prod: "sql-server-2016"
66
ms.reviewer: ""
77
ms.suite: ""
@@ -45,22 +45,22 @@ manager: "jhubbard"
4545
```
4646
--- Create a resource pool for production processing
4747
--- and set limits.
48-
USE master
48+
USE master;
4949
GO
5050
CREATE RESOURCE POOL pProductionProcessing
5151
WITH
5252
(
5353
MAX_CPU_PERCENT = 100,
5454
MIN_CPU_PERCENT = 50
55-
)
55+
);
5656
GO
5757
--- Create a workload group for production processing
5858
--- and configure the relative importance.
5959
CREATE WORKLOAD GROUP gProductionProcessing
6060
WITH
6161
(
6262
IMPORTANCE = MEDIUM
63-
)
63+
);
6464
--- Assign the workload group to the production processing
6565
--- resource pool.
6666
USING pProductionProcessing
@@ -73,7 +73,7 @@ manager: "jhubbard"
7373
(
7474
MAX_CPU_PERCENT = 50,
7575
MIN_CPU_PERCENT = 0
76-
)
76+
);
7777
GO
7878
--- Create a workload group for off-hours processing
7979
--- and configure the relative importance.
@@ -84,32 +84,32 @@ manager: "jhubbard"
8484
)
8585
--- Assign the workload group to the off-hours processing
8686
--- resource pool.
87-
USING pOffHoursProcessing
87+
USING pOffHoursProcessing;
8888
GO
8989
```
9090
9191
2. Update the in-memory configuration.
9292
9393
```
94-
ALTER RESOURCE GOVERNOR RECONFIGURE
94+
ALTER RESOURCE GOVERNOR RECONFIGURE;
9595
GO
9696
```
9797
9898
3. Create a table and define the start and end times for the production processing time range.
9999
100100
```
101-
USE master
101+
USE master;
102102
GO
103103
CREATE TABLE tblClassificationTimeTable
104104
(
105105
strGroupName sysname not null,
106106
tStartTime time not null,
107107
tEndTime time not null
108-
)
108+
);
109109
GO
110110
--- Add time values that the classifier will use to
111111
--- determine the workload group for a session.
112-
INSERT into tblClassificationTimeTable VALUES('gProductionProcessing', '6:35 AM', '6:15 PM')
112+
INSERT into tblClassificationTimeTable VALUES('gProductionProcessing', '6:35 AM', '6:15 PM');
113113
go
114114
```
115115
@@ -124,7 +124,9 @@ manager: "jhubbard"
124124
WITH SCHEMABINDING
125125
AS
126126
BEGIN
127-
/* We recommend running the classifier function code under snapshot isolation level OR using NOLOCK hint to avoid blocking on lookup table. In this example, we are using NOLOCK hint. */
127+
/* We recommend running the classifier function code under
128+
snapshot isolation level OR using NOLOCK hint to avoid blocking on
129+
lookup table. In this example, we are using NOLOCK hint. */
128130
DECLARE @strGroup sysname
129131
DECLARE @loginTime time
130132
SET @loginTime = CONVERT(time,GETDATE())
@@ -138,15 +140,15 @@ manager: "jhubbard"
138140
--- Use the default workload group if there is no match
139141
--- on the lookup.
140142
RETURN N'gOffHoursProcessing'
141-
END
143+
END;
142144
GO
143145
```
144146
145147
5. Register the classifier function and update the in-memory configuration.
146148
147149
```
148-
ALTER RESOURCE GOVERNOR with (CLASSIFIER_FUNCTION = dbo.fnTimeClassifier)
149-
ALTER RESOURCE GOVERNOR RECONFIGURE
150+
ALTER RESOURCE GOVERNOR with (CLASSIFIER_FUNCTION = dbo.fnTimeClassifier);
151+
ALTER RESOURCE GOVERNOR RECONFIGURE;
150152
GO
151153
```
152154
@@ -155,76 +157,78 @@ manager: "jhubbard"
155157
1. Obtain the resource pool and workload group configuration by using the following query.
156158
157159
```
158-
USE master
159-
SELECT * FROM sys.resource_governor_resource_pools
160-
SELECT * FROM sys.resource_governor_workload_groups
160+
USE master;
161+
SELECT * FROM sys.resource_governor_resource_pools;
162+
SELECT * FROM sys.resource_governor_workload_groups;
161163
GO
162164
```
163165
164166
2. Verify that the classifier function exists and is enabled by using the following queries.
165167
166168
```
167169
--- Get the classifier function Id and state (enabled).
168-
SELECT * FROM sys.resource_governor_configuration
170+
SELECT * FROM sys.resource_governor_configuration;
169171
GO
170172
--- Get the classifer function name and the name of the schema
171173
--- that it is bound to.
172174
SELECT
173175
object_schema_name(classifier_function_id) AS [schema_name],
174176
object_name(classifier_function_id) AS [function_name]
175-
FROM sys.dm_resource_governor_configuration
176-
177+
FROM sys.dm_resource_governor_configuration;
177178
```
178179
179180
3. Obtain the current runtime data for the resource pools and workload groups by using the following query.
180181
181182
```
182-
SELECT * FROM sys.dm_resource_governor_resource_pools
183-
SELECT * FROM sys.dm_resource_governor_workload_groups
183+
SELECT * FROM sys.dm_resource_governor_resource_pools;
184+
SELECT * FROM sys.dm_resource_governor_workload_groups;
184185
GO
185186
```
186187
187188
4. Find out what sessions are in each group by using the following query.
188189
189190
```
190-
SELECT s.group_id, CAST(g.name as nvarchar(20)), s.session_id, s.login_time, CAST(s.host_name as nvarchar(20)), CAST(s.program_name AS nvarchar(20))
191-
FROM sys.dm_exec_sessions s
192-
INNER JOIN sys.dm_resource_governor_workload_groups g
193-
ON g.group_id = s.group_id
194-
ORDER BY g.name
191+
SELECT s.group_id, CAST(g.name as nvarchar(20)), s.session_id, s.login_time,
192+
CAST(s.host_name as nvarchar(20)), CAST(s.program_name AS nvarchar(20))
193+
FROM sys.dm_exec_sessions AS s
194+
INNER JOIN sys.dm_resource_governor_workload_groups AS g
195+
ON g.group_id = s.group_id
196+
ORDER BY g.name;
195197
GO
196198
```
197199
198200
5. Find out which requests are in each group by using the following query.
199201
200202
```
201-
SELECT r.group_id, g.name, r.status, r.session_id, r.request_id, r.start_time, r.command, r.sql_handle, t.text
202-
FROM sys.dm_exec_requests r
203-
INNER JOIN sys.dm_resource_governor_workload_groups g
204-
ON g.group_id = r.group_id
205-
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) AS t
206-
ORDER BY g.name
203+
SELECT r.group_id, g.name, r.status, r.session_id, r.request_id,
204+
r.start_time, r.command, r.sql_handle, t.text
205+
FROM sys.dm_exec_requests AS r
206+
INNER JOIN sys.dm_resource_governor_workload_groups AS g
207+
ON g.group_id = r.group_id
208+
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) AS t
209+
ORDER BY g.name;
207210
GO
208211
```
209212
210213
6. Find out what requests are running in the classifier by using the following query.
211214
212215
```
213216
SELECT s.group_id, g.name, s.session_id, s.login_time, s.host_name, s.program_name
214-
FROM sys.dm_exec_sessions s
215-
INNER JOIN sys.dm_resource_governor_workload_groups g
216-
ON g.group_id = s.group_id
217-
AND 'preconnect' = s.status
218-
ORDER BY g.name
217+
FROM sys.dm_exec_sessions AS s
218+
INNER JOIN sys.dm_resource_governor_workload_groups AS g
219+
ON g.group_id = s.group_id
220+
AND 'preconnect' = s.status
221+
ORDER BY g.name;
219222
GO
220223
221-
SELECT r.group_id, g.name, r.status, r.session_id, r.request_id, r.start_time, r.command, r.sql_handle, t.text
222-
FROM sys.dm_exec_requests r
223-
INNER JOIN sys.dm_resource_governor_workload_groups g
224-
ON g.group_id = r.group_id
225-
AND 'preconnect' = r.status
226-
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) AS t
227-
ORDER BY g.name
224+
SELECT r.group_id, g.name, r.status, r.session_id, r.request_id, r.start_time,
225+
r.command, r.sql_handle, t.text
226+
FROM sys.dm_exec_requests AS r
227+
INNER JOIN sys.dm_resource_governor_workload_groups AS g
228+
ON g.group_id = r.group_id
229+
AND 'preconnect' = r.status
230+
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) AS t
231+
ORDER BY g.name;
228232
GO
229233
```
230234

0 commit comments

Comments
 (0)