How Oracle Decides To Share
Oracle uses a complex algorithm to decide whether a cursor that is about to be executed may reuse an already compiled version from the shared pool. Here is a simplified presentation of that algorithm:
Calculate the sum of the ASCII values of all characters in the cursor (excluding bind variables). For example, the total ASCII value of the following cursor is 2556:
SELECT order_date FROM orders
This is calculated as ASCII(S) + ASCII(E) + ASCII(L)...or 83 + 69 + 76 and so on.
Apply a hash algorithm to the ASCII total.
Peruse the shared pool for a cursor with the same hash value.
If one is found, it may be reused.
Tip
Note that I say “may” be reused. Most of the time, a matching ASCII hash is enough to allow reuse, but not always, as I’ll explain later in this section.
In item 1, I state that the ASCII value of every character is used. Thus, something as low level as mixing uppercase and lowercase has to be considered when planning for cursor reuse. Consider these two cursors run directly in SQL*Plus.
SQL>SELECT order_date
2FROM orders
3WHERE order_number = 11;
ORDER_DAT --------- 03-MAY-05 SQL>SELECT order_date
2FROM orders
3WHERE order_numbeR = 11;
ORDER_DAT --------- 03-MAY-05
The human eye can see that both of these examples do exactly the same thing—select the order date for order number 11. The only difference is that an uppercase R was used in the second one. That’s just enough for Oracle to consider them different, though, so two cursors wind up in ...
Get Oracle PL/SQL for DBAs now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.