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

Inner Join Performance issue

Former Member
0 Likes
691

Hi experts,

I have the following select statement which has three levels of inner joins.

SELECT pplnty pplnnr pplnkn mplnal mwerks mmatnr mr~meins

pvornr psteus sdatuv sloekz INTO TABLE it_group

FROM ( ( plpo AS p

INNER JOIN plas AS s ON splnty = pplnty AND

splnnr = pplnnr AND splnkn = pplnkn )

INNER JOIN mapl AS m ON mplnty = splnty AND

mplnnr = splnnr AND mplnal = splnal )

INNER JOIN mara AS mr ON mrmatnr = mmatnr

FOR ALL ENTRIES IN it_valid_opr

WHERE p~plnty = c_routing

AND p~plnnr = it_valid_opr-plnnr

AND sdatuv <= p_valdt AND mplnty =

c_routing AND mdatuv <= p_valdt AND mloekz <> c_x .

i have some 2500 entries in the internal table it_valid_opr. This query is taking very long time to get executed. Any anyone suggest an alternative for the above SELECT query.

6 REPLIES 6
Read only

Former Member
0 Likes
655

You have one expression in both a JOIN condition and the WHERE. I'd remove it from the WHERE:

SELECT p~plnty p~plnnr p~plnkn m~plnal m~werks m~matnr mr~meins
       p~vornr p~steus s~datuv s~loekz
  INTO TABLE it_group
  FROM ( ( plpo AS p
    INNER JOIN plas AS s
      ON s~plnty = p~plnty AND
         s~plnnr = p~plnnr AND
         s~plnkn = p~plnkn )
    INNER JOIN mapl AS m
      ON m~plnty = s~plnty AND
         m~plnnr = s~plnnr AND
         m~plnal = s~plnal )
    INNER JOIN mara AS mr
      ON mr~matnr = m~matnr
  FOR ALL ENTRIES IN it_valid_opr
  WHERE p~plnty = c_routing
    AND p~plnnr = it_valid_opr-plnnr
    AND s~datuv <= p_valdt
*   AND m~plnty = c_routing              "<====
    AND m~datuv <= p_valdt
    AND m~loekz <> c_x .

Rob

Read only

0 Likes
655

Thanks for ur quick reply. But is this the only reason wat is causing the performance slow down?

Read only

0 Likes
655

Performance can be bad for any number of reasons. The JOIN looks OK. How many records does it bring back?

Rob

Read only

Former Member
0 Likes
655

Hi,

Types: begin of ty_plpo,
        plnty type plnty,
        plnnr type plnnr,
        plnkn type plnkn,
        vornr type vornr,
        steus type steus,
       end of ty_plpo,

       begin of ty_plas,
        plnty type plnty,
        plnnr type plnnr,
        plnal type plnal,
        datuv type datuv,
        loekz type loekz,        
       end of ty_plas,

       begin of ty_mapl,
        plnty type plnty,
        plnnr type plnnr,
        plnkn type plnkn,
        plnal type plnal,
        werks type werks_d,
        matnr type matnr,
       end of ty_mapl,
  
       begin of ty_mara,
        matnr type matnr,
        meins type meins,
       end of ty_mara.

Data: it_plpo type table of ty_plpo,
      it_mplo type table of ty_mplo,
      it_mapl type table of ty_mapl,
      it_mara type table of ty_mara.



if it_valid_opr[] is not intial.
 SELECT plnty plnnr plnkn vornr steus from plpo into table it_plpo for all entries in it_valid_opr
where plnty = c_routing
  and plnnr = it_valid_opr-plnnr.
 if sy-subrc = 0.
  select plnty plnnr plnal datuv loekz from plas into table it_plas for all entries in it_mplo
 where plnty = it_mplo-plnty
   and plnnr = it_mplo-plnnr
   and plnkn = it_mplo-plnkn
   and datuv LE p_valdt.
  if sy-subrc = 0.
   select plnty plnnr plnkn plnal werks matnr from mapl into table it_mapl for all entries in it_plas
     where plnty = it_plas-plnty
       and plnnr = it_plas-plnnr
       and plnkn = it_plas-plnal
       or  plnty = c_routing
       and datuv LE p_valdt.
   if sy-subrc = 0.
     delete it_mapl where loekz EQ c_x.
     select matnr meins from mara into table it_mara for all entries in it_mapl 
      where matnr = it_mapl-matnr.
   endif. 
  endif.
 endif.
endif.

Regards,

Satish

Read only

Former Member
0 Likes
655

Hi Rob,

It returns about 300,000 records....

Read only

0 Likes
655

Well, that's probably it then. One of the first rules of performance tuning is to keep the selection set small. 300,000 records isn't huge, but it isn't small either. Coupled with the fact that you aren't using the entire key.

Rob