Oracle cursor Study Notes

@
Looking at the recent "sql oracle-based optimization," a book, and made some notes

A, oracle database cache

1.1 Introduction to library cache

Introduction oracle cursor (cursor) before first, tell us about the oracle of the library cache, Oracle library cache (Library Cache) is an area of ​​memory in the SGA, its main role is to cache just executed SQL statements or PL / SQL statements (such as stored procedures, functions, triggers, packages) corresponding implementation plan, the parse tree, Pcode, Mcode and other objects, SGA knowledge before I can refer to notes: https: //blog.csdn.net/u014427391/article/details/ 89,846,006

1.2 Related Concepts

  • Library cache objects: caching an object in the library cache is called an object library cache (Library Cache Object), they are in the library cache object library cache object handle (Library Cache Object Handle) structure stored in the library cache

  • Library cache object handle: the so-called library cache object handle is actually a complex structure of a C language definition, the library cache object handle to the hash table (Hash table) is stored in the library cache

1.3, the library cache structure

Oracle library cache configuration, FIG from "Oracle-based SQL optimization" book:
Figure from the "Oracle SQL-based optimization," a book
library cache is a set Hash Buckets composed of the same library cache object handle hash value Hash Buckets inside the store, and the Hash Buckets different libraries cache object handle is a pointer connected together, so as to constitute a list of object handles library cache

1.4, sql implementation process Introduction

Therefore, the implementation of sql, sql text will be hash calculation to obtain the object's hash value, then take a hash value, go Hash Buckets traverse the cache object handle in the list, find the corresponding cache object handle, then you can get the cached object handles sql in the corresponding implementation plan, parse trees and other objects, so when the same execution sql second performance will be faster, because there is no analytical obtain the execution plan, parse trees and other objects, if you can not find the library cache object handle it need to resolve, this process is resolved too easily lead to hard to resolve problems

Hard analysis: is the target in the implementation of Oracle SQL, you can not find in the library cache reuse parse tree and execution plan, and had to start from scratch and build process to resolve the destination SQL respective Parent Cursor and the Child Cursor.

Soft Analysis: Oracle refers to the target in the implementation of SQL, found in the Library Cache in a match of Parent Cursor and Child Cursor, the parse tree and execution plan and stored in the Child Cursor directly take over reuse without parsing from the beginning of the process .

二、oracle cursor

2.1, cursor classification

The cursor is actually oracle database cache object, Oracle in the cursor into two, one is shared cursor, the other is a session cursor

2.2、shared cursor

shared cursor storage target of sql SQL text, parse tree, bind variable type and length of use of the sql, as well as the SQL execution plan and other information

shared cursor oracle is subdivided into parent cursor and child cursor, we can separately query views v$SQLAREAand v$SQLto obtain information stored in the cache parent cursor and the child cursor

In fact, parent cursor and child cursor structure is similar, parsing sql time, sql text is stored in the cache object handle of the parent cursor attribute name, whereas the execution plan and parse tree is in the property heap6 child cursor in the then parent storage cursor and child cursor is how related? Stored in the property heap0 parent cursor in the address child cursor cache object handle, then you can know all the child cursor belong to the parent cursor

2.3、session cursor

Cursor session is used to resolve the current session and the SQL execution, a configuration session Cursor definition language is C, it is stored in a hash table structure, but is stored in the PGA

  • session and the session cursor is corresponding, different session the session cursor can not be shared
  • session cursor is a life cycle, in the course of each session cursor will experience at least once Bind, a Execute, Fetch and Close or more of the process

oracle for the first time parsing and executing sql, will generate a new session cursor and a pair of shared cursor (parent cursor and child cursor), and one of the shared cursor will store all the session can be shared, reusable content (such as the implementation plan, parse trees, etc.), and the session cursor will experience once open, or a multiple stage parse, bind, execute, fetch and close the

2.4, sql execution

In summary, oracle sql execution process will go inside to find session cursor, you can find a parent cursor can be found through association, if not found, it is necessary to regenerate the session cursor and a pair of shared cursor (parent cursor and child cursor) , if you can not find the child cursor will regenerate the session cursor and child cursor

Guess you like

Origin www.cnblogs.com/mzq123/p/11402697.html