Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SHOW cmd LIKE 'expr' filters on DBName not TableName #9373

Open
wentaojin opened this issue Feb 20, 2019 · 9 comments
Open

SHOW cmd LIKE 'expr' filters on DBName not TableName #9373

wentaojin opened this issue Feb 20, 2019 · 9 comments
Labels
severity/moderate sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@wentaojin
Copy link

wentaojin commented Feb 20, 2019

Bug Report

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?
    If possible, provide a recipe for reproducing the error.

TiDB cluster Show statistics can be perform fuzzy matching and equivalent query, The documentation is written for support, with a current documentation syntax description:

SHOW STATS_META[ShowLikeOrWhere]
SHOW STATS_BUCKETS [ShowLikeOrWhere]
SHOW STATS_STATISTICS [ShowLikeOrWhere]

After manual execute Analyze Table ,Unable to perform fuzzy matching, only equivalent query,As shown

default

  1. What did you expect to see?

expect to see the result of fuzzy matching

  1. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?

mysql> select tidb_version();
| Release Version: v2.1.4
Git Commit Hash: a1d10c1
Git Branch: release-2.1
UTC Build Time: 2019-02-15 06:24:33
GoVersion: go version go1.11.2 linux/amd64
Race Enabled: false
TiKV Min Version: 2.1.0-alpha.1-ff3dd160846b7d1aed9079c389fc188f7f5ea13e
Check Table Before Drop: false |

@wentaojin wentaojin changed the title Tidb 集群Show统计信息不能进行模糊匹配,只能进行等值匹配 TiDB V2.1.4 cluster Show statistics cannot be fuzzy matched, only equivalent matching Feb 20, 2019
@winoros winoros added the type/bug The issue is confirmed as a bug. label Feb 20, 2019
@winoros
Copy link
Member

winoros commented Feb 20, 2019

mysql> show stats_meta where table_name like 't%';
+---------+------------+---------------------+--------------+-----------+
| Db_name | Table_name | Update_time         | Modify_count | Row_count |
+---------+------------+---------------------+--------------+-----------+
| test    | t          | 2019-02-20 18:45:12 |            0 |         0 |
+---------+------------+---------------------+--------------+-----------+
1 row in set (0.01 sec)

mysql> show stats_meta where table_name like '%t';
+---------+------------+---------------------+--------------+-----------+
| Db_name | Table_name | Update_time         | Modify_count | Row_count |
+---------+------------+---------------------+--------------+-----------+
| test    | t          | 2019-02-20 18:45:12 |            0 |         0 |
+---------+------------+---------------------+--------------+-----------+
1 row in set (0.00 sec)

It's a little strange that i cannot reproduce this bug with the same TiDB version.

@wentaojin
Copy link
Author

mysql> show stats_meta where table_name like 't%';
+---------+------------+---------------------+--------------+-----------+
| Db_name | Table_name | Update_time         | Modify_count | Row_count |
+---------+------------+---------------------+--------------+-----------+
| test    | t          | 2019-02-20 18:45:12 |            0 |         0 |
+---------+------------+---------------------+--------------+-----------+
1 row in set (0.01 sec)

mysql> show stats_meta where table_name like '%t';
+---------+------------+---------------------+--------------+-----------+
| Db_name | Table_name | Update_time         | Modify_count | Row_count |
+---------+------------+---------------------+--------------+-----------+
| test    | t          | 2019-02-20 18:45:12 |            0 |         0 |
+---------+------------+---------------------+--------------+-----------+
1 row in set (0.00 sec)

It's a little strange that i cannot reproduce this bug with the same TiDB version.

But my environment existed... I also feel very strange. Can you see here ?

@winoros
Copy link
Member

winoros commented Feb 20, 2019

@wentaojin
Emm, what's the result of like '%'?

@wentaojin
Copy link
Author

@wentaojin
Emm, what's the result of like '%'?

show stats_meta where table_name like '%' ,this command can output results, as follow:

mysql> show stats_meta where table_name like '%';
+-----------+------------+---------------------+--------------+-----------+
| Db_name | Table_name | Update_time | Modify_count | Row_count |
+-----------+------------+---------------------+--------------+-----------+
| MARVIN | tidb | 2019-02-19 19:23:25 | 0 | 0 |
| MARVIN | foo_range | 2019-02-20 10:13:48 | 3 | 3 |
| MARVIN | fo_range | 2019-02-20 10:15:38 | 0 | 0 |
| bikeshare | trips | 2019-02-20 15:56:29 | 0 | 35041080 |
+-----------+------------+---------------------+--------------+-----------+
4 rows in set (0.00 sec)

mysql> show stats_meta where table_name like '%tidb';
Empty set (0.00 sec)

@winoros
Copy link
Member

winoros commented Feb 21, 2019

@wentaojin
What if you use an exact match like like 'trips'?

@wentaojin
Copy link
Author

@wentaojin
What if you use an exact match like like 'trips'?

No,it also can not output result,but I found a strange phenomenon that the result of like '%trip%' is match with db_name, as follow:

mysql> show stats_meta;
+-------------+------------+---------------------+--------------+-----------+
| Db_name | Table_name | Update_time | Modify_count | Row_count |
+-------------+------------+---------------------+--------------+-----------+
| MARVIN | tidb | 2019-02-19 19:23:25 | 0 | 0 |
| MARVIN | foo_range | 2019-02-20 10:13:48 | 3 | 3 |
| MARVIN | fo_range | 2019-02-20 10:15:38 | 0 | 0 |
| tidb | bike | 2019-02-21 16:26:20 | 0 | 7091771 |
| tidb | tb2 | 2019-02-21 16:30:48 | 5 | 5 |
| tidb_loader | checkpoint | 2019-02-21 17:42:48 | 1026 | 16 |
| bike | tidb | 2019-02-21 17:40:59 | 0 | 0 |
| bike | bike | 2019-02-21 17:43:16 | 0 | 7091773 |
| bikeshare | trips | 2019-02-20 15:56:29 | 0 | 35041080 |
+-------------+------------+---------------------+--------------+-----------+
9 rows in set (0.00 sec)

mysql> show stats_meta like '%f%';
Empty set (0.00 sec)

mysql> show stats_meta like '%b%';
+-------------+------------+---------------------+--------------+-----------+
| Db_name | Table_name | Update_time | Modify_count | Row_count |
+-------------+------------+---------------------+--------------+-----------+
| tidb | bike | 2019-02-21 16:26:20 | 0 | 7091771 |
| tidb | tb2 | 2019-02-21 16:30:48 | 5 | 5 |
| bike | tidb | 2019-02-21 17:40:59 | 0 | 0 |
| bike | bike | 2019-02-21 17:43:16 | 0 | 7091773 |
| bikeshare | trips | 2019-02-20 15:56:29 | 0 | 35041080 |
| tidb_loader | checkpoint | 2019-02-21 17:42:48 | 1026 | 16 |
+-------------+------------+---------------------+--------------+-----------+
6 rows in set (0.00 sec)

mysql> show stats_meta where table_name like '%b%';
+-------------+------------+---------------------+--------------+-----------+
| Db_name | Table_name | Update_time | Modify_count | Row_count |
+-------------+------------+---------------------+--------------+-----------+
| tidb | bike | 2019-02-21 16:26:20 | 0 | 7091771 |
| tidb | tb2 | 2019-02-21 16:30:48 | 5 | 5 |
| bike | tidb | 2019-02-21 17:40:59 | 0 | 0 |
| bike | bike | 2019-02-21 17:43:16 | 0 | 7091773 |
| bikeshare | trips | 2019-02-20 15:56:29 | 0 | 35041080 |
| tidb_loader | checkpoint | 2019-02-21 17:42:48 | 1026 | 16 |
+-------------+------------+---------------------+--------------+-----------+
6 rows in set (0.00 sec)

mysql> show stats_meta where table_name like '%f%';
Empty set (0.00 sec)

@winoros
Copy link
Member

winoros commented Feb 21, 2019

@wentaojin
If you directly use show stats_meta like ..., it will match the first column which in this case is DBName. So this behavior is correct.

I want to provide you a TiDB binary with more log information to help us understand why this happened. Is this ok for you?

@wentaojin
Copy link
Author

@wentaojin
If you directly use show stats_meta like ..., it will match the first column which in this case is DBName. So this behavior is correct.

I want to provide you a TiDB binary with more log information to help us understand why this happened. Is this ok for you?

So... Directly use show stats_meta like , It will match DBName that is correct , that's OK !!!
Then where table_name like should macth tableName, Why not match instead of match DBName?
Can not you Reproduce ?What information do you need tidb binary?
Server version: 5.7.10-TiDB-v2.1.4 MySQL Community Server (Apache License 2.0)

@ghost
Copy link

ghost commented Jul 14, 2020

I can confirm in master that the matching is on DBName, which doesn't really make sense, because it also applies filtering on the currently selected DBName. Here is a testcase:

DROP TABLE IF EXISTS ta1;
CREATE TABLE ta1 (id INT NOT NULL PRIMARY KEY auto_increment);
INSERT INTO ta1 VALUES (1);
ANALYZE TABLE ta1;
SELECT SLEEP(1);

SHOW STATS_META;
SHOW STATS_META LIKE 'ta1';
SHOW STATS_META LIKE 't%';
SHOW STATS_META LIKE 'ta%';
SHOW STATS_META LIKE 'te%';
..

mysql> SHOW STATS_META;
+---------+------------+----------------+---------------------+--------------+-----------+
| Db_name | Table_name | Partition_name | Update_time         | Modify_count | Row_count |
+---------+------------+----------------+---------------------+--------------+-----------+
| test    | ta1        |                | 2020-07-14 15:56:28 |            0 |         1 |
+---------+------------+----------------+---------------------+--------------+-----------+
1 row in set (0.00 sec)

mysql> SHOW STATS_META LIKE 'ta1';
Empty set (0.00 sec)

mysql> SHOW STATS_META LIKE 't%';
+---------+------------+----------------+---------------------+--------------+-----------+
| Db_name | Table_name | Partition_name | Update_time         | Modify_count | Row_count |
+---------+------------+----------------+---------------------+--------------+-----------+
| test    | ta1        |                | 2020-07-14 15:56:28 |            0 |         1 |
+---------+------------+----------------+---------------------+--------------+-----------+
1 row in set (0.00 sec)

mysql> SHOW STATS_META LIKE 'ta%';
Empty set (0.00 sec)

mysql> SHOW STATS_META LIKE 'te%';
+---------+------------+----------------+---------------------+--------------+-----------+
| Db_name | Table_name | Partition_name | Update_time         | Modify_count | Row_count |
+---------+------------+----------------+---------------------+--------------+-----------+
| test    | ta1        |                | 2020-07-14 15:56:28 |            0 |         1 |
+---------+------------+----------------+---------------------+--------------+-----------+
1 row in set (0.00 sec)


mysql> SELECT tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v4.0.0-beta.2-762-g77aecd4b2
Edition: Community
Git Commit Hash: 77aecd4b27e79a97215eb4fdd68f68f2ddf67d21
Git Branch: master
UTC Build Time: 2020-07-13 01:43:31
GoVersion: go1.13
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
1 row in set (0.00 sec)

@jebter jebter added the sig/planner SIG: Planner label Nov 16, 2020
@ghost ghost self-assigned this Nov 18, 2020
@ghost ghost changed the title TiDB V2.1.4 cluster Show statistics cannot be fuzzy matched, only equivalent matching SHOW cmd LIKE 'expr' filters on DBName not TableName Nov 18, 2020
@ghost ghost assigned morgo and unassigned ghost Dec 2, 2020
@yudongusa yudongusa added sig/sql-infra SIG: SQL Infra and removed sig/planner SIG: Planner labels Aug 24, 2021
@morgo morgo removed their assignment May 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/moderate sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

6 participants