Repository navigation
Fix the permissions required by sys.query_store_query_text and sys.query_store_query_hints - #10461
Conversation
|
Rudi Bruchez (@rudi-bruchez) : Thanks for your contribution! The author(s) and reviewer(s) have been notified to review your proposed change. |
|
Learn Build status updates of commit 4f63767: ✅ Validation status: passed
For more details, please refer to the build report. |
There was a problem hiding this comment.
🟢 Approval recommended
The documented permissions are corrected consistently, with no unresolved review issues.
No open issues 🎉
What changed in this PR
Corrects the documented database-level permissions for the Query Store catalog views sys.query_store_query_text and sys.query_store_query_hints.
Changes:
- Replaces incorrect server-level requirements with
VIEW DATABASE STATEfor pre-2022 SQL Server. - Documents
VIEW DATABASE PERFORMANCE STATEfor SQL Server 2022 and later. - Aligns both pages with related Query Store catalog view documentation.
| File | Description |
|---|---|
docs/relational-databases/system-catalog-views/sys-query-store-query-text-transact-sql.md |
Corrects permissions for SQL Server versions before 2022 and SQL Server 2022 and later. |
docs/relational-databases/system-catalog-views/sys-query-store-query-hints-transact-sql.md |
Corrects the database-level permission requirement for SQL Server 2022 and later. |
Review effort: Lite
|
Dimitri Furman (@dimitri-furman) Can you review the proposed changes? Important: When the changes are ready for publication, adding a #label:"aq-pr-triaged" |
What's wrong
On both pages, the Permissions section says that SQL Server 2019 and previous versions "require
VIEW SERVER STATEpermission on the server", and that SQL Server 2022 and later "requireVIEW SERVER PERFORMANCE STATEpermission on the server".The view is database scoped, like the other Query Store catalog views. A database user with only
VIEW DATABASE STATE(or, on SQL Server 2022 and later, onlyVIEW DATABASE PERFORMANCE STATE) reads it, without any server permission. A user without the database permission gets error 262, which namesVIEW DATABASE PERFORMANCE STATE. Until commit b33ab10 (November 2024), both pages said "Requires the VIEW DATABASE STATE permission", assys.query_store_query,sys.query_store_planandsys.query_store_runtime_stats_intervalstill do.Evidence
SQL Server 2019 CU32-GDR (15.0), 2022 CU26 (16.0.4265.3) and 2025 CU9-GDR (17.0.5015.4), Linux containers, fresh database with Query Store in
ALLcapture mode.Observed on the three versions:
has_view_server_state= 0,texts_as_reader= 1 (the same count as forsa). On 2022 and 2025, a user granted onlyVIEW DATABASE PERFORMANCE STATEreads the view too, and a user with no permission gets:Expected per the current text: the query fails without a server permission.
The same holds for
sys.query_store_query_hints(SQL Server 2025 CU9-GDR): aftersp_query_store_set_hints, a user with onlyVIEW DATABASE STATE, andHAS_PERMS_BY_NAME(NULL, NULL, 'VIEW SERVER STATE')= 0, reads the hint row.Change
On
sys.query_store_query_text, replace the two server-level sentences with the database-level wording used by the other Query Store catalog views. Onsys.query_store_query_hints, which applies to SQL Server 2022 and later, keep only the SQL Server 2022 wording.