I have a view call that takes 30 minutes when I’m calling the view like select * from PIVOTED_DATA where local_datetime>= '2024-06-13 00:00 and local_datetime<= '2024-06-13 01:00
, but if inside a query I set that condition, takes only 11 seconds.
The view definition is this:
create or replace view PIVOTED_DATA as (
with
long_format_data as(
select
src.local_datetime,
src.tag_name,
-- tag_description,
src.VALUE_FLOAT
from data_source as src
where
company='Huggies'
and tag_name in (
select
tag_name
from
master_tag_dictionary
where
DIVISION = 'Sales'
)
),
pivot_data as (
select *
from long_format_data
PIVOT (
MAX(VALUE_FLOAT)
FOR TAG_NAME IN (
ANY ORDER BY TAG_NAME
)
-- FOR tag_description IN (
-- ANY ORDER BY tag_description
-- )
)
order by
local_datetime desc
)
select
*
from
pivot_data
)
;
I tried to call a query directly and set a where clause inside long_format_data like
local_datetime>= '2024-06-13 00:00 and local_datetime<= '2024-06-13 01:00
the query only takes 11 seconds to return data.
What should I modify to the view to support that filtering first instead of probably filtering at the end?
Sin Nombre CO is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.