tidb icon indicating copy to clipboard operation
tidb copied to clipboard

Optimizer: Fix range intersection for CNF(conjunctive normal form) | tidb-test=pr/2350

Open ghazalfamilyusa opened this issue 1 year ago • 10 comments

What problem does this PR solve?

Issue Number: close #54337

Problem Summary:

Current code does not optimally find index range when we have the filter as complex conjuncts. A complex cojunct in this context is DNF. The code does well for each DNF and builds a union of ranges but for the CNF part, it does not do full intersection. The code does intersection only for point ranges which may not as selective as the full intersection. There is a simple example under https://github.com/tikv/tikv/issues/16798 that shows the optimization limitation.

What changed and how does it work?

We added code does full intersection of ranges. For example, if we have ((a1>1) or (a1=1 and b1 > 10)) and ((a1<10) or (a1=10 and b1 < 20)) then there are two conjuncts :

  • ((a1>1) or (a1=1 and b1 > 10))
  • ((a1<10) or (a1=10 and b1 < 20)) The first produces intervals : (1 10,1 +inf], (1,+inf] and second intervals is [-inf,10), [10 -inf,10 20) and their intersection is (1 10,1 +inf], (1,10), [10 -inf,10 20). Before this fix, the code just produce point ranges as [10,10], (1,1].

Check List

Tests

  • [X] 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.

Optimize query performance by pushing all relevant range conditions to table and index range scans.

ghazalfamilyusa avatar Jun 22 '24 07:06 ghazalfamilyusa

Hi @ghazalfamilyusa. 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.

tiprow[bot] avatar Jun 22 '24 07:06 tiprow[bot]

Codecov Report

Attention: Patch coverage is 74.54545% with 42 lines in your changes missing coverage. Please review.

Project coverage is 54.8637%. Comparing base (c71eece) to head (ee412bb). Report is 1 commits behind head on master.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #54166         +/-   ##
=================================================
- Coverage   72.8111%   54.8637%   -17.9475%     
=================================================
  Files          1534       1657        +123     
  Lines        435579     609485     +173906     
=================================================
+ Hits         317150     334386      +17236     
- Misses        98804     252537     +153733     
- Partials      19625      22562       +2937     
Flag Coverage Δ
integration 20.2130% <7.8787%> (?)
unit 71.8181% <74.5454%> (+0.0023%) :arrow_up:

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

Components Coverage Δ
dumpling 52.9656% <ø> (ø)
parser ∅ <ø> (∅)
br 46.3806% <ø> (+0.3196%) :arrow_up:

codecov[bot] avatar Jun 23 '24 04:06 codecov[bot]

/test mysql-test

ghazalfamilyusa avatar Jun 24 '24 17:06 ghazalfamilyusa

@ghazalfamilyusa: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/test mysql-test

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.

tiprow[bot] avatar Jun 24 '24 17:06 tiprow[bot]

Please supply the release note on the PR comment image

elsa0520 avatar Jun 26 '24 05:06 elsa0520

Please supply the release note on the PR comment image

Done

ghazalfamilyusa avatar Jun 26 '24 16:06 ghazalfamilyusa

/ok-to-test

hawkingrei avatar Jul 01 '24 05:07 hawkingrei

/test fast_test_tiprow

ghazalfamilyusa avatar Jul 01 '24 14:07 ghazalfamilyusa

@ghazalfamilyusa: The specified target(s) for /test were not found. The following commands are available to trigger required jobs:

  • /test build
  • /test check-dev
  • /test check-dev2
  • /test mysql-test
  • /test pull-br-integration-test
  • /test pull-integration-ddl-test
  • /test pull-lightning-integration-test
  • /test pull-mysql-client-test
  • /test unit-test

The following commands are available to trigger optional jobs:

  • /test canary-notify-when-compatibility-sections-changed
  • /test pingcap/tidb/canary_ghpr_unit_test
  • /test pull-common-test
  • /test pull-e2e-test
  • /test pull-integration-common-test
  • /test pull-integration-copr-test
  • /test pull-integration-jdbc-test
  • /test pull-integration-mysql-test
  • /test pull-integration-nodejs-test
  • /test pull-sqllogic-test
  • /test pull-tiflash-test

Use /test all to run the following jobs that were automatically triggered:

  • pingcap/tidb/ghpr_build
  • pingcap/tidb/ghpr_check
  • pingcap/tidb/ghpr_check2
  • pingcap/tidb/ghpr_mysql_test
  • pingcap/tidb/ghpr_unit_test
  • pingcap/tidb/pull_integration_ddl_test
  • pingcap/tidb/pull_mysql_client_test

In response to this:

/test fast_test_tiprow

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.

ti-chi-bot[bot] avatar Jul 01 '24 14:07 ti-chi-bot[bot]

/test unit-test

ghazalfamilyusa avatar Jul 01 '24 15:07 ghazalfamilyusa

@ghazalfamilyusa: The specified target(s) for /test were not found. The following commands are available to trigger required jobs:

  • /test fast_test_tiprow
  • /test tidb_parser_test

Use /test all to run all jobs.

In response to this:

/test unit-test

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.

tiprow[bot] avatar Jul 01 '24 15:07 tiprow[bot]

/test unit-test

ghazalfamilyusa avatar Jul 01 '24 16:07 ghazalfamilyusa

@ghazalfamilyusa: The specified target(s) for /test were not found. The following commands are available to trigger required jobs:

  • /test fast_test_tiprow
  • /test tidb_parser_test

Use /test all to run all jobs.

In response to this:

/test unit-test

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.

tiprow[bot] avatar Jul 01 '24 16:07 tiprow[bot]

/retest

hawkingrei avatar Jul 01 '24 17:07 hawkingrei

/retest

ghazalfamilyusa avatar Jul 02 '24 16:07 ghazalfamilyusa

for, "https://github.com/pingcap/tidb/pull/54166#discussion_r1662913214"

The test cases cover these combinations. I do not think it is a good idea to add examples as comments unless it is something simple and not covering combinations like this. We should have comments in the code and I hope I did that. The logic is no complicated. If one value is not equal to the other in the suffix then it is simple. The extra logic for cases where they are equal in the common length and it goes through cases of n1 == n2, n1 > n2 and n1 < n2. For each case, there is additional logic for lower/upper bounds.

ghazalfamilyusa avatar Jul 02 '24 18:07 ghazalfamilyusa

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: elsa0520, time-and-fate

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[bot] avatar Jul 03 '24 06:07 ti-chi-bot[bot]

[LGTM Timeline notifier]

Timeline:

  • 2024-07-01 05:37:51.318121421 +0000 UTC m=+1216397.803610255: :ballot_box_with_check: agreed by elsa0520.
  • 2024-07-03 06:24:50.322838738 +0000 UTC m=+1392016.808327570: :ballot_box_with_check: agreed by time-and-fate.

ti-chi-bot[bot] avatar Jul 03 '24 06:07 ti-chi-bot[bot]

/retest

ghazalfamilyusa avatar Jul 03 '24 06:07 ghazalfamilyusa

/retest

ghazalfamilyusa avatar Jul 03 '24 06:07 ghazalfamilyusa