Index usage making SQL slower.
Hello,
While working on a performance tuning activity on Oracle 10.2.0.4 on Solaris 10, I encountered a problem wherein one of our DBA's suggested indexing 2 columns of a certain table. One of the queries which is being run on that table has a RULE hint, and it is seen to be making use of this newly created index. Before the index was created, this query was running fine and getting completed within 30 mins or so. However after the index is created, it is now taking 12 hours on average to complete. Please note that in both the above cases, the CURSOR_SHARING parameter was set to EXACT. Yes, after the index was created its statistics were computed, and for both the index and the base table statistics were gathered. The query is making use of bind variables and is being run via the SQR engine of PeopleSoft.
Please advice what can be the possible reasons for such delays being caused?
For any information, please let me know and I would provide the same in this forum/
Note for moderators: I could not find the section for Performance tuning, so I am asking this question in the general forum. Apologies.
Thank You,
Prashant.
Index scans are not always faster.
Full table scans are not always bad.
I doubt that the RULE hint is necessary.
In general, [url http://www.centrexcc.com/Tuning%20by%20Cardinality%20Feedback.pdf]the CBO does an excellent job of finding the best access plan for a given sql provided it is able to accurately estimate the cardinalities of the row sources in the plan.
See advice and information required in the template tuning threads:
[url https://forums.oracle.com/forums/thread.jspa?threadID=863295]How to post a sql tuning request
[url https://forums.oracle.com/forums/thread.jspa?messageID=1812597]When your query takes too long
Similar Messages
-
Index Usage from SQL query in Oracle Forms
Would using LIKE/OR in where clause (of an indexed column) will force the the query to NOT use INDEX. We have these where clause in Oracle Forms Records Group.
Below are two examples...
1. If we have a where clause with LIKE would that NOT use the index?
Example: ColumnName like :block.Column||%
2. How about having an OR clause?
Example: and (ColumnName = :block.column or :block.column is null)
ThanksHi
Answer 1: Where with like clause WOULD use the index.
In this example index on ColumnName
Answer 2: Write better where:
Example: and (:block.column is null or ColumnName = :block.column)
When :block column is null then statement after 'or' is not used. Index will not be used with RBO, i think.
The best way to be sure is to look at explain plan on the original query.
Regards
Kuba -
hi,
I have a procedure which took 15-20 minutes in the past to execute.Suddently it is taking 2 hours.When i examined i came to know that the sql statement is not using one of the index.I dropped the index and created it.The explain plan is generated but still the index is not being used.I forced the index usage by using the index hint
SELECT /*+ INDEX(test_his test_hist_idx )*/ column 1.....
But still it does not use the index.Please suggest me some advice on this?
Thanksuser589320 wrote:
I have a procedure which took 15-20 minutes in the past to execute.Suddently it is taking 2 hours.When i examined i came to know that the sql statement is not using one of the index.I dropped the index and created it.The explain plan is generated but still the index is not being used.I forced the index usage by using the index hint
SELECT /*+ INDEX(test_his test_hist_idx )*/ column 1.....
I think you're going to have to post the entire text of your query if you want an answer, or people will simply be trying to guess what you've done wrong.
Do you also have the full execution plan from before and after the change in performance ?
If you do post the text, and plans, please use the 'code' tags to make the text readable.
p.s. My shot in the dark guess, based on the text you've supplied, is that you've used the table name in the hint, rather than the table alias.
Regards
Jonathan Lewis
http://jonathanlewis.wordpress.com
http://www.jlcomp.demon.co.uk
"The temptation to form premature theories upon insufficient data is the bane of our profession."
Sherlock Holmes (Sir Arthur Conan Doyle) in "The Valley of Fear".
To post code, statspack/AWR report, execution plans or trace files, start and end the section with the tag {noformat}{noformat} (lowercase, curly brackets, no spaces) so that the text appears in fixed format. -
Hi,
there are many queries my one of my packages, which has the SQL as follows:
Update table XYZ
Set Column A = NULL
Where Colum B IS NOT NULL;
Column B has NUMBER datatype.
Due to 'IS NOT NULL' the index (existing for Column B' is not being used in the above query, leading to Full table scan. Is there any ways of forcing teh index to be picked/used by the query?
Thanks,
Rosalinthansk again for response. Checked the % of the data
fetched by this query and it ranges from 20% to 50
%(varies due to teh fact the table data content could
have different set of data depending on the days
transactions done). So for sure index usage would
help.
Additionally this sql(used in multiple places) come
up in the v$longsops output.
so definitely needs tuning.
Any suggestions?That's not really true though if you understand the mechanisms employed for a full table scan vs an index scan / table lookup (by rowid since the table must also be visited).
Here's something good for you to read
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:4433887271030
A full tablescan reads the table using large sequential reads -- many blocks at a time.
Sequential reads are the fastest type of IO you can do on a disk in general.
An index read will do single block, random IO's. These are generally the slowest you can
do.
I would suggest to you that if you have statistics on the table/indexes that are representative of the data, the Optimizer will be smarter than you (most cases, not all).
Message was edited by:
Tubby -
UNUSED EXISTING INDEXES / Index usage
We are using CRM 2007, Netweaver 7.0 with DB2 UDB v9.1 fixpack4 on AIX.
Is there a way to find out UNUSED EXISTING INDEXES for tables ? We have close 12 indexes on the crmd_order_index table and want to find out if some of them can safely deleted. Is there any way to monitor index usage in SAP ? Is there any toold to aid this ?
Pls advise.
thank you
regards
LaxmiLaxmi,
I am not aware of any such tools with DB2 9.1. However, "last_used" columns are being added to various catalog tables in DB2 9.7. Below is an excerpt from a slide presented in the TLU2008A "DB2 LUW V9.7 Cobra u2013 Storage is Charmed" session.
The last reference time of an object will now be maintained in the LASTUSED column of
the corresponding catalog table for the object
u2013 SYSCAT.INDEXES.LASTUSED (prior to V9.7 db2pd u2013tcbstats indexes)
u2013 SYSCAT.TABLES.LASTUSED
u2013 SYSCAT.DATAPARTITIONS.LASTUSED
u2013 SYSCAT.PACKAGE.LASTUSED
The LASTUSED column is of type DATE (default value is 1/1/0001)
Use Cases:
u2013 Detach table partitions that are no longer actively used (esp. when not partitioned by time)
u2013 Determine inactive or infrequently used indexes
u2013 Easily identify tables which are no longer in use
u2013 Get rid of unused packages
The presenter said the code will begin populating these columns in an upcoming fixpack.
Regards,
Rick -
i am having a table in my schema named provider_rate_history
PROVIDER_RATE_HISTORY_ID NOT NULL NUMBER
WORK_ORDER_HISTORY_ID NOT NULL NUMBER
PROVIDER_RATE_TYPE_ID NOT NULL NUMBER
CREATED_BY NOT NULL NUMBER
DATE_CREATED NOT NULL DATE
MODIFIED_BY NUMBER
DATE_MODIFIED DATE
I created an index named provider_rate_type_idx on the provider_rate_type_id column of the table, but when i am using the following query index is used, but if i replace count(*) keyword in the select statement with any of the column name of the table a ful table scan is performed. What could be the reason for this error and how to correct it
select count(*) from provider_rate_history
where rate_type_id=7;
Index is used, if we replace count(*) with any column name of the table index is not used
select work_order_history_id from provider_rate_history
where rate_type_id=7;
Index is not usedHi,
Why count(*) will lead to full table scan?
APC have clearly told reason for not using Index.
Hope this illustration helps to clear the situation.
SQL> create table test111 as select * from all_objects where rownum < 1001;
Table created.
SQL> desc test111
Name Null? Type
OWNER NOT NULL VARCHAR2(30)
OBJECT_NAME NOT NULL VARCHAR2(30)
SUBOBJECT_NAME VARCHAR2(30)
OBJECT_ID NOT NULL NUMBER
DATA_OBJECT_ID NUMBER
OBJECT_TYPE VARCHAR2(19)
CREATED NOT NULL DATE
LAST_DDL_TIME NOT NULL DATE
TIMESTAMP VARCHAR2(19)
STATUS VARCHAR2(7)
TEMPORARY VARCHAR2(1)
GENERATED VARCHAR2(1)
SECONDARY VARCHAR2(1)
SQL> create index test111_indx1 on test111 (object_id);
Index created.
SQL>
SQL> set autotrace on
SQL> select count(1) from test111;
COUNT(1)
1000
Execution Plan
Plan hash value: 1326770390
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 3 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | INDEX FAST FULL SCAN| TEST111_INDX1 | 1000 | 3 (0)| 00:00:01 |
Note
- dynamic sampling used for this statement
Statistics
5 recursive calls
0 db block gets
23 consistent gets
3 physical reads
0 redo size
206 bytes sent via SQL*Net to client
239 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL>
SQL> select count(distinct owner) from test111;
COUNT(DISTINCTOWNER)
3
Execution Plan
Plan hash value: 991123090
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 17 | 5 (0)| 00:00:01 |
| 1 | SORT GROUP BY | | 1 | 17 | | |
| 2 | TABLE ACCESS FULL| TEST111 | 1000 | 17000 | 5 (0)| 00:00:01 |
Note
- dynamic sampling used for this statement
Statistics
27 recursive calls
0 db block gets
33 consistent gets
0 physical reads
0 redo size
233 bytes sent via SQL*Net to client
239 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> -
Error in accessing ResultSet - Descriptor index not valid SQL Exception
Hi
I am trying to execute a procedure in java and try to access the result set, but it is giving out Descriptor index not valid SQL Exception.
While printing the first record the error is thrown the code is as follows. Any help would be appreciated. Thanks in Advance.
1 . The Procedure
CREATE PROCEDURE library.fetchssncursor()
RESULT SETS 1
LANGUAGE SQL
BEGIN
DECLARE c1 CURSOR WITH RETURN FOR
SELECT * FROM VBPLTC.LTCP_DUMMY;
open c1;
END;2. Java Class
public class TestFunction2
public void getPassThruReport()
Connection objConnection=null;
ResultSet rs=null;
CallableStatement callableStatement=null;
try
List returnList=new ArrayList();
DriverManager.registerDriver(new com.ibm.as400.access.AS400JDBCDriver());
objConnection = DriverManager.getConnection("URL","USERID","PWD");
callableStatement = objConnection.prepareCall("{call fetchssncursor() }");
System.out.println("Got Connection "+ objConnection.toString());
callableStatement.execute();
rs = callableStatement.getResultSet();
// callableStatement.executeQuery (); i also tried this
if(rs!=null)
while(rs.next())
System.out.println(rs.getString(1)+","+rs.getString(2)+","+rs.getInt(3)+","+rs.getInt(4));
catch(SQLException e)
System.out.println("SQLException "+e);
catch(Exception e)
System.out.println("Exception "+e);
finally
try
if(rs!=null)
rs.close();
if(objConnection!=null)
objConnection.close();
catch (SQLException e) {
public static void main(String args[])
TestFunction2 obj = new TestFunction2();
obj.getPassThruReport();
}3. Output
Got Connection S101C3DE
shar,Sharath,123456,1 <------------- records
SQLException java.sql.SQLException: Descriptor index not valid.(1574
****************************************http://www-03.ibm.com/servers/eserver/iseries/toolbox/troubleshooting.htm
-
How to analyse Indexes with PL/SQL witch a $ in it's name
Hello there, I'm working on several sniplets of PL/SQL Code. In the end result there should be a PL/SQL Routine which decides which indexes to analyse online.
I just get stopped by some indexes which have the $ in It's name. Our Apllication provider uses uncommon names like ttols.pk_$lock for some of his indexes.
So when this procedure try to analyse the ttols.pk_$lock it gives me errors.
Can someone lend me a hand how I can analyse Indexes with PL/SQL with a $ in it'S name.
CREATE OR REPLACE PROCEDURE TTOOLS_DBA.rebuild_nonpart_idx
AS
BEGIN
FOR idxq IN (SELECT owner AS obj1, index_name AS obj2
FROM dba_indexes
WHERE partitioned = 'NO'
AND owner = 'TTOOLS'
AND index_name NOT LIKE '%$%')
LOOP
DBMS_OUTPUT.put_line ( 'ALTER INDEX '
|| idxq.obj1
|| '.'
|| idxq.obj2
|| ' REBUILD ONLINE COMPUTE STATISTICS;'
EXECUTE IMMEDIATE 'ALTER INDEX '
|| idxq.obj1
|| '.'
|| idxq.obj2
|| ' REBUILD ONLINE COMPUTE STATISTICS';
END LOOP;
END;
Greetings from sdohnhow I can analyse Indexes with PL/SQL with a $ in it'S name.You can try
create or replace procedure ttools_dba.rebuild_nonpart_idx
as
begin
for idxq
in (select owner as obj1, index_name as obj2
from dba_indexes
where partitioned = 'NO'
and owner = 'TTOOLS'
and index_name not like '%$%')
loop
dbms_output.put_line (
'ALTER INDEX ' || idxq.obj1 || '."' || idxq.obj2 || '" REBUILD ONLINE COMPUTE STATISTICS;'
execute immediate 'ALTER INDEX '
|| idxq.obj1
|| '."'
|| idxq.obj2
|| '" REBUILD ONLINE COMPUTE STATISTICS';
end loop;
end;
/but actually I don't think that the $ sign should cause an error.
Can you show us the actual error message?
Also please always mention your db version.
Edited by: michaels2 on Aug 10, 2009 9:45 AM -
Index to Improve SQL Performance
Please provide a link to information about how to use an Index to enhance SQL performance with Oracle 10g database.
user8973820 wrote:
I would like information regarding the use of clustered versus non-clustered indexes.The documentation is your friend :)
[Overview of Indexed Clusters|http://download.oracle.com/docs/cd/E11882_01/server.112/e10713/tablecls.htm#CFABHBAG]
[Indexes and Index-Organized Tables|http://download.oracle.com/docs/cd/E11882_01/server.112/e10713/indexiot.htm#BABHJAJF]
HTH! -
Index Organized Table getting slow over time
Hello,
I recently discovered a problem in our our production environment:
We use an IOT to store search results in the form of primary keys (and additional data). This results in an excessive amount of INSERTs and DELETEs (the application is mainly a research tool). After some time, some statements on the IOT like SELECT COUNT(*) (optimizer using INDEX FAST FULL SCAN) take longer and longer, however the IOT index is used correctly by the optimizer and SELECTs which specify WHERE primk... (optimizer using INDEX RANGE SCAN) are executed with best performance.
It seems that the IOT somehow gets fragmented or unbalanced. Now my question ist, what's would be the best approach against that problem.
Would a daily ALTER TABLE ... MOVE ONLINE; be a good solution for example? Is this common practice with high volatile IOTs in 24x7 production environments?
Are there any better solutions for storing temporary search results?
Looking forward for your comments.
-sdIn addition to above mentioning...
Have you verified the distribution of IOT?
Like "ANALYZE INDEX .... VALIDATE STRUCTURE"? or "DBMS_STATS.GATHER_TABLE_STATS"?
It's natural that your full table scan(index fast full scan) gets slower in case that your IOT is getting bigger.
If you have lots of free leaf nodes, moving index will be beneficial although moving itself should be abvoided on busy time.
You also need to do sql trace and tkprof to measure how much workload your IOT is making. -
SQL slow after upgrading to Oracle Database 10g Enterprise Edition Release
Hi all:
We have recently upgraded our database from Oracle9i Enterprise Edition Release 9.2.0.6.0 to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
After that we found that our some sql getting very slow
for example query with 9i showing result in 4 seconds while in 10g showing result in 28 seconds.
Following is the execution plan of my query in Oracle9i
Operation Object PARTITION_START PARTITION_STOP COST
SELECT STATEMENT () 9458
NESTED LOOPS () 9458
SORT (UNIQUE)
INDEX (RANGE SCAN) BL_EQ_PK_N 2
VIEW () CONTAINER_INFO 2
UNION-ALL (PARTITION)
TABLE ACCESS (BY INDEX ROW SERVICE_EVENTS 1
NESTED LOOPS () 11
NESTED LOOPS () 10
NESTED LOOPS (OUTER) 9
NESTED LOOPS () 8
NESTED LOOPS () 7
NESTED LOOPS () 6
NESTED LOOPS () 5
NESTED LOOPS () 4
NESTED LOOPS (OUT 3
TABLE ACCESS (BY EQUIPMENT_USES 2
INDEX (UNIQUE S EQUSE_PK 1
TABLE ACCESS (BY SHIPPING_LINES 1
INDEX (UNIQUE S LINE_PK
INDEX (UNIQUE SCA EQHT_PK
TABLE ACCESS (BY I EQUIPMENT_TYPES 1
INDEX (UNIQUE SCA EQTP_PK
TABLE ACCESS (BY IN EQUIPMENT_SIZES 1
INDEX (UNIQUE SCAN EQSZ_PK
TABLE ACCESS (BY IND SHIP_VISITS 2
INDEX (RANGE SCAN) SVISIT_UK 1
TABLE ACCESS (BY INDE SHIPS 1
INDEX (UNIQUE SCAN) SHIP_PK
TABLE ACCESS (BY INDEX CARE_VIR_MAP 1
INDEX (UNIQUE SCAN) VIR_VESVOY
TABLE ACCESS (BY INDEX EQUIPMENT 1
INDEX (RANGE SCAN) EQ_EQUSE_FK
INDEX (RANGE SCAN) SEVENTS_EQUSE_FK_N
NESTED LOOPS () 7
NESTED LOOPS () 6
NESTED LOOPS () 5
NESTED LOOPS () 4
NESTED LOOPS (OUTER) 3
TABLE ACCESS (BY INDE EQUIPMENT_USES 2
INDEX (UNIQUE SCAN) EQUSE_PK 1
TABLE ACCESS (BY INDE SHIPPING_LINES 1
INDEX (UNIQUE SCAN) LINE_PK
INDEX (UNIQUE SCAN) EQHT_PK
TABLE ACCESS (BY INDEX EQUIPMENT_TYPES 1
INDEX (UNIQUE SCAN) EQTP_PK
TABLE ACCESS (BY INDEX R EQUIPMENT_SIZES 1
INDEX (UNIQUE SCAN) EQSZ_PK
TABLE ACCESS (BY INDEX RO EQUIPMENT 1
INDEX (RANGE SCAN) EQ_EQUSE_FK and following is my query plan in Oracle 10g
Operation Object PARTITION_START PARTITION_STOP COST
SELECT STATEMENT () 2881202
NESTED LOOPS () 2881202
SORT (UNIQUE) 2
INDEX (RANGE SCAN) BL_EQ_PK_N 2
VIEW () CONTAINER_INFO 2881199
UNION-ALL ()
NESTED LOOPS (OUTER) 2763680
NESTED LOOPS () 2718271
NESTED LOOPS () 2694552
NESTED LOOPS () 2623398
NESTED LOOPS (OUTER) 2623380
NESTED LOOPS () 2393965
NESTED LOOPS () 2393949
NESTED LOOPS () 2164536
NESTED LOOPS () 1706647
NESTED LOOPS () 854120
TABLE ACCESS (FU BL_EQUIPMENT 1515
TABLE ACCESS (BY EQUIPMENT_USES 1
INDEX (UNIQUE S EQUSE_PK 1
TABLE ACCESS (BY EQUIPMENT 1
INDEX (RANGE SCA EQ_EQUSE_FK 1
TABLE ACCESS (BY I EQUIPMENT_TYPES 1
INDEX (UNIQUE SCA EQTP_PK 1
TABLE ACCESS (BY IN EQUIPMENT_SIZES 1
INDEX (UNIQUE SCAN EQSZ_PK 1
INDEX (UNIQUE SCAN) EQHT_PK 1
TABLE ACCESS (BY INDE SHIPPING_LINES 1
INDEX (UNIQUE SCAN) LINE_PK 1
INDEX (RANGE SCAN) SEVENTS_TSERV_FK_N 1
TABLE ACCESS (BY INDEX SHIP_VISITS 2
INDEX (RANGE SCAN) SVISIT_UK 2
TABLE ACCESS (BY INDEX R SHIPS 1
INDEX (UNIQUE SCAN) SHIP_PK 1
TABLE ACCESS (BY INDEX RO CARE_VIR_MAP 2
INDEX (UNIQUE SCAN) VIR_VESVOY 1
NESTED LOOPS (OUTER) 117519
NESTED LOOPS () 98158
NESTED LOOPS () 78798
NESTED LOOPS () 78795
NESTED LOOPS () 59432
TABLE ACCESS (FULL) EQUIPMENT_USES 20788
TABLE ACCESS (BY INDE EQUIPMENT_TYPES 1
INDEX (UNIQUE SCAN) EQTP_PK 1
TABLE ACCESS (BY INDEX EQUIPMENT 1
INDEX (RANGE SCAN) EQ_EQUSE_FK 1
INDEX (UNIQUE SCAN) EQHT_PK 1
TABLE ACCESS (BY INDEX R EQUIPMENT_SIZES 1
INDEX (UNIQUE SCAN) EQSZ_PK 1
TABLE ACCESS (BY INDEX RO SHIPPING_LINES 1
INDEX (UNIQUE SCAN) LINE_PK 1can somebody help me regarding this?
Thanks
HassanI would say ..gather stats on 9i/10gfor the required table and indexes , then post the expalin plan.
--Girish -
Please,
I have just migrated a database from one server to another powerful server, but the issue is that one of the sql statement is very very slowing down.
we downloaded the dump file to another server, and the same sql is very very fast.
I shrank/rebuilt , table/indexes but no changes found, I also created new indexes that show up into the excution plan,but nothing changed.
My Question:
There is another area where I could look at to tune this sql statment?
ThanksYou may need to consider two things here.
1. Make sure you keep the parameter optimizer_mode consistent between two databases? If not, you may experience performance degradation. Some legacy third-party application may still run upon RBO. That's what we ever experienced.
2. It's time to gather statistics. See below.
When to gather statistics:
Candidates
– After large amounts of data change (loads, purges, bulk
updates)
– New high/low values for keys generated
– Newly created tables
– Upgrading CPUs, I/O subsystem (system statistics)
– RBO to CBO migrations
– New database creations
An useful Oracle official doc available at http://www.oraclepoint.com/topic.php?filename=76&extra=page%3D1
Hope it helps.
Message was edited by:
R.Wang -
Have a multi coloured circle which is making system slow - what can I do to resolve this?
Hi, I have a multi coloured circle that keeps coming on the screen making moving around my mac incredibly slow - any suggestions on how to remove this annoying thing?
Many Thanks
VanessaFirst, back up all data immediately, as your boot drive may be failing.
If iCloud is enabled, disable it.
Disconnect all wired peripherals except keyboard, mouse, and monitor, if applicable. Launch the usual set of applications you use when you notice the problem.
Step 1
Launch the Activity Monitor application in any of the following ways:
☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
☞ If you’re running OS X 10.7 or later, open LaunchPad. Click Utilities, then Activity Monitor in the page that opens.
Select the CPU tab of the Activity Monitor window.
Select All Processes from the menu in the toolbar, if not already selected.
Click the heading of the % CPU column in the process table to sort the entries by CPU usage. You may have to click it twice to get the highest value at the top. What is it, and what is the process? Also post the values for % User, % System, and % Idle at the bottom of the window.
Select the System Memory tab. What values are shown in the bottom part of the window for Page outs and Swap used?
Step 2
You must be logged in as an administrator to carry out this step.
Launch the Console application in the same way as above. Make sure the title of the Console window is All Messages. If it isn't, select All Messages from the SYSTEM LOG QUERIES menu on the left.
Post the 50 or so most recent messages in the log — the text, please, not a screenshot.
Important: Some personal information, such as your name, may appear in the log. Edit it out before posting. -
Hi All,
Using Oracle 11.2.0.3 on a TEST server
create index emp_job_sal_idx on emp(job,sal) ;
SQL> create or replace view test1 as select d.deptno, d.dname, e.empno, e.job, e.sal from dept d, emp e where d.deptno=e.deptno and
(e.job='CLERK' and e.sal > 1000) OR
(e.job='ANALYST' and e.sal >= 3000) OR
(e.job='SALESMAN' and e.sal >=1500);
SQL> set autotrace on explain
SQL> select * from test1;
18 rows selected.
Execution Plan
Plan hash value: 4192419542
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 67 | 10 (0)| 00:00:01 |
| 1 | NESTED LOOPS | | 1 | 67 | 10 (0)| 00:00:01 |
| 2 | TABLE ACCESS FULL| DEPT | 4 | 88 | 3 (0)| 00:00:01 |
|* 3 | TABLE ACCESS FULL| EMP | 1 | 45 | 2 (0)| 00:00:01 |
---------------------------------------------------------------------------The index is not used, mostly due to a OR condition. How can we make the index use without using hints ?sb92075 wrote:
post EXPLAIN PLAN for problem SQL
Execution Plan
Plan hash value: 3466901445
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 331 | 383K (7)| 01:16:40 |
|* 1 | HASH JOIN | | 1 | 331 | 383K (7)| 01:16:40 |
|* 2 | TABLE ACCESS FULL| ENT_TRAN| 1 | 165 | 205K (9)| 00:41:07 |
| 3 | TABLE ACCESS FULL| ENT_MAST | 19M| 3111M| 177K (3)| 00:35:31 |
1 - access(NLSSORT("ENT_MAST"."ID",'nls_sort=''BINARY_CI''')=NLSSORT(
"ENT_TRAN"."RID",'nls_sort=''BINARY_CI'''))
2 - filter(NLSSORT("ENT_TRAN"."NAME",'nls_sort=''BINARY_CI'''
)=HEXTORAW('616D616E616820736168616D206E6173696F6E616C2062657268616400')
AND NLSSORT("ENT_TRAN"."PP_NO",'nls_sort=''BINARY_CI''')=HEXTORAW('343
73435377600') OR NLSSORT("ENT_TRAN"."NAME",'nls_sort=''BINARY_C
I''')=HEXTORAW('74656E616761206E6173696F6E616C2062657268616400') AND
NLSSORT("ENT_TRAN"."PP_NO",'nls_sort=''BINARY_CI''')=HEXTORAW('3230303
836367700') OR NLSSORT("ENT_TRAN"."NAME",'nls_sort=''BINARY_CI'
'')=HEXTORAW('74656C656B6F6D206D616C61797369612062657268616400') AND
NLSSORT("ENT_TRAN"."PP_NO",'nls_sort=''BINARY_CI''')=HEXTORAW('3132383
734307000') OR NLSSORT("ENT_TRAN"."NAME",'nls_sort=''BINARY_CI'
'')=HEXTORAW('6167726F2062616E6B00') AND
NLSSORT("ENT_TRAN"."PP_NO",'nls_sort=''BINARY_CI''')=HEXTORAW('3831313
831307500') OR NLSSORT("ENT_TRAN"."NAME",'nls_sort=''BINARY_CI'
'')=HEXTORAW('6272756365206C656520796565206C616D00') AND
NLSSORT("ENT_TRAN"."PP_NO",'nls_sort=''BINARY_CI''')=HEXTORAW('3530333
333373100') OR NLSSORT("ENT_TRAN"."NAME",'nls_sort=''BINARY_CI'
'')=HEXTORAW('616B6261722074726164696E6700') AND
NLSSORT("ENT_TRAN"."PP_NO",'nls_sort=''BINARY_CI''')=HEXTORAW('3030313
438383037397500') OR NLSSORT("ENT_TRAN"."NAME",'nls_sort=''BINA
RY_CI''')=HEXTORAW('372D656C6576656E206D616C61797369612073646E2062686400')
AND NLSSORT("ENT_TRAN"."PP_NO",'nls_sort=''BINARY_CI''')=HEXTORAW('3
132303936327000') OR NLSSORT("ENT_TRAN"."NAME",'nls_sort=''BINA
RY_CI''')=HEXTORAW('6368616E20796F6B65206368656E6700') AND
NLSSORT("ENT_TRAN"."PP_NO",'nls_sort=''BINARY_CI''')=HEXTORAW('3637303
532372D30362D3534393600') OR NLSSORT("ENT_TRAN"."NAME",'nls_sor
t=''BINARY_CI''')=HEXTORAW('646B7368206D616C61797369612073646E2062686400')
AND NLSSORT("ENT_TRAN"."PP_NO",'nls_sort=''BINARY_CI''')=HEXTORAW('3
030343437367500') OR NLSSORT("ENT_TRAN"."NAME",'nls_sort=''BINA
RY_CI''')=HEXTORAW('626574746572207B267D206265737420656E746572707269736500
') AND NLSSORT("ENT_TRAN"."PP_NO",'nls_sort=''BINARY_CI''')=HEXTORAW(
'3030313632353132347000') OR NLSSORT("ENT_TRAN"."NAME",'nls_sor
t=''BINARY_CI''')=HEXTORAW('6C696D20656E672073696F65206A756E6B657400')
AND NLSSORT("ENT_TRAN"."PP_NO",'nls_sort=''BINARY_CI''')=HEXTORAW('743
5353138393300') OR NLSSORT("ENT_TRAN"."NAME",'nls_sort=''BINARY
_CI''')=HEXTORAW('712E712E206A756E6B657400') AND
NLSSORT("ENT_TRAN"."PP_NO",'nls_sort=''BINARY_CI''')=HEXTORAW('7331373
233363200') OR NLSSORT("ENT_TRAN"."NAME",'nls_sort=''BINARY_CI'
'')=HEXTORAW('6572206B696D206B656F6E6700') AND
NLSSORT("ENT_TRAN"."PP_NO",'nls_sort=''BINARY_CI''')=HEXTORAW('3539303
932302D31302D3538333700') OR NLSSORT("ENT_TRAN"."NAME",'nls_sor
t=''BINARY_CI''')=HEXTORAW('726963686C616E64206C6569737572652067726F757000
') AND NLSSORT("ENT_TRAN"."PP_NO",'nls_sort=''BINARY_CI''')=HEXTORAW(
'3538303532382D30312D3539383500') OR
NLSSORT("ENT_TRAN"."NAME",'nls_sort=''BINARY_CI''')=HEXTORAW('74
69656E2079756E20656E74657270726973652073646E2E206268642E00') AND
NLSSORT("ENT_TRAN"."PP_NO",'nls_sort=''BINARY_CI''')=HEXTORAW('3637303
332382D31302D3534363700') OR NLSSORT("ENT_TRAN"."NAME",'nls_sor
t=''BINARY_CI''')=HEXTORAW('73686172696B617420686F636B2068696E00') AND
NLSSORT("ENT_TRAN"."PP_NO",'nls_sort=''BINARY_CI''')=HEXTORAW('3030303
234323136397000') OR NLSSORT("ENT_TRAN"."NAME",'nls_sort=''BINA
RY_CI''')=HEXTORAW('6D7964696E206D6F68616D656420686F6C64696E67732062686420
28666F726D65726C79206B6E6F776E206173206D7964696E206D6F68616D656420686F6C64
696E67732073646E206268642900') AND NLSSORT("ENT_TRAN"."PP_NO",'nls_so
rt=''BINARY_CI''')=HEXTORAW('3232313434386100') OR
NLSSORT("ENT_TRAN"."NAME",'nls_sort=''BINARY_CI''')=HEXTORAW('65
7665726973652076656E74757265732073646E2062686400') AND
NLSSORT("ENT_TRAN"."PP_NO",'nls_sort=''BINARY_CI''')=HEXTORAW('3239353
137377000') OR NLSSORT("EN)
Statistics
1 recursive calls
0 db block gets
1353887 consistent gets
1353339 physical reads
0 redo size
1204784 bytes sent via SQL*Net to client
4989 bytes received via SQL*Net from client
408 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
6092 rows processed
{code} -
Index Usage in 9i changed when used rownum
Hi List,My Application is in RBO
Here is one more brain twister ?
Assume following I Have table SHRI with a single column
COL I have created Index on COL column say IND_COL.
Now when I run Following query on 8i with AUTOTRACE ON
I can see that 8i Uses the Index IND_COL Clearly .
select * from shri where (h_name='ABC' or h_name='BOM')
or (h_name ='BOM' or h_name='MOM')
and rownum=1
select * from shri where (COL='ABC' or COL='BOM')
or (COL='ABC' or COL='BOM')
and rownum=1
(Note:Above example is just for ur understanding plz.dont see the usage)
Now my problem is when I see the explain plan for above query in 8i I can see that Query uses IND_COL .
But when I run the same in 9i It does not uses IND_COL Index (Strange!!!) .
However when I remove "and rownum=1" clause then It again uses the index in 9i.
Assume that such queries are existing many places .
I am badly stuck because of this problem can anybody suggest the best way (Other than changing RBO to CBO) ?
Regards
Sripad.Run below query, you will get all the details of tablespaces.
col "Tablespace" for a22
col "Used MB" for 99,999,999
col "Free MB" for 99,999,999
col "Total MB" for 99,999,999
select df.tablespace_name "Tablespace",
totalusedspace "Used MB",
(df.totalspace - tu.totalusedspace) "Free MB",
df.totalspace "Total MB",
round(100 * ( (df.totalspace - tu.totalusedspace)/ df.totalspace))
"Pct. Free"
from
(select tablespace_name,
round(sum(bytes) / 1048576) TotalSpace
from dba_data_files
group by tablespace_name) df,
(select round(sum(bytes)/(1024*1024)) totalusedspace, tablespace_name
from dba_segments
group by tablespace_name) tu
where df.tablespace_name = tu.tablespace_name ;
Maybe you are looking for
-
Refining JS script to control a pop up window
After much frustration... I have a working popup window to display small images. The script thanks to WEB DESIGN GARAGE by Marc Campbell is simple enough, he has me paste this in the body: <script language="JavaScript"> function doPopup(popupPath)
-
Definition of Non cumulative Key figure and web template
Hi all, Can anyone define a Non cumulative Key figure and a web template. Thanks in advance.
-
while processing termination for this employee i selected all plans for stop participation however got the response 0 plans selected from 9 plans and plans that are not selected, could you plz help me
-
IDVD how to set chapters markers according to the day
iDVD wont let me set chapters markers according to the day of the trip. No good by minutes! I did have markers in the imported iMovie which have been ignored.
-
USB Drive crashing my AEBSn: Part II
I posted previously on this issue but since then have attained a better understanding of the issue. I have an Acomdata 160 GB external drive that has been working fine for years. It works in all my machines just fine. However, when I plug it into the