Scheduler rules
A plan is a unit of work that is created by the optimizer to handle a query. Each plan is based on the content of a query and on statistics regarding the tables on which the query acts. A single query usually results in a single plan, but occasionally additional, auxiliary plans are generated also.
- Whether it is flagged as being short
- The resource group with which it is associated
- Its priority
- Zero or more conditions
- One action
- Whether it is to apply to admin plans as well as plans submitted on behalf of other users
- Modifying
- A modifying scheduler rule modifies the attributes of or
aborts a plan. For example, the following rule changes a plan with
normal priority to a plan with low priority:
Each time the scheduler receives a plan, it evaluates all modifying scheduler rules and carries out the appropriate actions.IF PRIORITY IS NORMAL THEN SET PRIORITY LOW
- Limiting
- A limiting scheduler rule limits the number of plans that
can run concurrently. For example, the following rule prevents more
than one plan associated with a query on tables or objects in the
database with the name DB1 from running at a time:
Each time the scheduler selects a plan for execution, it evaluates all limiting scheduler rules. The plan is executed only if doing so would not exceed a limit imposed by a limiting scheduler rule. Otherwise, the plan waits.IF DATABASE IS DB1 THEN LIMIT 1
By deft use of scheduler rules, you can exert a high level of control over plan execution. A scheduler rule does not apply to admin plans unless you explicitly specify otherwise when you create the rule.
Scheduler rule conditions
- RESOURCEGROUP
- The plan's resource group. Usually, this is the resource group of the user who submitted the corresponding query; however, it can be changed by a modifying scheduler rule. The specified resource group must already exist.
- PRIORITY
- The priority of the plan:
- CRITICAL
- HIGH
- NORMAL
- LOW
- TYPE
- The plan type:
- LOAD
- The plan loads (reads) data from an external table.
- UNLOAD
- The plan unloads (writes) data to an external table.
- GENERATE STATISTICS
- The plan generates or updates database statistics
- GROOM
- The plan removes outdated and deleted records from tables.
- UDX
- The plan runs a user-defined object.
- DATABASE
- The database that is to be accessed by the plan. This is the database to which the session is connected. The specified database must already exist.
- USER
- The user who submitted the query that corresponds to the plan. The specified user must already exist. The specified user cannot be Admin. To include plans associated with Admin jobs, specify the INCLUDING ADMIN option.
- TABLE
- A user table accessed by the plan. The specified table must already exist. If the database name or schema name are needed to uniquely identify the table, they must be specified as part of the table name.
- TAG
- A string that is to be associated with and can be used to reference the plan (see Tags).
- CLIENT_USER_ID
- The user ID under which the application that submitted the corresponding query is running. This value is specified for the session, and is usually set by an application. The value must be specified in single quotes.
- CLIENT_APPLICATION_NAME
- The name of the application that submitted the corresponding query. This value is specified for the session, and is usually set by an application. The value must be specified in single quotes.
- CLIENT_WORKSTATION_NAME
- The host name of the workstation on which the application that submitted the corresponding query runs. This value is specified for the session, and is usually set by an application. The value must be specified in single quotes.
- CLIENT_ACCOUNTING_STRING
- The value of the accounting string. This value is specified for the session, and is usually set by an application. The value must be specified in single quotes.
- ESTIMATE
- The lower bound, upper bound, or both of the estimated cost of
the plan, in seconds:
- Specify a lower bound using the > or >= operator.
- Specify an upper bound using the < or <= operator.
Actions of a modifying scheduler rule
- SET SHORT
- Set the SQB flag for the plan, regardless of its cost estimate and the threshold set by the host.schedSQBNominalSecs registry setting.
- SET NOT SHORT
- Do not set the SQB flag for the plan, regardless of its cost estimate and the threshold set by the host.schedSQBNominalSecs registry setting.
- ADD TAG
- Add a tag to this plan. Each plan can have any number of tags associated with it.
- SET PRIORITY
- Change the priority of the plan. This action ignores user and group limits on priority.
- SET ESTIMATE
- Set the cost estimate of the plan, in seconds. This action overrides the estimate calculated by the planner. It does not affect the SQB flag.
- INCREASE PRIORITY
- Increase the priority of the plan by one level, for example from NORMAL to HIGH. It ignores an attempt to increase a CRITICAL priority, and ignores user and group limits on priority.
- DECREASE PRIORITY
- Decrease the priority of the plan by one level, for example from NORMAL to LOW. It ignores an attempt to decrease a LOW priority, and ignores user and group limits on priority.
- EXECUTE AS RESOURCEGROUP
- Execute the plan as if it belonged to the specified resource group.
- ABORT
- Abort the plan. This provides a way to temporarily disallow jobs that involve particular tables, database, or users, for example, during maintenance. The specified message is passed to the user who issued the corresponding query.
Using scheduler rules with SQB, GRA, and PQE
- Resource group
- Priority
- Cost estimate
- Whether it is short
- Tags
- SQB
- You can specify whether a plan is short. For example, the following
scheduler rule causes all plans that run user-defined objects to be
regarded as being short, regardless of their cost estimates:
IF TYPE IS UDX THEN SET SHORT
- GRA
- You can associate plans with particular resource groups. For example,
the following scheduler rules associate plans with resource groups
based on the databases that they access:
By configuring resource groups RSG_A and RSG_B appropriately, you can make resource allocation dependent on which databases are being accessed. Note that the resource groups RSG_A and RSG_B do not have to have any users assigned to them, but can be used exclusively as a means to allocate system resources.IF DATABASE IS DB1 THEN EXECUTE AS RESOURCEGROUP RSG_A IF DATABASE IS DB2 THEN EXECUTE AS RESOURCEGROUP RSG_A IF DATABASE IS DB3 THEN EXECUTE AS RESOURCEGROUP RSG_B IF DATABASE IS DB4 THEN EXECUTE AS RESOURCEGROUP RSG_A IF DATABASE IS DB5 THEN EXECUTE AS RESOURCEGROUP RSG_B
- PQE
- You can modify plan priority. For example, the following scheduler
rules modify the priority of plans based on the tables that they access:
IF TABLE IS T1 THEN SET PRIORITY LOW IF TABLE IS T7 THEN DECREASE PRIORITY
Scheduler rule evaluation order
Rule name Rule
r2_decrease_normal IF PRIORITY IS NORMAL THEN DECREASE PRIORITY
r3_low_to_normal IF PRIORITY IS LOW THEN SET PRIORITY NORMAL
r2_decrease_normal
, which is processed first,
causes the priority of the plan to be decreased from NORMAL to LOW.
Then, the rule with the name r3_low_to_normal
causes
the priority of the plan to be set back to NORMAL.Tags
- Session tag
- A session tag applies to a particular session and to all the plans that are within the scope of that session. It is set by specifying the ADD TAG parameter for an ALTER SESSION command.
- Plan tag
- A plan tag applies to a particular plan. It is set by specifying the ADD TAG parameter for a CREATE SCHEDULER RULE command.
- To prevent an end-of-month test from sapping performance, you
might add a tag with the name
eom_test
to the corresponding session, and create a scheduler rule with a condition that refers to that tag and that automatically decreases the priority of any plan that originates from that session:IF TAG IS eom_test THEN DECREASE PRIORITY
- To prevent a session in which extract, transform, and load (ETL)
jobs run from sapping performance, you might add a tag with the name
etl
to that session, and create a scheduler rule with a condition that refers to that tag and that automatically set the priority of any plan that originates from that session to LOW:IF TAG IS etl THEN SET PRIORITY LOW
user_is_jill
to each plan for which
the associated user is jill:IF USER IS jill THEN ADD TAG user_is_jill
This
tag can then be referenced by subsequent scheduler rules. This is
helpful when you have a long or complex condition that is employed
by several scheduler rules.IF DATABASE IS reportdb THEN ADD TAG no_more_than_2
IF USER IS joe THEN ADD TAG no_more_than_2
IF TAG IS no_more_than_2 THEN LIMIT 2
Client information
- User ID
- The user ID under which the client is running.
- Application name
- The name of the client.
- Workstation name
- The host name of the workstation on which the client runs.
- Accounting string
- The value of the accounting string from the client information that is specified for the session.
- An administrator, by issuing the nzsql SET command
- An application program, by means of the ODBC API (see IBM® Netezza® ODBC, JDBC, OLE DB, and .NET Installation and Configuration Guide)
Scheduler rule security
To create a scheduler rule, you must either be the admin user or your user account must have the Scheduler Rule privilege. The admin user and a user with the Scheduler Rule privilege can also list, drop, alter, deactivate, or reactivate any rule, regardless of who created or owns it.
The owner of a scheduler rule is, by default, the user who created it; however, ownership can be reassigned to a different user. The owner of a scheduler rule can list, drop, alter, deactivate, or reactivate that rule, regardless of which privileges that user has been granted.