blob: eafdc5ad8eba2e32df63270adc39e44d8983ae12 [file] [log] [blame]
"use strict";(self.webpackChunkdoris_website=self.webpackChunkdoris_website||[]).push([[67779],{15680:(e,n,t)=>{t.d(n,{xA:()=>u,yg:()=>y});var a=t(296540);function r(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function i(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);n&&(a=a.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,a)}return t}function o(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?i(Object(t),!0).forEach((function(n){r(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):i(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}function s(e,n){if(null==e)return{};var t,a,r=function(e,n){if(null==e)return{};var t,a,r={},i=Object.keys(e);for(a=0;a<i.length;a++)t=i[a],n.indexOf(t)>=0||(r[t]=e[t]);return r}(e,n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(a=0;a<i.length;a++)t=i[a],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(r[t]=e[t])}return r}var l=a.createContext({}),c=function(e){var n=a.useContext(l),t=n;return e&&(t="function"==typeof e?e(n):o(o({},n),e)),t},u=function(e){var n=c(e.components);return a.createElement(l.Provider,{value:n},e.children)},d="mdxType",h={inlineCode:"code",wrapper:function(e){var n=e.children;return a.createElement(a.Fragment,{},n)}},p=a.forwardRef((function(e,n){var t=e.components,r=e.mdxType,i=e.originalType,l=e.parentName,u=s(e,["components","mdxType","originalType","parentName"]),d=c(t),p=r,y=d["".concat(l,".").concat(p)]||d[p]||h[p]||i;return t?a.createElement(y,o(o({ref:n},u),{},{components:t})):a.createElement(y,o({ref:n},u))}));function y(e,n){var t=arguments,r=n&&n.mdxType;if("string"==typeof e||r){var i=t.length,o=new Array(i);o[0]=p;var s={};for(var l in n)hasOwnProperty.call(n,l)&&(s[l]=n[l]);s.originalType=e,s[d]="string"==typeof e?e:r,o[1]=s;for(var c=2;c<i;c++)o[c]=t[c];return a.createElement.apply(null,o)}return a.createElement.apply(null,t)}p.displayName="MDXCreateElement"},189092:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>l,contentTitle:()=>o,default:()=>h,frontMatter:()=>i,metadata:()=>s,toc:()=>c});var a=t(58168),r=(t(296540),t(15680));const i={title:"SQL Cache",language:"en"},o=void 0,s={unversionedId:"query/query-cache/sql-cache-manual",id:"version-2.1/query/query-cache/sql-cache-manual",title:"SQL Cache",description:"\x3c!--",source:"@site/versioned_docs/version-2.1/query/query-cache/sql-cache-manual.md",sourceDirName:"query/query-cache",slug:"/query/query-cache/sql-cache-manual",permalink:"/docs/query/query-cache/sql-cache-manual",draft:!1,tags:[],version:"2.1",frontMatter:{title:"SQL Cache",language:"en"},sidebar:"docs",previous:{title:"Query Caches Overview",permalink:"/docs/query/query-cache/"},next:{title:"View",permalink:"/docs/query/view-materialized-view/create-view"}},l={},c=[{value:"Demand scenarios &amp; solutions",id:"demand-scenarios--solutions",level:2},{value:"Design principles",id:"design-principles",level:2},{value:"Usage",id:"usage",level:2},{value:"Cache conditions",id:"cache-conditions",level:2},{value:"Unfinished business",id:"unfinished-business",level:2}],u={toc:c},d="wrapper";function h(e){let{components:n,...t}=e;return(0,r.yg)(d,(0,a.A)({},u,t,{components:n,mdxType:"MDXLayout"}),(0,r.yg)("h1",{id:"sql-cache"},"SQL Cache"),(0,r.yg)("p",null,"The SQL statement will hit the cache if it is completely consistent."),(0,r.yg)("h2",{id:"demand-scenarios--solutions"},"Demand scenarios & solutions"),(0,r.yg)("p",null,"See ",(0,r.yg)("a",{parentName:"p",href:"/docs/query/query-cache/"},"Query Caches Overview")),(0,r.yg)("h2",{id:"design-principles"},"Design principles"),(0,r.yg)("p",null,"SQLCache stores and obtains the cache based on the SQL signature, the partition ID of the queried table, and the latest version of the partition. The combination of the three determines a cached data set. If any one of them changes, such as the SQL changes, the query fields or conditions are different, or the version changes after the data is updated, the cache will not be hit."),(0,r.yg)("p",null,"If multiple tables are joined, the most recently updated partition ID and latest version number are used. If one of the tables is updated, the partition ID or version number will be different, and the cache will not be hit."),(0,r.yg)("p",null,"SQLCache is more suitable for T+1 update scenarios. Data is updated in the early morning. The first query obtains the results from BE and puts them into the cache. Subsequent queries of the same nature obtain the results from the cache. Real-time update data can also be used, but there may be a problem of low hit rate."),(0,r.yg)("p",null,"Currently supports OlapTable internal table and Hive external table."),(0,r.yg)("h2",{id:"usage"},"Usage"),(0,r.yg)("p",null,"Make sure cache_enable_sql_mode=true in fe.conf (default is true)"),(0,r.yg)("pre",null,(0,r.yg)("code",{parentName:"pre",className:"language-text"},"vim fe/conf/fe.conf\ncache_enable_sql_mode=true\n")),(0,r.yg)("p",null,"Set variables in MySQL command line"),(0,r.yg)("pre",null,(0,r.yg)("code",{parentName:"pre",className:"language-sql"},"MySQL [(none)]> set [global] enable_sql_cache=true;\n")),(0,r.yg)("p",null,"Note: global is a global variable and does not refer to the current session variable."),(0,r.yg)("p",null,"In versions 2.1.3 and above, the Nereids optimizer saves cached key information, such as non-deterministic functions and their evaluation values, in the memory of FE. It can skip SQL parsing when the key information remains unchanged, optimizing the query speed of SQL cache."),(0,r.yg)("p",null,"The number of key information and elimination time can be controlled to reduce memory consumption on FE through the frontend configuration items sql_cache_manageNum and expires_sql_cache_in_fe_second."),(0,r.yg)("pre",null,(0,r.yg)("code",{parentName:"pre",className:"language-sql"},"MySQL [(none)]> ADMIN SET FRONTEND CONFIG ('sql_cache_manage_num' = '100');\nMySQL [(none)]> ADMIN SET FRONTEND CONFIG ('expire_sql_cache_in_fe_second' = '300');\n")),(0,r.yg)("h2",{id:"cache-conditions"},"Cache conditions"),(0,r.yg)("p",null,"After the first query, if the following three conditions are met, the query results will be cached."),(0,r.yg)("ol",null,(0,r.yg)("li",{parentName:"ol"},(0,r.yg)("p",{parentName:"li"},"(Current time - the last update time of the queried partition) is greater than cache_last_version_interval_second in fe.conf.")),(0,r.yg)("li",{parentName:"ol"},(0,r.yg)("p",{parentName:"li"},"The number of query result rows is less than cache_result_max_row_count in fe.conf.")),(0,r.yg)("li",{parentName:"ol"},(0,r.yg)("p",{parentName:"li"},"The query result bytes is less than cache_result_max_data_size in fe.conf."))),(0,r.yg)("p",null,"For detailed parameter introduction and unfinished matters, see query-cache.md."),(0,r.yg)("h2",{id:"unfinished-business"},"Unfinished business"),(0,r.yg)("ul",null,(0,r.yg)("li",{parentName:"ul"},(0,r.yg)("p",{parentName:"li"},"SQL contains functions that generate random values, such as random(). Using QueryCache will cause the query results to lose their randomness, and the same results will be obtained every time they are executed.")),(0,r.yg)("li",{parentName:"ul"},(0,r.yg)("p",{parentName:"li"},"Similar SQL, 2 indicators were queried before, and now 3 indicators are queried. Can the cache of 2 indicators be used? Not currently supported"))))}h.isMDXComponent=!0}}]);