![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, I have SQL query, that I'm trying to tune up. If I simplify it, I can say: When I run my select statement, where I'm calling function (that is just returning ABS(SUM) value) in main query, then it takes much more longer, than if I replace function with subselect(subquery). Why this happens? I'm expecting almost the same execution time. Please see query, execution time, explain plan and statistic below. (snip) Why when I use function instead subquery, my query takes so long? What I'm doing wrong? |
#3
| |||
| |||
|
|
Hi, I have SQL query, that I'm trying to tune up. If I simplify it, I can say: When I run my select statement, where I'm calling function (that is just returning ABS(SUM) value) in main query, then it takes much more longer, than if I replace function with subselect(subquery). Why this happens? I'm expecting almost the same execution time. Please see query, execution time, explain plan and statistic below. |
#4
| |||
| |||
|
|
Tomeo wrote: Hi, I have SQL query, that I'm trying to tune up. If I simplify it, I can say: When I run my select statement, where I'm calling function (that is just returning ABS(SUM) value) in main query, then it takes much more longer, than if I replace function with subselect(subquery). Why this happens? I'm expecting almost the same execution time. Please see query, execution time, explain plan and statistic below. User defined functions are one of the main killers of performance, they can probably make a more elegant and flexible solution sometimes but performance almost always are worse because there must be context switch from sql between pl/sql engines. If you are doing this switch for thousands of rows it adds up and takes a very observable time. So use user defined functions very cautiously and when you really need them. More info http://asktom.oracle.com/pls/ask/f?p...60122715103602 |

#5
| |||
| |||
|
When will they give me templates for my packaged SQL?!? ![]() cheers, Martin |
#6
| |||
| |||
|
|
Martin T. wrote: When will they give me templates for my packaged SQL?!? ![]() cheers, Martin Please explain ... off-line if you prefer. |
#7
| |||
| |||
|
|
[snip query with function] 3324 rows selected. Elapsed: 00:02:27.80 Statistics ---------------------------------------------------------- 29956 recursive calls 0 db block gets 15369502 consistent gets 0 physical reads 0 redo size 68024 bytes sent via SQL*Net to client 2861 bytes received via SQL*Net from client 223 SQL*Net roundtrips to/from client 6662 sorts (memory) 0 sorts (disk) 3324 rows processed [snip query with scalar subquery] 3324 rows selected. Elapsed: 00:00:04.87 Statistics ---------------------------------------------------------- 26632 recursive calls 0 db block gets 125433 consistent gets 0 physical reads 0 redo size 68029 bytes sent via SQL*Net to client 2861 bytes received via SQL*Net from client 223 SQL*Net roundtrips to/from client 6662 sorts (memory) 0 sorts (disk) 3324 rows processed Why when I use function instead subquery, my query takes so long? What I'm doing wrong? Tomas |
#8
| |||
| |||
|
|
DA Morgan wrote: Martin T. wrote: When will they give me templates for my packaged SQL?!? ![]() cheers, Martin Please explain ... off-line if you prefer. Hu? Off-line? It's just a fancy idea of mine ... So we have VIEWS ... which are stored queries to make things more organized. Why not have more flexible "views" where part of the "view" remains variable until used ... so that the user of the view could push predicates or whatever into the view ... the SQL engine wouldn't even be aware of it, just the PL/SQL compiler. Or at least give me packaged views ... cursors are alright but they're so awful to use in PL/SQL code compared to inline queries ... (And I so hate having to define everything on the schema level.) Well. Just my 002. I'm sure you disagree ;-) cheers, Martin |
#9
| |||
| |||
|
|
Martin T. wrote: DA Morgan wrote: Martin T. wrote: When will they give me templates for my packaged SQL?!? ![]() cheers, Martin Please explain ... off-line if you prefer. Hu? Off-line? It's just a fancy idea of mine ... So we have VIEWS ... which are stored queries to make things more organized. Why not have more flexible "views" where part of the "view" remains variable until used ... so that the user of the view could push predicates or whatever into the view ... the SQL engine wouldn't even be aware of it, just the PL/SQL compiler. Or at least give me packaged views ... cursors are alright but they're so awful to use in PL/SQL code compared to inline queries ... (And I so hate having to define everything on the schema level.) Well. Just my 002. I'm sure you disagree ;-) cheers, Martin I don't disagree. But how is this different from putting a pipelined table function with NDS into a package? -- Yes, this would be a possible solution (or work-around). |
![]() |
| Thread Tools | |
| Display Modes | |
| |