Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

planner: remove duplicate offset when push down pure limit down across outer join #59927

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

winoros
Copy link
Member

@winoros winoros commented Mar 5, 2025

What problem does this PR solve?

Issue Number: close #59926, to fix bug caused by #56483

Problem Summary:

What changed and how does it work?

in the pull #57471, we deal with the wrong case when there's order by. but doesn't fix the case if there's only a limit.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

修复当下推带有 OFFSET 没有 ORDER BY 子句的 LIMIT 至 JOIN 条件为 UNIQUE 而且内包含 NOT NULL 限制的 OUTER JOIN 下方时,结果可能出错的问题
Fix the issue that the result may be wrong when pushing down a limit that has an offset but doesn't have an order by clause down across an outer join, which join key is a unique key with the not null constraint.

@ti-chi-bot ti-chi-bot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/planner SIG: Planner size/S Denotes a PR that changes 10-29 lines, ignoring generated files. do-not-merge/needs-triage-completed and removed do-not-merge/needs-triage-completed labels Mar 5, 2025
@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Mar 5, 2025
drop table if exists t;
create table t(a int, primary key (a));
insert into t values(1), (2);
select * from t t1 left join t t2 on t1.a=t2.a limit 1, 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about desc the explain result, in the before case the top limit will be eliminated here

tidb> explain select * from t t1 left join t t2 on t1.a=t2.a limit 1, 1;
+----------------------------------+---------+-----------+---------------+--------------------------------------------------------------------------------------------------------------------------------------+
| id                               | estRows | task      | access object | operator info                                                                                                                        |
+----------------------------------+---------+-----------+---------------+--------------------------------------------------------------------------------------------------------------------------------------+
| Limit_14                         | 1.00    | root      |               | offset:1, count:1                                                                                                                    |
| └─IndexJoin_19                   | 1.25    | root      |               | left outer join, inner:TableReader_16, left side:Limit_26, outer key:test.t.a, inner key:test.t.a, equal cond:eq(test.t.a, test.t.a) |
|   ├─Limit_26(Build)              | 1.00    | root      |               | offset:1, count:1                                                                                                                    |
|   │ └─TableReader_30             | 2.00    | root      |               | data:Limit_29                                                                                                                        |
|   │   └─Limit_29                 | 2.00    | cop[tikv] |               | offset:0, count:2                                                                                                                    |
|   │     └─TableFullScan_28       | 2.00    | cop[tikv] | table:t1      | keep order:false, stats:pseudo                                                                                                       |
|   └─TableReader_16(Probe)        | 1.00    | root      |               | data:TableRangeScan_15                                                                                                               |
|     └─TableRangeScan_15          | 1.00    | cop[tikv] | table:t2      | range: decided by [test.t.a], keep order:false, stats:pseudo                                                                         |
+----------------------------------+---------+-----------+---------------+--------------------------------------------------------------------------------------------------------------------------------------+
8 rows in set (0.00 sec)

Copy link

tiprow bot commented Mar 5, 2025

@winoros: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
fast_test_tiprow a0fbdcb link true /test fast_test_tiprow

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Copy link

ti-chi-bot bot commented Mar 5, 2025

@winoros: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
idc-jenkins-ci-tidb/build a0fbdcb link true /test build
idc-jenkins-ci-tidb/check_dev a0fbdcb link true /test check-dev
idc-jenkins-ci-tidb/unit-test a0fbdcb link true /test unit-test
idc-jenkins-ci-tidb/check_dev_2 a0fbdcb link true /test check-dev2

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Copy link
Contributor

@elsa0520 elsa0520 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

ti-chi-bot bot commented Mar 6, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AilinKid, elsa0520

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Mar 6, 2025
Copy link

ti-chi-bot bot commented Mar 6, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-03-05 15:14:23.618495673 +0000 UTC m=+454576.747415418: ☑️ agreed by AilinKid.
  • 2025-03-06 02:43:12.166443298 +0000 UTC m=+495905.295363042: ☑️ agreed by elsa0520.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
approved lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/planner SIG: Planner size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

result may be wrong if there's a limit without order by placed above outer join
3 participants