SQL Programming Manual for Pascal
Program Compilation and Execution
HP NonStop SQL Programming Manual for Pascal—528614-001
5-26
Understanding the Run-Time Timestamp Check
recompile the statement. The SQL compiler then determines the best alternative
access path (if such a path exists) to execute the statement. Only the affected
statement is automatically recompiled when the access path becomes unavailable.
Attempted Execution of an Uncompiled SQL Statement
If the SQL executor encounters an uncompiled SQL statement, it invokes the SQL
compiler to compile the statement. A program can contain uncompiled SQL statements
if:
•
A table or view used by an SQL statement did not exist during explicit SQL
compilation.
•
A description of a table, view, or index needed for the execution plan of an SQL
statement was not available during explicit SQL compilation.
•
The program was explicitly compiled with the FORCE option and an SQL
statement had errors.
Understanding the Run-Time Timestamp Check
A program file and all SQL database objects (such as tables, protection views, and
indexes) have unique timestamps. The SQL executor checks each timestamp to
ensure that a program file uses the current definition of an object for its execution plan.
For example, consider the following case:
1. Program PROGRAMA, which is SQL valid when it runs, uses table TABLEA.
2. After PROGRAMA starts executing, a database administrator adds a new column
to TABLEA using the ALTER TABLE statement. The execution plans in
PROGRAMA that were generated from the old TABLEA definition during explicit
SQL compilation time are no longer valid.
3. When the first SQL statement that uses TABLEA executes, the SQL executor
opens TABLEA and checks the timestamp to ensure that PROGRAMA has a valid
definition for TABLEA. The SQL executor compares the TABLEA timestamp with
the PROGRAMA timestamp. The TABLEA timestamp is more recent than the
PROGRAMA timestamp.
4. The SQL executor invokes the SQL compiler to recompile the statement using the
current TABLEA definition. Recompilation does not modify PROGRAMA on disk or
record dependencies in the catalog; it only changes the copy of PROGRAMA in
memory.
If TABLEA is open when you execute the ALTER TABLE statement, the system
closes the table. The next time the SQL statement is executed, the SQL executor
reopens TABLEA, which forces the timestamp check and the statement to be
recompiled.
Figure 5-7 shows this run-time object definition check.