Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

DB uses wrong index

Former Member
0 Kudos

Hi,

I have a custom table, with 2 indexes:

1) Z01 with the ff. fields: client, plant, doc1, movmt_typ

2) Z02 with only one field: doc1

my select statement is below:

select single * from zcustom where doc1 = p_doc.

when i check on st05, the system uses the Z01 index instead of Z02 which has the field in my where condition.

i need to know why the system uses Z01 and not Z02.

Thansks!

1 ACCEPTED SOLUTION

Sandeep_Kumar
Product and Topic Expert
Product and Topic Expert

If you really want to use Z02 index then try using HINTS and the particular index.

7 REPLIES 7

former_member192616
Active Contributor
0 Kudos

Hi Freishz,

which DB (version) are you using? (Probably not MAXDB or MSSQL, but one of the following: DB2, DB4, DB6, ORACLE, right?).

Depending on your DB the following question might be interesting:

Do both of your indexes have good statistics?

Could you post the statistics for both indexes?

Without more information i assume the reason is in the statistics... .

Kind regards,

Hermann

ThomasZloch
Active Contributor
0 Kudos

In addition to that, why did you not include the client in index Z02? Depending on how many clients you have and the data distribution per client this may or may not make a difference for the index selection.

It might be worth a try to include the client in that index and check the result.

Thomas

Sandeep_Kumar
Product and Topic Expert
Product and Topic Expert

If you really want to use Z02 index then try using HINTS and the particular index.

0 Kudos

Hi Sandeep,

i think a hint should be the very last option. I prefer to understand the optimizer before trying to hint the opimizer. Maybe the optimizer is correct with the cost calculation and maybe the index Z01 leads to a better runtime as well... as Thomas pointed out this could easily be the case if we consider multiple clients... .

Kind regards,

Hermann

Sandeep_Kumar
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Hermann,

Yes HINTS should not be used until and unless this is the last resort .

But my suggestion was based on assumption that user wants to use Z02 ONLY.

Thanks

Regards,

Sandeep

former_member194613
Active Contributor
0 Kudos

first check whether the index exists on the DB and not only in DDIC and check statistics, use DB02,

or ST05 (with Oracle or IBM).

Check system -> status, if you are not aware what DB you use.

former_member555112
Active Contributor
0 Kudos

Hi,

Ask your basis team to update the database statistics for this table.

Regards,

Ankur Parab