Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[WIP] executor: skip null rows when deleting multiple tables #31330

Closed
wants to merge 2 commits into from

Conversation

ekexium
Copy link
Member

@ekexium ekexium commented Jan 5, 2022

Signed-off-by: ekexium [email protected]

What problem does this PR solve?

Issue Number: close #31321

Problem Summary:

Skip null rows when deleting using outer joins.

I'm not sure whether it's an appropriate way to fix this. Please be careful when reviewing.

What is changed and how it works?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

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

None

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has not been approved.

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

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

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jan 5, 2022
@ekexium ekexium force-pushed the fix-delete-outer-join branch from 154ba90 to d6d7b2b Compare January 5, 2022 08:50
@sre-bot
Copy link
Contributor

sre-bot commented Jan 5, 2022

@ekexium ekexium requested a review from cfzjywxk January 5, 2022 09:10
@ekexium
Copy link
Member Author

ekexium commented Jan 5, 2022

Only using null datums as a condition is bad. An example:

create table c(k1 int);
create table d(id int, k1 int);
insert into c(k1) values(null);
insert into d values(null, null);
delete c, d from c join d;
select * from d;

Before:

mysql> select * from d;
Empty set (0.00 sec)

This PR:

mysql> select * from d;
+------+------+
| id   | k1   |
+------+------+
| NULL | NULL |
+------+------+

@ekexium ekexium changed the title executor: skip null rows when deleting multiple tables [WIP] executor: skip null rows when deleting multiple tables Jan 5, 2022
@ti-chi-bot ti-chi-bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 5, 2022
@cfzjywxk
Copy link
Contributor

cfzjywxk commented Jan 5, 2022

Seems this will affect the result of delete c, d from c join d on c.k1 is null, or something like DELETE a FROM mt_order_delivery_address AS a LEFT JOIN mt_order AS o USING (order_id) WHERE o.order_id IS NULL;

Sometimes the null row is fetched from storage and sometimes they are generated by the left join operator. We may need to refer the mysql code to investigate the expected behaviour for such cases.

@ekexium
Copy link
Member Author

ekexium commented Jan 6, 2022

It seems to me that MySQL uses an explicit variable to indicate null rows generated by outer joins.

set_null_row() and reset_null_row() are used by the join executor to
signal the presence or absence of a NULL-extended row for an outer joined
table.

https://github.com/mysql/mysql-server/blob/3290a66c89eb1625a7058e0ef732432b6952b435/sql/table.h#L1961-L1975

And there is a check to skip such rows when deleting.

https://github.com/mysql/mysql-server/blob/3290a66c89eb1625a7058e0ef732432b6952b435/sql/sql_delete.cc#L1040-L1041

@ti-chi-bot
Copy link
Member

@ekexium: PR needs rebase.

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 ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 8, 2022
@ekexium ekexium closed this Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note-none Denotes a PR that doesn't merit a release note. 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.

Delete using outer join can mistakenly delete the row whose handle=0
4 participants