1

Let's say we have a database of Birthday Clowns that contains a geography column containing the binary representation of a Point where each clown is located (generated from the latitude and longitude of the clown's home address). There's a geo-index on the geography column.

The CEO of a major international software company sends us a CSV file of all of their employees in the US, and their street addresses, including latitude and longitude; we have to generate a report that says for each employee how many birthday clowns are within 15 miles.

Our where condition could look like this:

where 
(ClownLocationInBinary).STDistance( geography::Point(EES.lat, EES.lng, 4326) ) < radius

or like this:

where
   geography::Point(EES.lat, EES.lng, 4326).STDistance(ClownLocationInBinary) < radius

Will both where-clauses take advantage of the index we created on our BirthdayClowns table? Or does one of them use it but not the other? If so, which is which?

alroc
  • 27,574
  • 6
  • 51
  • 97
Tim
  • 8,669
  • 31
  • 105
  • 183

1 Answers1

0

When I asked yesterday, I wasn't at a machine with a SQL Server installation and couldn't check the query plan, and couldn't find the info by searching. But I've since had a chance to check out the query plan, and BOTH versions of the where clause use the index.

Tim
  • 8,669
  • 31
  • 105
  • 183