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
56adced3
Commit
56adced3
authored
Dec 04, 2017
by
Aleksey Midenkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SQL,IB: REPLACE semantics [#365 bug 8]
parent
f4898655
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
135 additions
and
34 deletions
+135
-34
mysql-test/suite/versioning/common.inc
mysql-test/suite/versioning/common.inc
+12
-0
mysql-test/suite/versioning/common_finish.inc
mysql-test/suite/versioning/common_finish.inc
+1
-0
mysql-test/suite/versioning/key_type.combinations
mysql-test/suite/versioning/key_type.combinations
+2
-0
mysql-test/suite/versioning/key_type.inc
mysql-test/suite/versioning/key_type.inc
+23
-0
mysql-test/suite/versioning/r/replace.result
mysql-test/suite/versioning/r/replace.result
+10
-0
mysql-test/suite/versioning/r/update.result
mysql-test/suite/versioning/r/update.result
+17
-16
mysql-test/suite/versioning/t/replace.test
mysql-test/suite/versioning/t/replace.test
+13
-0
mysql-test/suite/versioning/t/update.test
mysql-test/suite/versioning/t/update.test
+7
-5
sql/field.h
sql/field.h
+15
-0
sql/sql_insert.cc
sql/sql_insert.cc
+19
-4
sql/sql_update.cc
sql/sql_update.cc
+3
-3
sql/table.cc
sql/table.cc
+7
-4
sql/table.h
sql/table.h
+3
-0
storage/innobase/handler/ha_innodb.cc
storage/innobase/handler/ha_innodb.cc
+3
-2
No files found.
mysql-test/suite/versioning/common.inc
View file @
56adced3
...
...
@@ -43,6 +43,18 @@ begin
return
NULL
;
end
~~
create
function
if
not
exists
current_row
(
sys_trx_end
varbinary
(
255
))
returns
int
deterministic
begin
if
default_engine
()
=
'innodb'
then
return
sys_trx_end
=
18446744073709551615
;
elseif
default_engine
()
=
'myisam'
then
return
sys_trx_end
=
timestamp
'2038-01-19 03:14:07.999999'
;
end
if
;
return
NULL
;
end
~~
create
function
if
not
exists
sys_commit_ts
(
sys_field
varchar
(
255
))
returns
varchar
(
255
)
deterministic
...
...
mysql-test/suite/versioning/common_finish.inc
View file @
56adced3
...
...
@@ -4,6 +4,7 @@ drop procedure innodb_verify_vtq;
drop
function
default_engine
;
drop
function
sys_commit_ts
;
drop
function
sys_datatype
;
drop
function
current_row
;
drop
procedure
concat_exec2
;
drop
procedure
concat_exec3
;
--
enable_query_log
mysql-test/suite/versioning/key_type.combinations
0 → 100644
View file @
56adced3
[unique]
[pk]
mysql-test/suite/versioning/key_type.inc
0 → 100644
View file @
56adced3
--
disable_query_log
if
(
$MTR_COMBINATION_UNIQUE
)
{
set
@
KEY_TYPE
=
'unique'
;
}
if
(
$MTR_COMBINATION_PK
)
{
set
@
KEY_TYPE
=
'primary key'
;
}
delimiter
~~
;
create
procedure
create_table
(
name
varchar
(
255
),
cols
varchar
(
255
))
begin
if
(
cols
is
null
or
cols
=
''
)
then
set
cols
=
''
;
else
set
cols
=
concat
(
', '
,
cols
);
end
if
;
set
@
str
=
concat
(
'create or replace table '
,
name
,
'(id int '
,
@
KEY_TYPE
,
cols
,
') with system versioning'
);
prepare
stmt
from
@
str
;
execute
stmt
;
drop
prepare
stmt
;
end
~~
delimiter
;
~~
--
enable_query_log
mysql-test/suite/versioning/r/replace.result
0 → 100644
View file @
56adced3
call create_table('t', 'x int');
insert t values (1, 2);
replace t values (1, 3);
select *, current_row(sys_trx_end) as current from t for system_time all
order by x;
id x current
1 2 0
1 3 1
drop database test;
create database test;
mysql-test/suite/versioning/r/update.result
View file @
56adced3
...
...
@@ -66,14 +66,15 @@ set @str= concat('
with system versioning
engine ', engine);
prepare stmt from @str; execute stmt; drop prepare stmt;
insert into t1 (x, y) values (1, 1), (2, 1), (3, 1);
insert into t1 (x, y) values (1, 1), (2, 1), (3, 1)
, (4, 1), (5, 1)
;
start transaction;
update t1 set y= y + 1 where x = 3;
update t1 set y= y + 1 where x = 2;
update t1 set y= y + 1 where x = 3;
update t1 set y= y + 1 where x > 3;
update t1 set y= y + 1 where x > 4;
commit;
select x, y from t1 for system_time
between timestamp '0000-0-0 0:0:0'
and timestamp '2038-01-19 04:14:07';
select x, y, sys_trx_end = 18446744073709551615 as current from t1 for system_time all;
drop table t1;
end~~
create procedure test_04(
...
...
@@ -285,19 +286,19 @@ call verify_vtq;
No A B C D
1 1 1 1 1
2 1 1 1 1
call test_03('timestamp(6)', 'myisam', 'sys_end');
x y
1 1
2 1
3 3
3 1
3 2
# Multiple UPDATE of same rows in single transaction create historical
# rows only once (applicable to InnoDB only).
call test_03('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)');
x y
1 1
2 1
3 3
3 1
x y current
1 1 1
2 2 1
3 3 1
4 2 1
5 3 1
3 1 0
2 1 0
4 1 0
5 1 0
call verify_vtq;
No A B C D
1 1 1 1 1
...
...
mysql-test/suite/versioning/t/replace.test
0 → 100644
View file @
56adced3
--
source
suite
/
versioning
/
common
.
inc
--
source
suite
/
versioning
/
key_type
.
inc
--
source
suite
/
versioning
/
engines
.
inc
call
create_table
(
't'
,
'x int'
);
insert
t
values
(
1
,
2
);
replace
t
values
(
1
,
3
);
select
*
,
current_row
(
sys_trx_end
)
as
current
from
t
for
system_time
all
order
by
x
;
drop
database
test
;
create
database
test
;
mysql-test/suite/versioning/t/update.test
View file @
56adced3
...
...
@@ -74,16 +74,17 @@ begin
engine '
,
engine
);
prepare
stmt
from
@
str
;
execute
stmt
;
drop
prepare
stmt
;
insert
into
t1
(
x
,
y
)
values
(
1
,
1
),
(
2
,
1
),
(
3
,
1
);
insert
into
t1
(
x
,
y
)
values
(
1
,
1
),
(
2
,
1
),
(
3
,
1
)
,
(
4
,
1
),
(
5
,
1
)
;
start
transaction
;
update
t1
set
y
=
y
+
1
where
x
=
3
;
update
t1
set
y
=
y
+
1
where
x
=
2
;
update
t1
set
y
=
y
+
1
where
x
=
3
;
update
t1
set
y
=
y
+
1
where
x
>
3
;
update
t1
set
y
=
y
+
1
where
x
>
4
;
commit
;
select
x
,
y
from
t1
for
system_time
between
timestamp
'0000-0-0 0:0:0'
and
timestamp
'2038-01-19 04:14:07'
;
select
x
,
y
,
sys_trx_end
=
18446744073709551615
as
current
from
t1
for
system_time
all
;
drop
table
t1
;
end
~~
...
...
@@ -234,7 +235,8 @@ call test_02('timestamp(6)', 'myisam', 'sys_end');
call
test_02
(
'bigint unsigned'
,
'innodb'
,
'vtq_commit_ts(sys_end)'
);
call
verify_vtq
;
call
test_03
(
'timestamp(6)'
,
'myisam'
,
'sys_end'
);
--
echo
# Multiple UPDATE of same rows in single transaction create historical
--
echo
# rows only once (applicable to InnoDB only).
call
test_03
(
'bigint unsigned'
,
'innodb'
,
'vtq_commit_ts(sys_end)'
);
call
verify_vtq
;
...
...
sql/field.h
View file @
56adced3
...
...
@@ -4642,4 +4642,19 @@ bool check_expression(Virtual_column_info *vcol, LEX_CSTRING *name,
#define f_bit_as_char(x) ((x) & FIELDFLAG_TREAT_BIT_AS_CHAR)
#define f_is_hex_escape(x) ((x) & FIELDFLAG_HEX_ESCAPE)
inline
ulonglong
TABLE
::
vers_end_id
()
const
{
DBUG_ASSERT
(
versioned_by_engine
());
return
static_cast
<
ulonglong
>
(
vers_end_field
()
->
val_int
());
}
inline
ulonglong
TABLE
::
vers_start_id
()
const
{
DBUG_ASSERT
(
versioned_by_engine
());
return
static_cast
<
ulonglong
>
(
vers_start_field
()
->
val_int
());
}
#endif
/* FIELD_INCLUDED */
sql/sql_insert.cc
View file @
56adced3
...
...
@@ -1050,7 +1050,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
}
}
if
(
table
->
versioned
_by_sql
())
if
(
table
->
versioned
())
table
->
vers_update_fields
();
if
((
res
=
table_list
->
view_check_option
(
thd
,
...
...
@@ -1937,15 +1937,30 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
*/
if
(
last_uniq_key
(
table
,
key_nr
)
&&
!
table
->
file
->
referenced_by_foreign_key
()
&&
(
!
table
->
triggers
||
!
table
->
triggers
->
has_delete_triggers
())
&&
!
table
->
versioned_by_sql
())
(
!
table
->
triggers
||
!
table
->
triggers
->
has_delete_triggers
()))
{
if
(
table
->
versioned_by_engine
())
{
bitmap_set_bit
(
table
->
write_set
,
table
->
vers_start_field
()
->
field_index
);
table
->
vers_start_field
()
->
set_notnull
();
table
->
vers_start_field
()
->
store
(
0
,
false
);
}
if
((
error
=
table
->
file
->
ha_update_row
(
table
->
record
[
1
],
table
->
record
[
0
]))
&&
error
!=
HA_ERR_RECORD_IS_THE_SAME
)
goto
err
;
if
(
error
!=
HA_ERR_RECORD_IS_THE_SAME
)
{
info
->
deleted
++
;
if
(
table
->
versioned_by_sql
())
{
store_record
(
table
,
record
[
2
]);
error
=
vers_insert_history_row
(
table
);
restore_record
(
table
,
record
[
2
]);
if
(
error
)
goto
err
;
}
}
else
error
=
0
;
thd
->
record_first_successful_insert_id_in_cur_stmt
(
table
->
file
->
insert_id_for_cur_row
);
...
...
@@ -3832,7 +3847,7 @@ int select_insert::send_data(List<Item> &values)
DBUG_RETURN
(
0
);
thd
->
count_cuted_fields
=
CHECK_FIELD_WARN
;
// Calculate cuted fields
if
(
table
->
versioned
_by_sql
())
if
(
table
->
versioned
())
table
->
vers_update_fields
();
store_values
(
values
);
if
(
table
->
default_field
&&
table
->
update_default_fields
(
0
,
info
.
ignore
))
...
...
sql/sql_update.cc
View file @
56adced3
...
...
@@ -781,7 +781,7 @@ int mysql_update(THD *thd,
TRG_EVENT_UPDATE
))
break
;
/* purecov: inspected */
if
(
has_vers_fields
&&
table
->
versioned
_by_sql
())
if
(
has_vers_fields
&&
table
->
versioned
())
table
->
vers_update_fields
();
found
++
;
...
...
@@ -2195,7 +2195,7 @@ int multi_update::send_data(List<Item> ¬_used_values)
if
(
table
->
default_field
&&
table
->
update_default_fields
(
1
,
ignore
))
DBUG_RETURN
(
1
);
if
(
has_vers_fields
&&
table
->
versioned
_by_sql
())
if
(
has_vers_fields
&&
table
->
versioned
())
table
->
vers_update_fields
();
if
((
error
=
cur_table
->
view_check_option
(
thd
,
ignore
))
!=
...
...
@@ -2550,7 +2550,7 @@ int multi_update::do_updates()
goto
err2
;
}
}
if
(
has_vers_fields
&&
table
->
versioned
_by_sql
())
if
(
has_vers_fields
&&
table
->
versioned
())
table
->
vers_update_fields
();
if
((
local_error
=
table
->
file
->
ha_update_row
(
table
->
record
[
1
],
...
...
sql/table.cc
View file @
56adced3
...
...
@@ -7691,11 +7691,14 @@ void TABLE::vers_update_fields()
{
DBUG_ENTER
(
"vers_update_fields"
);
bitmap_set_bit
(
write_set
,
vers_start_field
()
->
field_index
);
bitmap_set_bit
(
write_set
,
vers_end_field
()
->
field_index
);
if
(
versioned_by_sql
())
{
bitmap_set_bit
(
write_set
,
vers_start_field
()
->
field_index
);
if
(
vers_start_field
()
->
set_time
())
DBUG_ASSERT
(
0
);
}
if
(
vers_start_field
()
->
set_time
())
DBUG_ASSERT
(
0
);
bitmap_set_bit
(
write_set
,
vers_end_field
()
->
field_index
);
vers_end_field
()
->
set_max
();
DBUG_VOID_RETURN
;
...
...
sql/table.h
View file @
56adced3
...
...
@@ -1546,6 +1546,9 @@ struct TABLE
return
field
[
s
->
row_end_field
];
}
ulonglong
vers_start_id
()
const
;
ulonglong
vers_end_id
()
const
;
int
delete_row
();
/** Number of additional fields used in versioned tables */
...
...
storage/innobase/handler/ha_innodb.cc
View file @
56adced3
...
...
@@ -9185,8 +9185,9 @@ ha_innobase::update_row(
error
=
row_update_for_mysql
(
m_prebuilt
);
if
(
error
==
DB_SUCCESS
&&
vers_ins_row
&&
trx
->
id
!=
static_cast
<
trx_id_t
>
(
table
->
vers_start_field
()
->
val_int
()))
{
/* Multiple UPDATE of same rows in single transaction create
historical rows only once. */
&&
trx
->
id
!=
table
->
vers_start_id
())
{
error
=
row_insert_for_mysql
((
byte
*
)
old_row
,
m_prebuilt
,
ROW_INS_HISTORICAL
);
...
...
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