具有内部联接的Select语句将永远占用

时间:2013-11-13 12:16:27

标签: sql sap database-performance abap

(....)
DATA: BEGIN OF g00 OCCURS 100,
            werks LIKE lqua-werks,
            lgort LIKE lqua-lgort,
            matnr LIKE lqua-matnr,
            charg LIKE lqua-charg,
            maktx LIKE makt-maktx,
            verme LIKE lqua-verme,
            meins LIKE lqua-meins,
            dispo LIKE marc-dispo,
      END OF g00.
(.....)
 CLEAR : g00.
  REFRESH : g00.
  SELECT lqua~bestq lqua~charg lqua~lgort lqua~lgnum lqua~lgpla
lqua~lgtyp lqua~matnr lqua~meins lqua~verme lqua~werks makt~maktx
         makt~matnr makt~spras mara~bismt mara~matnr marc~dispo
         marc~matnr marc~werks
  INTO (lqua-bestq , lqua-charg , lqua-lgort , lqua-lgnum , lqua-lgpla ,
 lqua-lgtyp , lqua-matnr , lqua-meins , lqua-verme , lqua-werks ,
makt-maktx , makt-matnr , makt-spras , mara-bismt , mara-matnr ,
marc-dispo , marc-matnr , marc-werks )
  FROM ( lqua
         INNER JOIN makt
         ON makt~matnr = lqua~matnr
         INNER JOIN mara
         ON mara~matnr = makt~matnr
         INNER JOIN marc
         ON marc~werks = lqua~werks
         AND marc~matnr = lqua~matnr )
         WHERE lqua~bestq IN sbestq
           AND lqua~lgnum IN slgnum
           AND lqua~lgpla IN slgpla
           AND lqua~lgtyp IN slgtyp
           AND lqua~matnr IN smatnr
           AND lqua~werks IN swerks
           AND makt~maktx IN smaktx
           AND makt~spras IN sspras
*           AND MARA~BISMT IN Sbismt
           AND marc~dispo IN sdispo.
    MOVE-CORRESPONDING mara TO g00.
    MOVE-CORRESPONDING makt TO g00.
    MOVE-CORRESPONDING marc TO g00.
    MOVE-CORRESPONDING lqua TO g00.
    COLLECT g00.
  ENDSELECT.

任何人都可以帮助提高上述代码的性能。

2 个答案:

答案 0 :(得分:2)

您的加入起始表(LQUA)不会选择键或索引字段,这些字段的运行速度始终低于您能够使用它们的速度。

虽然似乎没有办法在关键字段上加入所有,但如果您将查询调整为最初从MARA(其中MATNR是关键字段)拉出来,您可能会有更好的运气:

FROM ( mara
         INNER JOIN makt
         ON makt~matnr = mara~matnr
         INNER JOIN lqua
         ON lqua~matnr = mara~matnr
         INNER JOIN marc
         ON marc~werks = mara~werks
         AND marc~matnr = mara~matnr )...

答案 1 :(得分:2)

请勿在下面描述的场景中使用SELECT END SELECT。尝试执行以下操作:

- >使用您选择的字段创建一个本地类型select(lt_yourtype)

(lqua~bestq lqua~charg lqua~lgort lqua~lgnum lqua~lgpla lqua~lgtyp lqua~matnr lqua~meins lqua~verme lqua~werks makt~maktx          makt~matnr makt~spras mara~bismt mara~matnr marc~dispo          marc~matnr marc~werks)

- >创建工作区(首选字段符号)和上述本地类型的内部表(lt_yourtype)

- >用以下内容替换给定的选择:

选择lqua~bestq lqua~charg lqua~lgort lqua~lgnum lqua~lgpla lqua~lgtyp lqua~matnr lqua~meins lqua~verme lqua~werks makt~maktx          makt~matnr makt~spras mara~bismt mara~matnr marc~dispo          marc~matnr marc~werks 到表lt_yourtype 从(lqua          INNER JOIN makt          ON makt~matnr = lqua~matnr          INNER JOIN mara          ON mara~matnr = makt~matnr          INNER JOIN marc          在marc~werks = lqua~werks          和marc~matnr = lqua~matnr)          在哪里lqua~bestq在sbestq            和lqua~lgnum在slgnum            和lqua~lgpla在slgpla            和lqua~lgtyp在slgtyp            和lqua~matnr IN smatnr            并且lqua~在werks中晃动            和makt~maktx在smaktx            和makt~spras IN sspras *和MARA~BISMT在Sbismt            和marc~dispo IN sdispo。

循环进入lt_yourtype分配。

*将数据移动到正确的结构和字段

ENDLOOP。