-
-
Notifications
You must be signed in to change notification settings - Fork 209
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
Vinai/show create table check constraints #414
Vinai/show create table check constraints #414
Conversation
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.
Better but too many parens, see comments
@@ -3007,7 +3018,7 @@ func TestColumnDefaults(t *testing.T, harness Harness) { | |||
TestQuery(t, harness, e, "SHOW CREATE TABLE t29", []sql.Row{{"t29", "CREATE TABLE `t29` (\n" + | |||
" `pk` bigint NOT NULL,\n" + | |||
" `v1y` bigint,\n" + | |||
" `v2` bigint DEFAULT (v1y + 1),\n" + | |||
" `v2` bigint DEFAULT ((v1y + 1)),\n" + |
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.
You should strip these extra parens (just don't add them in the first place)
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.
This is actually the correct mysql behavior.
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.
Thanks for checking, would not have guessed this
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.
Add a TODO to backtick quote the columns in column defaults, this will break for some things as is
enginetest/queries.go
Outdated
@@ -5395,7 +5395,8 @@ var InfoSchemaQueries = []QueryTest{ | |||
" `s` varchar(20) NOT NULL COMMENT 'column s',\n" + | |||
" PRIMARY KEY (`i`),\n" + | |||
" KEY `mytable_i_s` (`i`,`s`),\n" + | |||
" UNIQUE KEY `mytable_s` (`s`)\n" + | |||
" UNIQUE KEY `mytable_s` (`s`),\n" + | |||
" CONSTRAINT `mycheck` CHECK ((`i` > -100))\n" + |
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.
Same here. You don't need to add parens to the check expression anymore, since every expression prints their own now
enginetest/query_plans.go
Outdated
@@ -26,11 +26,11 @@ var PlanTests = []QueryPlanTest{ | |||
{ | |||
Query: `SELECT t1.i FROM mytable t1 JOIN mytable t2 on t1.i = t2.i + 1 where t1.i = 2 and t2.i = 1`, | |||
ExpectedPlan: "Project(t1.i)\n" + | |||
" └─ IndexedJoin(t1.i = t2.i + 1)\n" + | |||
" ├─ Filter(t2.i = 1)\n" + | |||
" └─ IndexedJoin((t1.i = (t2.i + 1)))\n" + |
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.
Same comment throughout here. Change the String() methods of these nodes that print expressions within parens. They don't need parens anymore
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.
BTW after you make these changes, don't forget there's a skipped unit tests that regenerates this file for just this kind of emergency
enginetest/script_queries.go
Outdated
}, | ||
}, | ||
}, | ||
// TODO: Expression tree is Incorrect |
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.
?
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.
Bad comment on my part. I should've been explained that I thought this caused a bug on the expression tree. I just double checked and it's no longer a problem
sql/plan/show_create_table.go
Outdated
@@ -243,6 +246,18 @@ func (i *showCreateTablesIter) produceCreateTableStatement(table sql.Table) (str | |||
} | |||
} | |||
|
|||
if i.checks != nil { | |||
for _, check := range i.checks { | |||
fmted := fmt.Sprintf(" CONSTRAINT `%s` CHECK (%s)", check.Name, check.Expr.String()) |
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.
No need for parens here, as mentioned earlier
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.
LG, just a couple small changes for integrator compatibility necessary
@@ -3007,7 +3018,7 @@ func TestColumnDefaults(t *testing.T, harness Harness) { | |||
TestQuery(t, harness, e, "SHOW CREATE TABLE t29", []sql.Row{{"t29", "CREATE TABLE `t29` (\n" + | |||
" `pk` bigint NOT NULL,\n" + | |||
" `v1y` bigint,\n" + | |||
" `v2` bigint DEFAULT (v1y + 1),\n" + | |||
" `v2` bigint DEFAULT ((v1y + 1)),\n" + |
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.
Thanks for checking, would not have guessed this
@@ -3007,7 +3018,7 @@ func TestColumnDefaults(t *testing.T, harness Harness) { | |||
TestQuery(t, harness, e, "SHOW CREATE TABLE t29", []sql.Row{{"t29", "CREATE TABLE `t29` (\n" + | |||
" `pk` bigint NOT NULL,\n" + | |||
" `v1y` bigint,\n" + | |||
" `v2` bigint DEFAULT (v1y + 1),\n" + | |||
" `v2` bigint DEFAULT ((v1y + 1)),\n" + |
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.
Add a TODO to backtick quote the columns in column defaults, this will break for some things as is
enginetest/queries.go
Outdated
@@ -5395,7 +5395,8 @@ var InfoSchemaQueries = []QueryTest{ | |||
" `s` varchar(20) NOT NULL COMMENT 'column s',\n" + | |||
" PRIMARY KEY (`i`),\n" + | |||
" KEY `mytable_i_s` (`i`,`s`),\n" + | |||
" UNIQUE KEY `mytable_s` (`s`)\n" + | |||
" UNIQUE KEY `mytable_s` (`s`),\n" + | |||
" CONSTRAINT `mycheck` CHECK (`i` > -100)\n" + |
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.
You actually can't do this to myTable
, it's just too widely used. With this setup, nobody gets to use myTable unless they implement check constraints
Instead, conditionally create a new table in test_data.go only if the harness supports checks, OR
Just test this in the existing Check methods in enginetests.go (which integrators can decide to not test if they can't support it)
@@ -755,4 +755,156 @@ var ScriptTests = []ScriptTest{ | |||
}, | |||
}, | |||
}, | |||
{ |
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.
You can't put these in here for the same reason you can't change mytable
: ScriptTests is very generic, meant to support most implementors. Adding the necessity of check constraints breaks that
Put this script into its own var, probably in a new file
This pr allow for the printing of check constraints during "SHOW CREATE TABLE"