Skip to content

Latest commit

 

History

History
105 lines (76 loc) · 3.11 KB

File metadata and controls

105 lines (76 loc) · 3.11 KB
title DROP STATS
summary An overview of the usage of DROP STATS for the TiDB database.
aliases
/docs/dev/sql-statements/sql-statement-drop-stats/

DROP STATS

The DROP STATS statement is used to delete the statistics of the selected table from the selected database.

Synopsis

DropStatsStmt ::=
    'DROP' 'STATS' TableName  ("PARTITION" partition | "GLOBAL")? ( ',' TableName )*

TableName ::=
    Identifier ('.' Identifier)?

Usage

The following statement deletes all statistics of TableName. If a partitioned table is specified, this statement deletes statistics of all partitions in this table as well as global statistics generated in dynamic pruning mode.

DROP STATS TableName
Query OK, 0 rows affected (0.00 sec)

The following statement only deletes statistics of the specified partitions in PartitionNameList.

DROP STATS TableName PARTITION PartitionNameList;
Query OK, 0 rows affected (0.00 sec)

The following statement only deletes global statistics generated in dynamic pruning mode of the specified table.

DROP STATS TableName GLOBAL;
Query OK, 0 rows affected (0.00 sec)

Examples

CREATE TABLE t(a INT);
Query OK, 0 rows affected (0.01 sec)
SHOW STATS_META WHERE db_name='test' and table_name='t';
+---------+------------+----------------+---------------------+--------------+-----------+-------------------+
| Db_name | Table_name | Partition_name | Update_time         | Modify_count | Row_count | Last_analyze_time |
+---------+------------+----------------+---------------------+--------------+-----------+-------------------+
| test    | t          |                | 2020-05-25 20:34:33 |            0 |         0 | NULL              |
+---------+------------+----------------+---------------------+--------------+-----------+-------------------+
1 row in set (0.00 sec)
DROP STATS t;
Query OK, 0 rows affected (0.00 sec)

DROP STATS deletes statistics such as TopN and histogram buckets of the table, but does not delete the record of the table from STATS_META. Therefore, after you execute DROP STATS, SHOW STATS_META still returns the Modify_count and Row_count information of the table.

SHOW STATS_META WHERE db_name='test' and table_name='t';
+---------+------------+----------------+---------------------+--------------+-----------+-------------------+
| Db_name | Table_name | Partition_name | Update_time         | Modify_count | Row_count | Last_analyze_time |
+---------+------------+----------------+---------------------+--------------+-----------+-------------------+
| test    | t          |                | 2020-05-25 20:34:33 |            0 |         0 | NULL              |
+---------+------------+----------------+---------------------+--------------+-----------+-------------------+
1 row in set (0.00 sec)

MySQL compatibility

This statement is a TiDB extension to MySQL syntax.

See also