Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Programming PL SQL.doc
Скачиваний:
3
Добавлен:
01.07.2025
Размер:
5 Мб
Скачать
☆

20.4 The Processing of Server-Side pl/sql

To restateand amplify some of the main points covered so far, I'd like to enumerate the steps Oracle takes when you use a program such as SQL*Plus to submit PL/SQL to the server.

20.4.1 Compiling an Anonymous Block

Here are the major steps involved in compiling an anonymous block.

  1. The PL/SQL compiler parses the code to check its syntax. If the code does not pass the syntax check, stop here and return a compile error to the calling environment.

  2. The Oracle server determines whether valid parsed and executable versions of this block already exist in the library cache. It does this by computing the hash value of the text of the block, then by doing textual searches of potential matches using something like a memcmp, followed by a series of checks to make sure that the server environment hasn't changed. If it is OK to re-execute the block, skip to Step 1 of execution.

  3. If the block is not already in the library cache, Oracle passes the block to the PL/SQL compiler.

  4. The PL/SQL compiler resolves the names of PL/SQL identifiers, but sends any embedded SQL statements off to the SQL parser.

  5. The SQL parser does its own syntax check, name resolution, and semantics checks, but calls back to PL/SQL to resolve any remaining identifiers (such as bind variables).

  6. At the time of compilation, Oracle checks to make sure that the user who is compiling the code has privileges to (a) execute any referenced programs, and (b) perform the requested operations on SQL statements on any data structures, such as tables. This is true even when compiling invoker rights programs.

  7. Automatic recompilation of invalid referenced objects (even remote procedures) occurs when the PL/SQL compiler encounters the reference to the objects (as described in the earlier section Section 20.2).

  8. The compiler reads the DIANA of any referenced objects (including remote procedures) in order to validate that the call matches their signature. If the DIANA for a referenced object is not already present in the data dictionary, then it is generated at this point and stored persistently.

  9. If compilation succeeds, Oracle creates bytecode and loads it into library cache. The DIANA for the anonymous block is discarded.

20.4.2 Compiling a Stored Object

There are some variations on the compilation process for stored objects (package, package body, procedure, function, trigger, type, type body):

  1. Before recompiling an existing program, Oracle determines whether it is already running and waits until the run completes before recompiling. Steve Adams points out that this is "a (S)hare mode KGL pin held during execution, and compilation needs to take that pin in e(X)clusive mode." Watch out, because these pins can cause deadlocks or long-term waits.

  2. If the object being compiled is a package with state information, Oracle will tear down this package state and possibly the state of other packages in session memory.

  3. When you issue a DDL statement such as CREATE OR REPLACE PROCEDURE, Oracle saves the source code in the SOURCE$ table even if compilation ultimately fails. In addition, for each stored program, Oracle also stores the current compiler flags in the SETTINGS$ table.

  4. Successful compilation causes DIANA to be stored in the database for everything except package bodies and type bodies (even for natively compiled programs).

  5. Once the DIANA exists for a stored program, Oracle also saves information about the objects on which the program depends in the DEPENDENCY$ table.

  6. If the program uses any remote procedures, at compilation time Oracle retrieves the timestamp and the DIANA-based "signature" of the remote object and saves it with the compiled code of the local program

  7. If the session or database flags are set for native compilation, the PL/SQL compiler performs the usual syntax and semantic analysis. An internal translator then converts the PL/SQL into C and invokes the operating system's C compiler to generate a shared object file.

  8. If compiling a stored object fails, Oracle makes an entry in the ERROR$ table, which users may see via the USER_ERRORS view. Successful compilation removes any previous error information from the ERROR$ table.

  9. As with anonymous blocks, successful compilation loads all forms of compiled code into the library cache; with stored programs, Oracle also saves the DIANA, bytecode, and any debug data in the data dictionary.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]