当前位置:网站首页>Azure synapse analytics Performance Optimization Guide (4) -- optimize performance using result set caching
Azure synapse analytics Performance Optimization Guide (4) -- optimize performance using result set caching
2022-07-26 23:39:00 【zyypjc】
Catalog
1. Enable for user database / Disable result set caching
(1) Check the statistics settings of the database
(2) Enable query storage for the database
(3) Enable result set caching for the database
(4) Check the result set cache settings of the database
(5) Enable... For the database Read_Committed_Snapshot Options
2. Enable for session / Disable result set caching
3. Check the size of the cached result set
( 3、 ... and ) What is not cached
( Four ) When to use cached results
( 5、 ... and ) Manage cached results
( One ) Preface
After enabling result set caching , special SQL The pool will automatically cache the query results in the user database , For reuse . such , Subsequent query execution can get results directly from the persistence cache , So there's no need to recalculate . Result set caching improves query performance , And reduce the consumption of computing resources . Besides , Queries that use cached result sets do not occupy any concurrent slots , Therefore, the existing concurrency limit will not be included . For safety reasons , If the data access permission of the accessor user is the same as that of the user who created the cache results , Then the accessor user can only access the cached results . At the database and session levels , By default, the result set cache is “ close ”.
( Two ) Key orders
1. Enable for user database / Disable result set caching
(1) Check the statistics settings of the database
SELECT name, is_auto_create_stats_on FROM sys.databases(2) Enable query storage for the database
ALTER DATABASE [database_name]
SET QUERY_STORE = ON;(3) Enable result set caching for the database
-- Run this command when connecting to the MASTER database
ALTER DATABASE [database_name]
SET RESULT_SET_CACHING ON;(4) Check the result set cache settings of the database
SELECT name, is_result_set_caching_on
FROM sys.databases;(5) Enable... For the database Read_Committed_Snapshot Options
Connect to master Run this command while running the database .
ALTER DATABASE MyDatabase
SET READ_COMMITTED_SNAPSHOT ON;(6) Authority required
A . To set up RESULT_SET_CACHING Options , User needs server level principal login ( Login name created during provisioning ) Or become dbmanager Members of the database role .
B . To set up READ_COMMITTED_SNAPSHOT Options , Users need to have ALTER jurisdiction .
2. Enable for session / Disable result set caching
(1) Example
Using query request_id Inquire about sys.dm_pdw_exec_requests
Medium result_cache_hit Column to see if this query is executed using result cache hits or misses .
SELECT result_cache_hit
FROM sys.dm_pdw_exec_requests
WHERE request_id = 'QID58286'(2) jurisdiction
Require membership with public roles
3. Check the size of the cached result set
(1) Command statement
DBCC SHOWRESULTCACHESPACEUSED;remarks
A . Azure Synapse Analytics No server in SQL Pool does not support this syntax .
B .DBCC SHOWRESULTCACHESPACEUSEDThe command does not use any parameters , And it will return the space used by the database running this command .
(2) jurisdiction
need VIEW SERVER STATE jurisdiction .
(3) Result set
| Column | data type | explain |
|---|---|---|
| reserved_space | bigint | Total space for database , Unit is KB. This number changes as the cached result set increases . |
| data_space | bigint | Space for data , Unit is KB. |
| index_space | bigint | Space for indexing , Unit is KB. |
| unused_space | bigint | Unused space in reserved space , Unit is KB. |
4. Clean cache
from Azure Azure Synapse Analytics Delete all result set cache entries from the database .
(1) grammar
DBCC DROPRESULTSETCACHE
[;]remarks
This command will empty the result set cache of all queries .
Turning off the result set caching function of the database will also delete all cached results .
Pausing a database with result set caching enabled will not delete cached results .
Azure Synapse Analytics No server in SQL Pool does not support this syntax .
(2) jurisdiction
Require to have DB_OWNER Membership in the fixed server role .
( 3、 ... and ) What is not cached
After enabling result set caching for the database , The results of all queries will be cached before the cache is full , Except for the following queries :
- Queries with built-in functions or runtime expressions , These expressions are non deterministic expressions , Even if there is no change in the data or query of the base table . for example ,DateTime.Now()、GetDate().
- Queries using user-defined functions
- Queries using tables with row level security or column level security enabled
- The row size in the returned data exceeds 64KB Query for
- Return big data (>10GB) Query for
remarks
- Some non deterministic functions and runtime expressions can be deterministic for repeated queries of the same data . for example ,ROW_NUMBER().
- If the row order in the query result set / Sequences are important to application logic , Please use ORDER BY.
- If ORDER BY The data in the column is not unique , Whether the result set cache is enabled or disabled , There's no guarantee that ORDER BY Row order of rows with the same value in the column .
important
The operations of creating a result set cache and retrieving data from the cache are dedicated SQL On the control node of the pool instance . When the result set cache is on , Run to return a large result set ( for example ,>1GB) The query of may cause high bandwidth restriction on the control node , And reduce the overall query response speed on the instance . These queries are usually used in data browsing or ETL Use during operation . To avoid causing pressure on the control node and causing performance problems , Users should turn off the result set cache of the database before running such queries .
The run duration of this query should be the time required to perform the result set cache operation for a query :
SELECT step_index, operation_type, location_type, status, total_elapsed_time, command
FROM sys.dm_pdw_request_steps
WHERE request_id = <'request_id'>;The following is an example output of a query executed with result set caching disabled .

The following is an example output of a query executed with result set caching enabled .

( Four ) When to use cached results
If all the following requirements are met , The cached result set will be reused for queries :
- The user running the query has access to all tables referenced in the query .
- There is an exact match between the new query and the previous query that generated the result set cache .
- No data or schema changes have occurred in the table from which the cached result set was generated .
Run the following command to check whether a query has been executed and there are result cache hits or misses . result_cache_hit Column pair cache hit returns 1, Return for cache error 0, The reason why the result set cache is not used , Then return a negative value . For more information , Please check sys.dm_pdw_exec_requests
.
SELECT request_id, command, result_cache_hit FROM sys.dm_pdw_exec_requests
WHERE request_id = <'Your_Query_Request_ID'>
( 5、 ... and ) Manage cached results
The maximum size of the result set cache for each database is 1 TB. When the basic query data changes , The cached results will be invalidated automatically .
Cache eviction by dedicated SQL The pool is automatically managed according to the following plan :
- The result set has not been used or has expired ( Every time 48 Once per hour ).
- When the result set cache is close to the maximum size .
Users can manually empty the entire result set cache using one of the following options :
- Disable the result set caching function for the database
- Connect to the database and run DBCC DROPRESULTSETCACHE
Pausing the database will not empty the cached result set .
边栏推荐
- Basic operations of objects
- ES6新特性
- [Luogu] p1395 meeting
- 【C语言】经典的递归问题
- What are the use cases in the Internet of things industry in 2022?
- 2022.7.18-----leetcode.749
- Go uses flag package to parse command line parameters
- [step by step, even thousands of miles] key words in the specified time period of the statistical log
- 会议OA项目排座功能以及送审功能
- 第二部分—C语言提高篇_7. 结构体
猜你喜欢

How to use data pipeline to realize test modernization

Science | University of Washington uses AI and structural prediction to design new proteins

1. Configuration environment and project creation

研究阿尔茨海默病最经典的Nature论文涉嫌造假

The NFT market pattern has not changed. Can okaleido set off a new round of waves?

Part II - C language improvement_ 12. Packaging and use of dynamic / precision Library

Machine learning notes - building recommendation system (3) six research directions of deep recommendation system

Use Arthas to locate online problems

关于可穿戴式NFT你应该知道的一切!

上千Tile的倾斜模型浏览提速,告别一块一块往外蹦的尴尬
随机推荐
Distributed lock and its implementation
[interview: concurrency 26: multithreading: two-phase termination mode] volatile version
Hcia-r & s self use notes (23) DHCP
Dajiang Zhitu and CC have produced multiple copies of data. How to combine them into one and load them in the new earth map
Real time voice quality monitoring
np.transpose & np.expand_dims
About statefulwidget, you have to know the principle and main points!
2022.7.18-----leetcode.749
数据供应链的转型 协调一致走向成功的三大有效策略
Application of workflow engine in vivo marketing automation | engine 03
华裔科学家Ashe教授对涉嫌造假的Nature论文的正面回应
Re understand the life world and ourselves
公有云安全性和合规性方面的考虑事项
Part II - C language improvement_ 12. Packaging and use of dynamic / precision Library
百度网址收录
第二部分—C语言提高篇_13. 递归函数
np. transpose & np.expand_ dims
Professor Ashe, a Chinese scientist, made a positive response to the suspected fake Nature paper
8 other programming languages -- Recording
[H5 bottom scrolling paging loading]