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

Planner fails to eliminate outer join on unique keys #46248

Closed
fixdb opened this issue Aug 20, 2023 · 0 comments · Fixed by #46249
Closed

Planner fails to eliminate outer join on unique keys #46248

fixdb opened this issue Aug 20, 2023 · 0 comments · Fixed by #46249
Labels
severity/major sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.

Comments

@fixdb
Copy link
Contributor

fixdb commented Aug 20, 2023

Bug Report

1. Minimal reproduce step (Required)

CREATE TABLE `customer` (
  `C_CUSTKEY` bigint(20) NOT NULL,
  `C_NAME` varchar(25) NOT NULL,
  `C_ADDRESS` varchar(40) NOT NULL,
  `C_NATIONKEY` bigint(20) NOT NULL,
  `C_PHONE` char(15) NOT NULL,
  `C_ACCTBAL` decimal(15,2) NOT NULL,
  `C_MKTSEGMENT` char(10) NOT NULL,
  `C_COMMENT` varchar(117) NOT NULL,
  PRIMARY KEY (`C_CUSTKEY`) /*T![clustered_index] CLUSTERED */
);
CREATE TABLE `nation` (
  `N_NATIONKEY` bigint(20) NOT NULL,
  `N_NAME` char(25) NOT NULL,
  `N_REGIONKEY` bigint(20) NOT NULL,
  `N_COMMENT` varchar(152) DEFAULT NULL,
  PRIMARY KEY (`N_NATIONKEY`) /*T![clustered_index] CLUSTERED */
)

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

Join should be eliminated

3. What did you see instead (Required)

explain select count(*) from customer a left join nation b on a.C_NATIONKEY=b.N_NATIONKEY;
+-------------------------------+----------+-----------+---------------+---------------------------------------------------------------------------------+
| id                            | estRows  | task      | access object | operator info                                                                   |
+-------------------------------+----------+-----------+---------------+---------------------------------------------------------------------------------+
| HashAgg_8                     | 1.00     | root      |               | funcs:count(1)->Column#13                                                       |
| └─HashJoin_19                 | 12500.00 | root      |               | left outer join, equal:[eq(test.customer.c_nationkey, test.nation.n_nationkey)] |
|   ├─TableReader_24(Build)     | 10000.00 | root      |               | data:TableFullScan_23                                                           |
|   │ └─TableFullScan_23        | 10000.00 | cop[tikv] | table:b       | keep order:false, stats:pseudo                                                  |
|   └─TableReader_22(Probe)     | 10000.00 | root      |               | data:TableFullScan_21                                                           |
|     └─TableFullScan_21        | 10000.00 | cop[tikv] | table:a       | keep order:false, stats:pseudo                                                  |
+-------------------------------+----------+-----------+---------------+---------------------------------------------------------------------------------+
6 rows in set (0.00 sec)

4. What is your TiDB version? (Required)

master

@fixdb fixdb added the type/bug The issue is confirmed as a bug. label Aug 20, 2023
@ti-chi-bot ti-chi-bot bot added 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.1 may-affects-6.5 may-affects-7.1 labels Aug 21, 2023
@qw4990 qw4990 added affects-6.5 affects-7.1 and removed 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.1 may-affects-6.5 may-affects-7.1 labels Aug 21, 2023
@chrysan chrysan added type/enhancement The issue or PR belongs to an enhancement. and removed type/bug The issue is confirmed as a bug. affects-6.5 affects-7.1 labels Sep 12, 2023
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/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants