Which Query is Better in terms of Performance

Database

Which Query is Better in terms of Performance

i have 1 table with millions of records in it and wanted to write one query.

I have written 2 query's, since i am not a Teradata expert want to validate need your expert advice.

Query1:
where extract(month from date) in (3,6,9,12)
and fscl_yr_nbr = case when extract(month from date) in (1,2,3,4,5) Then extract(Year from date) else extract(Year from date) + 1 end
and fscl_qtr_nbr = case when extract(month from date) in (12,1,2) Then 3
when extract(month from date) in (3,4,5) Then 4
when extract(month from date) in (6,7,8) Then 1 else 2
end

Query2:
where EXISTS (select 1 from sys_calendar.calendar where month_of_Year = Extract (Month From Current_Date)
and month_of_year in(3,6,9,12))
and fscl_yr_nbr = case when extract(month from date) in (1,2,3,4,5) Then extract(Year from date) else extract(Year from date) + 1 end
and fscl_qtr_nbr = case when extract(month from date) in (12,1,2) Then 3
when extract(month from date) in (3,4,5) Then 4
when extract(month from date) in (6,7,8) Then 1 else 2
end
Tags (1)
1 REPLY
Enthusiast

Re: Which Query is Better in terms of Performance

The best way to answer this question is to run an explain plan and see which query has a lower overal cost estimate. Paste the query text into the query window and press F6, or you could preface the query text with the keyword "explain" (without the quotes) and run the query with either F5 or F9.