Understanding the UID in sysquerymetrics

The user ID (UID) of sysquerymetrics is 0 when all table names in a query that are not qualified by user name are owned by the database owner.

Example 1

select * from t1 where cl = 1

t1 is owned by database owner and is shared by different users. 0 is the UID for the entry into sysquerymetrics no matter which user issues the query.

Example 2

select * from t2 where cl = 1

In this case, t2 is owned by user1. user1’s UID is used for the entry in sysquerymetrics, since t2 is unqualified and is not owned by the database owner.

Example 3

select * from u1.t3 where cl = 1

Here, t3 is owned by u1 and is qualified by u1, so UID 0 is used.

This increases the sharing of metrics between user IDs to reduce the number of entries in sysqueryplans. Aggregation of metrics for identical queries with different user IDs is done automatically. Turn on trace flag 15361 to use the UID of the user who issues the query.

NoteQP metrics for insert...selec, /update, delete statements are captured when at least one table is involved. CIS-related queries and insert...values statements are not included.