AUTO_READAHEAD session environment option
Use the AUTO_READAHEAD environment option to change the automatic read-ahead mode, the batch size, the threshold, or to disable automatic read-ahead operations for the current session.
The AUTO_READAHEAD session environment option has this syntax:
|--SET ENVIRONMENT AUTO_READAHEAD -'--+0+--+------+--+----------+--'|
+1+ ',pages' ',threshold'
'2'
Element | Description | Restrictions | Syntax |
---|---|---|---|
pages | Number of data pages to read ahead | Must be an integer in the range 4 pages
4096 |
Literal Number |
threshold | Percentage of unprocessed pages that will trigger next read | Must be an integer in the range 1 threshold
100 |
Literal Number |
Usage
- A required mode setting, encoded as a digit in the range
0
mode2
- An optional pages setting, encoded as an integer in the range
4
pages4096
. - An optional threshold setting, encoded as an integer in the range
1
threshold100
.
Setting the mode to aggressive, standard, or disabled
You can change the automatic read-ahead mode for the current session by specifying one of the following values as the first AUTO_READAHEAD parameter:
- 0
- Disable automatic read-ahead requests.
- 1
- Enable automatic read-ahead requests in the standard mode. The server will automatically process read-ahead requests only when a query waits on I/O.
- 2
- Enable automatic read-ahead requests in the aggressive mode. The server will automatically process read-ahead requests at the start of the query, and continuously through the duration of the query.
The value that you specify for the mode overrides the setting of the AUTO_READAHEAD configuration parameter for the session.
- The SET ENVIRONMENT AUTO_READAHEAD statement (for a session)
- The AUTO_READAHEAD configuration parameter value of 1 or 2.
- If AUTO_READAHEAD has no setting in the onconfig file, but the AUTO_TUNE configuration parameter is set to 1, the server performs automatic read-ahead on 128 data pages, equivalent to the default pages value in the standard mode.
Setting the number of pages to read ahead
- pages
- Specifies the batch size in pages (as an integer in the range
4
pages4096
) read by the database server when it receives an automatic read-ahead request.
The specified pages value overrides the explicit or default batch size setting of the AUTO_READAHEAD configuration parameter for the current session.
If the SET ENVIRONMENT AUTO_READAHEAD statement includes no second parameter, the batch size value defaults to the explicit AUTO_READAHEAD configuration parameter setting, or to 128 pages, if that configuration parameter is not set.
Setting the threshold
Besides setting the automatic read-ahead mode and the batch size, you can also optionally specify a threshold value as the third AUTO_READAHEAD parameter:
- threshold
- Specifies the percentage (as an integer in the range 1 ≤ threshold ≤ 100) of the current batch that will remain unprocessed when the next batch of pages is requested.
Use a comma ( , ) as the separator between the values of read-ahead pages and read-ahead threshold.
The specified threshold value overrides the explicit or default threshold setting of the AUTO_READAHEAD configuration parameter for the current session.
If the SET ENVIRONMENT AUTO_READAHEAD statement includes no third parameter, the threshold value defaults to the explicit AUTO_READAHEAD configuration parameter setting, or to 50, if that configuration parameter is not set.
Examples of setting AUTO_READAHEAD
Note that the value in the statement must be quoted, either with single or double quotes.
SET ENVIRONMENT AUTO_READAHEAD '0';
SET ENVIRONMENT AUTO_READAHEAD '1';
SET ENVIRONMENT AUTO_READAHEAD '1,1024';
SET ENVIRONMENT AUTO_READAHEAD '1,1000,30';
Generally, the standard mode (AUTO_READAHEAD = 1) is appropriate in typical production environments, even for cached environments, but the SET ENVIRONMENT AUTO_READAHEAD statement enables you to take action in contexts where the efficiency of specific scans might benefit from modifying the read-ahead behavior.
SET ENVIRONMENT AUTO_READAHEAD '2';
Use aggressive read-ahead operations only in situations in which you tested both settings and know that aggressive read-ahead operations are more effective. Do not use aggressive read-ahead operations if you are not sure that they are more effective.
For scans that might turn read-ahead operations off and on because the scan encounters pockets of cached data, aggressive mode read-ahead operations do not turn off read-ahead operations.