I have the following script. To reduce the execution time, I replaced get_function() with a constant ‘ABCD’ ( which is the result of get_function() ). I expect to decrease the execution time ;while, interestingly the execution time is increased almost 4 times.
alter system flush buffer_cache;
alter system flush shared_pool;
Set timing on;
declare x number(3);
begin
select v.QTY
into x
from viewName v
where v.col1 = get_function() --'ABCD';
exception when others then dbms_output.put_line(sqlerrm||' '||sqlcode);
end;
Set timing off;
So far without the filter on column1, it might be using some indexes. Once you introduced column1 which is not part of any of these indexes, a table scan will be performed (since this is a varchar column) and hence the increase in the execution time. You should go through the execution plan of your view before and after the addition of this new filter on column1 and you will be able to figure out the right index definition/modification.