Translate into your own language

Thursday, April 28, 2016

Step by step --- How SQL query gets executed in Oracle database

All the SQL query goes through the below 4 phases while in execution:

1. Parsing

2. Binding

3. Execute

4. Fetch

Parsing:  During the parse phase, Oracle checks whether the statement is ok in terms of syntactically and symentically.

Syntax checking: It checks for all keywords the keywords are present in the statement "select . . . from", etc . .

Symentic checking: Oracle check the object names in the statement against the dictionary - Are all table names are spelled correctly also checks for the mentioned objects exist and are accessible, etc..etc...

Then it creates the execution plan for the statement.  Parsing does not return an error if the statement is not syntactically correct. Once the execution plan is created, it is stored in the library cache (part of the shared_pool_size) to facilitate re-execution.  There are two types of parses, soft parse and hard parse.

Bind phase: Once the plan is syntactically created, Oracle gathers the parameters from the client program needed for the execution. It makes the addresses of the program variables known to Oracle.

Execute Phase - During the execute phase, Oracle executes the statement, reports any possible errors, and if everything is as it should be, forms the result set. Unless the SQL statement being executed is a query, this is the last step of the execution.

Fetch Phase - During the fetch phase, Oracle brings the rows of the result to the program and makes them available to the user.




No comments:

Post a Comment