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
62470fc7
Commit
62470fc7
authored
Nov 24, 2017
by
Eugene Kosov
Committed by
Aleksey Midenkov
Nov 27, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SQL: recreate PRIMARY KEY on DROP SYSTEM VERSIONING [#348]
parent
0c571f8c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
0 deletions
+76
-0
mysql-test/suite/versioning/t/alter.test
mysql-test/suite/versioning/t/alter.test
+17
-0
sql/handler.cc
sql/handler.cc
+59
-0
No files found.
mysql-test/suite/versioning/t/alter.test
View file @
62470fc7
...
...
@@ -320,6 +320,23 @@ alter table non_empty
change
column
sys_trx_end
sys_trx_end
bigint
(
20
)
unsigned
generated
always
as
row
end
;
drop
table
non_empty
;
create
or
replace
table
t
(
a
int
primary
key
)
with
system
versioning
;
insert
into
t
values
(
1
);
update
t
set
a
=
2
;
alter
table
t
drop
primary
key
,
add
primary
key
(
a
),
drop
system
versioning
;
select
*
from
t
;
--
replace_result
InnoDB
INNODB_OR_MYISAM
MyISAM
INNODB_OR_MYISAM
show
create
table
t
;
create
or
replace
table
t
(
a
int
primary
key
)
with
system
versioning
;
insert
into
t
values
(
1
);
update
t
set
a
=
2
;
alter
table
t
drop
system
versioning
;
select
*
from
t
;
--
replace_result
InnoDB
INNODB_OR_MYISAM
MyISAM
INNODB_OR_MYISAM
show
create
table
t
;
call
verify_vtq
;
}
...
...
sql/handler.cc
View file @
62470fc7
...
...
@@ -6927,6 +6927,29 @@ static bool add_field_to_drop_list(THD *thd, Alter_info *alter_info,
return
!
ad
||
alter_info
->
drop_list
.
push_back
(
ad
,
thd
->
mem_root
);
}
static
bool
is_dropping_primary_key
(
Alter_info
*
alter_info
)
{
List_iterator_fast
<
Alter_drop
>
it
(
alter_info
->
drop_list
);
while
(
Alter_drop
*
ad
=
it
++
)
{
if
(
ad
->
type
==
Alter_drop
::
KEY
&&
!
my_strcasecmp
(
system_charset_info
,
ad
->
name
,
primary_key_name
))
return
true
;
}
return
false
;
}
static
bool
is_adding_primary_key
(
Alter_info
*
alter_info
)
{
List_iterator_fast
<
Key
>
it
(
alter_info
->
key_list
);
while
(
Key
*
key
=
it
++
)
{
if
(
key
->
type
==
Key
::
PRIMARY
)
return
true
;
}
return
false
;
}
bool
Vers_parse_info
::
check_and_fix_alter
(
THD
*
thd
,
Alter_info
*
alter_info
,
HA_CREATE_INFO
*
create_info
,
TABLE
*
table
)
...
...
@@ -6964,6 +6987,42 @@ bool Vers_parse_info::check_and_fix_alter(THD *thd, Alter_info *alter_info,
add_field_to_drop_list
(
thd
,
alter_info
,
share
->
vers_end_field
()))
return
true
;
if
(
share
->
primary_key
!=
MAX_KEY
&&
!
is_adding_primary_key
(
alter_info
)
&&
!
is_dropping_primary_key
(
alter_info
))
{
alter_info
->
flags
|=
Alter_info
::
ALTER_DROP_INDEX
;
Alter_drop
*
ad
=
new
(
thd
->
mem_root
)
Alter_drop
(
Alter_drop
::
KEY
,
primary_key_name
,
false
);
if
(
!
ad
||
alter_info
->
drop_list
.
push_back
(
ad
,
thd
->
mem_root
))
return
true
;
alter_info
->
flags
|=
Alter_info
::
ALTER_ADD_INDEX
;
LEX_CSTRING
key_name
=
{
NULL
,
0
};
DDL_options_st
options
;
options
.
init
();
Key
*
pk
=
new
(
thd
->
mem_root
)
Key
(
Key
::
PRIMARY
,
&
key_name
,
HA_KEY_ALG_UNDEF
,
false
,
options
);
if
(
!
pk
)
return
true
;
st_key
&
key
=
table
->
key_info
[
share
->
primary_key
];
for
(
st_key_part_info
*
it
=
key
.
key_part
,
*
end
=
it
+
key
.
user_defined_key_parts
;
it
!=
end
;
++
it
)
{
if
(
it
->
field
->
vers_sys_field
())
continue
;
Key_part_spec
*
key_part_spec
=
new
(
thd
->
mem_root
)
Key_part_spec
(
&
it
->
field
->
field_name
,
it
->
length
);
if
(
!
key_part_spec
||
pk
->
columns
.
push_back
(
key_part_spec
,
thd
->
mem_root
))
return
true
;
}
alter_info
->
key_list
.
push_back
(
pk
);
}
return
false
;
}
...
...
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