473,397 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Indexes not being used when using bind variables

Hi all,

I ran an explain plan for a sql query which has some bind variables used in it. The plan shows that index is being used but the execution takes a very long time. Also, in another query the use of bind variables totally discards the usage of indexes and the explain plan also does not show the use of indexes.

Any idea how the optimizer behaves when using bind variables? It would be great if someone can help me out in making sure that the indexes are always used even in the case of using bind variables.

Thanks.
Mar 10 '08 #1
3 4536
Dave44
153 100+
Hi all,

I ran an explain plan for a sql query which has some bind variables used in it. The plan shows that index is being used but the execution takes a very long time. Also, in another query the use of bind variables totally discards the usage of indexes and the explain plan also does not show the use of indexes.

Any idea how the optimizer behaves when using bind variables? It would be great if someone can help me out in making sure that the indexes are always used even in the case of using bind variables.

Thanks.
How is the data being used? How many rows in the table? In general if >= 20% of rows in a table are going to be needed it will be faster for a full table scan than an index search. If your stats on the table are refreshed often then the optimizer will make the best possible decisions.

string bind variables behave differently than number bind variables as far as hard parses are conerned. If you are concerned about bind variable usage in a query try replacing the binds with actual values and see if the plan changes much.

Indexes do not always mean faster queries, it depends on the table and amount of data to be used within the table.
Mar 11 '08 #2
debasisdas
8,127 Expert 4TB
Please find a related discussion here .
Mar 11 '08 #3
I have given the query details below. The oracle version used in Oracle 9.2. The details about this query are that HISTORY_VIEW_NOW is a view and it is very large. The columns begin_inst and end_inst have indexes on them.

Using bind variables in the query and very slow execution:
Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT *
  3. FROM HISTORY_VIEW_NOW
  4. WHERE begin_inst <= :endTime
  5. AND end_inst >= :beginTime
  6. AND family = 'ABC';
  7.  
  8. Explain plan:
  9.  
  10. Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
  11.  
  12. SELECT STATEMENT Optimizer Mode=CHOOSE 3 3396
  13. HASH JOIN 3 441 3396
  14. HASH JOIN 6 444 103
  15. TABLE ACCESS BY INDEX ROWID USER1.TABLE1 4 180 4
  16. INDEX RANGE SCAN USER1.ENT_IDX1 4 2
  17. VIEW USER1.MNT_TABLE1 1 K 52 K 99
  18. UNION-ALL
  19. HASH JOIN OUTER 630 25 K 6
  20. TABLE ACCESS FULL USER1.TABLE1 630 7 K 4
  21. TABLE ACCESS FULL USER1.TABLE2 507 14 K 1
  22. HASH JOIN 107 2 K 44
  23. VIEW 107 1 K 39
  24. SORT UNIQUE 107 1 K 39
  25. INDEX FAST FULL SCAN USER1.TABLE2_U01 507 5 K 1
  26. TABLE ACCESS FULL USER1.TABLE1 630 7 K 4
  27. HASH JOIN 503 16 K 45
  28. TABLE ACCESS FULL USER1.TABLE1 630 7 K 4
  29. VIEW 503 10 K 40
  30. SORT UNIQUE 503 14 K 40
  31. TABLE ACCESS FULL USER1.TABLE2 503 14 K 1
  32. TABLE ACCESS FULL USER1.TABLE1 629 11 K 4
  33. VIEW 4 K 304 K 3292
  34. UNION-ALL
  35. TABLE ACCESS BY INDEX ROWID USER1.HISTORY_TABLE 2 K 101 K 1643
  36. INDEX RANGE SCAN USER1.OEE_H_BEGIN_IDX 7 K 25
  37. TABLE ACCESS BY INDEX ROWID USER1.HISTORY_TABLE 2 K 74 K 1643
  38. INDEX RANGE SCAN USER1.OEE_H_BEGIN_IDX 7 K 25
  39. FILTER
  40. TABLE ACCESS FULL USER1.TABLE3 51 1 K 3
  41. FILTER
  42. TABLE ACCESS FULL USER1.TABLE3 38 1 K 3
  43.  

Without using bind variables in the query and very fast execution: (I am using the same values in this query as used for the bind variables above)

Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT STATEMENT Optimizer Mode=CHOOSE 1 120
  3. HASH JOIN 1 147 120
  4. HASH JOIN 6 444 103
  5. TABLE ACCESS BY INDEX ROWID user1.table1 4 180 4
  6. INDEX RANGE SCAN user1.ENT_IDX1 4 2
  7. VIEW user1.MNT_table1 1 K 52 K 99
  8. UNION-ALL
  9. HASH JOIN OUTER 630 25 K 6
  10. TABLE ACCESS FULL user1.table1 630 7 K 4
  11. TABLE ACCESS FULL user1.table2 507 14 K 1
  12. HASH JOIN 107 2 K 44
  13. VIEW 107 1 K 39
  14. SORT UNIQUE 107 1 K 39
  15. INDEX FAST FULL SCAN user1.table2_U01 507 5 K 1
  16. TABLE ACCESS FULL user1.table1 630 7 K 4
  17. HASH JOIN 503 16 K 45
  18. TABLE ACCESS FULL user1.table1 630 7 K 4
  19. VIEW 503 10 K 40
  20. SORT UNIQUE 503 14 K 40
  21. TABLE ACCESS FULL user1.table2 503 14 K 1
  22. TABLE ACCESS FULL user1.table1 629 11 K 4
  23. VIEW 1 K 128 K 16
  24. UNION-ALL
  25. TABLE ACCESS BY INDEX ROWID user1.history_table 4 192 5
  26. INDEX RANGE SCAN user1.OEE_H_END_IDX 4 3
  27. TABLE ACCESS BY INDEX ROWID user1.history_table 4 152 5
  28. INDEX RANGE SCAN user1.OEE_H_END_IDX 4 3
  29. FILTER
  30. TABLE ACCESS FULL user1.table3 1 K 39 K 3
  31. FILTER
  32. TABLE ACCESS FULL user1.table3 769 21 K 3
  33.  
Note that the cost for the query that uses the bind variables is much higher than the cost of the query without bind variables. I also tried the same query with the underlying table alone and still the execution time was long.

The modified query with the base table of the HISTORY_VIEW_NOW view is below.
Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT *
  3. FROM HISTORY_TABLE
  4. WHERE begin_inst <= :endTime
  5. AND end_inst >= :beginTime
  6.  
  7. --Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
  8.  
  9. SELECT STATEMENT Optimizer Mode=CHOOSE 2 K 1643
  10. TABLE ACCESS BY INDEX ROWID USER1.HISTORY_TABLE 2 K 110 K 1643
  11. INDEX RANGE SCAN USER1.OEE_H_BEGIN_IDX 7 K 25
  12.  
  13. --The modified query without bind variables (and using the same values as used ---for the bind variables) produced the explain plan below.
  14.  
  15. --Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
  16.  
  17. SELECT STATEMENT Optimizer Mode=CHOOSE 4 5
  18. TABLE ACCESS BY INDEX ROWID USER1.HISTORY_TABLE 4 208 5
  19. INDEX RANGE SCAN USER1.OEE_H_END_IDX 4 3
  20.  
Any pointers to this problem would be very helpful.

Thanks.
Mar 11 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Steve_CA | last post by:
Hi, The more I read, the more confused I'm getting ! (no wonder they say ignorance is bliss) I just got back from the bookstore and was flipping through some SQL Server Administration...
9
by: Igor | last post by:
Is there a way to force optimizer to use indexes without hints? (some server setting or index type...) I'll give an example to clarify : I have a table with fields Customer_Code char(10) not...
15
by: pranab_bajpai | last post by:
So I want to define a method that takes a "boolean" in a module, eg. def getDBName(l2): .... Now, in Python variables are bound to types when used, right? Eg. x = 10 # makes it an INT...
4
by: Mike Leahy | last post by:
Hello all, I have a question related to the use of indexes. One of my tables is part of a census, with over 2.5 million records in it. Clearly, just about any query takes a rather long time to...
5
by: bughunter | last post by:
For example - very large table with a lot indexes and updates work very slow. I'd like found unused or rarely used indexes. How? Yes, for static I found all sql in packages and, after analyse,...
4
by: WindAndWaves | last post by:
Hi Everyone Is there anyone who has some sound rules of thumb for using indexes. I see that, for example, access automatically adds them to linked tables, but I feel, they are probably of more...
14
by: Jeff | last post by:
This is the first time that I remember ever having too many indexes on a table, but it has happened. I have en employees table and store in many places, on tables, the id of the employee that...
2
by: umair.cheema | last post by:
Hi! 1-I read in MS Access help that Indexes are automatically made when we declare a primary key and they are used for fast searching and sorting purpose. But i am still confused that how can i...
0
MMcCarthy
by: MMcCarthy | last post by:
The more data you include in your tables the more you will need to have indexes to search and sort that data. However, there is a balance between having enough indexes and too many. Too many...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.