Query rewrite ( tuning )

Database
Highlighted
KN
Enthusiast

Query rewrite ( tuning )

Hi ,

 

I have  ticket sale data joined with the Date dimension table.. This is going for product join.  Is there a way that the construct of the qry could be changed?

 

QRY:

select c.oper_Carr_cd,
c.dprt_dt,c.issued_dt,i.calendar_dt,i.calendar_dt + 364 calendar_dt1, c.dprt_dt + 364 as Dprt_dt1,last_day(Dprt_dt1) as last_day_dprt_dtl,
c.Coup_orig_cd,
c.Coup_dest_cd,
c.RCRD_ID,
c.prorate_amt_usd,
c.fuel_Charge_amt_usd
from DB1.Ticket_sale_cons c

inner join DB2.date_dimension i
on i.calendar_dt <= c.issued_dt
and calendar_dt1 <= last_day_dprt_dtl
and calendar_dt1 <= '2019-07-06'

where Dprt_dt1 between '2019-03-31' and '2019-11-30'
and c.issued_dt between c.dprt_dt - 330 and current_date - 14 - 364
and c.oper_carr_cd in ('xx','yy','zz','aa')

1 REPLY 1
Teradata Employee

Re: Query rewrite ( tuning )

If you have no equality conditions in the ON clause, you will get a product join.

Do you really want to join each ticket sale to all prior calendar dates in the date dimension?