performance - absolutely NO functions surrounding a tstamp in a SQL? Hourly historical data query -
i need obtain specific hours data specific week day 10 weeks. db work on oracle. came following condtions time stamp field:
to_char(hy.tstamp,'hh24')='10' , hy.tstamp > sysdate - 70 , mod(extract ( day sysdate-1) - extract ( day hy.tstamp), 7) =0
someone told me "absolutely no functions surrounding tstamp" (for performance reasons?). how specify conditions without operations on time stamp field?
you can filter out time slices without functions or function indexes if join table of acceptable ranges. can create 1 on fly (note need functions create table, won't need them afterward):
select trunc(sysdate + 6) - (7 * level) + interval '10' hour startat, trunc(sysdate + 6) - (7 * level) + interval '11' hour endat dual connect level <= 10
with today's date being 5/8/2013, give following:
startat endat ------------------- ------------------- 05/07/2013 10:00:00 05/07/2013 11:00:00 04/30/2013 10:00:00 04/30/2013 11:00:00 04/23/2013 10:00:00 04/23/2013 11:00:00 04/16/2013 10:00:00 04/16/2013 11:00:00 04/09/2013 10:00:00 04/09/2013 11:00:00 04/02/2013 10:00:00 04/02/2013 11:00:00 03/26/2013 10:00:00 03/26/2013 11:00:00 03/19/2013 10:00:00 03/19/2013 11:00:00 03/12/2013 10:00:00 03/12/2013 11:00:00 03/05/2013 10:00:00 03/05/2013 11:00:00
now join query time slices want, , note don't need functions:
with timeranges ( select trunc(sysdate + 6) - (7 * level) + interval '10' hour startat, trunc(sysdate + 6) - (7 * level) + interval '11' hour endat dual connect level <= 10 ) select ... whatever ... your_table hy inner join timeranges on hy.tstamp >= timeranges.startat , hy.tstamp < timeranges.endat
if db person understands filtering on timestamp functions kills performance (unless, woot4moo points out, implement function indexes), they'll understand functions used create table of timeslices won't impact larger query.
Comments
Post a Comment