INFORMIX
Extending INFORMIX-Universal Server: User-Defined Routines
Chapter 5: Performance Considerations
Home Contents Index Master Index New Book

SPL Considerations

This section describes the compilation, execution, and optimization processes of an SPL routine.

Tip: Not all the encapsulated SPL that you created as SPL procedures in earlier Informix products has the properties currently associated with procedures. If the SPL routine returns a value, you now refer to it as an SPL function. If the SPL routine does not return a value, you still refer to it as an SPL procedure.

SPL Compilation

Universal Server compiles an SPL routine when you execute the CREATE PROCEDURE or CREATE FUNCTION. The following activities occur in the compilation process of the SPL routine:

    The database server puts the SQL statements into an execution plan. An execution plan is a structure that enables the database server to store and execute the SQL statements efficiently.

    A dependency list contains items that the database server checks to decide if an SPL routine needs to be reoptimized at execution time. For example, the database server checks for the existence of all tables, indexes, and columns involved in the query.

    The term pcode refers to pseudocode that an interpreter executes quickly.

    The database server stores these ASCII formats as character columns in the system catalog tables, sysprocbody and sysprocplan.

SPL Execution

When you execute an SPL routine with the EXECUTE FUNCTION, EXECUTE ROUTINE, EXECUTE PROCEDURE, or CALL statement, the database server performs the following tasks:

    If an item in the dependency list indicates that reoptimization is needed, optimization occurs at this point.

SPL Optimization

A query plan is a specific way that a query might be performed. A query plan includes how to access tables, the order of joining tables, and the use of temporary tables. During SPL optimization, the query optimizer evaluates the possible query plans and selects the query plan with the lowest cost. The database server puts the selected query plan for each SQL statement into an execution plan for the SPL routine.

Optimization Levels

The current optimization level set in an SPL routine affects how the SPL routine is optimized.

The algorithm that a SET OPTIMIZATION HIGH statement invokes is a sophisticated, cost-based strategy that examines all reasonable query plans and selects the best overall alternative. For large joins, this algorithm can incur more overhead than desired. In extreme cases, you can run out of memory.

The alternative algorithm that a SET OPTIMIZATION LOW statement invokes eliminates unlikely join strategies during the early stages, which reduces the time and resources spent during optimization. However, when you specify a low level of optimization, the optimal strategy might not be selected because it was eliminated from consideration during early stages of the algorithm.

For SPL routines that remain unchanged or change only slightly, you might want to set the SET OPTIMIZATION statement to HIGH when you create the routine. This optimization level stores the best query plans for the routine. Then set optimization to LOW before you execute the routine. The routine then uses the optimal query plans and runs at the more cost-effective rate if reoptimization occurs.

When Optimization Occurs Automatically

When you create an SPL routine, the database server attempts to optimize the SQL statements within the routine at that time. If the tables cannot be examined at compile time (they might not exist or might not be available), the creation does not fail. In this case, the database server optimizes the SQL statements the first time that the SPL routine executes. The database server stores the optimized execution plan in the sysprocplan system catalog table for use by other processes.

The database server uses the dependency list to keep track of changes that would cause reoptimization the next time that an SPL routine executes. The database server reoptimizes an SQL statement the next time that an SPL routine executes after one of the following situations:

    The UPDATE STATISTICS FOR TABLE statement changes the version number of the specified table in systables.

The database server updates the sysprocplan system catalog table with the reoptimized execution plan.

Updating Statistics for a UDR

The database server stores statistics about the amount and nature of the data in a table in the systables, syscolumns, and sysindices system catalog tables. The statistics that the database server stores include the following information:

The query optimizer uses these statistics to determine the cost of each possible query plan. Run UPDATE STATISTICS to update these values whenever you have made a large number of changes to the table.

If you do not run UPDATE STATISTICS after the size or content of any table changes, no SQL statements within the SPL routine are reoptimized. The next time a routine executes, the database server reoptimizes its execution plan if any objects that are referenced in the procedure have changed.

The various clauses on the UPDATE STATISTICS statement influence re-optimization in the following ways:

    When you specify no clauses, the database server reoptimizes SQL statements in all SPL routines and changes the statistics for all tables.

    When you specify a table name in the FOR TABLE clause, the database server changes the statistics for the specified table.This statement does not reoptimize any SQL statements in SPL routines.

    When you specify the FOR TABLE clause without a table name, the database server changes the statistics for all tables and does not reoptimize any SQL statements in SPL routines.

    When you specify one of the following clauses with a name, the database server reoptimizes SQL statements in only the SPL routine listed:

    When you specify one of these clauses, the database server does not update the statistics in the system catalog tables.

    When you specify one of the following clauses without a name, the database server reoptimizes SQL statements in all SPL routines:

    When you specify one of these clauses, the database server does not update the statistics in the system catalog tables.

The database server updates the sysprocplan system catalog table with the reoptimized execution plan.




Extending INFORMIX-Universal Server: User-Defined Routines, version 9.1
Copyright © 1998, Informix Software, Inc. All rights reserved.