Skip to content

Conversation

@hawkingrei
Copy link
Member

@hawkingrei hawkingrei commented Jan 31, 2026

What problem does this PR solve?

Issue Number: close #65937

Problem Summary:

  • Double NOT in outer join ON conditions stayed as other cond and could lead to cartesian-like joins.

What changed and how does it work?

  • Normalize outer join OtherConditions by applying PushDownNot when UnaryNot is present.
  • Add predicate pushdown cases for double NOT left/right/semi joins and record plan + result.
  • Add integration test case in planner/core/issuetest to validate checksum parity.
  • Document optimizer/test experience in docs and update skills guidance.

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. do-not-merge/needs-triage-completed sig/planner SIG: Planner size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jan 31, 2026
@hawkingrei hawkingrei force-pushed the fix_double_not_outer_join branch from 539d0fa to 645443d Compare January 31, 2026 12:52
@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jan 31, 2026
@codecov
Copy link

codecov bot commented Jan 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.5746%. Comparing base (97c2efc) to head (7a76b40).
⚠️ Report is 7 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #65942        +/-   ##
================================================
- Coverage   77.7249%   77.5746%   -0.1504%     
================================================
  Files          2001       1923        -78     
  Lines        545885     533722     -12163     
================================================
- Hits         424289     414033     -10256     
+ Misses       119934     119683       -251     
+ Partials       1662          6      -1656     
Flag Coverage Δ
integration 41.4756% <100.0000%> (-6.7111%) ⬇️
unit 76.7033% <100.0000%> (+0.3171%) ⬆️

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

Components Coverage Δ
dumpling 56.7974% <ø> (ø)
parser ∅ <ø> (∅)
br 48.8756% <ø> (-12.1080%) ⬇️
🚀 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.

@qw4990 qw4990 added the type/bugfix This PR fixes a bug. label Feb 2, 2026
@hawkingrei hawkingrei added the AI-Correction Bugfix by AI label Feb 2, 2026
@qw4990
Copy link
Contributor

qw4990 commented Feb 2, 2026

/test check-dev2

@tiprow
Copy link

tiprow bot commented Feb 2, 2026

@qw4990: 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.

Details

In response to this:

/test check-dev2

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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where double NOT in outer join ON conditions (LEFT JOIN t2 ON NOT NOT (t0.k0 = t2.k0)) were not normalized, causing them to remain as "other conditions" and potentially leading to cartesian-like joins with incorrect results.

Changes:

  • Added normalization step for outer join OtherConditions to apply PushDownNot when UnaryNot is present
  • Enhanced PushDownNot to recognize and simplify double-NOT patterns for logical expressions
  • Added comprehensive test cases for double-NOT in left/right/semi joins with both plan and result validation
  • Added documentation to guide future optimizer development

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/planner/core/operator/logicalop/logical_join.go Added normalizeJoinConditionsForOuterJoin() to apply PushDownNot on outer join OtherConditions when UnaryNot is present
pkg/expression/util.go Enhanced pushNotAcrossExpr() to detect and simplify double-NOT patterns (NOT NOT expr) for logical expressions
pkg/expression/util_test.go Added test cases for double-NOT simplification including comparison operations and multiple NOT levels
pkg/planner/core/casetest/rule/rule_predicate_pushdown_test.go Added runPredicatePushdownTestDataWithResult() to validate both plans and execution results
pkg/planner/core/casetest/rule/testdata/*.json Added test cases for double-NOT in various join types and updated schema to include Result field
docs/note/planner/rule/optimizer_ai_notes.md Added documentation about the fix with background, implementation choices, and testing guidance
AGENTS.md Added reference to optimizer notes documentation
.github/skills/tidb-test-guidelines/* Updated test guidance for predicate pushdown cases

@ti-chi-bot ti-chi-bot bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Feb 2, 2026
Copy link
Contributor

@AilinKid AilinKid left a comment

Choose a reason for hiding this comment

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

rest is good

Copy link
Contributor

@qw4990 qw4990 left a comment

Choose a reason for hiding this comment

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

LGTM, but please address @AilinKid 's comment before merging.

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Feb 2, 2026
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Feb 2, 2026
@ti-chi-bot
Copy link

ti-chi-bot bot commented Feb 2, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-02-02 06:54:18.948962868 +0000 UTC m=+77130.050361588: ☑️ agreed by qw4990.
  • 2026-02-02 08:02:00.268270506 +0000 UTC m=+81191.369669226: ☑️ agreed by AilinKid.

@hawkingrei
Copy link
Member Author

/retest

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.

@hawkingrei
Copy link
Member Author

/retest

@fixdb fixdb changed the title *: handle double NOT in outer join planner: handle double NOT in outer join Feb 2, 2026
@fixdb
Copy link
Contributor

fixdb commented Feb 2, 2026

@windtalker please take a look

@ti-chi-bot ti-chi-bot bot added the approved label Feb 3, 2026
@hawkingrei
Copy link
Member Author

/retest

return
}
exprCtx := p.SCtx().GetExprCtx()
for i := range p.OtherConditions {
Copy link
Contributor

@windtalker windtalker Feb 3, 2026

Choose a reason for hiding this comment

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

Looks like if only one of p.OtherConditions contains unary not, all the expression in p.OtherConditions will call expression.PushDownNot, it seems not necessary to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have refactored it.

@windtalker
Copy link
Contributor

/hold

@ti-chi-bot ti-chi-bot bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 3, 2026
@hawkingrei hawkingrei force-pushed the fix_double_not_outer_join branch from 5ed4824 to 7a76b40 Compare February 3, 2026 06:22
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
Copy link

ti-chi-bot bot commented Feb 3, 2026

[APPROVALNOTIFIER] This PR is APPROVED

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

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

@windtalker
Copy link
Contributor

/hold cancel

@ti-chi-bot ti-chi-bot bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 3, 2026
@hawkingrei
Copy link
Member Author

/retest

@ti-chi-bot ti-chi-bot bot merged commit 6c97ced into master Feb 3, 2026
30 checks passed
@ti-chi-bot ti-chi-bot bot deleted the fix_double_not_outer_join branch February 3, 2026 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI-Correction Bugfix by AI AI-Testing approved lgtm release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. type/bugfix This PR fixes a bug.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

planner: multi-way LEFT JOINT with NOT conditions are not stable as MySQL

7 participants