I have an Oracle SQL query like so, and it takes 44 seconds to run.
select shipment_id, Shipment_Flow_API.Get_Next_Step(SHIPMENT_ID) Shipment_flow
from shipment_line_ovw
where
SHIPMENT_STATE = 'Preliminary'
and Shipment_Flow_API.Get_Next_Step(SHIPMENT_ID) = 'Report picking, Print pick list'
If I take out the last line and do it like this. It only take 0.43 seconds to run, and returns about 100 records.
select shipment_id, Shipment_Flow_API.Get_Next_Step(SHIPMENT_ID) Shipment_flow
from shipment_line_ovw
where
SHIPMENT_STATE = 'Preliminary'
Was thinking that if I tried to make the above a cte or a subquery of 100 records, then filter on the shipment flow column after, it should run fast, like below. but the oracle engine still tries to reselect from the original table and filter by all the records, so it still takes over 40 seconds
with cte as (
select
shipment_id, Shipment_Flow_API.Get_Next_Step(SHIPMENT_ID) Shipment_flow
from shipment_line_ovw
where
SHIPMENT_STATE = 'Preliminary'
)
select * from cte
where Shipment_flow = 'Report picking, Print pick list';
How to I get this to be a set of records in memory first before filtering so that it runs faster?