Skip to content

Conversation

YangKeao
Copy link
Member

What problem does this PR solve?

Issue Number: close #56655

Problem Summary:

INSERT IGNORE cannot lock the rows in parent, so the constraint may be broken.

What changed and how does it work?

Try to lock the rows even when the toBeCheckedKeys and toBeCheckedPrefixKeys are empty.

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.

Release note

None

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 15, 2024

func TestLockKeysInInsertIgnore(t *testing.T) {
// FIXME: this test will fail in the unistore. After fixing the issue in unistore, please move
// this test to `foreign_key_test.go`.
Copy link
Member Author

@YangKeao YangKeao Oct 15, 2024

Choose a reason for hiding this comment

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

I still don't know why this case will fail in the unistore. Maybe the transaction implementation has some bugs (or just different behaviors).

I tried this case with/without IGNORE. It seems that the foreign key behaves strangely in unistore 🤔 :

Prepare:

create table parent (id int primary key);
create table child(id int primary key, ref int, foreign key (ref) references parent(id));

insert into parent values (1);

Execute:

Transaction 1 Transaction 2
BEGIN; BEGIN;
INSERT INTO child VALUES (1, 1);
UPDATE parent SET id = 2 WHERE id = 1
COMMIT;
COMMIT;

Copy link
Member Author

@YangKeao YangKeao Oct 15, 2024

Choose a reason for hiding this comment

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

I record this issue in #56663. It's confirmed as a transaction bug in unistore.

Copy link
Member Author

Choose a reason for hiding this comment

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

It'll be fixed in #56821

Copy link

codecov bot commented Oct 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 56.2956%. Comparing base (49c3eba) to head (5179c92).
Report is 1 commits behind head on master.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #56661         +/-   ##
=================================================
- Coverage   73.2689%   56.2956%   -16.9733%     
=================================================
  Files          1650       1776        +126     
  Lines        455646     634548     +178902     
=================================================
+ Hits         333847     357223      +23376     
- Misses       101279     253233     +151954     
- Partials      20520      24092       +3572     
Flag Coverage Δ
integration 37.0345% <100.0000%> (?)
unit 72.5107% <100.0000%> (-0.0485%) ⬇️

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

Components Coverage Δ
dumpling 52.9478% <ø> (ø)
parser ∅ <ø> (∅)
br 52.6262% <ø> (+6.6255%) ⬆️

@YangKeao
Copy link
Member Author

/retest

@YangKeao YangKeao force-pushed the fix-56655 branch 2 times, most recently from 7f2ab9a to 8e9e9ee Compare October 16, 2024 11:05
@YangKeao YangKeao changed the title fk: fix the issue that INSERT IGNORE doesn't lock the parent table executor: fix the issue that INSERT IGNORE doesn't lock the parent table Oct 17, 2024
@YangKeao
Copy link
Member Author

/retest

@YangKeao
Copy link
Member Author

run test [planner/core/indexmerge_path] err: sql:explain select * from t use index (iad) where a = 1;: failed to run query 
"explain select * from t use index (iad) where a = 1;" 
 around line 233, 
we need(299):
explain select * from t use index (iad) where a = 1;
id      estRows task    access object   operator info
TableReader_7   1.00    root            data:Selection_6
└─Selection_6   1.00    cop[tikv]               eq(planner__core__indexmerge_path.t.a, 1)
  └─TableFullScan_5     2.00    cop[tikv]       table:t keep order:false
explain select * fro
but got(299):
explain select * from t use index (iad) where a = 1;
id      estRows task    access object   operator info
TableReader_7   10.00   root            data:Selection_6
└─Selection_6   10.00   cop[tikv]               eq(planner__core__indexmerge_path.t.a, 1)
  └─TableFullScan_5     10000.00        cop[tikv]       table:t keep order:false, stats:pseudo

This test failure cannot be reproduced locally 🤔 . Investigating.

@YangKeao YangKeao requested review from crazycs520 and bb7133 October 18, 2024 07:27
@YangKeao
Copy link
Member Author

/retest

@YangKeao
Copy link
Member Author

/retest

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Oct 28, 2024
@YangKeao YangKeao mentioned this pull request Oct 29, 2024
17 tasks
Copy link
Member

@bb7133 bb7133 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

ti-chi-bot bot commented Oct 29, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bb7133, crazycs520

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 Oct 29, 2024
Copy link

ti-chi-bot bot commented Oct 29, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-10-28 06:12:21.410051194 +0000 UTC m=+243854.249206740: ☑️ agreed by crazycs520.
  • 2024-10-29 18:35:36.774626435 +0000 UTC m=+374849.613781981: ☑️ agreed by bb7133.

@YangKeao
Copy link
Member Author

/retest

1 similar comment
@YangKeao
Copy link
Member Author

/retest

@YangKeao YangKeao force-pushed the fix-56655 branch 2 times, most recently from b7807d3 to 7aeba7b Compare October 30, 2024 12:19
@YangKeao
Copy link
Member Author

/retest

@ti-chi-bot ti-chi-bot bot merged commit 0c0d637 into pingcap:master Oct 31, 2024
23 checks passed
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. 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.

INSERT IGNORE didn't lock the referenced row in parent table
3 participants