Function much slower than same statement.

Ask a Question related to Oracle Server, Design and Development.

  1. #1

    Default Function much slower than same statement.

    Hi all:

    I am facing stunning performance results with a user defined function.
    This is the story:
    I have a function that basically performs a validation and branches
    into two selects. One of them (a three table select) was behaving very
    bad (26 secs) although the joins are PK based, and, to my surprise,
    another function that performs a query very similar to the bad one,
    but with one more 'child table' in the join performs just OK.
    "Let's see" I thought.
    I Opened SqlPlus and executed this annoying query. Again It last 26
    secs.
    Then I used a hint ('ORDERED') in the select and the query executed in
    0.10 secs. "OK" I thought "Next step: put the hint in the select
    within the function..." but the function still takes 26 secs to
    execute!! Same select statement, same hint but the Function seems to
    be 260 times slower than the single select (Is the optimizer using the
    hint?).
    The validation issue in the function is only "if variable_val <
    fixed_val then SELECT... else SELECT..." so It shouldn't penalize.

    Can anybody throw some light on it?

    The infamous SELECT (works OK as statement -with the hint- but very
    bad inside the function):

    SELECT/*+ORDERED*/ NVL( SUM( ( b.N_AP_AS_A +
    b.N_AP_AS_M +
    b.N_AP_AV_A +
    b.N_AP_AV_M ) * c.N_CR_AP ), 0 )
    INTO v_ret
    FROM TC a, VEN_SOR_JA b, MOD_SOR_JA c
    WHERE a.ID_N_PV = p_ID_N_PV
    AND b.ID_N_TC = a.ID_N_TC
    AND b.ID_N_JR >= p_jr_ini
    AND b.ID_N_JR <= p_jr_fin
    AND c.ID_N_JGO = b.ID_N_JGO
    AND c.ID_N_SOR = b.ID_N_SOR
    AND c.ID_N_MOD = b.ID_N_MOD;


    The SELECT with one more table (in another user defined function) that
    performs OK (0.20 secs.):
    SELECT NVL ( SUM(
    (
    ( b.N_AP_AS_A +
    b.N_AP_AS_M +
    b.N_AP_AV_A +
    b.N_AP_AV_M ) * c.N_CR_AP )
    * d.N_COM_VEN / 100 )
    , 0 )
    INTO v_ret
    FROM TC a, VEN_SOR_JA b, MOD_SOR_JA c, JGO_TC d
    WHERE a.ID_N_PV = p_ID_N_PV
    AND b.ID_N_TC = a.ID_N_TC
    AND b.ID_N_JR >= p_jornada_ini
    AND b.ID_N_JR <= p_jornada_fin
    AND c.ID_N_JGO = b.ID_N_JGO
    AND c.ID_N_SOR = b.ID_N_SOR
    AND c.ID_N_MOD = b.ID_N_MOD
    AND d.ID_N_JGO = b.ID_N_JGO
    AND d.ID_N_TC = a.ID_N_TC;

    This is running on Oracle 8.1.6 on Win NT sp 6 (This is not my
    fault!!)

    Thanks in advance.
    Carlos Guest

  2. Similar Questions and Discussions

    1. #38057 [Com]: closeCursor method not function with CALL statement
      ID: 38057 Comment by: engine_no9 at gmx dot net Reported By: draeli at draeli dot com Status: No Feedback Bug...
    2. invoking component method slower than local function ?
      Hello all, I am currently re-coding in object way an old application with linear code under coldfusion 6.1 MX. Components are ok but I encounter...
    3. Problem with SQL Statement/Sort Function
      Hey everyone, I am inserting a drop down menu that will allow a user to sort the database result on my page. The problem is, i'm not sure where to...
    4. calling function in print statement?
      is it possible to call a function in a print statement? In the statement below Change_Color(3, 4) is the function en it should change the color...
    5. #22558 [Com]: DB2 seems to be 10x slower than MYSQL running a simple select statement
      ID: 22558 Comment by: port at iname dot com Reported By: danl at icarz dot com Status: Bogus Bug Type: ...
  3. #2

    Default Re: Function much slower than same statement.

    Could you please provide us the execution plans? (do a search on this
    site if you're not sure how, you'll get tons of results).

    Daniel
    Daniel Roy Guest

  4. #3

    Default Re: Function much slower than same statement.

    Carlos wrote:
    >
    > Hi all:
    >
    > I am facing stunning performance results with a user defined function.
    > This is the story:
    > I have a function that basically performs a validation and branches
    > into two selects. One of them (a three table select) was behaving very
    > bad (26 secs) although the joins are PK based, and, to my surprise,
    > another function that performs a query very similar to the bad one,
    > but with one more 'child table' in the join performs just OK.
    > "Let's see" I thought.
    > I Opened SqlPlus and executed this annoying query. Again It last 26
    > secs.
    > Then I used a hint ('ORDERED') in the select and the query executed in
    > 0.10 secs. "OK" I thought "Next step: put the hint in the select
    > within the function..." but the function still takes 26 secs to
    > execute!! Same select statement, same hint but the Function seems to
    > be 260 times slower than the single select (Is the optimizer using the
    > hint?).
    > The validation issue in the function is only "if variable_val <
    > fixed_val then SELECT... else SELECT..." so It shouldn't penalize.
    >
    > Can anybody throw some light on it?
    >
    > The infamous SELECT (works OK as statement -with the hint- but very
    > bad inside the function):
    >
    > SELECT/*+ORDERED*/ NVL( SUM( ( b.N_AP_AS_A +
    > b.N_AP_AS_M +
    > b.N_AP_AV_A +
    > b.N_AP_AV_M ) * c.N_CR_AP ), 0 )
    > INTO v_ret
    > FROM TC a, VEN_SOR_JA b, MOD_SOR_JA c
    > WHERE a.ID_N_PV = p_ID_N_PV
    > AND b.ID_N_TC = a.ID_N_TC
    > AND b.ID_N_JR >= p_jr_ini
    > AND b.ID_N_JR <= p_jr_fin
    > AND c.ID_N_JGO = b.ID_N_JGO
    > AND c.ID_N_SOR = b.ID_N_SOR
    > AND c.ID_N_MOD = b.ID_N_MOD;
    >
    > The SELECT with one more table (in another user defined function) that
    > performs OK (0.20 secs.):
    > SELECT NVL ( SUM(
    > (
    > ( b.N_AP_AS_A +
    > b.N_AP_AS_M +
    > b.N_AP_AV_A +
    > b.N_AP_AV_M ) * c.N_CR_AP )
    > * d.N_COM_VEN / 100 )
    > , 0 )
    > INTO v_ret
    > FROM TC a, VEN_SOR_JA b, MOD_SOR_JA c, JGO_TC d
    > WHERE a.ID_N_PV = p_ID_N_PV
    > AND b.ID_N_TC = a.ID_N_TC
    > AND b.ID_N_JR >= p_jornada_ini
    > AND b.ID_N_JR <= p_jornada_fin
    > AND c.ID_N_JGO = b.ID_N_JGO
    > AND c.ID_N_SOR = b.ID_N_SOR
    > AND c.ID_N_MOD = b.ID_N_MOD
    > AND d.ID_N_JGO = b.ID_N_JGO
    > AND d.ID_N_TC = a.ID_N_TC;
    >
    > This is running on Oracle 8.1.6 on Win NT sp 6 (This is not my
    > fault!!)
    >
    > Thanks in advance.
    You need a space:

    select /*+ORDERED*/ works in SQL but not PLSQL

    select /*+ ORDERED */ works in both

    hth
    connor
    --
    =========================
    Connor McDonald
    [url]http://www.oracledba.co.uk[/url]

    "Some days you're the pigeon, some days you're the statue"
    Connor McDonald Guest

  5. #4

    Default Re: Function much slower than same statement.

    Connor McDonald <connor_mcdonald@yahoo.com> wrote in message news:<3F09928D.2F7@yahoo.com>...
    >
    > You need a space:
    >
    > select /*+ORDERED*/ works in SQL but not PLSQL
    >
    > select /*+ ORDERED */ works in both
    >
    > hth
    > connor
    Thank you so much, Connor. I knew there was a space issue, but I was
    not sure if I shoud place a space or not, and when It worked in
    sqlplus without spaces I inferred (wrong!) that this was the right
    way, so I didn't try the other (stupid!!).
    I will never forget again.

    Greetings from Spain.
    Carlos Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139