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

Can't find column when count star rewriter is enable #39506

Closed
elsa0520 opened this issue Nov 30, 2022 · 3 comments
Closed

Can't find column when count star rewriter is enable #39506

elsa0520 opened this issue Nov 30, 2022 · 3 comments
Labels
severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@elsa0520
Copy link
Contributor

elsa0520 commented Nov 30, 2022

Bug Report

MySQL [test]> explain select count(*) from github_events_1;
ERROR 1105 (HY000): Can't find column test.github_events_1.test_count in schema Column: [Column#8] Unique key: []

1. Minimal reproduce step (Required)

  1. create table with a not null and not key column
CREATE TABLE `github_events_1` (
  `id` bigint(20) DEFAULT NULL,
  `test_count` tinyint(1) NOT NULL DEFAULT '1',
  KEY `index_github_events_on_id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
  1. add a tiflash replica
alter table github_events_1 set tiflash replica 1;
  1. remove tiflash read engine
set tidb_isolation_read_engines = "tikv,tidb";
  1. query count(*)
 explain select count(*) from github_events_1;
ERROR 1105 (HY000): Can't find column test.github_events_1.test_count in schema Column: [Column#8] Unique key: []

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

MySQL [test]> explain select count(*) from github_events_1;
+----------------------------+----------+-------------------+-----------------------+---------------------------------------------------------+
| id                         | estRows  | task              | access object         | operator info                                           |
+----------------------------+----------+-------------------+-----------------------+---------------------------------------------------------+
| StreamAgg_30               | 1.00     | root              |                       | funcs:count(Column#13)->Column#4                        |
| └─TableReader_31           | 1.00     | root              |                       | data:StreamAgg_10                                       |
|   └─StreamAgg_10           | 1.00     | cop[tikv]  |                       | funcs:count(test.github_events_1._tidb_rowid)->Column#13 |
|     └─TableFullScan_28     | 10000.00 | cop[tikv]  | table:github_events_1 | keep order:false, stats:pseudo                          |
+----------------------------+----------+-------------------+-----------------------+---------------------------------------------------------+
4 rows in set (0.00 sec)

3. What did you see instead (Required)

 explain select count(*) from github_events_1;
ERROR 1105 (HY000): Can't find column test.github_events_1.test_count in schema Column: [Column#8] Unique key: []

4. What is your TiDB version? (Required)

After tidb 6.4 , before tidb 6.5
master branch

@elsa0520 elsa0520 added the type/bug The issue is confirmed as a bug. label Nov 30, 2022
@elsa0520
Copy link
Contributor Author

#39197

@elsa0520
Copy link
Contributor Author

#37165

elsa0520 added a commit to elsa0520/tidb that referenced this issue Nov 30, 2022
If the index and `count_star` optimizations exist at the same time,
a `can't find column` error may occur.
The main reason is that the `count_star` optimization strategy selects a not null column,
but due to the column is not added to the `colsRequiringFullLen` attribute,
the planner mistakenly selects the index scan.
Eventually the previously selected column could not be found.

This PR fixed pingcap#39506 the problem above
@ti-chi-bot ti-chi-bot added may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.0 may-affects-6.1 may-affects-6.2 may-affects-6.3 may-affects-6.4 labels Nov 30, 2022
@qw4990 qw4990 removed may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-6.0 may-affects-6.1 may-affects-6.2 may-affects-6.3 may-affects-6.4 labels Nov 30, 2022
@elsa0520
Copy link
Contributor Author

elsa0520 commented Dec 2, 2022

The count star has been changed from logical rule to post phase.
So this issue doesn't exist.

@elsa0520 elsa0520 closed this as completed Dec 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants