Oracle7 Server Concepts

Contents Index Home Previous Next

Advanced Dependency Management Topics

The previous section described conceptually the dependency management mechanisms of Oracle. The following sections offer additional information about Oracle's automatic dependency management features. For information on forcing the recompilation of an invalid view or program unit, see the Oracle7 Server Application Developer's Guide. If you are using Trusted Oracle, also see the Trusted Oracle7 Server Administrator's Guide.

Dependency Management and Non-Existent Schema Objects

When a dependent object is created, Oracle attempts to resolve all references by first searching in the current schema. If a referenced object is not found in the current schema, Oracle attempts to resolve the reference by searching for a private synonym in the same schema. If a private synonym is not found, Oracle moves on, looking for a public synonym. If a public synonym is not found, Oracle searches for a schema name that matches the first portion of the object name. If a matching schema name is found, Oracle attempts to find the object in that schema. If no schema is found, an error is returned.

Because of how Oracle resolves references, it is possible for an object to depend on the non-existence of other objects. This occurs when the dependent object uses a reference that would be interpreted differently were another object present. For example, assume the following:

		CREATE VIEW dept_salaries AS 
		   SELECT deptno, MIN(sal), AVG(sal), MAX(sal) FROM emp 
		   GROUP BY deptno 
		   ORDER BY deptno;

When JWARD creates the DEPT_SALARIES view, the reference to EMP is resolved by first looking for JWARD.EMP as a table, view, or private synonym, none of which is found, and then as a public synonym named EMP, which is found. As a result, Oracle notes that JWARD.DEPT_SALARIES depends on the non-existence of JWARD.EMP and on the existence of PUBLIC.EMP.

Now assume that JWARD decides to create a new view named EMP in his schema using the following statement:

CREATE VIEW emp AS 
	SELECT empno, ename, mgr, deptno 
	FROM company.emp; 

Note: Notice that JWARD.EMP does not have the same structure as COMPANY.EMP.

As it attempts to resolve references in object definitions, Oracle internally makes note of dependencies that the new dependent object has on "non-existent" objects -- objects that, if they existed, would change the interpretation of the object's definition. Such dependencies must be noted in case a non-existent object is later created. If a non-existent object is created, all dependent objects must be invalidated so that dependent objects can be recompiled and verified.

Therefore, in the example above, as JWARD.EMP is created, JWARD.DEPT_SALARIES is invalidated because it depends on JWARD.EMP. Then when JWARD.DEPT_SALARIES is used, Oracle attempts to recompile the view. As Oracle resolves the reference to EMP, it finds JWARD.EMP (PUBLIC.EMP is no longer the referenced object). Because JWARD.EMP does not have a SAL column, Oracle finds errors when replacing the view, leaving it invalid.

In summary, dependencies on non-existent objects checked during object resolution must be managed in case the non-existent object is later created.

Shared SQL Dependency Management

In addition to managing the dependencies among schema objects, Oracle also manages the dependencies of each shared SQL area in the shared pool. If a table, view, synonym, or sequence is created, altered, or dropped, or a procedure or package specification is recompiled, all dependent shared SQL areas are invalidated. At a subsequent execution of the cursor that corresponds to an invalidated shared SQL area, Oracle reparses the SQL statement to regenerate the shared SQL area.

Package Invalidations and Session State

Each session that references a package construct has its own instance of the corresponding package, including a persistent state of any public and private variables, cursors, and constants. All of a session's package instantiations (including state) can be lost if any of the session's instantiated packages (specification or body) are subsequently invalidated and recompiled.

Local and Remote Dependency Management

Tracking dependencies and completing necessary recompilations are important tasks automatically performed by Oracle. In the simplest case, dependencies must be managed among the objects in a single database (local dependency management). For example, a statement in a procedure can reference a table in the same database. In more complex systems, Oracle must manage the dependencies in distributed environments across a network (remote dependency management). For example, an Oracle Forms trigger can depend on a schema object in the database. In a distributed database, a local view's defining query can reference a remote table.

Managing Local Dependencies

Oracle manages all local dependency checking using the database's internal "depends-on" table, which keeps track of each object's dependent objects. When a referenced object is modified, Oracle uses the depends-on table to identify dependent objects, which are then invalidated. For example, assume that there is a stored procedure UPDATE_SAL that references the table JWARD.EMP. If the definition of the table is altered in any way, the status of every object that references JWARD.EMP is changed to INVALID, including the stored procedure UPDATE_SAL. This implies that the procedure cannot be executed until the procedure has been recompiled and is valid. Similarly, when a DML privilege is revoked from a user, every dependent object in the user's schema is invalidated. However, an object that is invalid because authorization was revoked can be revalidated by "reauthorization", which incurs less overhead than a full recompilation.

Managing Remote Dependencies

Application-to-database and distributed database dependencies must also be considered. For example, an Oracle Forms application can contain a trigger that references a table, or a local stored procedure can call a remote procedure in a distributed database system. The database system must account for dependencies among such objects. Oracle manages remote dependencies using different mechanisms, depending on the objects involved.

Dependencies Among Local and Remote Database Procedures Dependencies among stored procedures (including functions, packages, and triggers) in a distributed database system are managed using timestamp checking. For example, when a procedure is compiled, such as during creation or subsequent replacement, its timestamp (the time it is created, altered, or replaced) is recorded in the data dictionary. Additionally, the compiled version of the procedure includes information (such as schema, package name, procedure name, and timestamp) for each remote procedure it references.

When a dependent procedure is used, Oracle compares the remote timestamps recorded at compile time with the current timestamps of the remotely referenced procedures. Depending on the result of this comparison, two situations can occur:

Actual timestamp comparison occurs when a statement in the body of a local procedure executes a remote procedure; only at this moment are the timestamps compared via the distributed database's communications link. Therefore, all statements in a local procedure, previous to an invalid procedure call, might execute successfully, while statements subsequent to an invalid procedure call do not execute at all (compilation is required). However, any DML statements executed before the invalid procedure call are rolled back.

Dependencies Among Other Remote Schema Objects Dependencies among remote schema objects other than local procedure-to-remote procedure dependencies are not managed by Oracle.

For example, assume that a local view is created and defined by a query that references a remote table. Also assume that a local procedure includes a SQL statement that references the same remote table. Later, the definition of the table is altered.

As a result, the local view and procedure are never invalidated, even if the view or procedure is used after the table is altered, and even if the view or procedure now returns errors when used (in this case, the view or procedure must be altered manually so errors are not returned). Lack of dependency management is preferable in such cases to avoid unnecessary recompilations of dependent objects.

Dependencies of Applications Code in database applications can reference objects in the connected database; for example, OCI, Precompiler, and SQL*Module applications can submit anonymous PL/SQL blocks, and triggers in Oracle Forms applications can reference a schema object.

Such applications are dependent on the schema objects they reference. Dependency management techniques vary, depending on the development environment. Refer to the appropriate manuals for your application development tools and your operating system for more information about managing the remote dependencies within database applications.


Contents Index Home Previous Next