title: Query processor could not produce a query plan because of the hints defined in this query. Resubmit the query and without using SET FORCEPLAN
body: <p>I am running following:</p>
  
  <pre><code>DECLARE @g geography;
  declare @point nvarchar(50)  =''
  declare @i int =0,
          @lat decimal(8,6) =0.0,
          @long decimal(8,6) =0.0,
          @start datetime = getdate()
  set @lat =(select (0.9 -Rand()*1.8)*100)
  set @long =(select (0.9 -Rand()*1.8)*100)
  set @point = (select 'POINT('+CONVERT(varchar(10), @lat)+ '  ' 
               +CONVERT(varchar(10), @long)+')')
  SET @g = geography::STGeomFromText(@point, 4326);
  SELECT TOP 1000
      @lat,
      @long,
          @g.STDistance(st.[coord]) AS [DistanceFromPoint (in meters)] 
      ,   st.[coord]
      ,   st.id
  FROM    Temp st with(index([SpatialIndex_1]))
  </code></pre>
  
  <p>this query performed poorly because it does not use spacial index, so I added <code>with(index([SpatialIndex_1]))</code> to force it.</p>
  
  <p>geography index looks following:</p>
  
  <pre><code>CREATE SPATIAL INDEX [SpatialIndex_1] ON [dbo].Temp
  (
      [coord]
  )USING  GEOGRAPHY_GRID 
  WITH (GRIDS =(LEVEL_1 = LOW,LEVEL_2 = MEDIUM,LEVEL_3 = LOW,LEVEL_4 = LOW), 
  CELLS_PER_OBJECT = 16, PAD_INDEX = OFF,
  STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF,
  ONLINE = OFF, ALLOW_ROW_LOCKS = OFF, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 95) 
  ON [PRIMARY]
  </code></pre>
  
  <p>Now it gives me error message </p>
  
  <blockquote>
    <p>Msg 8622, Level 16, State 1, Line 15 Query processor could not
    produce a query plan because of the hints defined in this query.
    Resubmit the query without specifying any hints and without using SET
    FORCEPLAN.</p>
  </blockquote>
  
  <p>I can read and understand that it tells me to remove hint, question is why does it succeed at compilation but fails on run-time? Is there something wrong with my index? </p>
  
  <p><strong>What do I need to change for SQL to start using Spatial index?</strong></p>
  
  <p>to generate some data you could use following script.</p>
  
  <pre><code>CREATE TABLE dbo.Temp
      (
      Id int NOT NULL IDENTITY (1, 1),
      Coord geography NOT NULL
      )  ON [PRIMARY]
       TEXTIMAGE_ON [PRIMARY]
  GO
  ALTER TABLE dbo.Temp ADD CONSTRAINT
      PK_Temp PRIMARY KEY CLUSTERED 
      (
      Id
      ) 
  WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
        ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) 
  ON [PRIMARY]
  GO
  
  
  declare @i int =0
  declare @lat decimal(8,6) =0.0
  declare @long decimal(8,6) =0.0
  while (@i &lt; 47000)
  begin
     set @lat =(select (0.9 -Rand()*1.8)*100)
     set @long =(select (0.9 -Rand()*1.8)*100)
     insert into Temp
     select geography::Point(@lat, @long,4326)
     set @i =@i+1
  end
  go
  
  CREATE SPATIAL INDEX [SpatialIndex_1] ON [dbo].Temp
  (
      [coord]
  )USING  GEOGRAPHY_GRID 
  WITH (GRIDS =(LEVEL_1 = LOW,LEVEL_2 = MEDIUM,LEVEL_3 = LOW,LEVEL_4 = LOW), 
     CELLS_PER_OBJECT = 16, PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
     SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF,
     ALLOW_ROW_LOCKS = OFF, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 95) 
  ON [PRIMARY]
  GO
  </code></pre>