Why oracle stored procedure execution time is greatly increased depending on how it is executed?

前端 未结 1 1868
天命终不由人
天命终不由人 2020-12-29 13:53

This is my problem: we have a stored procedure called HEAVY_SP and depending on how it is executed, execution time is greatly increased:

(1)

相关标签:
1条回答
  • 2020-12-29 14:16

    Try getting nls parameters from your diferent cases(ide's or java programs) they must be diferent

    select * from NLS_SESSION_PARAMETERS
    

    Then inside of your store procedure set the variables to make them equals from the fastest case.

      execute immediate 'alter session set NLS_SORT=''SPANISH''';
    

    Once you SP have all nls parameters . It will run fast.

    I just recently found a similar case in Alter session slows down the query through Hibernate . but in their case they change de parameters and then became slow.

    I investigated and found that The parameters NLS_COMP y NLS_SORT may affect how oracle make uses of execute plan for string ( when it is comparing or ordering)

    When NLS_COMP is defined as LINGUISTIC it will use the language define in NLS_SORT.

    for example, if NLS_COMP = LINGUISTIC and NLS_SORT=BINARI_AI your querys is

    select * from table where string_column like 'HI%'
    

    internally it will do

    select * from table where  
    NLSSORT(string_column,'BINARI_AI') >= HEXTORAW('324242432')
    NLSSORT(string_column,'BINARI_AI') >= HEXTORAW('675757576')
    

    so if you dont have a index for NLSSORT(column,'BINARI_AI') it will be very slow.

    knowing that NLS_SORT=BINARY_AI will make accent-insensitive and case-insensitive your ordering and comparisons.

    0 讨论(0)
提交回复
热议问题