Skip to content

expression: replace equal condition by true when to constant propagation | tidb-test=pr/2625 #64309

Merged
ti-chi-bot[bot] merged 9 commits intopingcap:masterfrom
hawkingrei:64216
Nov 26, 2025
Merged

expression: replace equal condition by true when to constant propagation | tidb-test=pr/2625 #64309
ti-chi-bot[bot] merged 9 commits intopingcap:masterfrom
hawkingrei:64216

Conversation

@hawkingrei
Copy link
Member

@hawkingrei hawkingrei commented Nov 6, 2025

What problem does this PR solve?

Issue Number: close #64216

Problem Summary:

What changed and how does it work?

There are three scenarios here.

a = b and (a=b or c=d) => a=b and (a=b or c=d) and (a=a or c=d)
a = b and a in (b, c, d) => a = b and a in (b, c, d) and a in (a, c ,d)
a = b and b = c and c = d and a = d => a = b and b = c and c = d // remove a=d

In the previous implementation, we only passed through constant values to create a new expression. However, what we actually need is to directly replace the equivalent conditions in the expression with true, in order to avoid generating unnecessary expressions.

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 do-not-merge/needs-tests-checked release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. sig/planner SIG: Planner and removed do-not-merge/needs-tests-checked labels Nov 6, 2025
@codecov
Copy link

codecov bot commented Nov 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.4696%. Comparing base (eeee02d) to head (f713b33).
⚠️ Report is 12 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #64309        +/-   ##
================================================
- Coverage   74.7061%   73.4696%   -1.2365%     
================================================
  Files          1888       1868        -20     
  Lines        515172     508779      -6393     
================================================
- Hits         384865     373798     -11067     
- Misses       106492     112765      +6273     
+ Partials      23815      22216      -1599     
Flag Coverage Δ
integration 41.7457% <74.6666%> (-6.4109%) ⬇️
unit 72.5863% <100.0000%> (+0.3166%) ⬆️

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

Components Coverage Δ
dumpling 52.8700% <ø> (+0.1132%) ⬆️
parser ∅ <ø> (∅)
br 46.2966% <ø> (-16.8872%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hawkingrei hawkingrei changed the title expression: replace equal condition by true when to constant propagation expression: replace equal condition by true when to constant propagation | | tidb-test=pr/2625 Nov 7, 2025
@hawkingrei hawkingrei changed the title expression: replace equal condition by true when to constant propagation | | tidb-test=pr/2625 expression: replace equal condition by true when to constant propagation | tidb-test=pr/2625 Nov 7, 2025
@hawkingrei
Copy link
Member Author

/retest

4 similar comments
@hawkingrei
Copy link
Member Author

/retest

@hawkingrei
Copy link
Member Author

/retest

@hawkingrei
Copy link
Member Author

/retest

@hawkingrei
Copy link
Member Author

/retest

@hawkingrei hawkingrei force-pushed the 64216 branch 2 times, most recently from 049807e to b1221ce Compare November 10, 2025 06:11
@hawkingrei
Copy link
Member Author

/retest

@hawkingrei
Copy link
Member Author

/retest

1 similar comment
@hawkingrei
Copy link
Member Author

/retest

Signed-off-by: Weizhen Wang <[email protected]>
@hawkingrei
Copy link
Member Author

/retest

Signed-off-by: Weizhen Wang <[email protected]>
Signed-off-by: Weizhen Wang <[email protected]>
Signed-off-by: Weizhen Wang <[email protected]>
Signed-off-by: Weizhen Wang <[email protected]>
Signed-off-by: Weizhen Wang <[email protected]>
Copy link
Contributor

@windtalker windtalker left a comment

Choose a reason for hiding this comment

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

lgtm

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Nov 26, 2025
@hawkingrei
Copy link
Member Author

/retest

1 similar comment
@hawkingrei
Copy link
Member Author

/retest

// It will be deleted in the replaceEqCondtionWithTrueitionsWithConstants
s.unionSet.Union(lID, rID)
} else if lID != rID {
s.conditions[i] = &Constant{
Copy link
Contributor

Choose a reason for hiding this comment

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

here means LID and RID is already in the union set(the equiv relationship is catched, so we can safely convert this EQ(LID, RID) to be a true)

what i concern here is that, next time, if we wanna do the constant prop one more time, we should build the union set from these condition slice again, while may we still be able to catch the equiv relation ship between LID and RID?

Copy link
Contributor

Choose a reason for hiding this comment

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

looks like we only substitute for appended condition, yes ok.

Copy link
Member Author

Choose a reason for hiding this comment

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

Unionset can capture any equivalence relations of the inferred type. for example,

a = b, b = c, c = d, d = e 

We get a = e by the unionset.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, it doesn't affect the logic here, since all equivalence relations are preserved, and only the redundant equivalence relations are eliminated.

@hawkingrei
Copy link
Member Author

/retest

Signed-off-by: Weizhen Wang <[email protected]>
@hawkingrei
Copy link
Member Author

/retest

@ti-chi-bot
Copy link

ti-chi-bot bot commented Nov 26, 2025

[APPROVALNOTIFIER] This PR is APPROVED

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

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

The pull request process is described here

Details 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 approved lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Nov 26, 2025
@ti-chi-bot
Copy link

ti-chi-bot bot commented Nov 26, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-11-26 04:03:13.942723421 +0000 UTC m=+675557.591917868: ☑️ agreed by windtalker.
  • 2025-11-26 08:16:34.172432699 +0000 UTC m=+690757.821627146: ☑️ agreed by AilinKid.

@ti-chi-bot ti-chi-bot bot merged commit 9b517a1 into pingcap:master Nov 26, 2025
29 checks passed
@hawkingrei hawkingrei deleted the 64216 branch November 26, 2025 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cannot simplify the predicate

3 participants