两个SQL语句写法的性能测试

测试表: MARA,MAKT
MARA表的记录数大约为44000

=======================================
测试一:
DATA: BEGIN OF it_mara OCCURS 0,
        matnr LIKE mara-matnr,
        maktx LIKE makt-maktx,
      END OF it_mara.
第一种写法:
  SELECT matnr
  INTO it_mara
  FROM mara.
    APPEND it_mara.
  ENDSELECT.      
平均运行结果: 366,740微秒

第二种写法:
  SELECT matnr
  INTO TABLE it_mara
  FROM mara.
平均运行结果: 148,360微秒
=======================================
测试二:  
DATA: BEGIN OF it_mara OCCURS 0,
        matnr LIKE mara-matnr,
        maktx LIKE makt-maktx,
      END OF it_mara.

DATA: BEGIN OF it_makt OCCURS 0,
        matnr LIKE mara-matnr,
        maktx LIKE makt-maktx,
      END OF it_makt.
第一种写法:
  LOOP AT it_mara.
    SELECT SINGLE maktx
    INTO it_mara-maktx
    FROM makt
    WHERE matnr = it_mara-matnr AND
          spras = sy-langu.
    MODIFY it_mara TRANSPORTING maktx.
  ENDLOOP.      
平均运行结果: 13,327,526微秒

第二种写法:  
  SELECT matnr maktx
  INTO TABLE it_makt
  FROM makt
  FOR ALL ENTRIES IN it_mara
  WHERE matnr = it_mara-matnr and
        spras = sy-langu.
平均运行结果: 5,787,685微秒
=======================================
   

Comments are closed.