溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Sql優(yōu)化的大提升是什么

發(fā)布時(shí)間:2021-10-20 16:04:08 來(lái)源:億速云 閱讀:94 作者:柒染 欄目:大數(shù)據(jù)

Sql優(yōu)化的大提升是什么,很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲。

最近在做集團(tuán)任務(wù)中心視圖的優(yōu)化  發(fā)現(xiàn)幾個(gè)系統(tǒng)的sql視圖慢的過分  直接po代碼  核心的業(yè)務(wù)sql 已蒙蔽

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

create or replace view km_todotasklist as

select "ID","DEVICE_TYPE","SYSTEM_TYPE","TASK_CODE","TASK_TYPE1","TASK_TYPE2","TITLE","STATUS","OWNER_ID","OWNER_NAME","PRIORITY","CREATE_ID","CREATE_TIME","UPDATE_ID","UPDATE_TIME" from 

select    t.id_ as id,

  CASE

         WHEN (select t.cfg_value from SYS_OT_CONFIG t where t.code ='SERVER_H5_MODELID'  and   INSTR( t.cfg_value ,a.module_id)>0   ) is null  THEN

          'PC,APP'

         WHEN (select t.cfg_value from SYS_OT_CONFIG t where t.code ='SERVER_H5_MODELID'  and  INSTR( t.cfg_value ,a.module_id)>0    ) is not  null THEN

          'PC'

         ELSE

         (select t.cfg_value from SYS_OT_CONFIG t where t.code ='SERVER_H5_MODELID'  and  INSTR( t.cfg_value ,a.module_id)>0   )

       END as device_type,

       'KM' as system_type,

       '核心業(yè)務(wù)URL’||utl_raw.cast_to_varchar2(utl_encode.base64_encode(utl_raw.cast_to_raw((select to_char(t.next_user_id_)

          from OA_OT_PROCESS_RECORD t

         where t.next_task_id_ = t.id_ and rownum=1))))  as task_code,

       '代辦' as task_type1,

       to_char(mo.name)  as task_type2,

        to_char(a.title) as title,

       '0' as status,

       (select to_char(t.next_user_id_)

          from OA_OT_PROCESS_RECORD t

         where t.next_task_id_ = t.id_ and rownum=1) as owner_id,

       (select em.real_name

          from IMS_OT_USER t

         inner join IMS_OT_EMPLOYEE em

            on t.employee_id = em.id

         where t.user_login_name =

               (select t.next_user_id_

                  from OA_OT_PROCESS_RECORD t

                 where t.next_task_id_ = t.id_ and rownum=1) and rownum=1) as owner_name,

       '' as priority,

       a.creator as create_id,

       a.create_time as create_time,

       '' as update_id,

       '' as update_time

  from oa_ot_application a

 inner join act_ru_task t

    on t.proc_inst_id_ = a.pro_inst_id  and   t.task_def_key_ <> 'usertask2'

 inner join oa_ot_application_ext et

    on et.app_id = a.id and et.business_type ='1'

 inner join   OA_OT_APP_MODULE  mo on a.module_id =mo.id

UNION ALL

select    t.id as id,

       'PC' as device_type,

       'KM' as system_type,

        'http://10.XX.XXX.XXX'||(select  t.oa_req_url   from OA_OT_APP_MODULE t where   t.id  =a.module_id)||'/input.htm?taskId='||t.id||'&appId='||a.id||'&sid='|| utl_raw.cast_to_varchar2(utl_encode.base64_encode(utl_raw.cast_to_raw(to_char(t.user_id))))  as task_code,

       '待閱' as task_type1,

        to_char(mo.name)  as task_type2,

       to_char(a.title) as title,

       '0' as status,

       to_char(t.user_id)  as owner_id,

       (select em.real_name

          from IMS_OT_USER t

         inner join IMS_OT_EMPLOYEE em

            on t.employee_id = em.id

         where t.user_login_name = t.user_id  and rownum=1) as owner_name,

       '' as priority,

       a.creator as create_id,

       a.create_time as create_time,

       '' as update_id,

       'as update_time

  from oa_ot_application a

 inner join oa_ru_circulation t

    on t.proc_inst_id = a.pro_inst_id

 inner join oa_ot_application_ext et

    on et.app_id = a.id

    inner join   OA_OT_APP_MODULE  mo on a.module_id =mo.id

  ) t  order by t.create_time desc;

全局查詢大概15秒左右。

1 了解核心業(yè)務(wù)需求

2 了解目前sql痛點(diǎn) 

3 改進(jìn)sql 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

create or replace view km_todotasklist as

select    t.id_ as id,

  CASE

         WHEN (select t.cfg_value from SYS_OT_CONFIG t where t.code ='SERVER_H5_MODELID'  and   INSTR( t.cfg_value ,a.module_id)>0   ) is null  THEN

          'PC,APP'

         WHEN (select t.cfg_value from SYS_OT_CONFIG t where t.code ='SERVER_H5_MODELID'  and  INSTR( t.cfg_value ,a.module_id)>0    ) is not  null THEN

          'PC'

         ELSE

         (select t.cfg_value from SYS_OT_CONFIG t where t.code ='SERVER_H5_MODELID'  and  INSTR( t.cfg_value ,a.module_id)>0   )

       END as device_type,

       'KM' as system_type,

       '核心業(yè)務(wù)URL'||utl_raw.cast_to_varchar2(utl_encode.base64_encode(utl_raw.cast_to_raw(re.next_user_id_)))  as task_code,

       '代辦' as task_type1,

       to_char(mo.name)  as task_type2,

        to_char(a.title) as title,

       '0' as status,

      re.next_user_id_ as owner_id,

      emp.real_name as owner_name,

       '' as priority,

       a.creator as create_id,

       a.create_time as create_time,

       '' as update_id,

       '' as update_time

  from oa_ot_application a

 inner join act_ru_task t

    on t.proc_inst_id_ = a.pro_inst_id

 inner join oa_ot_application_ext et

    on et.app_id = a.id and et.business_type ='1'

 inner join   OA_OT_APP_MODULE  mo on a.module_id =mo.id

 left join   OA_OT_PROCESS_RECORD re  on re.next_task_id_ = t.id_

 left join IMS_OT_USER uss  on re.next_user_id_ =uss.user_login_name 

 left join IMS_OT_EMPLOYEE emp on uss.employee_id= emp.id;


 
 目前sql已優(yōu)化到0.3秒 

看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注億速云行業(yè)資訊頻道,感謝您對(duì)億速云的支持。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

sql
AI