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

add foreign key as part of set statement when reserved connection is needed #14696

Merged
merged 9 commits into from
Dec 6, 2023

Conversation

harshit-gangal
Copy link
Member

@harshit-gangal harshit-gangal commented Dec 6, 2023

Description

This PR fixes the issue with DDL statements which do not acknowledge the foreign_key_checks setting.

Related Issue(s)

Checklist

  • "Backport to:" labels have been added if this change should be back-ported - Only on main
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on the CI
  • Documentation was added or is not required

Copy link
Contributor

vitess-bot bot commented Dec 6, 2023

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@vitess-bot vitess-bot bot added NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says labels Dec 6, 2023
@github-actions github-actions bot added this to the v19.0.0 milestone Dec 6, 2023
@harshit-gangal harshit-gangal added Type: Bug Component: Query Serving Type: Regression and removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says NeedsIssue A linked issue is missing for this Pull Request labels Dec 6, 2023
@harshit-gangal harshit-gangal marked this pull request as ready for review December 6, 2023 09:15
Copy link
Member

@GuptaManan100 GuptaManan100 left a comment

Choose a reason for hiding this comment

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

Does this change affect only DDL queries or will it also cause DML queries to execute a set statement too?

@harshit-gangal
Copy link
Member Author

Does this change affect only DDL queries or will it also cause DML queries to execute a set statement too?

It is session-based. If a session receives a DDL and there was a foreign_key_checks off set on that session. The session will be marked for reserved connection. This means that any query sent down after will send set foreign_key_checks = off to the vttablet along with the query. This set statement is used to select the right connection which has those system settings on it.

@GuptaManan100
Copy link
Member

The new test is failing in CI -

2023-12-06T09:51:42.8063742Z === RUN   TestDDLFk
2023-12-06T09:51:42.8063872Z     fk_test.go:1224: 
2023-12-06T09:51:42.8064346Z         	Error Trace:	/home/runner/work/vitess/vitess/go/test/endtoend/utils/cmp.go:195
2023-12-06T09:51:42.8065180Z         	            				/home/runner/work/vitess/vitess/go/test/endtoend/vtgate/foreignkey/fk_test.go:1224
2023-12-06T09:51:42.8065402Z         	Error:      	Received unexpected error:
2023-12-06T09:51:42.8069112Z         	            	target: uks.0.primary: vttablet: rpc error: code = Unknown desc = Failed to open the referenced table 'temp2' (errno 1824) (sqlstate HY000) (CallerID: userData1): Sql: "create table temp1 (\n\tid bigint auto_increment primary key,\n\tcol varchar(20) not null,\n\tforeign key (col) references temp2 (col)\n)", BindVars: {} (errno 1824) (sqlstate HY000) during query: create table temp1(id bigint auto_increment primary key, col varchar(20) not null,
2023-12-06T09:51:42.8069489Z         	            	foreign key (col) references temp2(col))
2023-12-06T09:51:42.8069637Z         	Test:       	TestDDLFk
2023-12-06T09:51:42.8069856Z         	Messages:   	[Vitess Error] for query: 
2023-12-06T09:51:42.8070519Z         	            	create table temp1(id bigint auto_increment primary key, col varchar(20) not null,
2023-12-06T09:51:42.8070892Z         	            	foreign key (col) references temp2(col))
2023-12-06T09:51:42.8071028Z --- FAIL: TestDDLFk (0.28s)

…lace statement, make foreign_key_checks as reserved connection variable

Signed-off-by: Harshit Gangal <[email protected]>
Signed-off-by: Harshit Gangal <[email protected]>
Signed-off-by: Harshit Gangal <[email protected]>
Copy link
Member

@GuptaManan100 GuptaManan100 left a comment

Choose a reason for hiding this comment

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

Couple more things to fix. Approving because they are just refactors, the code changes look good to me

go/vt/vtgate/safe_session.go Outdated Show resolved Hide resolved
go/vt/vtgate/engine/set.go Show resolved Hide resolved
Signed-off-by: Harshit Gangal <[email protected]>
Signed-off-by: Harshit Gangal <[email protected]>
@dbussink dbussink merged commit 0019c4e into vitessio:main Dec 6, 2023
116 checks passed
@dbussink dbussink deleted the fk-sysvar-fix branch December 6, 2023 15:45
ejortegau pushed a commit to slackhq/vitess that referenced this pull request Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug Report: Cannot import mysqldump due to order of tables and foreign keys
3 participants