Skip to content

Commit

Permalink
added e2e test for join with using in information_schema
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
  • Loading branch information
harshit-gangal committed Dec 8, 2020
1 parent 82e6565 commit 044de24
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
11 changes: 11 additions & 0 deletions go/test/endtoend/vtgate/information_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,14 @@ func TestInformationSchemaQueryGetsRoutedToTheRightTableAndKeyspace(t *testing.T
result := exec(t, conn, "SELECT * FROM information_schema.tables WHERE table_schema = database() and table_name='t1000'")
assert.NotEmpty(t, result.Rows)
}

func TestFKConstraintUsingInformationSchema(t *testing.T) {
defer cluster.PanicHandler(t)
ctx := context.Background()
conn, err := mysql.Connect(ctx, &vtParams)
require.NoError(t, err)
defer conn.Close()

query := "select fk.referenced_table_name as to_table, fk.referenced_column_name as primary_key, fk.column_name as `column`, fk.constraint_name as name, rc.update_rule as on_update, rc.delete_rule as on_delete from information_schema.referential_constraints as rc join information_schema.key_column_usage as fk using (constraint_schema, constraint_name) where fk.referenced_column_name is not null and fk.table_schema = database() and fk.table_name = 't7_fk' and rc.constraint_schema = database() and rc.table_name = 't7_fk'"
assertMatches(t, conn, query, `[[VARCHAR("t7_xxhash") VARCHAR("uid") VARCHAR("t7_uid") VARCHAR("t7_fk_ibfk_1") VARCHAR("CASCADE") VARCHAR("SET NULL")]]`)
}
19 changes: 18 additions & 1 deletion go/test/endtoend/vtgate/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,16 @@ create table t7_xxhash_idx(
phone bigint,
keyspace_id varbinary(50),
primary key(phone, keyspace_id)
) Engine=InnoDB;`
) Engine=InnoDB;
create table t7_fk(
id bigint,
t7_uid varchar(50),
primary key(id),
CONSTRAINT t7_fk_ibfk_1 foreign key (t7_uid) references t7_xxhash(uid)
on delete set null on update cascade
) Engine=InnoDB;
`

VSchema = `
{
Expand Down Expand Up @@ -353,6 +362,14 @@ create table t7_xxhash_idx(
"name": "unicode_loose_xxhash"
}
]
},
"t7_fk": {
"column_vindexes": [
{
"column": "t7_uid",
"name": "unicode_loose_xxhash"
}
]
}
}
}`
Expand Down

0 comments on commit 044de24

Please sign in to comment.