Commit 193b5ed5 authored by Vicențiu Ciorbaru's avatar Vicențiu Ciorbaru

Merge branch '10.2' into 10.3

parents 3466b47b a134f1eb
#
# MDEV-17323: Backport INFORMATION_SCHEMA.CHECK_CONSTRAINTS to 10.2
#
CREATE user boo1;
GRANT select,create,alter,drop on foo.* to boo1;
SHOW GRANTS for boo1;
Grants for boo1@%
GRANT USAGE ON *.* TO 'boo1'@'%'
GRANT SELECT, CREATE, DROP, ALTER ON `foo`.* TO 'boo1'@'%'
CREATE user boo2;
create database foo;
CONNECT con1,localhost, boo1,, foo;
SET check_constraint_checks=1;
CREATE TABLE t0
(
t int, check (t>32) # table constraint
) ENGINE=myisam;
SELECT * from information_schema.check_constraints;
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_NAME CHECK_CLAUSE
def foo CONSTRAINT_1 t0 `t` > 32
ALTER TABLE t0
ADD CONSTRAINT CHK_t0_t CHECK(t<100);
SELECT * from information_schema.check_constraints;
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_NAME CHECK_CLAUSE
def foo CHK_t0_t t0 `t` < 100
def foo CONSTRAINT_1 t0 `t` > 32
ALTER TABLE t0
DROP CONSTRAINT CHK_t0_t;
SELECT * from information_schema.check_constraints;
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_NAME CHECK_CLAUSE
def foo CONSTRAINT_1 t0 `t` > 32
ALTER TABLE t0
ADD CONSTRAINT CHECK(t<50);
SELECT * from information_schema.check_constraints;
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_NAME CHECK_CLAUSE
def foo CONSTRAINT_1 t0 `t` > 32
def foo CONSTRAINT_2 t0 `t` < 50
CREATE TABLE t1
( t int CHECK(t>2), # field constraint
tt int,
CONSTRAINT CHECK (tt > 32), CONSTRAINT CHECK (tt <50),# autogenerated names table constraints
CONSTRAINT CHK_tt CHECK(tt<100) # named table constraint
) ENGINE=InnoDB;
SELECT * from information_schema.check_constraints;
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_NAME CHECK_CLAUSE
def foo CHK_tt t1 `tt` < 100
def foo CONSTRAINT_1 t0 `t` > 32
def foo CONSTRAINT_1 t1 `tt` > 32
def foo CONSTRAINT_2 t0 `t` < 50
def foo CONSTRAINT_2 t1 `tt` < 50
def foo t t1 `t` > 2
ALTER TABLE t1
DROP CONSTRAINT CHK_tt;
SELECT * from information_schema.check_constraints;
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_NAME CHECK_CLAUSE
def foo CONSTRAINT_1 t0 `t` > 32
def foo CONSTRAINT_1 t1 `tt` > 32
def foo CONSTRAINT_2 t0 `t` < 50
def foo CONSTRAINT_2 t1 `tt` < 50
def foo t t1 `t` > 2
CREATE TABLE t2
(
name VARCHAR(30) CHECK(CHAR_LENGTH(name)>2), #field constraint
start_date DATE,
end_date DATE,
CONSTRAINT CHK_dates CHECK(start_date IS NULL) #table constraint
)ENGINE=Innodb;
SELECT * from information_schema.check_constraints;
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_NAME CHECK_CLAUSE
def foo CHK_dates t2 `start_date` is null
def foo CONSTRAINT_1 t0 `t` > 32
def foo CONSTRAINT_1 t1 `tt` > 32
def foo CONSTRAINT_2 t0 `t` < 50
def foo CONSTRAINT_2 t1 `tt` < 50
def foo name t2 char_length(`name`) > 2
def foo t t1 `t` > 2
ALTER TABLE t1
ADD CONSTRAINT CHK_new_ CHECK(t>tt);
SELECT * from information_schema.check_constraints;
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_NAME CHECK_CLAUSE
def foo CHK_dates t2 `start_date` is null
def foo CHK_new_ t1 `t` > `tt`
def foo CONSTRAINT_1 t0 `t` > 32
def foo CONSTRAINT_1 t1 `tt` > 32
def foo CONSTRAINT_2 t0 `t` < 50
def foo CONSTRAINT_2 t1 `tt` < 50
def foo name t2 char_length(`name`) > 2
def foo t t1 `t` > 2
CREATE TABLE t3
(
a int,
b int check (b>0), # field constraint named 'b'
CONSTRAINT b check (b>10) # table constraint
) ENGINE=InnoDB;
SELECT * from information_schema.check_constraints;
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_NAME CHECK_CLAUSE
def foo CHK_dates t2 `start_date` is null
def foo CHK_new_ t1 `t` > `tt`
def foo CONSTRAINT_1 t0 `t` > 32
def foo CONSTRAINT_1 t1 `tt` > 32
def foo CONSTRAINT_2 t0 `t` < 50
def foo CONSTRAINT_2 t1 `tt` < 50
def foo b t3 `b` > 0
def foo b t3 `b` > 10
def foo name t2 char_length(`name`) > 2
def foo t t1 `t` > 2
disconnect con1;
CONNECT con2, localhost, boo2,, test;
SELECT * from information_schema.check_constraints;
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_NAME CHECK_CLAUSE
disconnect con2;
CONNECT con1, localhost, boo1,,foo;
DROP TABLE t0;
DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
DROP DATABASE foo;
disconnect con1;
connection default;
DROP USER boo1;
DROP USER boo2;
# #
# MDEV-14474: Create INFORMATION_SCHEMA.CHECK_CONSTRAINTS # MDEV-14474: Create INFORMATION_SCHEMA.CHECK_CONSTRAINTS
# #
set check_constraint_checks=1; CREATE user boo1;
use test; GRANT select,create,alter,drop on foo.* to boo1;
create table t0 SHOW GRANTS for boo1;
Grants for boo1@%
GRANT USAGE ON *.* TO 'boo1'@'%'
GRANT SELECT, CREATE, DROP, ALTER ON `foo`.* TO 'boo1'@'%'
CREATE user boo2;
create database foo;
CONNECT con1,localhost, boo1,, foo;
SET check_constraint_checks=1;
CREATE TABLE t0
( (
t int, check (t>32) # table constraint t int, check (t>32) # table constraint
) ENGINE=myisam; ) ENGINE=myisam;
SELECT * from information_schema.check_constraints order by check_clause; SELECT * from information_schema.check_constraints;
CONSTRAINT_CATALOG def CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
CONSTRAINT_SCHEMA test def foo t0 CONSTRAINT_1 `t` > 32
CONSTRAINT_NAME CONSTRAINT_1
TABLE_NAME t0
CHECK_CLAUSE `t` > 32
ALTER TABLE t0 ALTER TABLE t0
ADD CONSTRAINT CHK_t0_t CHECK(t<100); ADD CONSTRAINT CHK_t0_t CHECK(t<100);
SELECT * from information_schema.check_constraints order by check_clause; SELECT * from information_schema.check_constraints;
CONSTRAINT_CATALOG def CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
CONSTRAINT_SCHEMA test def foo t0 CHK_t0_t `t` < 100
CONSTRAINT_NAME CHK_t0_t def foo t0 CONSTRAINT_1 `t` > 32
TABLE_NAME t0
CHECK_CLAUSE `t` < 100
CONSTRAINT_CATALOG def
CONSTRAINT_SCHEMA test
CONSTRAINT_NAME CONSTRAINT_1
TABLE_NAME t0
CHECK_CLAUSE `t` > 32
ALTER TABLE t0 ALTER TABLE t0
DROP CONSTRAINT CHK_t0_t; DROP CONSTRAINT CHK_t0_t;
SELECT * from information_schema.check_constraints order by check_clause; SELECT * from information_schema.check_constraints;
CONSTRAINT_CATALOG def CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
CONSTRAINT_SCHEMA test def foo t0 CONSTRAINT_1 `t` > 32
CONSTRAINT_NAME CONSTRAINT_1 ALTER TABLE t0
TABLE_NAME t0 ADD CONSTRAINT CHECK(t<50);
CHECK_CLAUSE `t` > 32 SELECT * from information_schema.check_constraints;
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
def foo t0 CONSTRAINT_1 `t` > 32
def foo t0 CONSTRAINT_2 `t` < 50
CREATE TABLE t1 CREATE TABLE t1
( t int CHECK(t>2), # field constraint ( t int CHECK(t>2), # field constraint
tt int, CONSTRAINT CHK_tt CHECK(tt<100) # table constraint tt int,
CONSTRAINT CHECK (tt > 32), CONSTRAINT CHECK (tt <50),# autogenerated names table constraints
CONSTRAINT CHK_tt CHECK(tt<100) # named table constraint
) ENGINE=InnoDB; ) ENGINE=InnoDB;
SELECT * from information_schema.check_constraints order by check_clause; SELECT * from information_schema.check_constraints;
CONSTRAINT_CATALOG def CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
CONSTRAINT_SCHEMA test def foo t0 CONSTRAINT_1 `t` > 32
CONSTRAINT_NAME CHK_tt def foo t0 CONSTRAINT_2 `t` < 50
TABLE_NAME t1 def foo t1 CHK_tt `tt` < 100
CHECK_CLAUSE `tt` < 100 def foo t1 CONSTRAINT_1 `tt` > 32
CONSTRAINT_CATALOG def def foo t1 CONSTRAINT_2 `tt` < 50
CONSTRAINT_SCHEMA test def foo t1 t `t` > 2
CONSTRAINT_NAME t
TABLE_NAME t1
CHECK_CLAUSE `t` > 2
CONSTRAINT_CATALOG def
CONSTRAINT_SCHEMA test
CONSTRAINT_NAME CONSTRAINT_1
TABLE_NAME t0
CHECK_CLAUSE `t` > 32
ALTER TABLE t1 ALTER TABLE t1
DROP CONSTRAINT CHK_tt; DROP CONSTRAINT CHK_tt;
SELECT * from information_schema.check_constraints order by check_clause; SELECT * from information_schema.check_constraints;
CONSTRAINT_CATALOG def CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
CONSTRAINT_SCHEMA test def foo t0 CONSTRAINT_1 `t` > 32
CONSTRAINT_NAME t def foo t0 CONSTRAINT_2 `t` < 50
TABLE_NAME t1 def foo t1 CONSTRAINT_1 `tt` > 32
CHECK_CLAUSE `t` > 2 def foo t1 CONSTRAINT_2 `tt` < 50
CONSTRAINT_CATALOG def def foo t1 t `t` > 2
CONSTRAINT_SCHEMA test CREATE TABLE t2
CONSTRAINT_NAME CONSTRAINT_1
TABLE_NAME t0
CHECK_CLAUSE `t` > 32
create table t2
( (
name VARCHAR(30) CHECK(CHAR_LENGTH(name)>2), #field constraint name VARCHAR(30) CHECK(CHAR_LENGTH(name)>2), #field constraint
start_date DATE, start_date DATE,
end_date DATE, end_date DATE,
CONSTRAINT CHK_dates CHECK(start_date IS NULL) #table constraint CONSTRAINT CHK_dates CHECK(start_date IS NULL) #table constraint
)ENGINE=Innodb; )ENGINE=Innodb;
SELECT * from information_schema.check_constraints order by check_clause; SELECT * from information_schema.check_constraints;
CONSTRAINT_CATALOG def CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
CONSTRAINT_SCHEMA test def foo t0 CONSTRAINT_1 `t` > 32
CONSTRAINT_NAME name def foo t0 CONSTRAINT_2 `t` < 50
TABLE_NAME t2 def foo t1 CONSTRAINT_1 `tt` > 32
CHECK_CLAUSE char_length(`name`) > 2 def foo t1 CONSTRAINT_2 `tt` < 50
CONSTRAINT_CATALOG def def foo t1 t `t` > 2
CONSTRAINT_SCHEMA test def foo t2 CHK_dates `start_date` is null
CONSTRAINT_NAME CHK_dates def foo t2 name char_length(`name`) > 2
TABLE_NAME t2
CHECK_CLAUSE `start_date` is null
CONSTRAINT_CATALOG def
CONSTRAINT_SCHEMA test
CONSTRAINT_NAME t
TABLE_NAME t1
CHECK_CLAUSE `t` > 2
CONSTRAINT_CATALOG def
CONSTRAINT_SCHEMA test
CONSTRAINT_NAME CONSTRAINT_1
TABLE_NAME t0
CHECK_CLAUSE `t` > 32
ALTER TABLE t1 ALTER TABLE t1
ADD CONSTRAINT CHK_new_ CHECK(t>tt); ADD CONSTRAINT CHK_new_ CHECK(t>tt);
SELECT * from information_schema.check_constraints order by check_clause; SELECT * from information_schema.check_constraints;
CONSTRAINT_CATALOG def CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
CONSTRAINT_SCHEMA test def foo t0 CONSTRAINT_1 `t` > 32
CONSTRAINT_NAME name def foo t0 CONSTRAINT_2 `t` < 50
TABLE_NAME t2 def foo t1 CHK_new_ `t` > `tt`
CHECK_CLAUSE char_length(`name`) > 2 def foo t1 CONSTRAINT_1 `tt` > 32
CONSTRAINT_CATALOG def def foo t1 CONSTRAINT_2 `tt` < 50
CONSTRAINT_SCHEMA test def foo t1 t `t` > 2
CONSTRAINT_NAME CHK_dates def foo t2 CHK_dates `start_date` is null
TABLE_NAME t2 def foo t2 name char_length(`name`) > 2
CHECK_CLAUSE `start_date` is null CREATE TABLE t3
CONSTRAINT_CATALOG def
CONSTRAINT_SCHEMA test
CONSTRAINT_NAME t
TABLE_NAME t1
CHECK_CLAUSE `t` > 2
CONSTRAINT_CATALOG def
CONSTRAINT_SCHEMA test
CONSTRAINT_NAME CONSTRAINT_1
TABLE_NAME t0
CHECK_CLAUSE `t` > 32
CONSTRAINT_CATALOG def
CONSTRAINT_SCHEMA test
CONSTRAINT_NAME CHK_new_
TABLE_NAME t1
CHECK_CLAUSE `t` > `tt`
create table t3
( (
a int, a int,
b int check (b>0), # field constraint named 'b' b int check (b>0), # field constraint named 'b'
CONSTRAINT b check (b>10) # table constraint CONSTRAINT b check (b>10) # table constraint
) ENGINE=InnoDB; ) ENGINE=InnoDB;
select * from information_schema.check_constraints order by check_clause; SELECT * from information_schema.check_constraints;
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_NAME CHECK_CLAUSE CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
def test name t2 char_length(`name`) > 2 def foo t0 CONSTRAINT_1 `t` > 32
def test b t3 `b` > 0 def foo t0 CONSTRAINT_2 `t` < 50
def test b t3 `b` > 10 def foo t1 CHK_new_ `t` > `tt`
def test CHK_dates t2 `start_date` is null def foo t1 CONSTRAINT_1 `tt` > 32
def test t t1 `t` > 2 def foo t1 CONSTRAINT_2 `tt` < 50
def test CONSTRAINT_1 t0 `t` > 32 def foo t1 t `t` > 2
def test CHK_new_ t1 `t` > `tt` def foo t2 CHK_dates `start_date` is null
drop table t0; def foo t2 name char_length(`name`) > 2
drop table t1; def foo t3 b `b` > 0
drop table t2; def foo t3 b `b` > 10
drop table t3; disconnect con1;
CONNECT con2, localhost, boo2,, test;
SELECT * from information_schema.check_constraints;
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
disconnect con2;
CONNECT con1, localhost, boo1,,foo;
DROP TABLE t0;
DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
DROP DATABASE foo;
disconnect con1;
connection default;
DROP USER boo1;
DROP USER boo2;
#
# MDEV-18440: Information_schema.check_constraints possible data leak
#
CREATE USER foo;
CREATE DATABASE db;
USE db;
CREATE TABLE t1 (a int, b int, CONSTRAINT CHECK (b > 0));
INSERT INTO t1 VALUES (1, 2), (2, 3);
GRANT SELECT (a) ON t1 TO foo;
SHOW GRANTS FOR foo;
Grants for foo@%
GRANT USAGE ON *.* TO 'foo'@'%'
GRANT SELECT (a) ON `db`.`t1` TO 'foo'@'%'
SELECT * FROM information_schema.check_constraints;
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
def db t1 CONSTRAINT_1 `b` > 0
CONNECT con1,localhost, foo,, db;
SELECT a FROM t1;
a
1
2
SELECT * FROM information_schema.check_constraints;
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
connection default;
DROP USER foo;
DROP DATABASE db;
--source include/have_innodb.inc
--source include/not_embedded.inc
--echo #
--echo # MDEV-17323: Backport INFORMATION_SCHEMA.CHECK_CONSTRAINTS to 10.2
--echo #
CREATE user boo1;
GRANT select,create,alter,drop on foo.* to boo1;
SHOW GRANTS for boo1;
CREATE user boo2;
create database foo;
# Connect with user boo1
CONNECT(con1,localhost, boo1,, foo);
SET check_constraint_checks=1;
CREATE TABLE t0
(
t int, check (t>32) # table constraint
) ENGINE=myisam;
--sorted_result
SELECT * from information_schema.check_constraints;
ALTER TABLE t0
ADD CONSTRAINT CHK_t0_t CHECK(t<100);
--sorted_result
SELECT * from information_schema.check_constraints;
ALTER TABLE t0
DROP CONSTRAINT CHK_t0_t;
--sorted_result
SELECT * from information_schema.check_constraints;
ALTER TABLE t0
ADD CONSTRAINT CHECK(t<50);
--sorted_result
SELECT * from information_schema.check_constraints;
CREATE TABLE t1
( t int CHECK(t>2), # field constraint
tt int,
CONSTRAINT CHECK (tt > 32), CONSTRAINT CHECK (tt <50),# autogenerated names table constraints
CONSTRAINT CHK_tt CHECK(tt<100) # named table constraint
) ENGINE=InnoDB;
--sorted_result
SELECT * from information_schema.check_constraints;
ALTER TABLE t1
DROP CONSTRAINT CHK_tt;
--sorted_result
SELECT * from information_schema.check_constraints;
CREATE TABLE t2
(
name VARCHAR(30) CHECK(CHAR_LENGTH(name)>2), #field constraint
start_date DATE,
end_date DATE,
CONSTRAINT CHK_dates CHECK(start_date IS NULL) #table constraint
)ENGINE=Innodb;
--sorted_result
SELECT * from information_schema.check_constraints;
ALTER TABLE t1
ADD CONSTRAINT CHK_new_ CHECK(t>tt);
--sorted_result
SELECT * from information_schema.check_constraints;
# Create table with same field and table check constraint name
CREATE TABLE t3
(
a int,
b int check (b>0), # field constraint named 'b'
CONSTRAINT b check (b>10) # table constraint
) ENGINE=InnoDB;
--sorted_result
SELECT * from information_schema.check_constraints;
DISCONNECT con1;
CONNECT(con2, localhost, boo2,, test);
--sorted_result
SELECT * from information_schema.check_constraints;
DISCONNECT con2;
CONNECT(con1, localhost, boo1,,foo);
DROP TABLE t0;
DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
DROP DATABASE foo;
DISCONNECT con1;
--CONNECTION default
DROP USER boo1;
DROP USER boo2;
--source include/have_innodb.inc --source include/have_innodb.inc
--source include/not_embedded.inc
--echo # --echo #
--echo # MDEV-14474: Create INFORMATION_SCHEMA.CHECK_CONSTRAINTS --echo # MDEV-14474: Create INFORMATION_SCHEMA.CHECK_CONSTRAINTS
--echo # --echo #
set check_constraint_checks=1; CREATE user boo1;
GRANT select,create,alter,drop on foo.* to boo1;
SHOW GRANTS for boo1;
CREATE user boo2;
create database foo;
# Connect with user boo1
CONNECT(con1,localhost, boo1,, foo);
use test; SET check_constraint_checks=1;
create table t0 CREATE TABLE t0
( (
t int, check (t>32) # table constraint t int, check (t>32) # table constraint
) ENGINE=myisam; ) ENGINE=myisam;
--sorted_result
--vertical_results SELECT * from information_schema.check_constraints;
SELECT * from information_schema.check_constraints order by check_clause;
ALTER TABLE t0 ALTER TABLE t0
ADD CONSTRAINT CHK_t0_t CHECK(t<100); ADD CONSTRAINT CHK_t0_t CHECK(t<100);
--sorted_result
SELECT * from information_schema.check_constraints order by check_clause; SELECT * from information_schema.check_constraints;
ALTER TABLE t0 ALTER TABLE t0
DROP CONSTRAINT CHK_t0_t; DROP CONSTRAINT CHK_t0_t;
--sorted_result
SELECT * from information_schema.check_constraints;
SELECT * from information_schema.check_constraints order by check_clause; ALTER TABLE t0
ADD CONSTRAINT CHECK(t<50);
--sorted_result
SELECT * from information_schema.check_constraints;
CREATE TABLE t1 CREATE TABLE t1
( t int CHECK(t>2), # field constraint ( t int CHECK(t>2), # field constraint
tt int, CONSTRAINT CHK_tt CHECK(tt<100) # table constraint tt int,
CONSTRAINT CHECK (tt > 32), CONSTRAINT CHECK (tt <50),# autogenerated names table constraints
CONSTRAINT CHK_tt CHECK(tt<100) # named table constraint
) ENGINE=InnoDB; ) ENGINE=InnoDB;
--sorted_result
SELECT * from information_schema.check_constraints order by check_clause; SELECT * from information_schema.check_constraints;
ALTER TABLE t1 ALTER TABLE t1
DROP CONSTRAINT CHK_tt; DROP CONSTRAINT CHK_tt;
--sorted_result
SELECT * from information_schema.check_constraints;
SELECT * from information_schema.check_constraints order by check_clause; CREATE TABLE t2
create table t2
( (
name VARCHAR(30) CHECK(CHAR_LENGTH(name)>2), #field constraint name VARCHAR(30) CHECK(CHAR_LENGTH(name)>2), #field constraint
start_date DATE, start_date DATE,
end_date DATE, end_date DATE,
CONSTRAINT CHK_dates CHECK(start_date IS NULL) #table constraint CONSTRAINT CHK_dates CHECK(start_date IS NULL) #table constraint
)ENGINE=Innodb; )ENGINE=Innodb;
--sorted_result
SELECT * from information_schema.check_constraints order by check_clause; SELECT * from information_schema.check_constraints;
ALTER TABLE t1 ALTER TABLE t1
ADD CONSTRAINT CHK_new_ CHECK(t>tt); ADD CONSTRAINT CHK_new_ CHECK(t>tt);
--sorted_result
SELECT * from information_schema.check_constraints order by check_clause; SELECT * from information_schema.check_constraints;
# Create table with same field and table check constraint name # Create table with same field and table check constraint name
create table t3 CREATE TABLE t3
( (
a int, a int,
b int check (b>0), # field constraint named 'b' b int check (b>0), # field constraint named 'b'
CONSTRAINT b check (b>10) # table constraint CONSTRAINT b check (b>10) # table constraint
) ENGINE=InnoDB; ) ENGINE=InnoDB;
--sorted_result
SELECT * from information_schema.check_constraints;
DISCONNECT con1;
CONNECT(con2, localhost, boo2,, test);
--sorted_result
SELECT * from information_schema.check_constraints;
DISCONNECT con2;
CONNECT(con1, localhost, boo1,,foo);
DROP TABLE t0;
DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
DROP DATABASE foo;
DISCONNECT con1;
--CONNECTION default
DROP USER boo1;
DROP USER boo2;
--echo #
--echo # MDEV-18440: Information_schema.check_constraints possible data leak
--echo #
CREATE USER foo;
CREATE DATABASE db;
USE db;
CREATE TABLE t1 (a int, b int, CONSTRAINT CHECK (b > 0));
INSERT INTO t1 VALUES (1, 2), (2, 3);
GRANT SELECT (a) ON t1 TO foo;
SHOW GRANTS FOR foo;
--sorted_result
SELECT * FROM information_schema.check_constraints;
CONNECT(con1,localhost, foo,, db);
SELECT a FROM t1;
--sorted_result
SELECT * FROM information_schema.check_constraints;
--horizontal_results --CONNECTION default
select * from information_schema.check_constraints order by check_clause;
drop table t0; DROP USER foo;
drop table t1; DROP DATABASE db;
drop table t2;
drop table t3;
...@@ -6865,23 +6865,35 @@ static int get_check_constraints_record(THD *thd, TABLE_LIST *tables, ...@@ -6865,23 +6865,35 @@ static int get_check_constraints_record(THD *thd, TABLE_LIST *tables,
thd->clear_error(); thd->clear_error();
DBUG_RETURN(0); DBUG_RETURN(0);
} }
else if (!tables->view) if (!tables->view)
{ {
if (tables->table->s->table_check_constraints) StringBuffer<MAX_FIELD_WIDTH> str(system_charset_info);
#ifndef NO_EMBEDDED_ACCESS_CHECKS
TABLE_LIST table_acl_check;
bzero((char*) &table_acl_check, sizeof(table_acl_check));
#endif
for (uint i= 0; i < tables->table->s->table_check_constraints; i++)
{ {
for (uint i= 0; i < tables->table->s->table_check_constraints; i++) #ifndef NO_EMBEDDED_ACCESS_CHECKS
if (!(thd->col_access & TABLE_ACLS))
{ {
StringBuffer<MAX_FIELD_WIDTH> str(system_charset_info); table_acl_check.db= *db_name;
Virtual_column_info *check= tables->table->check_constraints[i]; table_acl_check.table_name= *table_name;
restore_record(table, s->default_values); table_acl_check.grant.privilege= thd->col_access;
table->field[0]->store(STRING_WITH_LEN("def"), system_charset_info); if (check_grant(thd, TABLE_ACLS, &table_acl_check, FALSE, 1, TRUE))
table->field[1]->store(db_name->str, db_name->length, system_charset_info); continue;
table->field[2]->store(check->name.str, check->name.length, system_charset_info);
table->field[3]->store(table_name->str, table_name->length, system_charset_info);
check->print(&str);
table->field[4]->store(str.ptr(), str.length(), system_charset_info);
schema_table_store_record(thd, table);
} }
#endif
Virtual_column_info *check= tables->table->check_constraints[i];
table->field[0]->store(STRING_WITH_LEN("def"), system_charset_info);
table->field[3]->store(check->name.str, check->name.length,
system_charset_info);
/* Make sure the string is empty between each print. */
str.length(0);
check->print(&str);
table->field[4]->store(str.ptr(), str.length(), system_charset_info);
if (schema_table_store_record(thd, table))
DBUG_RETURN(1);
} }
} }
DBUG_RETURN(res); DBUG_RETURN(res);
...@@ -9806,9 +9818,9 @@ ST_FIELD_INFO check_constraints_fields_info[]= ...@@ -9806,9 +9818,9 @@ ST_FIELD_INFO check_constraints_fields_info[]=
{"CONSTRAINT_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE}, {"CONSTRAINT_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
{"CONSTRAINT_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, {"CONSTRAINT_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
OPEN_FULL_TABLE}, OPEN_FULL_TABLE},
{"TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
{"CONSTRAINT_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, {"CONSTRAINT_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
OPEN_FULL_TABLE}, OPEN_FULL_TABLE},
{"TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
{"CHECK_CLAUSE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, {"CHECK_CLAUSE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
OPEN_FULL_TABLE}, OPEN_FULL_TABLE},
{0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE} {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
...@@ -9828,8 +9840,8 @@ ST_SCHEMA_TABLE schema_tables[]= ...@@ -9828,8 +9840,8 @@ ST_SCHEMA_TABLE schema_tables[]=
fill_schema_applicable_roles, 0, 0, -1, -1, 0, 0}, fill_schema_applicable_roles, 0, 0, -1, -1, 0, 0},
{"CHARACTER_SETS", charsets_fields_info, 0, {"CHARACTER_SETS", charsets_fields_info, 0,
fill_schema_charsets, make_character_sets_old_format, 0, -1, -1, 0, 0}, fill_schema_charsets, make_character_sets_old_format, 0, -1, -1, 0, 0},
{"CHECK_CONSTRAINTS", check_constraints_fields_info, 0, {"CHECK_CONSTRAINTS", check_constraints_fields_info, 0, get_all_tables, 0,
get_all_tables, 0, get_check_constraints_record, 1, 2, 0, OPTIMIZE_I_S_TABLE|OPEN_TABLE_ONLY}, get_check_constraints_record, 1, 2, 0, OPTIMIZE_I_S_TABLE|OPEN_TABLE_ONLY},
{"COLLATIONS", collation_fields_info, 0, {"COLLATIONS", collation_fields_info, 0,
fill_schema_collation, make_old_format, 0, -1, -1, 0, 0}, fill_schema_collation, make_old_format, 0, -1, -1, 0, 0},
{"COLLATION_CHARACTER_SET_APPLICABILITY", coll_charset_app_fields_info, {"COLLATION_CHARACTER_SET_APPLICABILITY", coll_charset_app_fields_info,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment