如何获取执行计划
如何oracle的获取执行计划1.获取普通执行计划,效果类似于先执行set autot on exp;然后执行sql。 explan plan for your_sql; select * from table(dbms_xplan.display);2.获取具有outline信息的执行计划,用sqlprofile调优时非常有用,或者用这个执行计划了
如何oracle的获取执行计划 1.获取普通执行计划,效果类似于先执行set autot on exp;然后执行sql。 explan plan for your_sql; select * from table(dbms_xplan.display); 2.获取具有outline信息的执行计划,用sqlprofile调优时非常有用,或者用这个执行计划了解更多oracle内部的hint explan plan for your_sql; select * from table(dbms_xplan.display(null, null,'advanced -projection')) 3.真实的执行计划,可以看到实际的 Starts(执行次数) | E-Rows(估算的返回行数) | A-Rows(实际的返回行数) ALTER SESSION SET STATISTICS_LEVEL=ALL; execute your_sql; SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(NULL,NULL,'ALLSTATS LAST')) 那么这3中获取执行计划的方式可以写到一个脚本getplan.sql,用的时候非常方便。 --getplan.sql set feedback off timing off ver off pro 'general,outline,starts' pro acc type prompt 'Enter value for plan type:' default 'general' SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(NULL,NULL,'ALLSTATS LAST')) where '&&type'='starts'; select * from table(dbms_xplan.display) where '&&type'='general'; select * from table(dbms_xplan.display(null, null,'advanced -projection')) where '&&type'='outline'; set feedback on timing on ver on undef type 测试如下: SQL> select * from a; ID NAME ---------- ---------- 1 a1 2 a2 3 a3 4 a4 5 a5 SQL> select * from b; ID NAME ---------- ---------- 1 b1 2 b2 --执行计划1:普通执行计划 SQL> explain plan for select a.*,(select name from b where b.id=a.id) from a; Explained. Elapsed: 00:00:00.04 SQL> @getplan 'general,outline,starts' Enter value for plan type: ----这里输入general或回车 PLAN_TABLE_OUTPUT ----------------------------------------------------------------------------------------- Plan hash value: 3653839899 -------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 5 | 100 | 3 (0)| 00:00:01 | |* 1 | TABLE ACCESS FULL| B | 1 | 20 | 3 (0)| 00:00:01 | | 2 | TABLE ACCESS FULL| A | 5 | 100 | 3 (0)| 00:00:01 | -------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("B"."ID"=:B1) Note ----- - dynamic sampling used for this statement --执行计划2:outline执行计划 SQL> explain plan for select a.*,(select name from b where b.id=a.id) from a; Explained. Elapsed: 00:00:00.01 SQL> @getplan 'general,outline,starts' Enter value for plan type:outline --这里输入outline PLAN_TABLE_OUTPUT --------------------------------------------------------------------------------------- Plan hash value: 3653839899 -------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 5 | 100 | 3 (0)| 00:00:01 | |* 1 | TABLE ACCESS FULL| B | 1 | 20 | 3 (0)| 00:00:01 | | 2 | TABLE ACCESS FULL| A | 5 | 100 | 3 (0)| 00:00:01 | -------------------------------------------------------------------------- Query Block Name / Object Alias (identified by operation id): ------------------------------------------------------------- 1 - SEL$2 / B@SEL$2 2 - SEL$1 / A@SEL$1 Outline Data ------------- /*+ BEGIN_OUTLINE_DATA FULL(@"SEL$2" "B"@"SEL$2") FULL(@"SEL$1" "A"@"SEL$1") OUTLINE_LEAF(@"SEL$1") OUTLINE_LEAF(@"SEL$2") ALL_ROWS OPTIMIZER_FEATURES_ENABLE('10.2.0.4') IGNORE_OPTIM_EMBEDDED_HINTS END_OUTLINE_DATA */ Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("B"."ID"=:B1) Note ----- - dynamic sampling used for this statement --执行计划3:real执行计划 SQL> set serveroutput off SQL> ALTER SESSION SET STATISTICS_LEVEL=ALL; Session altered. Elapsed: 00:00:00.00 SQL> select a.*,(select name from b where b.id=a.id) from a; ID NAME (SELECTNAM ---------- ---------- ---------- 1 a1 b1 2 a2 b2 3 a3 4 a4 5 a5 5 rows selected. Elapsed: 00:00:00.03 SQL> @getplan 'general,outline,starts' Enter value for plan type:starts --这里输入starts PLAN_TABLE_OUTPUT ---------------------------------------------------------------------------------------------- SQL_ID 8rv825dykpx1m, child number 0 ------------------------------------- select a.*,(select name from b where b.id=a.id) from a Plan hash value: 3653839899 ------------------------------------------------------------------------------------ | Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | ------------------------------------------------------------------------------------ |* 1 | TABLE ACCESS FULL| B | 5 | 1 | 2 |00:00:00.01 | 35 | | 2 | TABLE ACCESS FULL| A | 1 | 5 | 5 |00:00:00.01 | 8 | ------------------------------------------------------------------------------------ Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("B"."ID"=:B1) Note ----- - dynamic sampling used for this statement --注意: --第3种执行计划不能多次获取,只能执行1次,获取一次,否则会获取不到 下面再次获取一下试试: SQL> @getplan 'general,outline,starts' Enter value for plan type:starts PLAN_TABLE_OUTPUT ----------------------------------------------------------------------------------------------- SQL_ID dvp8nn63wuhs8, child number 0 ------------------------------------- select * from table(dbms_xplan.display(null, null,'advanced -projection')) where 'starts'='outline' Plan hash value: 3440229843 ------------------------------------------------------------------------------------- | Id | Operation | Name | Starts | A-Rows | A-Time | ------------------------------------------------------------------------------------- |* 1 | FILTER | | 1 | 0 |00:00:00.01 | | 2 | COLLECTION ITERATOR PICKLER FETCH| DISPLAY | 0 | 0 |00:00:00.01 | --第二次无法获取真实的执行计划 ------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter(NULL IS NOT NULL) Note ----- - rule based optimizer used (consider using cbo) --第3种执行计划要关掉set serveroutput off,否则也不能获取执行计划。 测试如下: 这里和上面的测试是同一个会话,所以没有再执行ALTER SESSION SET STATISTICS_LEVEL=ALL;了。 SQL> set serveroutput on SQL> select a.*,(select name from b where b.id=a.id) from a; ID NAME (SELECTNAM ---------- ---------- ---------- 1 a1 b1 2 a2 b2 3 a3 4 a4 5 a5 5 rows selected. Elapsed: 00:00:00.03 SQL> @getplan 'general,outline,starts' Enter value for plan type:starts PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------- SQL_ID 9babjv8yq8ru3, child number 0 BEGIN DBMS_OUTPUT.GET_LINES(:LINES, :NUMLINES); END; --也无法获取真实的执行计划 NOTE: cannot fetch plan for SQL_ID: 9babjv8yq8ru3, CHILD_NUMBER: 0 Please verify value of SQL_ID and CHILD_NUMBER; It could also be that the plan is no longer in cursor cache (check v$sql_plan)

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node

When Oracle log files are full, the following solutions can be adopted: 1) Clean old log files; 2) Increase the log file size; 3) Increase the log file group; 4) Set up automatic log management; 5) Reinitialize the database. Before implementing any solution, it is recommended to back up the database to prevent data loss.

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

SQL statements can be created and executed based on runtime input by using Oracle's dynamic SQL. The steps include: preparing an empty string variable to store dynamically generated SQL statements. Use the EXECUTE IMMEDIATE or PREPARE statement to compile and execute dynamic SQL statements. Use bind variable to pass user input or other dynamic values to dynamic SQL. Use EXECUTE IMMEDIATE or EXECUTE to execute dynamic SQL statements.
