# Tidb Server Cache
__*TiDB Server cache*__
__*tidb-mem-quota-query*__
__*oom-action*__
+ TiDB Server cache composition
  + SQL results
  + thread cache
  + meta data, statistics
+ TiDB Server cache management
  + `tidb_mem_quota_query` 
  + `oom-action` 

------------------------------------------------------------
TiDB Server cache uses all of the server's memory by default. First, let's take a look at the key links where memory is used:

1. TiDB Server cache composition
  1. Complex SQL queries such as hash joins and too many subquery are used in the execution plan. These calculations cannot be done entirely by operators pushed down to the TiKV node. The data must be sorted in TIDB Server's cache before it can be return to the user. Update&Delete involves a large amount of data and also consumes a lot of cache.
  2. Threads are cached using TiDB Server, and if there are too many active threads, it will also cause a lot of cache usage.
  3. The table metadata, information schema, user authentication authorization data, and statistics need to be cached.

So what are the parameters to better manage the cache?

2. TiDB Server cache management
  1. The tidb-mem-quota-query parameter can control the default cache usage of each query. In addition, there are similar parameters, we can refer to the documentation: https://docs.pingcap.com/zh/tidb/stable/configure-memory-usage
  2. If the configuration item of oom-action is "cancel", then when the memory usage of a SQL exceeds a certain threshold, TiDB will immediately interrupt the execution of the SQL and return an error to the client. The error message will specify in detail each physical execution that takes up more memory during the execution of the SQL The memory usage of the operator.