Click here to Skip to main content
15,887,849 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
Hi,
SQL
 declare @points nvarchar(500)='POINT(-76.5921662 39.2674632)'

SELECT *
  FROM [NeighborhoodsTable] 
  WHERE [NbhoodPolygon].MakeValid().STIntersects(geometry::STGeomFromText(@points, 4326)) =1


This query taking 20 seconds.
NbhoodPolygon column datatype is geometry.
In my database 2 lakhs records is there.
Help me Plz...

What I have tried:

I need to optimize the query, I want results in quickly.
Posted
Updated 20-Apr-16 14:16pm
v3
Comments
John C Rayan 20-Apr-16 8:50am    
I have not used geometry in my projects but you have to use spatial indexes using Bounding Box I guess.
NagaRaju Pesarlanka 20-Apr-16 9:00am    
yes

1 solution

Firstly do not use SELECT *. Specify the columns you want to return in your query or SQL needs to perform another query to get the column names.

Secondly, use the Database Engine Tuning Adviser to determine what indexes are required for the query - it is on the Windows Start Menu under SQL >> Performance Tools
This can be also normally be done by selecting your query & then right-clicking or can also be done by using SQL Profiler to capture a trace of the query.
You can also use the option in SQL Management Studio to "Include actual execution plan". This will often advise of missing indexes but it is not as effective as the Tuning Wizard.

Neither method is foolproof nor do they take into account your typical workload. Read up on Indexing for additional information on what you need to take into account before blindly applying recommendations & test against real workloads - indexes need to be updated when the table data is changed & this may negatively affect performance.

Kind Regards
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900