Sql: Optimizing BETWEEN clause

前端 未结 9 852
孤街浪徒
孤街浪徒 2021-02-06 07:38

I wrote a statement that takes almost an hour to run so I am asking help so I can get to do this faster. So here we go:

I am making an inner join of two tables :

<
9条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-06 08:19

    Your SQL is equivalent to:

    select m.measure. m.time, 
         i.entry_time, i.exit_time
    from intervals i
        join measures m
            on m.time Between i.entry_time And i.exit_time  
    order by time asc
    

    The only thing I might suggest is making sure there's an index on m.Time. Then if that doesn't improve performance enough, try adding indices on i.Start_Time and i.End_Time as well

提交回复
热议问题