Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6841457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:58:09+00:00 2026-05-26T23:58:09+00:00

I am having serious performance issues with a spatial update query in SQL Server

  • 0

I am having serious performance issues with a spatial update query in SQL Server 2008 (not R2) using STDistance(). The goal is simple enough: I have a table with 120,000 records, Houses with the column NearestLibrary. I have a second table with 12 records, Libraries with the column Name. Both tables have a geography column LatLngGeography. I want to update Houses.NearestLibrary with the name of the closest library from Libraries.

This query takes around 50 seconds to run:

UPDATE Houses
    SET NearestLibrary = (
    SELECT TOP 1 Name
    FROM Libraries
    ORDER BY Houses.LatLngGeography.STDistance(Libraries.LatLngGeography)
)

That would almost be acceptable, except that when I run it for Parks instead of Libraries where I have about 100 parks, it takes almost 10 times as long. Both tables have properly constructed spatial indexes named IX_Houses_LatLngGeography and IX_Libraries_LatLngGeography respectively but thus far I have been unable to work out how make my query use them.

Is there a way to improve the performance of my query?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:58:09+00:00Added an answer on May 26, 2026 at 11:58 pm

    Use an “Index Hint”.

    UPDATE Houses     
    SET NearestLibrary = (     
        SELECT TOP 1 Name     
        FROM Libraries WITH(INDEX( SPATIAL_INDEX_NAME_HERE ))
        ORDER BY Houses.LatLngGeography.STDistance(Libraries.LatLngGeography) 
    ) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some serious performance issues with a multi-million row table that I feel
I am having some serious issues trying to tweak my layout in a table.
I am writing a webapp in ZF and am having serious issues with UTF8.
I am having serious issues trying to use the Javascript API for facebook. I
I'm having serious trouble configuring my OpenLDAP server to have the memberOf overlay enabled.
I'm having serious problems in how to update the record that has just been
Maybe im just an idiot, but I am having serious issues mapping relationships with
I'm having serious issues linking a library despite doing the same routine I've done
I'm having some serious rails issues. I haven't used it in quite some time
I've been having some serious issues with Visual Studio 2010 as of late. It's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.