Skip to content

Conversation

ari-e
Copy link
Contributor

@ari-e ari-e commented Jun 26, 2024

What problem does this PR solve?

Issue Number: close #54188

Problem Summary: Properly classify columns with null predicates (e.g. WHERE a IS NULL) as constant so index selection can take advantage of that to satisfy a sort in

if path.ConstCols == nil || i >= len(path.ConstCols) || !path.ConstCols[i] {
.

What changed and how does it work?

Added checks for is null predicate during planning and fill corresponding data structures marking that column as a constant.

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.

None

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/M Denotes a PR that changes 30-99 lines, ignoring generated files. needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. labels Jun 26, 2024
Copy link

ti-chi-bot bot commented Jun 26, 2024

Welcome @ari-e!

It looks like this is your first PR to pingcap/tidb 🎉.

I'm the bot to help you request reviewers, add labels and more, See available commands.

We want to make sure your contribution gets all the attention it needs!



Thank you, and welcome to pingcap/tidb. 😃

Copy link

ti-chi-bot bot commented Jun 26, 2024

Hi @ari-e. Thanks for your PR.

I'm waiting for a pingcap member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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/test-infra repository.

Copy link

tiprow bot commented Jun 26, 2024

Hi @ari-e. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

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.

@hawkingrei
Copy link
Member

/ok-to-test

@ti-chi-bot ti-chi-bot bot added ok-to-test Indicates a PR is ready to be tested. and removed needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. labels Jun 27, 2024
@hawkingrei hawkingrei self-requested a review June 27, 2024 00:00
Copy link

codecov bot commented Jun 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 55.9786%. Comparing base (c361587) to head (e71d8f2).

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #54253         +/-   ##
=================================================
- Coverage   74.8413%   55.9786%   -18.8628%     
=================================================
  Files          1555       1676        +121     
  Lines        363239     609792     +246553     
=================================================
+ Hits         271853     341353      +69500     
- Misses        71804     245136     +173332     
- Partials      19582      23303       +3721     
Flag Coverage Δ
integration 37.0598% <100.0000%> (?)
unit 71.7446% <100.0000%> (-2.0380%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 52.9656% <ø> (-2.2339%) ⬇️
parser ∅ <ø> (∅)
br 52.5929% <ø> (+4.8890%) ⬆️

@@ -148,3 +148,15 @@ func TestRowFunctionMatchTheIndexRangeScan(t *testing.T) {
tk.MustQuery(tt).Sort().Check(testkit.Rows(output[i].Result...))
Copy link
Member

@hawkingrei hawkingrei Jun 27, 2024

Choose a reason for hiding this comment

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

Please run the make bazel_prepare and upload the changement.

Copy link
Contributor

Choose a reason for hiding this comment

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

@hawkingrei thanks! unfortunately @ari-e is out for a bit and I don't have permissions to update this PR, so I've addressed the comment separately in #54290

@mzhang77
Copy link

Please ignore this PR and review #54290 instead.

@ti-chi-bot ti-chi-bot bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 5, 2024
@ari-e ari-e force-pushed the ari--use-ordered-index-with-is-null branch 2 times, most recently from 031c2c5 to fd9d15a Compare July 11, 2024 19:52
@ti-chi-bot ti-chi-bot bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 11, 2024
@ari-e ari-e force-pushed the ari--use-ordered-index-with-is-null branch 2 times, most recently from 9653ec3 to 01a7e18 Compare July 12, 2024 00:15
@ari-e
Copy link
Contributor Author

ari-e commented Jul 12, 2024

/retest

@ari-e
Copy link
Contributor Author

ari-e commented Jul 12, 2024

Picked this PR back up now that I'm back from vacation. So please consider this one and we'll abandon #54290 #54512.

I've fixed the unit test failures and bazel build issues. Now the 3 issues left are failed integration tests. I suspect though that these are failing because the plan output is legitimately different with my change. The outputs of those 3 tests are:

run test [util/ranger] err: sql:explain format='brief' select * from t where a = 1 and (b is null or b = 2) and c > 1;: failed to run query
"explain format='brief' select * from t where a = 1 and (b is null or b = 2) and c > 1;"
 around line 176,
we need(316):
explain format='brief' select * from t where a = 1 and (b is null or b = 2) and c > 1;
id      estRows task    access object   operator info
IndexReader     0.07    root            index:Selection
└─Selection     0.07    cop[tikv]               gt(util__ranger.t.c, 1)
  └─IndexRangeScan      0.20    cop[tikv]       table:t, index:a(a, b, c)       range:[1 NULL,1 NULL], [1
but got(316):
explain format='brief' select * from t where a = 1 and (b is null or b = 2) and c > 1;
id      estRows task    access object   operator info
IndexReader     0.67    root            index:IndexRangeScan
└─IndexRangeScan        0.67    cop[tikv]       table:t, index:a(a, b, c)       range:(1 NULL 1,1 NULL +inf], (1 2 1,1 2 +inf], keep order:false, stats:pseudo
run test [util/ranger] err: sql:explain format='brief' select * from t where a = 1 and (b is null or b = 2) and c > 1;: failed to run query
"explain format='brief' select * from t where a = 1 and (b is null or b = 2) and c > 1;"
 around line 176,
we need(316):
explain format='brief' select * from t where a = 1 and (b is null or b = 2) and c > 1;
id      estRows task    access object   operator info
IndexReader     0.07    root            index:Selection
└─Selection     0.07    cop[tikv]               gt(util__ranger.t.c, 1)
  └─IndexRangeScan      0.20    cop[tikv]       table:t, index:a(a, b, c)       range:[1 NULL,1 NULL], [1
but got(316):
explain format='brief' select * from t where a = 1 and (b is null or b = 2) and c > 1;
id      estRows task    access object   operator info
IndexReader     0.67    root            index:IndexRangeScan
└─IndexRangeScan        0.67    cop[tikv]       table:t, index:a(a, b, c)       range:(1 NULL 1,1 NULL +inf], (1 2 1,1 2 +inf], keep order:false, stats:pseudo
run test [func_group] err: sql:explain format="brief"
select max(a3) from t1 where a2 is null;: failed to run query
"explain format="brief"
select max(a3) from t1 where a2 is null;"
 around line 330,
we need(421):
explain format="brief"
select max(a3) from t1 where a2 is null;
id      estRows task    access object   operator info
StreamAgg       1.00    root            funcs:max(func_group.t1.a3)->Column#7
└─TopN  1.00    root            func_group.t1.a3:desc, offset:0, count:1
  └─IndexReader 1.00    root            index:TopN
    └─TopN      1.00    cop[tikv]               func_group.t1.a3:desc, offset:0, count:1
      └─IndexRangeScan  2.00    cop[tikv]       table:t1, index:k1(a2, a3)      range:[N
but got(421):
explain format="brief"
select max(a3) from t1 where a2 is null;
id      estRows task    access object   operator info
StreamAgg       1.00    root            funcs:max(func_group.t1.a3)->Column#7
└─Limit 1.00    root            offset:0, count:1
  └─IndexReader 1.00    root            index:Limit
    └─Limit     1.00    cop[tikv]               offset:0, count:1
      └─IndexRangeScan  1.00    cop[tikv]       table:t1, index:k1(a2, a3)      range:[NULL -inf,NULL +inf], keep order:true, desc

@hawkingrei can you provide any guidance for whether these seem like legitimate cases where the integration test needs to be updated, or whether my PR needs to change to not affect these query plans?

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jul 17, 2024
@hawkingrei hawkingrei self-requested a review July 17, 2024 12:45
@hawkingrei
Copy link
Member

@ari-e LGTM

But you should update the result in the tests/integrationtest.

for example

cd tests/integrationtest
./run-tests.sh -r executor/merge_join

@ari-e ari-e force-pushed the ari--use-ordered-index-with-is-null branch from 01a7e18 to d81df44 Compare July 17, 2024 16:42
@ari-e
Copy link
Contributor Author

ari-e commented Jul 17, 2024

@hawkingrei I fixed the integration test in tests/integrationtest but it looks like there's some test external to this repo that is being run that is still failing called func_group which is part of ghpr_mysql_test. Do you know where that is defined? Jenkins log

@ari-e ari-e force-pushed the ari--use-ordered-index-with-is-null branch from d81df44 to eb7d420 Compare July 18, 2024 16:55
@ari-e
Copy link
Contributor Author

ari-e commented Jul 18, 2024

/retest

@ari-e ari-e force-pushed the ari--use-ordered-index-with-is-null branch from eb7d420 to 3543c79 Compare July 19, 2024 16:18
@hawkingrei hawkingrei changed the title planner: use ordered index with is null predicate planner: use ordered index with is null predicate | tidb-test=pr/2368 Jul 19, 2024
@hawkingrei
Copy link
Member

/retest

@hawkingrei
Copy link
Member

hawkingrei commented Jul 19, 2024

@ari-e Please sync code with master.

@winoros
Copy link
Member

winoros commented Jul 19, 2024

/retest

@hawkingrei
Copy link
Member

/test all

@ari-e ari-e force-pushed the ari--use-ordered-index-with-is-null branch from 3543c79 to e71d8f2 Compare July 19, 2024 17:30
@ari-e
Copy link
Contributor Author

ari-e commented Jul 19, 2024

Rebased on master @hawkingrei @winoros

@winoros
Copy link
Member

winoros commented Jul 19, 2024

The idc-jenkins-ci-tidb/mysql-test passed. I think your pr should have passed all tests now. Other failures are not caused by your main code changes.

Copy link

ti-chi-bot bot commented Jul 19, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hawkingrei, winoros

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 Jul 19, 2024
Copy link

ti-chi-bot bot commented Jul 19, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-07-17 12:42:49.389601575 +0000 UTC m=+444191.380543045: ☑️ agreed by hawkingrei.
  • 2024-07-19 18:41:52.244257202 +0000 UTC m=+638534.235198671: ☑️ agreed by winoros.

@ti-chi-bot ti-chi-bot bot merged commit 41ed0e5 into pingcap:master Jul 19, 2024
@ti-chi-bot ti-chi-bot added the needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. label Jul 22, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.5: #54788.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jul 22, 2024
@ti-chi-bot ti-chi-bot bot removed the needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. label Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm ok-to-test Indicates a PR is ready to be tested. release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

optimizer does not consider using ordered index scan when is null is used
6 participants