Skip to content

wrong NDV in the global stats when to disable async-merge-global-stats #53752

@hawkingrei

Description

@hawkingrei

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

set @@tidb_enable_async_merge_global_stats=OFF;
CREATE TABLE employees  (
    id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    fname VARCHAR(25) NOT NULL,
    lname VARCHAR(25) NOT NULL,
    store_id INT NOT NULL,
    department_id INT NOT NULL
)

PARTITION BY RANGE(id)  (
    PARTITION p0 VALUES LESS THAN (5),
    PARTITION p1 VALUES LESS THAN (10),
    PARTITION p2 VALUES LESS THAN (15),
    PARTITION p3 VALUES LESS THAN MAXVALUE
);



INSERT INTO employees(FNAME,LNAME,STORE_ID,DEPARTMENT_ID) VALUES
    ('Bob', 'Taylor', 3, 2), ('Frank', 'Williams', 1, 2),
    ('Ellen', 'Johnson', 3, 4), ('Jim', 'Smith', 2, 4),
    ('Mary', 'Jones', 1, 1), ('Linda', 'Black', 2, 3),
    ('Ed', 'Jones', 2, 1), ('June', 'Wilson', 3, 1),
    ('Andy', 'Smith', 1, 3), ('Lou', 'Waters', 2, 4),
    ('Jill', 'Stone', 1, 4), ('Roger', 'White', 3, 2),
    ('Howard', 'Andrews', 1, 2), ('Fred', 'Goldberg', 3, 3),
    ('Barbara', 'Brown', 2, 3), ('Alice', 'Rogers', 2, 2),
    ('Mark', 'Morgan', 3, 3), ('Karen', 'Cole', 3, 2);

ANALYZE TABLE employees;

select * from employees;

SHOW STATS_HISTOGRAMS WHERE TABLE_NAME='employees';

alter table employees truncate   partition p0 ; 

select * from employees;

SHOW STATS_HISTOGRAMS WHERE TABLE_NAME='employees';



analyze table employees partition p3;

select * from employees;

SHOW STATS_HISTOGRAMS WHERE TABLE_NAME='employees'

2. What did you expect to see? (Required)

+---------+------------+----------------+---------------+----------+---------------------+----------------+------------+--------------+-------------+-------------+-----------------+----------------+----------------+---------------+
| Db_name | Table_name | Partition_name | Column_name   | Is_index | Update_time         | Distinct_count | Null_count | Avg_col_size | Correlation | Load_status | Total_mem_usage | Hist_mem_usage | Topn_mem_usage | Cms_mem_usage |
+---------+------------+----------------+---------------+----------+---------------------+----------------+------------+--------------+-------------+-------------+-----------------+----------------+----------------+---------------+
| test    | employees  | global         | id            | 0        | 2024-06-03 14:36:02 | 14             | 0          | 8.0          | 0.0         | allEvicted  | 0               | 0              | 0              | 0             |
| test    | employees  | global         | fname         | 0        | 2024-06-03 14:36:02 | 14             | 0          | 5.29         | 0.0         | allEvicted  | 0               | 0              | 0              | 0             |
| test    | employees  | global         | lname         | 0        | 2024-06-03 14:36:02 | 13             | 0          | 6.63         | 0.0         | allEvicted  | 0               | 0              | 0              | 0             |
| test    | employees  | global         | store_id      | 0        | 2024-06-03 14:36:02 | 3              | 0          | 5.08         | 0.0         | allEvicted  | 0               | 0              | 0              | 0             |
| test    | employees  | global         | department_id | 0        | 2024-06-03 14:36:02 | 4              | 0          | 5.08         | 0.0         | allEvicted  | 0               | 0              | 0              | 0             |
+---------+------------+----------------+---------------+----------+---------------------+----------------+------------+--------------+-------------+-------------+-----------------+----------------+----------------+---------------+

3. What did you see instead (Required)

+---------+------------+----------------+---------------+----------+---------------------+----------------+------------+--------------+-------------+-------------+-----------------+----------------+----------------+---------------+
| Db_name | Table_name | Partition_name | Column_name   | Is_index | Update_time         | Distinct_count | Null_count | Avg_col_size | Correlation | Load_status | Total_mem_usage | Hist_mem_usage | Topn_mem_usage | Cms_mem_usage |
+---------+------------+----------------+---------------+----------+---------------------+----------------+------------+--------------+-------------+-------------+-----------------+----------------+----------------+---------------+
| test    | employees  | global         | id            |        0 | 2024-06-03 15:04:21 |              0 |          0 |            8 |           0 | allEvicted  |               0 |              0 |              0 |             0 |
| test    | employees  | global         | fname         |        0 | 2024-06-03 15:04:21 |              0 |          0 |         5.29 |           0 | allEvicted  |               0 |              0 |              0 |             0 |
| test    | employees  | global         | lname         |        0 | 2024-06-03 15:04:21 |              0 |          0 |         6.63 |           0 | allEvicted  |               0 |              0 |              0 |             0 |
| test    | employees  | global         | store_id      |        0 | 2024-06-03 15:04:21 |              0 |          0 |         5.08 |           0 | allEvicted  |               0 |              0 |              0 |             0 |
| test    | employees  | global         | department_id |        0 | 2024-06-03 15:04:21 |              0 |          0 |         5.08 |           0 | allEvicted  |               0 |              0 |              0 |             0 |
+---------+------------+----------------+---------------+----------+---------------------+----------------+------------+--------------+-------------+-------------+-----------------+----------------+----------------+---------------+
5 rows in set (0.00 sec)

4. What is your TiDB version? (Required)

master

Metadata

Metadata

Assignees

Labels

affects-6.5This bug affects the 6.5.x(LTS) versions.affects-7.1This bug affects the 7.1.x(LTS) versions.affects-7.5This bug affects the 7.5.x(LTS) versions.affects-8.1This bug affects the 8.1.x(LTS) versions.severity/majorsig/plannerSIG: Plannertype/bugThe issue is confirmed as a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions