# Spatial Data/Indexing performance issues

### คำตอบ

• Without trying to be obtuse, perhaps I can answer your question with another question: "What made you think that using the geography datatype would make this query faster than using the old skool method?"

The geography datatype allows you to describe and store complex shapes - LineStrings, Polygons, Curves (from SQL 2012), and collections of these types, each one potentially containing thousands or more points. These shapes are positioned on an ellipsoidal surface, using one of a recognised number of geodetic models that approximate the shape of the earth. It provides methods not only to derive the distance between points, but to perform complex tests such as whether (and where) two shapes intersect, whether two shapes cross, overlap, or are contained within one another, and to calculate the area contained within an abstract shape, for example.

So, the geography datatype is good for performing accurate spatial computations between complex geometries. The trade-off is that it is not necessarily as fast as "old-skool" methods for performing simple Point-to-Point distance calculations. If you're happy using a simple approximation of the shape of the earth as a sphere, and you're only dealing with locations that can be described by a single pair of latitude/longitude coordinates, and you only want to do simple calculations such as straight-line distance, you will almost always get better performance using simple numerical methods on two columns of the float datatype.

I covered this a little in my talk at SQLBits 5 - you can see the slide deck and video online:

http://sqlbits.com/Sessions/Event5/Creating_High_Performance_Spatial_Databases

• ทำเครื่องหมายเป็นคำตอบโดย 2 พฤษภาคม 2555 10:13
1 พฤษภาคม 2555 13:15

### ตอบทั้งหมด

• Without trying to be obtuse, perhaps I can answer your question with another question: "What made you think that using the geography datatype would make this query faster than using the old skool method?"

The geography datatype allows you to describe and store complex shapes - LineStrings, Polygons, Curves (from SQL 2012), and collections of these types, each one potentially containing thousands or more points. These shapes are positioned on an ellipsoidal surface, using one of a recognised number of geodetic models that approximate the shape of the earth. It provides methods not only to derive the distance between points, but to perform complex tests such as whether (and where) two shapes intersect, whether two shapes cross, overlap, or are contained within one another, and to calculate the area contained within an abstract shape, for example.

So, the geography datatype is good for performing accurate spatial computations between complex geometries. The trade-off is that it is not necessarily as fast as "old-skool" methods for performing simple Point-to-Point distance calculations. If you're happy using a simple approximation of the shape of the earth as a sphere, and you're only dealing with locations that can be described by a single pair of latitude/longitude coordinates, and you only want to do simple calculations such as straight-line distance, you will almost always get better performance using simple numerical methods on two columns of the float datatype.

I covered this a little in my talk at SQLBits 5 - you can see the slide deck and video online:

http://sqlbits.com/Sessions/Event5/Creating_High_Performance_Spatial_Databases