The query below is using the StackOverflow2010 sample database:
DECLARE @Id INT = 18471 SELECT c.UserId FROM dbo.Comments AS c INNER HASH JOIN dbo.Users AS u ON c.UserId = u.Id AND c.UserId = @Id
With a hash join hint, it returns the following error:
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
It works when I add
OPTION(RECOMPILE) or replace the variable with a string literal.
What could be causing this issue?