RE: When we give SELECT * FROM EMP; How does oracle re...
Oracle first parsed that SQL then make a execution plan for that which will take minimum CPU I/O and Memory and internally it's declare a implicit cursor which will return all the record from that particular table EMP by using set theory of cartesdian product.
RE: When we give SELECT * FROM EMP; How does oracle respond:
Select command executes and retrieves all of the coulumns values are in table EMP. means you will see columns name and related data for every column from the table EMP
RE: When we give SELECT * FROM EMP; How does oracle respond:
Following this as an example let us see how the select execution happens in database.
SELECT ename sal job FROM emp
WHERE job 'clerk'
ORDER BY sal;
How does the query execution occur?
SQL*plus checks the syntax on client side.
If syntax is correct the query is stamped as a valid SQL statement and encrypted into OCI (Oracle Call Interface) packets and sent via LAN using TCP to the server.
Once the packets reach the server the server process will rebuild the query and again perform a syntax check on server side.
Then if syntax is correct SP will continue execution of the query.
The SP will go to the library cache. The L.C. will keep the recently executed SQL statements along with their execution plan.
In the library cache the server process will search from the MRU (Most Recently Used) end to the LRU (Least Recently Used) end for a match for the SQL statement. It does this by using a hash algorithm that returns a hash value. If the hash value of the query we have written matches with that of the query in L.C. Then SP need not generate an execution plan (soft parsing) but if no match is found then SP has to proceed with the generation of execution plan (hard parsing).
Parsing is the process undertaken by Oracle to generate an execution plan.
The first step in parsing involves performing a semantic check. This is nothing but check for the existence of the obj and its structure in the database.
This check is done by SP in the data dictionary cache. Here SP will ask for the definition of the object if already available within the DDC SP will process the check. If not available then SP will retrieve the required information from the system tablespace.
After this SP will approach the optimizer who will read the SQL statement and generate the execution plan of the query.
After generation of the e-plan's the SP will pick the best e-plan and go to the L.C.
SP will keep the e-plan in the L.C. Along with the original SQL text.
At this point in time the parsing ends and the execution of the SQL statement will begin.
SP will then go to the database cache and checks whether the data required by the query is already available or not in the cache.
If available that data can be returned to the client else it brings the data from the database files.
If sorting and filtering is required by the query then the PGA is utilized along with the temporary tablespace for performing sort run.
After sort run the data is returned to the client and SQL*plus client will show the data to the users.