SqlGeography spatial operations are slow - SQL Server 2016

I ran several tests in the new SqlGeography spatial library in SQL Server 2016, which, according to Microsoft, should be much faster than previous versions:

SQL Server 2016 - it just works faster: proprietary spatial implementations. Apply SQL Server 2016, and the breadth of methods and spatial actions are faster and better. There are no application or database changes since SQL Server binary updates show significant improvement.

However, tests show that the new library is slower than the old. I tested it in C # with Nugets published by Microsoft, Microsoft.SqlServer.Types . I tested version 11 compared to version 14 (SQL Server 2016).

What should I do to improve the performance of the new spatial library?

Source code for a little test:

 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; } 
+5
source share
1 answer

In this article, Microsoft writes that Microsoft.SqlServer.Types is no longer used in T-SQL code in SQL Server 2016. https://blogs.msdn.microsoft.com/psssql/2016/03/03/sql-2016-it -just-runs-faster-native-spatial-implementations /

How it works in SQL 2014:

As the SQL Server spatial data types matured, we discovered Unmanaged (SQL Server) for Managed (Microsoft.SqlServer.Types) SqlServerSpatial ###. Dll (unmanaged) transitions (PInvoke and PUnInvoke) can become a scalability bottleneck

In SQL 2016:

(T-SQL) SQL Server 2016 invokes the implementation of native methods, avoiding unmanaged to managed unmanaged transitions, improving performance.

It seems that SQL 2016 directly uses SqlServerSpatial ###. dll, and performance is only in T-SQL code

+8
source

All Articles