我有一个包含 400,000 条记录的 Oracle 表,并且 DATA_NAME 和 SEQU_ID 字段有索引。今天我们还重建了该表的索引。但是,执行以下查询需要 2 到 3 分钟。谁能提出解决方案吗?
Select distinct SEQU_ID,DATA_VALUE from DATA_MYSUBMISSION_DETAILS where DATA_NAME ='PLAN_ID';
Initializing connection...
Connection ready. Took 2.405 seconds.
Statement completed successfully. (21832 results). 2 minutes, 12 seconds. (Line 1).
Finished. Total time: 2 minutes, 15 seconds.
表结构 => DESC DATA_MYSUBMISSION_DETAILS
Name Null? Type
----------------- -------- --------------
RECORD_ID NOT NULL VARCHAR2(34)
SEQU_ID NOT NULL VARCHAR2(34)
DATA_NAME NOT NULL VARCHAR2(100)
DATA_VALUE NVARCHAR2(512)
DATA_INDEX NOT NULL NUMBER(18)
RELATED_RECORD_ID VARCHAR2(34)
CREATED_BY VARCHAR2(34)
CREATED_TS TIMESTAMP(6)
MODIFIED_BY VARCHAR2(34)
MODIFIED_TS TIMESTAMP(6)
INDEXS => 从所有索引中选择索引名称,其中表名称 = 'DATA_MYSUBMISSION_DETAILS';
"INDEX_NAME"
"IDXDATADETSEQID"
"IDXDATADETPROPVAL"
"INDXDATADETPROPNAME"
"DATA_MYSUBMISSION_DETAILS_PK"
1. set autotrace trace explain
set autotrace trace explain;
--run your select
--check the plan using index or not.
--turn off autotrace
set autotrace off;
2. use dbms_session to trace the sql.
alter session set tracefile_identifier='xyz';
exec dbms_session.session_trace_enable();
--run your select
exec dbms_session.session_trace_disable();
3. tkprof
cd $ORACLE_BASE/diag/rdbms/orcl/orcl/trace
tkprof *xyz.trc a.out
check a.out the details of timing.
HR@asp>set autotrace trace explain
HR@asp>select * from employees where employee_id=100;
Execution Plan
----------------------------------------------------------
Plan hash value: 1833546154
--------------------------------------------------------------------------------
-------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU
)| Time |
--------------------------------------------------------------------------------
-------------
| 0 | SELECT STATEMENT | | 1 | 69 | 1 (0
)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| EMPLOYEES | 1 | 69 | 1 (0
)| 00:00:01 |
|* 2 | INDEX UNIQUE SCAN | EMP_EMP_ID_PK | 1 | | 0 (0
)| 00:00:01 |
--------------------------------------------------------------------------------
-------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("EMPLOYEE_ID"=100)
HR@asp>set autotrace off;
HR@asp>exec dbms_session.session_trace_enable();
PL/SQL procedure successfully completed.
HR@asp>alter session set tracefile_identifier='xyz';
Session altered.
HR@asp>select * from employees where employee_id=100;
EMPLOYEE_ID FIRST_NAME LAST_NAME
----------- -------------------- -------------------------
EMAIL PHONE_NUMBER HIRE_DATE JOB_ID
------------------------- -------------------- ------------------ ----------
SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- -------------- ---------- -------------
100 Steven King
SKING 515.123.4567 17-JUN-03 AD_PRES
24000 90
HR@asp>exec dbms_session.session_trace_disable();
PL/SQL procedure successfully completed.
HR@asp>exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@hol trace]$ ls -lt|grep xyz
-rw-r----- 1 oracle dba 4068 Mar 28 19:25 asp_ora_30627_xyz.trc
-rw-r----- 1 oracle dba 96 Mar 28 19:25 asp_ora_30627_xyz.trm
-rw-r----- 1 oracle dba 5612 Mar 28 19:14 asp_ora_29418_xyz.trc
-rw-r----- 1 oracle dba 162 Mar 28 19:14 asp_ora_29418_xyz.trm
[oracle@hol trace]$ tkprof asp_ora_30627_xyz.trc c.out
TKPROF: Release 11.2.0.4.0 - Development on Thu Mar 28 19:26:26 2024
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
[oracle@hol trace]$ ls -l c.out
-rw-r--r-- 1 oracle dba 6623 Mar 28 19:26 c.out