Query tuning
- Last Updated: January 17, 2024
- 2 minute read
- OpenEdge
- Version 12.8
- Documentation
How you structure a query determines how efficiently
you access a database. Using your MS SQL Server data source efficiently
enhances the performance of DataServer applications. The standard
approach to enhancement is using selection criteria to refine access
to data, but you can further optimize the DataServer's
execution of a query by specifying the OpenEdge QUERY-TUNING phrase.
You can include the QUERY-TUNING phrase in these OpenEdge statements:
-
FOR EACHFOR EACH table QUERY-TUNING(query-tuning-option query-tuning-option...) -
OPEN QUERYOPEN QUERY query QUERY-TUNING(query-tuning-option query-tuning-option...) -
DO PRESELECTDO PRESELECT table QUERY-TUNING(query-tuning-option query-tuning-option...) -
REPEAT PRESELECTREPEAT PRESELECT table QUERY-TUNING(query-tuning-option query-tuning-option...)
You must place the QUERY-TUNING phrase after
the last record phrase. For example, place it near the end of the
statement where you also place block modifier phrases such as BREAK, ON ERROR,
and TRANSACTION.
You can include multiple query-tuning options in a single statement; simply separate each option from the previous one by a single space.
The following table describes the query-tuning options.
| Option | Description |
|---|---|
|
|
Specifies whether the DataServer sends multiple result rows in a single logical network message, thereby reducing network traffic. Default: |
|
|
Specifies the size in bytes of the cache used by lookahead cursors. A larger cache
size can improve performance for queries that return a large number of records
because the DataServer might need fewer SQL statements to get the results. This
value will override a cache size specified with Minimum: The DataServer always caches at least one record. Maximum: None. Default: 30000. |
|
|
Specifies whether the DataServer should print to the dataserv.lg file the debugging information that it generates for a query. Specify Specify Specify Default: |
|
|
Specifies whether the DataServer allows its data source to perform
a join (this usually improves performance). Default:
You can turn off the Note: JOIN-BY-SQLDB is the
default behavior for outer join operations. |
|
|
Specifies whether the DataServer uses lookahead or standard cursors. Lookahead
cursors fetch as many records as fit in the allocated cache (see the
Using lookahead cursors results in behavior that is different from an OpenEdge
database because changes made to the records in the cache might not be immediately
visible. Specify Default: |
|
|
Specifies whether each cursor should use a separate database connection. Executing cursors in separate connections might improve performance because the DataServer does not have to restart the cursors and sort the results. Do not specify Default: |
|
|
Specifies that OpenEdge should not choose an index in the absence of a
Note: If you elect to use this option to omit index selection on the
query, you may see better performance using the optimizer's sort selections.
However, compatibility with OpenEdge forward/backward scrolling and reposition
capability may be lost. Only use this option when compatibility is not required and
can be overlooked for the sake of better performance.
|
|
|
Specifies that OpenEdge should omit the record identifier from the end of the
query's generated Note: If you elect to use this option, the query may find an index match
to provide better performance. However, turning off uniqueness in a query where
scrolling is required may result in behavior that is incompatible with the OpenEdge
ABL. Only use this option when compatibility is not required and can be overlooked
for the sake of better performance.
|
|
|
Specifies at the query level that the firehose cursor type should be considered to
satisfy the query when the Note: This query-level option overrides the connection-level
-Dsrv options, QT_FIREHOSE and
QT_NO_FIREHOSE that determine if firehose cursors should be
considered for the DataServer connection.Specifies at the query level that the firehose cursor type should not be considered
to satisfy the query when the Note: This query-level option overrides the connection-level
-Dsrv options, QT_FIREHOSE and
QT-NO-FIREHOSE that determine if firehose cursors should be
considered for the DataServer connection.By default, firehose cursors are available to satisfy |
|
|
When performing an outer join operation, SELECT-ON-JOIN specifies that any search condition separate from the join predicate be bracketed after the join is performed. This option eliminates all the records with NULL values contained in the non-matching results, if the columns with the NULL values appear in the join search criteria. When performing an outer join operation, JOIN-ON-SELECT specifies that any search condition separate from the join predicate be bracketed before the join is performed. This option includes all the records with NULL values contained in the non-matching results and causes records that join on NULL to be included in the results of an OUTER-JOIN which is consistent with OpenEdge join handling of the unknown value. Default: |
All but two of the QUERY-TUNING options take
effect at both compile time and run time. The exceptions are JOIN-BY-SQLDB and NO-JOIN-BY-SQLDB,
which apply only at compile time. You can override query-tuning
defaults (except JOIN-BY-SQLDB) at run-time by
specifying the appropriate startup parameters.
The following example shows how to use the QUERY-TUNING phrase
to enhance performance. It includes a join, JOIN-BY-SQLDB,
that the DataServer instructs the MS SQL Server data source to perform
by default, as shown:
|
The QUERY-TUNING options in this example specifies
the following:
- Lookahead cursors are not used (the
NO-LOOKAHEADoption) - The DataServer writes an extended report on the SQL statements
that it executes (the
DEBUG EXTENDEDoption)
When the DataServer constructs queries for a MS SQL Server data
source, it uses the QUERY-TUNING options that you
specify as guidelines. This is because there might be syntax considerations
that prevent the DataServer from applying the QUERY-TUNING options
as specified. In such a case, the DataServer executes the query
using the most appropriate options.
QUERY-TUNING options
that you specify.