简体   繁体   中英

Oracle Query upon a Pipelined function works ok but chokes if I add a condition

I have a pipelind functions that returns a collection of custom objects, ie a nested table.

It works great ( < 4 seconds) when I select from it like this;

select e.* from table(MY_PIPLINED_FUNCTION)e

But when I add any condition (apart from where rownum<X ), the query takes forever to execute (like 5+ minutes) but it does return the desired value correctly at the end .

What's boggling me is that it is working but it takes an enormous amount of time to complete.

Has anyone got any ideas on this?

ps: it's a large result set, both in number of rows (30K+) and in number of columns (50+columns).

Are you comparing the time to get the entire result set? Or just the first N rows?

Does your predicate filter out 99% of the data, making one query work much harder to get those N rows?

The pipelined function may not have anything to do with it. You can have a pipelined function and still retrieve the first N rows without evaluating the entire result set. For example, the infinite loop below will quickly return results in an IDE that only retrieves a small number of rows.

create or replace type number_nt as table of number;

create or replace function pipe_function return number_nt pipelined is
begin
    while 1 = 1 loop
        pipe row(1);
    end loop;
end;
/

select column_value
from table(pipe_function)
where column_value < 2;

You may need to add more details about your function and predicate.

It gets the entire result set in order to apply filters.

You should improve the MY_PIPLINED_FUNCTION. Probably now it uses indexes and because of this the first_rows comes fast.

1.You can try to force it to use hash for joins.(this may get the full resultset in less time, but first rows will not come rapidly)

2.You can modify the function, and put the contiditions in the arguments of the function, modifying the function consequently - filter the rows from specific table. (IE instead of

select e.* from table(MY_PIPLINED_FUNCTION)e 
where e.name = 'mark'

to do

select e.* from table(MY_PIPLINED_FUNCTION('mark'))e 

)

These things may help...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM