Home  >  Article  >  Database  >  Summarize Oracle query execution plan

Summarize Oracle query execution plan

WBOY
WBOYforward
2022-06-08 17:25:232112browse

This article brings you relevant knowledge about Oracle, which mainly introduces the relevant content about query execution plan. It is the specific steps and process of executing SQL statements in the database. Let’s take a look. Take a look, hope it helps everyone.

Summarize Oracle query execution plan

Recommended tutorial: "Oracle Video Tutorial"

Execution Plan (Execution Plan) is also called Query Plan (Query Plan), which is the specific steps and process for the database to execute SQL statements. The execution plan of a SQL query statement mainly includes:

  • How to access the table. The database accesses data in the table through indexes or full table scans.

  • How to join multiple tables. What connection algorithm is used by the database to connect tables, including the sequential access sequence of multiple tables.

  • How to implement operations such as grouping, aggregation and sorting.

Although different databases adopt different implementation methods for the execution process of SQL queries, a query statement generally needs to be processed by the analyzer, optimizer and executor and return the final result. At the same time, various caches may also be used to improve access performance.

Simply put, a query statement starts from the submission of the client until the server returns the final result. The entire process is roughly as shown in the figure.

First, the client submits the SQL statement. Before this, the client must connect to the database server. The connector in the figure is the component responsible for establishing and managing client connections.

Then, the analyzer (parser) parses the various components of the SQL statement, performs syntax analysis, and checks whether the syntax of the SQL statement conforms to the specification.

For example, the FROM keyword in the following statement is incorrectly written as FORM:

In this case, all database management systems will return a syntax mistake.

The optimizer then uses the statistical information collected by the database to determine the best way to execute the SQL statement. For example, whether to access a single table through an index or a full table scan, what order to use to connect multiple tables, how to sort data, etc.

The optimizer is a key component that determines query performance, and the statistical information of the database is the basis for the optimizer's judgment.

Finally, the executor calls the corresponding execution module to obtain the data according to the optimized execution plan, and returns the result to the client.

How to view the execution plan

Method 1: Statement view

In the Oracle database, we can also use the EXPLAIN PLAN FOR command to generate an execution plan , but two commands need to be executed:

EXPLAIN PLAN FOR

SELECT * FROM  T_USER1 t where t.user_name = 'Admin';

SELECT * FROM  TABLE(dbms_xplan.display);

Use the EXPLAIN PLAN FOR command to generate an execution plan, store it in the system table PLAN_TABLE, and then display the generated execution plan through a query statement execution plan.

Where dbms_xplan.display is an Oracle system function. The returned results show that the statement finds data through 'SYS_C0016771' index range scan in Oracle.

Method 2: Use tools to view

In the commonly used Oracle database development tool PL/SQL, select a SQL script, Press the F5 key to automatically display the execution plan information of the script, which is the same as the result queried in method 1.

Execution process analysis

In the Oracle database, we can query the index and related field information through the system tables user_indexes and user_ind_columns.

SELECT * FROM  user_indexes;

SELECT * FROM  user_ind_columns;

Recommended tutorial: "Oracle Video Tutorial"

The above is the detailed content of Summarize Oracle query execution plan. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete