pingcap / tidb

TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://www.pingcap.com/tidb-serverless/
https://pingcap.com
Apache License 2.0
36.8k stars 5.8k forks source link

uniform the way to represent full range scan #11082

Open zz-jason opened 5 years ago

zz-jason commented 5 years ago

Feature Request

Is your feature request related to a problem? Please describe:

We use different range representations for full range scans in different contexts. For example, range:[-inf,+inf] is used to represent a full range scan on a signed int column:

TiDB(root@127.0.0.1:test) > create table t(a bigint primary key, b bigint);
Query OK, 0 rows affected (0.01 sec)

TiDB(root@127.0.0.1:test) > desc select * from t;
+-------------------+----------+------+------------------------------------------------------------+
| id                | count    | task | operator info                                              |
+-------------------+----------+------+------------------------------------------------------------+
| TableReader_5     | 10000.00 | root | data:TableScan_4                                           |
| └─TableScan_4     | 10000.00 | cop  | table:t, range:[-inf,+inf], keep order:false, stats:pseudo |
+-------------------+----------+------+------------------------------------------------------------+
2 rows in set (0.00 sec)

While for an unsigned column, the full range representation is range:[0,+inf]:

TiDB(root@127.0.0.1:test) > create table t(a bigint unsigned primary key, b bigint);
Query OK, 0 rows affected (0.01 sec)

TiDB(root@127.0.0.1:test) > desc select * from t;
+-------------------+----------+------+---------------------------------------------------------+
| id                | count    | task | operator info                                           |
+-------------------+----------+------+---------------------------------------------------------+
| TableReader_5     | 10000.00 | root | data:TableScan_4                                        |
| └─TableScan_4     | 10000.00 | cop  | table:t, range:[0,+inf], keep order:false, stats:pseudo |
+-------------------+----------+------+---------------------------------------------------------+
2 rows in set (0.00 sec)

Describe the feature you'd like:

Uniform the way to represent a full range scan, make things clear, less confusion, less thinking.

For example, we can directly display like range:full to represent the full range scan operation.

Describe alternatives you've considered:

No

Teachability, Documentation, Adoption, Migration Strategy:

No

ghost commented 4 years ago

Confirming this is still an issue (actually I would say it's even more of an issue, since they should both say TableFullScan imho):

drop table if exists t1, t2;
create table t1 (a bigint primary key, b bigint);
create table t2 (a bigint unsigned primary key, b bigint);
explain select * from t1;
explain select * from t2;

..

mysql> explain select * from t1;
+-----------------------+----------+-----------+---------------+--------------------------------+
| id                    | estRows  | task      | access object | operator info                  |
+-----------------------+----------+-----------+---------------+--------------------------------+
| TableReader_5         | 10000.00 | root      |               | data:TableFullScan_4           |
| └─TableFullScan_4     | 10000.00 | cop[tikv] | table:t1      | keep order:false, stats:pseudo |
+-----------------------+----------+-----------+---------------+--------------------------------+
2 rows in set (0.00 sec)

mysql> explain select * from t2;
+------------------------+----------+-----------+---------------+------------------------------------------------+
| id                     | estRows  | task      | access object | operator info                                  |
+------------------------+----------+-----------+---------------+------------------------------------------------+
| TableReader_5          | 10000.00 | root      |               | data:TableRangeScan_4                          |
| └─TableRangeScan_4     | 10000.00 | cop[tikv] | table:t2      | range:[0,+inf], keep order:false, stats:pseudo |
+------------------------+----------+-----------+---------------+------------------------------------------------+
2 rows in set (0.00 sec)