-
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
schemadiff: reject non-deterministic function in new column's default value #16684
schemadiff: reject non-deterministic function in new column's default value #16684
Conversation
…ministic function in column's default value Signed-off-by: Shlomi Noach <[email protected]>
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
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #16684 +/- ##
========================================
Coverage 68.93% 68.94%
========================================
Files 1564 1565 +1
Lines 201371 201553 +182
========================================
+ Hits 138821 138959 +138
- Misses 62550 62594 +44 ☔ View full report in Codecov by Sentry. |
go/vt/schemadiff/errors.go
Outdated
} | ||
|
||
func (e *NonDeterministicDefaultError) Error() string { | ||
return fmt.Sprintf("column %s.%s default value uses non-deterministic function: %v", sqlescape.EscapeID(e.Table), sqlescape.EscapeID(e.Column), e.Function) |
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.
Super nitty, but e.Function is a string so we can use %s instead of %v.
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.
Fixed.
go/vt/schemadiff/table.go
Outdated
foundFunction = node.Name.String() | ||
return false, nil | ||
default: | ||
// recurse into function argument expressions |
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 recursion needed? Walk already visits everything doesn't it?
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.
Confirmed, the recursion is not needed. An earlier iteration led me to believe it was. The existing unit tests already cover two inner function scenarios so this is testes.
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
go/vt/schemadiff/table_test.go
Outdated
from: "create table t1 (id int primary key, a int)", | ||
to: "create table t2 (id int primary key, a int, v varchar(36) not null default (uuid()))", | ||
diff: "alter table t1 add column v varchar(36) not null default (uuid())", | ||
cdiff: "ALTER TABLE `t1` ADD COLUMN `v` varchar(36) NOT NULL DEFAULT (uuid())", |
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.
If this always errors on MySQL, should it even be a flag on schemadiff or should we also always use error?
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.
Agreed. Removed the option altogether, the issue title is now misleading and I'll fix it. Confirmed that MySQL rejects this kind of statement even for empty tables (as opposed to another issue we found the other day where the success depends on whether the table is empty or not). This is a bit of inconsistent behavior for MySQL, but at least we're consistent with it...
…'s behavior reliably rejects adding columns with nondeterministic functions, even in the case of empty tables Signed-off-by: Shlomi Noach <[email protected]>
NonDeterministicDefaultStrategy
, can reject non-deterministic function in column's default value
Description
This PR introduces a new diff hint:NonDeterministicDefaultStrategy
, which can take these values:When it's set toNonDeterministicDefaultReject
,schemadiff
now errors on table diffs where:SYSDATE()
UUID()
RAND()
This matches MySQL behavior as in:
There is no need to handle
MODIFY COLUMN
orCHANGE COLUMN
statements, because those cannot introduce un-computed column data, and only operate on existing columns.Related Issue(s)
Checklist
Deployment Notes