I have run some tests on the new spatial library SqlGeography
in SQL Server 2016, which according to Microsoft should be a lot faster than the previous versions:
SQL Server 2016 – It Just Runs Faster: Native Spatial Implementation(s). Apply SQL Server 2016 and a breadth of methods and spatial activities are faster and scale better. There are no application or database changes just the SQL Server binary updates showing dramatic improvement.
However, the tests shows that the new library is slower than the old one.
I have tested it in C# with the Nugets published by Microsoft, Microsoft.SqlServer.Types
. I have tested version 11 against version 14 (SQL Server 2016).
What should I do in order to get the new spatial library to perform better?
The source code for the small test is:
var line1 = CreateLine(56, -4, 58, 16);
var line2 = CreateLine(58, -4, 56, 16);
for (int i = 0; i < 50000; i++)
{
var intersection = line1.STIntersects(line2);
var contains = line1.STBuffer(1000).STContains(line1);
}
public static SqlGeography CreateLine(double fromLat, double fromLon, double toLat, double toLon)
{
SqlGeographyBuilder constructed = new SqlGeographyBuilder();
constructed.SetSrid(4326);
constructed.BeginGeography(OpenGisGeographyType.LineString);
constructed.BeginFigure(fromLat, fromLon);
constructed.AddLine(toLat, toLon);
constructed.EndFigure();
constructed.EndGeography();
var line = constructed.ConstructedGeography;
return line;
}