Skip to Main Content
SQL Server 2017 Developer???s Guide
book

SQL Server 2017 Developer???s Guide

by Dejan Sarka, Miloš Radivojević, William Durkin
March 2018
Intermediate to advanced content levelIntermediate to advanced
816 pages
19h 35m
English
Packt Publishing
Content preview from SQL Server 2017 Developer???s Guide

Optimizing temporal queries

The problem with temporal queries is that when reading from a table, SQL Server can use only one index, successfully eliminate rows that are not candidates for the result from one side only, and then scan the rest of the data. For example, you need to find all intervals in the table that overlap with a given interval. Remember, two intervals overlap when the beginning of the first one is lower than or equal to the end of the second one, and the beginning of the second one is lower than or equal to the end of the first one, or mathematically when (b1 ≤ e2) AND (b2 ≤ e1).

The following query searches for all of the intervals that overlap with the interval (10, 30). Note that the second condition (b2 ≤ e1) is turned ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

SQL Server 2016 Developer's Guide

SQL Server 2016 Developer's Guide

Miloš Radivojević, Dejan Sarka, William Durkin
Mastering SQL Server 2017

Mastering SQL Server 2017

Milos Radivojevic, Dejan Sarka, William Durkin, Christian Cote, Matija Lah

Publisher Resources

ISBN: 9781788476195Supplemental Content