Changeset: bd112e07a0a7 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/bd112e07a0a7
Modified Files:
sql/server/rel_schema.c
sql/test/miscellaneous/Tests/simple_selects.test
Branch: Jan2022
Log Message:
When creating a key/index check if the counterpart name exists and throw error,
because it will be ambiguous on the backend
diffs (99 lines):
diff --git a/sql/server/rel_schema.c b/sql/server/rel_schema.c
--- a/sql/server/rel_schema.c
+++ b/sql/server/rel_schema.c
@@ -376,6 +376,10 @@ column_constraint_type(mvc *sql, const c
(void) sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT
%s: key %s already exists", (kt == pkey) ? "PRIMARY KEY" : "UNIQUE", name);
return res;
}
+ if (ol_find_name(t->idxs, name) || mvc_bind_idx(sql, ss, name))
{
+ (void) sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT
%s: an index named '%s' already exists, and it would conflict with the key", kt
== pkey ? "PRIMARY KEY" : "UNIQUE", name);
+ return res;
+ }
switch (mvc_create_ukey(&k, sql, t, name, kt)) {
case -1:
(void) sql_error(sql, 02, SQLSTATE(HY013)
MAL_MALLOC_FAIL);
@@ -455,6 +459,10 @@ column_constraint_type(mvc *sql, const c
(void) sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT
FOREIGN KEY: key '%s' already exists", name);
return res;
}
+ if (ol_find_name(t->idxs, name) || mvc_bind_idx(sql, ss, name))
{
+ (void) sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT
FOREIGN KEY: an index named '%s' already exists, and it would conflict with the
key", name);
+ return res;
+ }
/* find unique referenced key */
if (n->next->data.lval) {
@@ -709,6 +717,10 @@ table_foreign_key(mvc *sql, const char *
(void) sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT
FOREIGN KEY: key '%s' already exists", name);
return SQL_ERR;
}
+ if (ol_find_name(t->idxs, name) || mvc_bind_idx(sql, ss, name))
{
+ (void) sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT
FOREIGN KEY: an index named '%s' already exists, and it would conflict with the
key", name);
+ return SQL_ERR;
+ }
if (n->next->next->data.lval) { /* find unique referenced key */
dnode *rnms = n->next->next->data.lval->h;
list *cols = sa_list(sql->sa);
@@ -815,6 +827,10 @@ table_constraint_type(mvc *sql, const ch
(void) sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT
%s: key '%s' already exists", kt == pkey ? "PRIMARY KEY" : "UNIQUE", name);
return SQL_ERR;
}
+ if (ol_find_name(t->idxs, name) || mvc_bind_idx(sql, ss, name))
{
+ (void) sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT
%s: an index named '%s' already exists, and it would conflict with the key", kt
== pkey ? "PRIMARY KEY" : "UNIQUE", name);
+ return SQL_ERR;
+ }
switch (mvc_create_ukey(&k, sql, t, name, kt)) {
case -1:
@@ -2185,6 +2201,8 @@ rel_create_index(mvc *sql, char *iname,
return sql_error(sql, 02, SQLSTATE(42000) "CREATE INDEX: index
name cannot contain just digit characters (0 through 9)");
if ((i = mvc_bind_idx(sql, t->s, iname)))
return sql_error(sql, 02, SQLSTATE(42S11) "CREATE INDEX: name
'%s' already in use", iname);
+ if (ol_find_name(t->keys, iname) || mvc_bind_key(sql, t->s, iname))
+ return sql_error(sql, 02, SQLSTATE(42000) "CREATE INDEX: a key
named '%s' already exists, and it would conflict with the index", iname);
if (!isTable(t))
return sql_error(sql, 02, SQLSTATE(42S02) "CREATE INDEX: cannot
create index on %s '%s'", TABLE_TYPE_DESCRIPTION(t->type, t->properties),
tname);
nt = dup_sql_table(sql->sa, t);
diff --git a/sql/test/miscellaneous/Tests/simple_selects.test
b/sql/test/miscellaneous/Tests/simple_selects.test
--- a/sql/test/miscellaneous/Tests/simple_selects.test
+++ b/sql/test/miscellaneous/Tests/simple_selects.test
@@ -951,3 +951,39 @@ create table bar (i int, FOREIGN KEY (i)
statement ok
ROLLBACK
+
+statement ok
+START TRANSACTION
+
+statement ok
+create table x (x int primary key)
+
+statement ok
+create table y (y int)
+
+statement ok
+create index ups on y(y)
+
+statement error 42000!CONSTRAINT FOREIGN KEY: an index named 'ups' already
exists, and it would conflict with the key
+alter table y add constraint ups foreign key (y) references x (x)
+
+statement ok
+ROLLBACK
+
+statement ok
+START TRANSACTION
+
+statement ok
+create table x (x int primary key)
+
+statement ok
+create table y (y int)
+
+statement ok
+alter table y add constraint ups2 foreign key (y) references x (x)
+
+statement error 42S11!CREATE INDEX: name 'ups2' already in use
+create index ups2 on y(y)
+
+statement ok
+ROLLBACK
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]