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
36.53k stars 5.74k forks source link

TiDB Query Insight Logging #46733

Open xsfeng-zodiac opened 10 months ago

xsfeng-zodiac commented 10 months ago

Enhancement

Currently there are three types of TiDB query logging: slow query log, general log and audit log. General logs keeps the general information within query execution context, e.g. username, connection id, startTs, forUpdateTs, schemaVersion, etc. Slow query log keeps all information within general log, as well as query level performance related metrics, e.g. # of mvcc version being scanned, # of rows actually read, lock wait time, TiKV cpu time etc.
Audit log is out of scope here so won't be discussed.

We hope to understand the query performance better and predict of query impacts under organic data growth, thus we are hoping to have query metrics in slow queries logged for all queries for data analysis.

xsfeng-zodiac commented 10 months ago

Here are some metrics we are interested in (from @weili-db):

the high level query execution plan

the running duration

the walltime of the query running time

the rows scanned

total keys scanned caused by LSM tree’s depth for keep all GC record

the rows filtered out

the rows returned

the request unit for 7.1 multi-tenant env

the IO time (might be stretch, optional)

the CPU time (might be stretch, optional)

the lock waiting time (might be stretch, optional)