Application Development and Automation 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: 
Read only

using indexes.

Former Member
0 Likes
591

Hi,

I have executed below statement

select vkorg

vkbur

vtweg

spart

into table it_vbak_tmp

from vbak

where vkorg eq p_vkorg

and vkbur in s_off

and vtweg in s_vtweg

and spart in s_spart.

I have following index on vbak table

NONUNIQUE Index VBAK~Z03

VKORG

VKBUR

VTWEG

SPART

when I am executing select statment above and simultaneously checking ST05, i find that index VBAKz03 is not at all followed. it still goes on index VBAKZ01 (MANDT, VBELN).

what changes i need to do in above select statement so that index VBAK~z03 is followed on table VBAK ?

Please help

Regards,

Santosh

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
533

Hi Santosh B,

Include/add MANDT field in your INDEX Z03..

In Open SQL if you are not specifying the MANDT then also Optimizer includes it by itself... That is why it's not using Z03

So Make the above change in your VBAK table index Z03

Hope it will solve your problem..

Thanks & Regards

ilesh 24x7

ilesh Nandaniya

3 REPLIES 3
Read only

Rui_Dantas
Active Contributor
0 Likes
533

Are statistics for the index updated?

(you can check that also in ST05)

And yes, you are right, index Z03 should be used. In fact, even if you only had:

select  vkorg
         vkbur
         vtweg
         spart
 into table it_vbak_tmp
 from vbak.

... then that should be enough to use the index (in this case, an index full scan).

Read only

Former Member
0 Likes
533

Hi Santosh,

That's strange system uses index Z01 rather than Z03 : have you checked if p_vkorg is filled? If not as there is less fields in Z01, it is normal that database optimizer uses this one since it should be smaller and thus faster...

But if you want to force the use of an index (but you should avoid that if possible!), you can use database hint like this :

SELECT vkorg vkbur vtweg spart
  INTO TABLE it_vbak_tmp
  FROM vbak
    WHERE vkorg EQ p_vkorg AND
          vkbur IN s_off AND
          vtweg IN s_vtweg AND
          spart IN s_spart
  %_HINTS ORACLE 'INDEX("VBAK", "VBAK~Z03")'. 
" Hint for Oracle but you can adapt for other databases

Best regards,

Samuel

Read only

Former Member
0 Likes
534

Hi Santosh B,

Include/add MANDT field in your INDEX Z03..

In Open SQL if you are not specifying the MANDT then also Optimizer includes it by itself... That is why it's not using Z03

So Make the above change in your VBAK table index Z03

Hope it will solve your problem..

Thanks & Regards

ilesh 24x7

ilesh Nandaniya