Skip to content

Wrong value when query a partition table with LIMIT #24636

Closed
@bb7133

Description

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

Scripts:

drop table if exists test_partition;

CREATE TABLE `test_partition` (
  `a` varchar(100) NOT NULL,
  `b` date NOT NULL,
  `c` varchar(100) NOT NULL,
  `d` datetime DEFAULT NULL,
  `e` datetime DEFAULT NULL,
  `f` bigint(20) DEFAULT NULL,
  `g` bigint(20) DEFAULT NULL,
  `h` bigint(20) DEFAULT NULL,
  `i` bigint(20) DEFAULT NULL,
  `j` bigint(20) DEFAULT NULL,
  `k` bigint(20) DEFAULT NULL,
  `l` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`a`,`b`,`c`) /*T![clustered_index] NONCLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
PARTITION BY RANGE ( TO_DAYS(`b`) ) (
  PARTITION `pmin` VALUES LESS THAN (737821),
  PARTITION `p20200601` VALUES LESS THAN (738289)
);

INSERT INTO test_partition (a, b, c, d, e, f, g, h, i, j, k, l) VALUES('aaa', '2021-05-05', '428ff6a1-bb37-42ac-9883-33d7a29961e6', '2021-05-06 08:13:38', '2021-05-06 13:28:08', 0, 8, 3, 0, 9, 1, 0);

select c,j,l
from test_partition 
where `c`='428ff6a1-bb37-42ac-9883-33d7a29961e6' and `a`='aaa';

select c,j,l
from test_partition 
where `c`='428ff6a1-bb37-42ac-9883-33d7a29961e6' and `a`='aaa' limit 0, 200;

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

tidb> select c,j,l from test_partition  where `c`='428ff6a1-bb37-42ac-9883-33d7a29961e6' and `a`='aaa';
+--------------------------------------+------+------+
| c                                    | j    | l    |
+--------------------------------------+------+------+
| 428ff6a1-bb37-42ac-9883-33d7a29961e6 |    9 |    0 |
+--------------------------------------+------+------+
1 row in set (0.00 sec)

tidb> select c,j,l from test_partition  where `c`='428ff6a1-bb37-42ac-9883-33d7a29961e6' and `a`='aaa' limit 0, 200;
+--------------------------------------+------+------+
| c                                    | j    | l    |
+--------------------------------------+------+------+
| 428ff6a1-bb37-42ac-9883-33d7a29961e6 |    9 |    0 |
+--------------------------------------+------+------+
1 row in set (0.00 sec)

3. What did you see instead (Required)

tidb> select c,j,l from test_partition  where `c`='428ff6a1-bb37-42ac-9883-33d7a29961e6' and `a`='aaa';
+--------------------------------------+------+------+
| c                                    | j    | l    |
+--------------------------------------+------+------+
| 428ff6a1-bb37-42ac-9883-33d7a29961e6 |    9 |    0 |
+--------------------------------------+------+------+
1 row in set (0.00 sec)

tidb> select c,j,l from test_partition  where `c`='428ff6a1-bb37-42ac-9883-33d7a29961e6' and `a`='aaa' limit 0, 200;
+-----+---------------------+------+
| c   | j                   | l    |
+-----+---------------------+------+
| aaa | 3558184994028925492 |    9 |
+-----+---------------------+------+
1 row in set (0.00 sec)

4. What is your TiDB version? (Required)

TiDB v5.0.1

Other versions

It is not reproduced in v4.0, but in current master(aecff1c), an error is reported:

tidb> select c,j,l from test_partition  where `c`='428ff6a1-bb37-42ac-9883-33d7a29961e6' and `a`='aaa' limit 0, 200;
ERROR 1105 (HY000): Internal error: UnionExec chunk column count mismatch, req: 3, result: 4

So I'll assume it is not a known bug.

Update: when the table is specified as `clustered, the error doesn't reproduce.

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions