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

wrong count output of explain for TableScan plan #7582

Closed
eurekaka opened this issue Sep 2, 2018 · 3 comments
Closed

wrong count output of explain for TableScan plan #7582

eurekaka opened this issue Sep 2, 2018 · 3 comments

Comments

@eurekaka
Copy link
Contributor

eurekaka commented Sep 2, 2018

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?
    If possible, provide a recipe for reproducing the error.
MySQL [test]> create table t1(a int primary key);
Query OK, 0 rows affected (0.01 sec)

MySQL [test]> explain select * from t1 where a = 1 and a = 2;
+-------------------+----------+------+------------------------------------------+
| id                | count    | task | operator info                            |
+-------------------+----------+------+------------------------------------------+
| TableReader_6     | 10000.00 | root | data:TableScan_5                         |
| └─TableScan_5     | 10000.00 | cop  | table:t1, keep order:false, stats:pseudo |
+-------------------+----------+------+------------------------------------------+
2 rows in set (0.00 sec)

MySQL [test]> analyze table t1;
Query OK, 0 rows affected (0.02 sec)

MySQL [test]> explain select * from t1 where a = 1 and a = 2;
+-------------------+----------+------+------------------------------------------+
| id                | count    | task | operator info                            |
+-------------------+----------+------+------------------------------------------+
| TableReader_6     | 10000.00 | root | data:TableScan_5                         |
| └─TableScan_5     | 10000.00 | cop  | table:t1, keep order:false, stats:pseudo |
+-------------------+----------+------+------------------------------------------+
2 rows in set (0.01 sec)

MySQL [test]> insert into t1 values(1);
Query OK, 1 row affected (0.00 sec)

MySQL [test]> explain select * from t1 where a = 1 and a = 2;
+-------------------+----------+------+------------------------------------------+
| id                | count    | task | operator info                            |
+-------------------+----------+------+------------------------------------------+
| TableReader_6     | 10000.00 | root | data:TableScan_5                         |
| └─TableScan_5     | 10000.00 | cop  | table:t1, keep order:false, stats:pseudo |
+-------------------+----------+------+------------------------------------------+
2 rows in set (0.00 sec)

MySQL [test]> analyze table t1;
Query OK, 0 rows affected (0.00 sec)

MySQL [test]> explain select * from t1 where a = 1 and a = 2;
+-------------------+-------+------+----------------------------+
| id                | count | task | operator info              |
+-------------------+-------+------+----------------------------+
| TableReader_6     | 0.00  | root | data:TableScan_5           |
| └─TableScan_5     | 0.00  | cop  | table:t1, keep order:false |
+-------------------+-------+------+----------------------------+
2 rows in set (0.00 sec)
  1. What did you expect to see?

count outputs should all be 0.00 for the above explain statements.

  1. What did you see instead?

count field is 10000.00.

Three requirements to trigger this problem:

  • filter is on primary key;
  • filter would be simplified to false;
  • table is empty or table has not been analyzed, i.e, satisfy function HistColl::ColumnIsInvalid
  1. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?
MySQL [test]> select tidb_version();
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                                                                                    |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v2.1.0-rc.1-18-geec6899
Git Commit Hash: eec68995689d5811f4d52846586e969652ed8ffc
Git Branch: master
UTC Build Time: 2018-09-02 12:04:09
GoVersion: go version go1.11rc1 linux/amd64
Race Enabled: false
TiKV Min Version: 2.1.0-alpha.1-ff3dd160846b7d1aed9079c389fc188f7f5ea13e
Check Table Before Drop: false |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
@eurekaka
Copy link
Contributor Author

eurekaka commented Sep 3, 2018

#7583 merged

@eurekaka eurekaka closed this as completed Sep 3, 2018
@zz-jason
Copy link
Member

zz-jason commented Sep 3, 2018

does index scan have the same problem?

@eurekaka
Copy link
Contributor Author

eurekaka commented Sep 3, 2018

@zz-jason no, only happens on PK table scan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants