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

partition table does not return the right rows by quering by _tidb_rowid #54583

Closed
lcwangchao opened this issue Jul 11, 2024 · 8 comments · Fixed by #54592
Closed

partition table does not return the right rows by quering by _tidb_rowid #54583

lcwangchao opened this issue Jul 11, 2024 · 8 comments · Fixed by #54592
Assignees
Labels
affects-8.1 This bug affects the 8.1.x(LTS) versions. severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@lcwangchao
Copy link
Collaborator

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

> create table tt(id int) PARTITION BY LIST(id) (partition p0 values in (0));
> insert into tt values(0),(0);
> select _tidb_rowid from tt;
+-------------+
| _tidb_rowid |
+-------------+
| 1           |
| 2           |
+-------------+
2 rows in set
Time: 0.007s
> select * from tt where _tidb_rowid=1;

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

select * from tt where _tidb_rowid=1 should return one row.

3. What did you see instead (Required)

> select * from tt where _tidb_rowid=1;
+----+
| id |
+----+
+----+
0 rows in set
Time: 0.007s

4. What is your TiDB version? (Required)

master

@lcwangchao
Copy link
Collaborator Author

The plan is wrong:

> desc select * from tt where _tidb_rowid=1;
+-------------+---------+------+--------------------------+---------------+
| id          | estRows | task | access object            | operator info |
+-------------+---------+------+--------------------------+---------------+
| Point_Get_1 | 1.00    | root | table:tt, partition:dual | handle:1      |
+-------------+---------+------+--------------------------+---------------+
1 row in set
Time: 0.005s

@Defined2014 Defined2014 self-assigned this Jul 11, 2024
@Defined2014
Copy link
Contributor

partition table + _tidb_rowid shoudn't support Point_Get, because we can't use _tidb_rowid to locate a partition.

@lcwangchao
Copy link
Collaborator Author

lcwangchao commented Jul 12, 2024

partition table + _tidb_rowid shoudn't support Point_Get, because we can't use _tidb_rowid to locate a partition.

TTL is using delete from tt partition(p0) where _tidb_rowid in (...) to delete rows. I think it is reasonable to support the point get here because partition is specified.

@Defined2014 Defined2014 added the affects-8.1 This bug affects the 8.1.x(LTS) versions. label Jul 12, 2024
@Defined2014
Copy link
Contributor

Defined2014 commented Jul 12, 2024

@mjonss
Copy link
Contributor

mjonss commented Jul 12, 2024

https://github.com/pingcap/tidb/pull/49161/files#diff-7ab669fbd07f777ce6a8b33025e95960e50d6c6be00a0781d33aafca2150bf6bL2585

So do you have any comment about this issue? @mjonss

@Defined2014 Did it work before? How?

I think it could work if also the partition is specified, like SELECT * FROM t PARTITION (p) WHERE _tidb_rowid = N
But I don't really see it useful.
When is 'WHERE _tidb_rowid =` used? If mostly for debugging etc. I'm OK with not allowing it as Point_Select for partitioned tables.

@Defined2014
Copy link
Contributor

Defined2014 commented Jul 12, 2024

@Defined2014 Did it work before? How?

Yes. Before this PR, we do prune in planner phase and if remained more than one partition, we will forbid PointGet plan.

I think it could work if also the partition is specified, like SELECT * FROM t PARTITION (p) WHERE _tidb_rowid = N But I don't really see it useful.

I agree with it.

When is 'WHERE _tidb_rowid =` used? If mostly for debugging etc. I'm OK with not allowing it as Point_Select for partitioned tables.

TTL will use it to delete rows. But I think tableRangeScan maybe acceptable.

@mjonss
Copy link
Contributor

mjonss commented Jul 12, 2024

TTL will use it to delete rows. But I think tableRangeScan maybe acceptable.

There may be duplicates of _tidb_rowid, so I don't think it is acceptable, since it cannot distinguish which row (i.e. from which partition) to delete. If it still using the explicit partition selection FROM t PARTITION(p) is it OK.

@Defined2014
Copy link
Contributor

TTL will use it to delete rows. But I think tableRangeScan maybe acceptable.

There may be duplicates of _tidb_rowid, so I don't think it is acceptable, since it cannot distinguish which row (i.e. from which partition) to delete. If it still using the explicit partition selection FROM t PARTITION(p) is it OK.

Yeah, it will explicit selection FROM t PARTITION(p). The acceptable is about performance of TableRangeScan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-8.1 This bug affects the 8.1.x(LTS) versions. severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants