TiDB Development Guide
  • TiDB Development Guide
  • Contributing to TiDB Development Guide
  • .github
    • pull_request_template
  • TiDB Development Guide
    • Summary
    • contribute-to-tidb
      • Cherry-pick a Pull Request
      • TiDB Code Style and Quality Guide
      • Committer Guide
      • Community Guideline
      • Contribute Code
      • Contribute to TiDB
      • Issue Triage
      • Make a Proposal
      • Miscellaneous Topics
      • Release Notes Language Style Guide
      • Report an Issue
      • Review a Pull Request
      • Write Document
    • extending-tidb
      • Add a function
      • Extending TiDB
    • get-started
      • Get the code, build, and run
      • Commit the code and submit a pull request
      • Debug and profile
      • Install Golang
      • Get Started
      • run-and-debug-integration-tests
      • Setup an IDE
      • Write and run unit tests
    • project-management
      • Project Management
      • Release Train Model
      • TiDB Versioning
    • system-tables
      • System tables
      • slow_query
    • understand-tidb
      • 1PC
      • Async Commit
      • Cost-based Optimization
      • DDL - Data Definition Language / Schema change handling
      • DML
      • DQL
      • Execution
      • Implementation of Typical Operators
      • Implementation of Vectorized Execution
      • Introduction of TiDB Architecture
      • Lock Resolver
      • Memory Management Mechanism
      • MVCC Garbage Collection
      • Optimistic Transaction
      • Parallel Execution Framework
      • Parser
      • Pessimistic Transaction
      • Plan Cache
      • Planner
      • Plugin
      • Privilege
      • Rule-based Optimization
      • Session
      • SQL Plan Management
      • Table Statistics
      • The Life cycle of a Statement
      • transaction-on-tikv
      • Transaction
      • system-tables
        • System tables
        • information_schema
          • information_schema
          • slow_query
Powered by GitBook
On this page
  • Overview
  • SLOW_QUERY
  • CLUSTER_SLOW_QUERY
  • Documentation

Was this helpful?

  1. TiDB Development Guide
  2. understand-tidb
  3. system-tables
  4. information_schema

slow_query

Previousinformation_schema

Last updated 4 months ago

Was this helpful?

Overview

Slow queries logs are written to tidb-slow.log (set with slow-query-file in the config) if they are over the slow-threshold (300ms by default). If record-plan-in-slow-log is enabled this will include the execution plan. This uses .

Each TiDB node writes its own slow logs.

SLOW_QUERY

   +------------+
   | App or CLI |
   +------------+
         |
     SQL Query
     SLOW_QUERY
         |
     +--------+
     |  TiDB  |
     +--------+
         |
  +---------------+
  | tidb-slow.log |
  +---------------+

The slow log can be viewed directly or via the information_schema.SLOW_QUERY table.

CLUSTER_SLOW_QUERY

There is also the information_schema.CLUSTER_SLOW_QUERY table that combines the slow log from all nodes into a single table.

                  +----------------+
                  | TiDB Dashboard |
                  |   or App/CLI   |
                  +----------------+
                         |
                      SQL Query
                  CLUSTER_SLOW_QUERY
                         |
                      +--------+
        +--gRPC-------| TiDB 1 |------gRPC--+
        |             +--------+            |
   +--------+            |               +--------+
   | TiDB 0 |            |               | TiDB 2 |
   +--------+            |               +--------+
      |                  |                  |
+---------------+  +---------------+  +---------------+
| tidb-slow.log |  | tidb-slow.log |  | tidb-slow.log |
+---------------+  +---------------+  +---------------+

CLUSTER_SLOW_QUERY is using the coprocessor gRPC interface to send cop requests to the TiDB node. This allows the reuse of query condition push down and column prune, to reduce unnecessary data transfer.

Documentation

  • User docs

The column definition is in .

The helps to extract some predicates of slow_query.

A lot of the other logic can be found in .

This table has , which adds stats to EXPLAIN ANALYZE output.

The uses the CLUSTER_SLOW_QUERY table to display the slow queries in a webpage.

There are no RuntimeStats for this table, see for a request to add that.

slowLogEncoder
slowQueryCols
SlowQueryExtractor
slow_query.go
RuntimeStats
TiDB Dashboard
this issue
information_schema.slow_query
Identify Slow Queries