Writing queries for performance
- Last Updated: January 17, 2024
- 2 minute read
- OpenEdge
- Version 12.8
- Documentation
Writing queries for performance
This section provides a collection of tips
and guidelines to follow when writing queries. For example, a query
that processes a large number of rows performs best if it uses NO-LOCK,
lookahead cursors, a large cache size, and a small field list. The
following suggestions might help improve the performance of your
DataServer applications. Try some of the following and use the DEBUG diagnostic
options to gather statistics on how your application runs:
- Use
FOR EACH,GET, andOPEN QUERYstatements as opposed toFINDstatements, which generally perform more slowly. Consider using theFOR FIRSTstatement instead ofFINDFIRST. The only exception is thatFIND LASTis faster thanGET LASTbecauseGET LASTcauses the client to process all the records. TheFIND LASTstatement allows the server to retrieve the last record. - Take advantage of field lists.
- Take advantage of the
QUERY-TUNINGoptions. - Use lookahead cursors.
- Use
NO-LOCKwhere possible. - Avoid specifying lock upgrades. Allow the DataServer and Oracle to handle lock upgrades.
- Do not ask for a particular ordering of results with
USE-INDEXorBYclauses, unless your application requires it. Allow the DataServer and Oracle to determine which index (if any) is most efficient for processing a query and avoid the overhead of sorting results. - For aggregates, use the
RUN-STORED-PROC send-sql-statementsyntax or use an OpenEdge SQL statement. If you use an OpenEdge SQL statement with a cursor, declare the cursor read-only. - If you are testing for the existence of a record, use the
CAN-FINDfunction, which does not retrieve the record if the DataServer passes the entireWHEREclause to Oracle for processing. However, avoid nestingCAN-FINDfunctions. - Avoid using the
RECIDfunction. Use theROWIDfunction.
See Analyzing application execution with Enhanced Logger for information on collecting statistics.