%3CLINGO-SUB%20id%3D%22lingo-sub-688544%22%20slang%3D%22en-US%22%3EAzure%20DW%20Result%20Set%20Caching%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-688544%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20recently%20announced%20the%20release%20of%20Result%20Set%20caching%20for%20Azure%20Data%20Warehouse%20at%20Build%20and%20within%20our%20May%202019%20Release%20notes%20for%20Azure%20DW%2C%20this%20new%20feature%20allows%20you%20to%20cache%20the%20final%20return%20results%20for%20user%20queries.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20feature%20is%20only%20Available%20with%20Azure%20DW%20Gen%202%20and%20not%20for%20Azure%20SQL%20DB%20or%20APS%2FPDW.%3C%2FP%3E%0A%3CP%3EThe%20feature%20will%20not%20cache%20intermediate%20result%20sets%20and%20will%20not%20be%20used%20during%20CTAS%20or%20CRUD%20operations.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20cached%20results%20will%20be%20stored%20within%20the%20control%20node%20database%20and%20will%20consume%20a%20maximum%20of%201TB%20storage.%3C%2FP%3E%0A%3CP%3EThe%20results%20will%20be%20evicted%20from%20the%20cache%20if%20not%20referenced%20in%20the%20last%2048%20hours.%3C%2FP%3E%0A%3CP%3EQueries%20which%20are%20a%20cache%20hit%20will%20simply%20return%20the%20data%20from%20the%20result%20cache%20instead%20of%20running%20the%20full%20plan%20creation%20and%20retrieving%20the%20data%20across%20all%20of%20the%20distributions.%3C%2FP%3E%0A%3CP%3EIn%20the%20event%20of%20the%20query%20being%20a%20Cache%20miss%2C%20it%20will%20populate%20a%20result%20set%20table%20in%20the%20cache%20DB%20synchronously%20for%20the%20next%20execution%20of%20the%20statement.%3C%2FP%3E%0A%3CP%3EOnly%20pure%20select%20statements%20are%20cached%20against%20non-system%20and%20non-external%20objects%20which%20have%20no%20run%20time%20constraints%20or%20row%20level%20security%20predicates.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EEnabling%20the%20Feature%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3ETo%20enable%20the%20feature%2C%20you%20would%20require%20the%20following%20permissions%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EServer%20Level%20Principal%20Login%3C%2FLI%3E%0A%3CLI%3EMember%20of%20the%20dbmanager%20database%20role%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOnce%20the%20relevant%20permissions%20have%20been%20granted%20you%20will%20enable%20the%20feature%20from%20the%20master%20database%3C%2FP%3E%0A%3CP%3EAlter%20Database%20%3CDBNAME%3E%20Set%20Result_Set_Caching%20ON%3C%2FDBNAME%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20verify%20that%20the%20feature%20is%20enabled%20you%20can%20run%20the%20following%20statement%3C%2FP%3E%0A%3CP%3ESelect%20is_result_set_caching_on%20from%20sys.databases%20where%20name%20%3D%20'%3CDBNAME%3E'%3C%2FDBNAME%3E%3C%2FP%3E%0A%3CP%3EThis%20will%20return%20a%201%20if%20it%20is%20enabled%20and%200%20if%20it%20is%20not.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20disable%20the%20feature%3C%2FP%3E%0A%3CP%3EAlter%20Database%20%3CDBNAME%3E%20Set%20Result_Set_Caching%20OFF%3C%2FDBNAME%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EMonitoring%20use%20of%20the%20Feature%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3ECache%20usage%20can%20be%20monitored%20via%20DMV%20and%20will%20allow%20you%20review%20within%20the%20Query%20Request%20Steps%20if%20the%20specific%20Query%20ID%20had%20a%20cache%20hit%20or%20miss%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20(SELECT%26nbsp%3Bstep_index%26nbsp%3BFROM%26nbsp%3Bsys.dm_pdw_request_steps%26nbsp%3BWHERE%26nbsp%3Brequest_id%26nbsp%3B%3D%20'%3CQUERY%20id%3D%22%22%3E'%20and%26nbsp%3Boperation_type%26nbsp%3B%3D%20'ReturnOperation'%20and%20command%20like%20'%25DWResultCacheDb%25')%20%3D%200%26nbsp%3B%3C%2FQUERY%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20SELECT%201%20as%26nbsp%3Bis_cache_hit%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20ELSE%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESELECT%200%20as%26nbsp%3Bis_cache_hit%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAdditional%20statements%20are%20available%20on%20the%20Microsoft%20Docs%20website%20which%20will%20provide%20insight%20into%20the%20number%20of%20queries%20which%20have%20cache%20hit%20or%20miss.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EReference%20Information%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsql-data-warehouse%2Frelease-notes-10-0-10106-0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsql-data-warehouse%2Frelease-notes-10-0-10106-0%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Ft-sql%2Fstatements%2Fset-result-set-caching-transact-sql%3Fview%3Dazure-sqldw-latest%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Ft-sql%2Fstatements%2Fset-result-set-caching-transact-sql%3Fview%3Dazure-sqldw-latest%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-688544%22%20slang%3D%22en-US%22%3E%3CP%3EAzure%20DW%20has%20release%20a%20new%20feature%20which%20allows%20you%20to%20Cache%20results%20for%20re-use%20and%20increased%20performance%2C%20find%20out%20more%20on%20the%20new%20feature%20here.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-688544%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESynapse%20SQL%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESynapse%20Support%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

 

We recently announced the release of Result Set caching for Azure Data Warehouse at Build and within our May 2019 Release notes for Azure DW, this new feature allows you to cache the final return results for user queries.

 

The feature is only Available with Azure DW Gen 2 and not for Azure SQL DB or APS/PDW.

The feature will not cache intermediate result sets and will not be used during CTAS or CRUD operations.

 

The cached results will be stored within the control node database and will consume a maximum of 1TB storage.

The results will be evicted from the cache if not referenced in the last 48 hours.

Queries which are a cache hit will simply return the data from the result cache instead of running the full plan creation and retrieving the data across all of the distributions.

In the event of the query being a Cache miss, it will populate a result set table in the cache DB synchronously for the next execution of the statement.

Only pure select statements are cached against non-system and non-external objects which have no run time constraints or row level security predicates.

 

Enabling the Feature

To enable the feature, you would require the following permissions

  • Server Level Principal Login
  • Member of the dbmanager database role

 

Once the relevant permissions have been granted you will enable the feature from the master database

Alter Database <DBNAME> Set Result_Set_Caching ON

 

To verify that the feature is enabled you can run the following statement

Select is_result_set_caching_on from sys.databases where name = '<dbname>'

This will return a 1 if it is enabled and 0 if it is not.

 

To disable the feature

Alter Database <DBNAME> Set Result_Set_Caching OFF

 

Monitoring use of the Feature

Cache usage can be monitored via DMV and will allow you review within the Query Request Steps if the specific Query ID had a cache hit or miss

 

If (SELECT step_index FROM sys.dm_pdw_request_steps WHERE request_id = '<Query Id>' and operation_type = 'ReturnOperation' and command like '%DWResultCacheDb%') = 0 ​

       SELECT 1 as is_cache_hit ​

       ELSE ​

SELECT 0 as is_cache_hit​

 

Additional statements are available on the Microsoft Docs website which will provide insight into the number of queries which have cache hit or miss.

 

Reference Information

https://docs.microsoft.com/en-us/azure/sql-data-warehouse/release-notes-10-0-10106-0

https://docs.microsoft.com/en-us/sql/t-sql/statements/set-result-set-caching-transact-sql?view=azure...