WuZixing commented on a change in pull request #4479:
URL: https://github.com/apache/incubator-doris/pull/4479#discussion_r478873939
##########
File path: docs/en/administrator-guide/query_cache.md
##########
@@ -0,0 +1,190 @@
+---
+{
+ "title": "QUERY CACHE",
+ "language": "en"
+}
+---
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+# QUERY CACHE
+
+
+## 一 Demond
+
+Usually, we have cache in the corresponding database layer which is focus on
the query content.However the data granularity in the cache is too slow and it
would have effect only when data in the table didn't change.Obviously, it
could not reduce the heavy IO load from the CRUD of the business system. So it
comes the database caching technology, which could highspeed caching the hot
data, improve the response speed of the application and greatly relieve the
load of the backend database.
+
+- High concurrency scenarios
+ Doris have a well support for high concurrency while single sever is unable
to load too high QPS.
+
+
+
+- Complex Graph Dashboard
+ It is not uncommon to see that, data of the complex Dashboard and the lage
screen applications come from many table together which have tens of queries in
a single page.Even though every single query cost only few milliseconds, the
total queries would cost seconds.
+
+
+- Trend Analysis
+ In some scenarios, the queries are in a given date range , the index is
shown by date.For example, we want to query the treend of the number of user in
the last 7 days.This type of queries has a large amount of data and a wide
range of fields, and the queries often takes tens of seconds.
+
+
+- User repeated query
+ If the product does not have an anti-re-flash mechanism, the user
accidentally refreshes the page repeatedly due many reasons, which resulting
in submitting a large number of repeated SQL
+
+
+
+In the above four scenarios, we have solutions at the application layer. We
put the result of queries in the Redis and update the cache periodically or
the user update the cache manually.However, this solution has the following
problems:
+
+
+
+- Inconsistence of data , we are unable to sense the update of data, causing
users to often see old data
+
+- Low hit rate, we usually cache the whole result of query.If the data is
writed real-time, we would often failed in cache, resulting in low hit rate and
overload for the system.
+
+- Extra Cost we introduce external cache components, which will bring system
complexity and increase additional costs.
+
+
+
+## 二 Solutions
+
+At present, we design two modules: result cache and partition cache
+
+
+
+## 三 Explanation of terms
+
+1. result cache
+
+SQL directly caches the result collection of queries for users
+
+
+
+2. partition cache
+
+In the partition granularity, cache the results of each partition query
+
+
+
+## 四 Design
+
+### 1 `result cache`
+
+result_cache is divided into two layers. The first layer is result_ cache_ The
second layer of TTL is result_ cache_ version
+
+
+
+#### `result_cache_ttl`
+
+result_ cache_ ttl variable is set in the user session. The user can
customize whether to turn it on or not. The TTL time is used to determine
whether the user's SQL uses cache. The correctness of the data is not
guaranteed when the data is changed`
+
+
+
+The cache is stored and retrieved according to the user connected and the
query SQL. If it exceeds the cache expiration time, the cache will not be hit
and the cache will be cleaned
+
+
+
+#### ` result_cache_version`
+
+result_ cache_ version stores and fetches the cache according to the signature
of SQL, partition ID of the query table, latest version of partition. The
combination of the three determines a cache dataset. If any one of them
changes, such as SQL changes, query fields or conditions are not the same, or
the version after data update changes, the cache will not be hit.
+
+
+
+If multiple tables are joined, the latest partition ID and the 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.
+
+
+
+### 2 `partition_cache`
+
+1. SQL can be split in parallel,Q = Q1 ∪ Q2 ... ∪ Qn,R= R1 ∪ R2 ... ∪ Rn,Q is
the query statement and R is the result set
+
+2. Split into read-only partition and updatable partition, read-only partition
cache, update partition not cache
+
+
+
+## 五 parameter
+
+### fe
+
+- Cache switch
+
+```
+enable_result_cache_ttl
+
+enable_result_cache_version
+
+enable_partition_cache
+```
+
+- Whether each query is cached or not
+
+```
+cache_per_query_max_row_count
+
+cache_per_query_max_size_in_bytes
+```
+
+- result cache til
+
+```
+result_cache_ttl_in_milliseconds
+```
+
+
+
+### be
+
+- Be maximum number of partitions cache_ max_ partition_ Count refers to the
maximum number of partitions corresponding to each SQL. If the partition is
based on date, the data can be cached for more than 2 years. If you want to
keep the cache for a longer time, please set this parameter larger and modify
the cache_ result_ max_ row_ Count parameter.
Review comment:
*... data can be cached for more than 2 years. If you want to keep the
cache for a longer time, ...*.
I am not very clear about why count of cached partitions can affect the
lifetime of the cache.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]