pingcap / tidb

TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://www.pingcap.com/tidb-serverless/
https://pingcap.com
Apache License 2.0
37.07k stars 5.83k forks source link

Dump execution details of all SQLs when server is consuming lots of memory #20800

Open qw4990 opened 3 years ago

qw4990 commented 3 years ago

Feature Request

Is your feature request related to a problem? Please describe:

After https://github.com/pingcap/tidb/issues/17095, TiDB can dump SQLs and the heap profile when consuming most of the system memory(like 80% of system memory), which helps us investigate memory problems.

But the information above may be not enough, it's better to record all ongoing SQLs' execution details(like explain analyze) as well. (we can use explain for connectionID to get all execution details)

With these details, we can know actual plans of these SQLs, and memory usages of all operators in these plans. This information can help us verify something like if there is an inappropriate join-order and which join consumes the most memory, which is useful when investigating memory problems.

qw4990 commented 3 years ago

PTAL @wshwsh12 @XuHuaiyu @SunRunAway @zz-jason

XuHuaiyu commented 3 years ago

Not only the SQLs and heap profile will be recorded, but also the expensive query log, and the plan will also be recorded.

I think what you really needed is the result of explain analyze for conn?