Microsoft SQL Server Index Type

Spatial Indexes in Microsoft SQL Server: How It Works and When to Use It

Tessellates spatial objects into hierarchical grids, narrowing candidate objects for supported spatial methods.

What Is a Spatial Indexes in Microsoft SQL Server?

Tessellates spatial objects into hierarchical grids, narrowing candidate objects for supported spatial methods.

How the Spatial Indexes Algorithm Works

Tessellates spatial objects into hierarchical grids, narrowing candidate objects for supported spatial methods.

Diagram showing the Spatial Indexes lookup algorithm
Conceptual Spatial Indexes algorithm. Exact behavior depends on the database version and query plan.

When to Use Spatial Indexes

Geometry/geography intersection, distance, and containment predicates compatible with spatial indexing.

How to Create a Microsoft SQL Server Spatial Indexes

Review data quality, existing structures, feature support, build time, and deployment requirements before creating an index on a production table.

CREATE SPATIAL INDEX IX_Stores_Location ON dbo.Stores (Location) USING GEOGRAPHY_AUTO_GRID;

Spatial Indexes Query Example

This example demonstrates the matching query shape. Check the execution plan to confirm that the engine can use the index.

SELECT StoreId FROM dbo.Stores WHERE Location.STDistance(geography::Point(47.6, -122.3, 4326)) <= 5000;

Queries Supported by Spatial Indexes

Geometry/geography intersection, distance, and containment predicates compatible with spatial indexing. A similar-looking predicate may not use the same access path; operators, expressions, key order, and data type all matter.

Read Performance, Storage, and Write Costs

Grid tessellation controls candidate count; exact calculations may recheck candidates. Indexes reduce some search work but require storage and add maintenance to writes.

Spatial Indexes Limitations and Common Mistakes

Coordinate argument order, units, SRID, and method affect eligibility and correctness.

Do not assume that an index being present means the optimizer chose it or that the query became selective.

How to Measure and Tune Spatial Indexes

Validate SRID/units and use actual plans to inspect spatial-index use and candidates.

Compare representative plans and timings before and after, including concurrent writes and realistic data volumes.

Spatial Indexes Questions

Will the database always use this index?

No. The optimizer weighs selectivity, estimated costs, statistics, cache state, and the amount of data returned.

What should I verify before production?

Confirm version support, query compatibility, write overhead, build/rollback procedures, and index behavior during backup and recovery.

Official Microsoft SQL Server Index Documentation

Check Microsoft Learn: SQL Server Indexes for release-specific requirements and supported operators.