-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
lightning: disable foreign key checks #40032
Changes from 2 commits
09c4290
ea48bcc
376e42b
188723c
c4bc87e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[tikv-importer] | ||
# Set on-duplicate=error to force using insert statement to write data. | ||
# It seems that foreign key check is not supported in replace statement. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. didn't find the document about foreign_key_check with REPLACE INTO, could you explain what's the behaviour? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't delved into it yet. I just tested it with the latest TiDB and it doesn't seem to work with REPLACE INTO yet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @crazycs520 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch, it is a bug of TiDB, foreign_key_check should work with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fix in #40069
sleepymole marked this conversation as resolved.
Show resolved
Hide resolved
|
||
on-duplicate = "error" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CREATE TABLE `t` | ||
( | ||
`a` bigint(20) NOT NULL, | ||
`b` bigint(20) DEFAULT NULL, | ||
PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */, | ||
KEY `fk_1` (`b`), | ||
CONSTRAINT `fk_1` FOREIGN KEY (`b`) REFERENCES `test`.`t2` (`a`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
a,b | ||
1,1 | ||
2,2 | ||
3,3 | ||
4,4 | ||
5,5 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright 2022 PingCAP, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -eu | ||
|
||
# Create existing tables that import data will reference. | ||
run_sql 'CREATE DATABASE IF NOT EXISTS fk;' | ||
run_sql 'CREATE TABLE fk.t2 (a BIGINT PRIMARY KEY);' | ||
|
||
for BACKEND in tidb local; do | ||
run_sql 'DROP TABLE IF EXISTS fk.t;' | ||
run_lightning --backend $BACKEND | ||
run_sql 'SELECT GROUP_CONCAT(a) FROM fk.t ORDER BY a;' | ||
check_contains '1,2,3,4,5' | ||
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct for
create view
sql? I'm not so sure.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mydump.ExportStatment
ignores all executable comments like/*!40014 SET FOREIGN_KEY_CHECKS=0*/
.tidb/br/pkg/lightning/mydump/reader.go
Line 108 in 4a72171
In common cases, these set statements are written as comments. So I guess it's safe to ignore the set statements explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These set statements are not written as comments for mydumper and dumpling. They are real sqls in sql files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. But I think they are actually equivalent to the statements in the comments. It is inconsistent to ignore one while keeping the other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe check gbk integration tests to see if
character_set_client
can be written to gbk, so lightning must execute the statementThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lightning_new_collation seems to pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about just allow
set
statement? Because it's a view sql feature. Or I think we can ignore allset
statement in sqls but execute theseset
sqls separately forcreate view
statement.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that these SET statements will most likely not work with the local backend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lichunzhu What
set
statement is needed for view sql?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I revert the change that ignores set statements. If the user adds some other type of SQL statement to the schema file, it is their responsibility to make sure that these statements do not affect the other logic.
@lichunzhu @lance6716 PTAL