Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
cce76fef
Commit
cce76fef
authored
Nov 03, 2022
by
Sergei Golubchik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ADD CONSTRAINT IF NOT EXISTS didn't work in SP
"if not exists" must be stored in a separate read-only property
parent
a5eff044
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
5 deletions
+54
-5
mysql-test/main/constraints.result
mysql-test/main/constraints.result
+34
-0
mysql-test/main/constraints.test
mysql-test/main/constraints.test
+17
-0
sql/field.h
sql/field.h
+1
-1
sql/sql_lex.h
sql/sql_lex.h
+1
-1
sql/sql_table.cc
sql/sql_table.cc
+1
-3
No files found.
mysql-test/main/constraints.result
View file @
cce76fef
...
...
@@ -183,7 +183,9 @@ t1 CREATE TABLE `t1` (
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
DROP PROCEDURE sp;
DROP TABLE t1;
#
# End of 10.2 tests
#
create table t1 (a int check (a>10)) select 100 as 'a';
show create table t1;
Table Create Table
...
...
@@ -201,3 +203,35 @@ a
19
ccc
drop table t1;
create table t1 (a int, b int);
create procedure sp() alter table t1 add constraint if not exists foo check (b > 0);
call sp;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
CONSTRAINT `foo` CHECK (`b` > 0)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
call sp;
Warnings:
Note 1826 Duplicate CHECK constraint name 'foo'
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
CONSTRAINT `foo` CHECK (`b` > 0)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
call sp;
Warnings:
Note 1826 Duplicate CHECK constraint name 'foo'
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
CONSTRAINT `foo` CHECK (`b` > 0)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
drop procedure sp;
drop table t1;
mysql-test/main/constraints.test
View file @
cce76fef
...
...
@@ -151,7 +151,9 @@ show create table t1;
DROP
PROCEDURE
sp
;
DROP
TABLE
t1
;
--
echo
#
--
echo
# End of 10.2 tests
--
echo
#
#
# Check that we don't lose constraints as part of CREATE ... SELECT
...
...
@@ -172,3 +174,18 @@ insert into t1 values ("ccc");
insert
into
t1
values
(
""
);
select
*
from
t1
;
drop
table
t1
;
#
# add if not exists in SP
#
create
table
t1
(
a
int
,
b
int
);
create
procedure
sp
()
alter
table
t1
add
constraint
if
not
exists
foo
check
(
b
>
0
);
call
sp
;
show
create
table
t1
;
call
sp
;
show
create
table
t1
;
call
sp
;
show
create
table
t1
;
drop
procedure
sp
;
drop
table
t1
;
sql/field.h
View file @
cce76fef
...
...
@@ -558,7 +558,6 @@ static inline const char *vcol_type_name(enum_vcol_info_type type)
#define VCOL_AUTO_INC 16
#define VCOL_IMPOSSIBLE 32
#define VCOL_NEXTVAL 64
/* NEXTVAL is not implemented for vcols */
#define VCOL_CHECK_CONSTRAINT_IF_NOT_EXISTS 128
#define VCOL_NOT_STRICTLY_DETERMINISTIC \
(VCOL_NON_DETERMINISTIC | VCOL_TIME_FUNC | VCOL_SESSION_FUNC)
...
...
@@ -590,6 +589,7 @@ class Virtual_column_info: public Sql_alloc,
bool
stored_in_db
;
bool
utf8
;
/* Already in utf8 */
bool
automatic_name
;
bool
if_not_exists
;
Item
*
expr
;
Lex_ident
name
;
/* Name of constraint */
/* see VCOL_* (VCOL_FIELD_REF, ...) */
...
...
sql/sql_lex.h
View file @
cce76fef
...
...
@@ -4375,7 +4375,7 @@ struct LEX: public Query_tables_list
bool
if_not_exists
)
{
constr
->
name
=
name
;
constr
->
flags
=
if_not_exists
?
VCOL_CHECK_CONSTRAINT_IF_NOT_EXISTS
:
0
;
constr
->
if_not_exists
=
if_not_exists
;
alter_info
.
check_constraint_list
.
push_back
(
constr
);
return
false
;
}
...
...
sql/sql_table.cc
View file @
cce76fef
...
...
@@ -6928,10 +6928,8 @@ handle_if_exists_options(THD *thd, TABLE *table, Alter_info *alter_info,
while
((
check
=
it
++
))
{
if
(
!
(
check
->
flags
&
VCOL_CHECK_CONSTRAINT_IF_NOT_EXISTS
)
&&
check
->
name
.
length
)
if
(
!
check
->
if_not_exists
&&
check
->
name
.
length
)
continue
;
check
->
flags
=
0
;
for
(
c
=
share
->
field_check_constraints
;
c
<
share
->
table_check_constraints
;
c
++
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment