-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Type Cast all update expressions in verify queries #14555
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Signed-off-by: Manan Gupta <manan@planetscale.com>
…e correct data type Signed-off-by: Manan Gupta <manan@planetscale.com>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
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
Nov 21, 2023
Signed-off-by: Manan Gupta <manan@planetscale.com>
Signed-off-by: Manan Gupta <manan@planetscale.com>
Signed-off-by: Manan Gupta <manan@planetscale.com>
Signed-off-by: Manan Gupta <manan@planetscale.com>
GuptaManan100
changed the title
Zero problem
Type Cast all update expressions in verify queries
Nov 23, 2023
GuptaManan100
added
Type: Bug
Component: Query Serving
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
Nov 23, 2023
GuptaManan100
requested review from
harshit-gangal,
systay,
frouioui and
arthurschreiber
as code owners
November 23, 2023 08:42
frouioui
approved these changes
Nov 23, 2023
harshit-gangal
approved these changes
Nov 24, 2023
jwangace
pushed a commit
to jwangace/vitess
that referenced
this pull request
Nov 24, 2023
Signed-off-by: Manan Gupta <manan@planetscale.com> Signed-off-by: Jun Wang <jun.wang@demonware.net>
ejortegau
pushed a commit
to slackhq/vitess
that referenced
this pull request
Dec 13, 2023
Signed-off-by: Manan Gupta <manan@planetscale.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes the bug described in #14589.
Since
fk_t16
has child tables and this is a non-literal update, Vitess has to cascade the changes and then update thefk_t16
table with foreign key checks turned off. This requires Vitess to verify that the updated values are present in the parent table i.e.fk_t15
.Previously Vitess was using a query like
select 1 from fk_t16 left join fk_t15 on fk_t15.col = fk_t16.col * (fk_t16.col - fk_t16.col) where fk_t16.col * (fk_t16.col - fk_t16.col) is not null and not (fk_t16.col) <=> (fk_t16.col * (fk_t16.col - fk_t16.col)) and fk_t16.id = 3 and fk_t15.col is null limit 1 for share nowait
.The problem is that
fk_t16.col * (fk_t16.col - fk_t16.col)
evaluates to-0
but of type float. When compared tofk_t15.col
of type varchar0
, MySQL ends up doing the comparison in float space and concludes that -0 and 0 are the same values. This makes Vitess infer that the verification is successful and it is safe to proceed with the update.The final value however is set in Varchar since the column is of varchar type. This leads to Vitess ending up in a broken state and allowing an update that otherwise should have been rejected.
The way adopted to fix this problem has been to CAST the update expression to the type of the column before using it for comparison. i.e. the verification query now looks like
select 1 from fk_t16 left join fk_t15 on fk_t15.col = cast(fk_t16.col * (fk_t16.col - fk_t16.col) as CHAR) where cast(fk_t16.col * (fk_t16.col - fk_t16.col) as CHAR) is not null and not (fk_t16.col) <=> (cast(fk_t16.col * (fk_t16.col - fk_t16.col) as CHAR)) and fk_t16.id = 3 and fk_t15.col is null limit 1 for share nowait
The overall plan looks like -
This works as intended.
Since we are now type-casting the expressions using the
CAST
function, we get the correctly typed expressions in SELECT and the changes introduced in #14524 are no longer required. They have now been reverted.Related Issue(s)
-0
when the parent has0
if the update is done via an arithmetic expression #14589Checklist
Deployment Notes