4

I need to apply a query hint (like NOWAIT or NOLOCK) to the CROSS APPLY in this query. How do I do it:

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;

SELECT *
FROM sys.objects obj WITH (NOLOCK) 
INNER JOIN sys.stats stat WITH (NOLOCK) ON stat.object_id = obj.object_id  
CROSS APPLY sys.dm_db_stats_properties(stat.object_id, stat.stats_id) sp

I don't have access to the function contents (for obvious reasons.)

I went ahead and removed the repro from the question to make it more clear. I'm less concerned about the ability to reproduce the blocking. (It's also happening at customer environments, and in the First Responder Kit in issue # 2548.)

0
5

You can't, as far as I'm aware.

One might try things like:

OPTION (TABLE HINT (sp, READUNCOMMITTED))

...but this will fail for things that aren't real tables.

Table-valued or OPENROWSET function 'sp' cannot be specified in the TABLE HINT clause.

It would also fail because the desired hint is semantic-affecting.

If the thing you need to access doesn't respond to setting the isolation level, you'll have to report the deficiency and hope for a fix.

There was a Connect item about DMVs and whatnot not respecting isolation level, and as best I recall, the official word was that isolation level was not guaranteed for system functions.

Aaron Bertrand said:

There are some built-ins that simply don't obey isolation level no matter how the hint gets there (e.g. OBJECT_SCHEMA_NAME().


Also, as Martin Smith remarked:

The issue is really how to apply it to a TVF - not a CROSS APPLY

SELECT * FROM sys.dm_db_stats_properties(1,1) WITH (NOLOCK)

also fails. But conversely this succeeds:

SELECT *
FROM sys.objects obj WITH (NOLOCK) 
INNER JOIN sys.stats stat WITH (NOLOCK) ON stat.object_id = obj.object_id  
CROSS APPLY sys.objects obj2 WITH (NOLOCK)

Not the answer you're looking for? Browse other questions tagged or ask your own question.