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

Vinai/show create table check constraints #414

Merged
merged 36 commits into from
May 15, 2021

Conversation

VinaiRachakonda
Copy link
Contributor

@VinaiRachakonda VinaiRachakonda commented May 11, 2021

This pr allow for the printing of check constraints during "SHOW CREATE TABLE"

@VinaiRachakonda VinaiRachakonda changed the title [wip] Vinai/show create table check constraints Vinai/show create table check constraints May 12, 2021
Copy link
Member

@zachmu zachmu left a 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" +
Copy link
Member

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)

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Member

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

@@ -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" +
Copy link
Member

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

@@ -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" +
Copy link
Member

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

Copy link
Member

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

},
},
},
// TODO: Expression tree is Incorrect
Copy link
Member

Choose a reason for hiding this comment

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

?

Copy link
Contributor Author

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

enginetest/script_queries.go Show resolved Hide resolved
@@ -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())
Copy link
Member

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

Copy link
Member

@zachmu zachmu left a 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" +
Copy link
Member

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" +
Copy link
Member

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

@@ -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" +
Copy link
Member

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{
},
},
},
{
Copy link
Member

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

@VinaiRachakonda VinaiRachakonda merged commit c64084a into master May 15, 2021
@Hydrocharged Hydrocharged deleted the vinai/show-create-table-check-constraints branch December 8, 2021 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants