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
617e108f
Commit
617e108f
authored
Dec 16, 2017
by
Sergei Golubchik
Committed by
Aleksey Midenkov
Dec 19, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
s/TRUNCATE ... TO/DELETE HISTORY FROM ... BEFORE/
parent
ee68d019
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
59 additions
and
49 deletions
+59
-49
mysql-test/suite/versioning/r/truncate.result
mysql-test/suite/versioning/r/truncate.result
+12
-9
mysql-test/suite/versioning/r/truncate_privilege.result
mysql-test/suite/versioning/r/truncate_privilege.result
+2
-2
mysql-test/suite/versioning/t/truncate.test
mysql-test/suite/versioning/t/truncate.test
+9
-9
mysql-test/suite/versioning/t/truncate_privilege.test
mysql-test/suite/versioning/t/truncate_privilege.test
+2
-2
sql/sql_parse.cc
sql/sql_parse.cc
+12
-4
sql/sql_truncate.cc
sql/sql_truncate.cc
+0
-7
sql/sql_yacc.yy
sql/sql_yacc.yy
+22
-16
No files found.
mysql-test/suite/versioning/r/truncate.result
View file @
617e108f
create table t (a int);
create table t (a int);
truncate t to
system_time now();
delete history from t before
system_time now();
ERROR HY000: System versioning required: t
ERROR HY000: System versioning required: t
create or replace table t (a int) with system versioning;
create or replace table t (a int) with system versioning;
insert into t values (1);
insert into t values (1);
...
@@ -7,7 +7,7 @@ update t set a=2;
...
@@ -7,7 +7,7 @@ update t set a=2;
set @test = 'correct';
set @test = 'correct';
create trigger trg_before before delete on t for each row set @test = 'incorrect';
create trigger trg_before before delete on t for each row set @test = 'incorrect';
create trigger trg_after after delete on t for each row set @test = 'incorrect';
create trigger trg_after after delete on t for each row set @test = 'incorrect';
truncate t to
system_time now(6);
delete history from t before
system_time now(6);
select @test from t;
select @test from t;
@test
@test
correct
correct
...
@@ -23,17 +23,20 @@ a
...
@@ -23,17 +23,20 @@ a
22
22
1
1
2
2
truncate t to
system_time timestamp @ts1;
delete history from t before
system_time timestamp @ts1;
select * from t for system_time all;
select * from t for system_time all;
a
a
11
11
22
22
1
2
2
truncate table t to
system_time timestamp now(6);
delete history from t before
system_time timestamp now(6);
select * from t for system_time all;
select * from t for system_time all;
a
a
11
11
22
22
1
2
### Issue #399, truncate partitioned table is now unimplemented
### Issue #399, truncate partitioned table is now unimplemented
create or replace table t (a int)
create or replace table t (a int)
with system versioning
with system versioning
...
@@ -41,18 +44,18 @@ engine myisam
...
@@ -41,18 +44,18 @@ engine myisam
partition by system_time (
partition by system_time (
partition p0 history,
partition p0 history,
partition pn current);
partition pn current);
truncate table t to
system_time current_timestamp;
delete history from t before
system_time current_timestamp;
ERROR 42000: The used command is not allowed with this MariaDB version
ERROR 42000: The used command is not allowed with this MariaDB version
create or replace table t (i int) with system versioning;
create or replace table t (i int) with system versioning;
truncate t to
system_time now();
delete history from t before
system_time now();
create or replace view v as select * from t;
create or replace view v as select * from t;
truncate v to
system_time now();
delete history from v before
system_time now();
ERROR HY000: TRUNCATE table_name TO doesn't work with VIEWs
ERROR HY000: TRUNCATE table_name TO doesn't work with VIEWs
create or replace table t (i int);
create or replace table t (i int);
truncate t to
system_time now();
delete history from t before
system_time now();
ERROR HY000: System versioning required: t
ERROR HY000: System versioning required: t
create or replace view v as select * from t;
create or replace view v as select * from t;
truncate v to
system_time now();
delete history from v before
system_time now();
ERROR HY000: TRUNCATE table_name TO doesn't work with VIEWs
ERROR HY000: TRUNCATE table_name TO doesn't work with VIEWs
drop table t;
drop table t;
drop view v;
drop view v;
mysql-test/suite/versioning/r/truncate_privilege.result
View file @
617e108f
...
@@ -10,7 +10,7 @@ connection user1;
...
@@ -10,7 +10,7 @@ connection user1;
show grants;
show grants;
Grants for mysqltest_1@localhost
Grants for mysqltest_1@localhost
GRANT USAGE ON *.* TO 'mysqltest_1'@'localhost'
GRANT USAGE ON *.* TO 'mysqltest_1'@'localhost'
truncate mysqltest.t to
system_time now();
delete history from mysqltest.t before
system_time now();
ERROR 42000: DELETE VERSIONING ROWS command denied to user 'mysqltest_1'@'localhost' for table 't'
ERROR 42000: DELETE VERSIONING ROWS command denied to user 'mysqltest_1'@'localhost' for table 't'
connection root;
connection root;
grant delete history on mysqltest.* to mysqltest_1@localhost;
grant delete history on mysqltest.* to mysqltest_1@localhost;
...
@@ -21,7 +21,7 @@ Grants for mysqltest_1@localhost
...
@@ -21,7 +21,7 @@ Grants for mysqltest_1@localhost
GRANT USAGE ON *.* TO 'mysqltest_1'@'localhost'
GRANT USAGE ON *.* TO 'mysqltest_1'@'localhost'
GRANT DELETE VERSIONING ROWS ON `mysqltest`.* TO 'mysqltest_1'@'localhost'
GRANT DELETE VERSIONING ROWS ON `mysqltest`.* TO 'mysqltest_1'@'localhost'
GRANT DELETE VERSIONING ROWS ON `mysqltest`.`t` TO 'mysqltest_1'@'localhost'
GRANT DELETE VERSIONING ROWS ON `mysqltest`.`t` TO 'mysqltest_1'@'localhost'
truncate mysqltest.t to
system_time now();
delete history from mysqltest.t before
system_time now();
connection root;
connection root;
grant all on *.* to mysqltest_1@localhost;
grant all on *.* to mysqltest_1@localhost;
show grants for mysqltest_1@localhost;
show grants for mysqltest_1@localhost;
...
...
mysql-test/suite/versioning/t/truncate.test
View file @
617e108f
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
create
table
t
(
a
int
);
create
table
t
(
a
int
);
--
error
ER_VERSIONING_REQUIRED
--
error
ER_VERSIONING_REQUIRED
truncate
t
to
system_time
now
();
delete
history
from
t
before
system_time
now
();
# TRUNCATE is not DELETE and trigger must not be called.
# TRUNCATE is not DELETE and trigger must not be called.
create
or
replace
table
t
(
a
int
)
with
system
versioning
;
create
or
replace
table
t
(
a
int
)
with
system
versioning
;
...
@@ -11,7 +11,7 @@ update t set a=2;
...
@@ -11,7 +11,7 @@ update t set a=2;
set
@
test
=
'correct'
;
set
@
test
=
'correct'
;
create
trigger
trg_before
before
delete
on
t
for
each
row
set
@
test
=
'incorrect'
;
create
trigger
trg_before
before
delete
on
t
for
each
row
set
@
test
=
'incorrect'
;
create
trigger
trg_after
after
delete
on
t
for
each
row
set
@
test
=
'incorrect'
;
create
trigger
trg_after
after
delete
on
t
for
each
row
set
@
test
=
'incorrect'
;
truncate
t
to
system_time
now
(
6
);
delete
history
from
t
before
system_time
now
(
6
);
select
@
test
from
t
;
select
@
test
from
t
;
drop
table
t
;
drop
table
t
;
...
@@ -23,9 +23,9 @@ set @ts1=now(6);
...
@@ -23,9 +23,9 @@ set @ts1=now(6);
--
real_sleep
0.01
--
real_sleep
0.01
update
t
set
a
=
22
where
a
=
2
;
update
t
set
a
=
22
where
a
=
2
;
select
*
from
t
for
system_time
all
;
select
*
from
t
for
system_time
all
;
truncate
t
to
system_time
timestamp
@
ts1
;
delete
history
from
t
before
system_time
timestamp
@
ts1
;
select
*
from
t
for
system_time
all
;
select
*
from
t
for
system_time
all
;
truncate
table
t
to
system_time
timestamp
now
(
6
);
delete
history
from
t
before
system_time
timestamp
now
(
6
);
select
*
from
t
for
system_time
all
;
select
*
from
t
for
system_time
all
;
--
echo
### Issue #399, truncate partitioned table is now unimplemented
--
echo
### Issue #399, truncate partitioned table is now unimplemented
...
@@ -38,20 +38,20 @@ partition by system_time (
...
@@ -38,20 +38,20 @@ partition by system_time (
partition
pn
current
);
partition
pn
current
);
--
error
ER_NOT_ALLOWED_COMMAND
--
error
ER_NOT_ALLOWED_COMMAND
truncate
table
t
to
system_time
current_timestamp
;
delete
history
from
t
before
system_time
current_timestamp
;
create
or
replace
table
t
(
i
int
)
with
system
versioning
;
create
or
replace
table
t
(
i
int
)
with
system
versioning
;
truncate
t
to
system_time
now
();
delete
history
from
t
before
system_time
now
();
create
or
replace
view
v
as
select
*
from
t
;
create
or
replace
view
v
as
select
*
from
t
;
--
error
ER_VERS_TRUNCATE_TO_VIEW
--
error
ER_VERS_TRUNCATE_TO_VIEW
truncate
v
to
system_time
now
();
delete
history
from
v
before
system_time
now
();
create
or
replace
table
t
(
i
int
);
create
or
replace
table
t
(
i
int
);
--
error
ER_VERSIONING_REQUIRED
--
error
ER_VERSIONING_REQUIRED
truncate
t
to
system_time
now
();
delete
history
from
t
before
system_time
now
();
create
or
replace
view
v
as
select
*
from
t
;
create
or
replace
view
v
as
select
*
from
t
;
--
error
ER_VERS_TRUNCATE_TO_VIEW
--
error
ER_VERS_TRUNCATE_TO_VIEW
truncate
v
to
system_time
now
();
delete
history
from
v
before
system_time
now
();
drop
table
t
;
drop
table
t
;
drop
view
v
;
drop
view
v
;
mysql-test/suite/versioning/t/truncate_privilege.test
View file @
617e108f
...
@@ -23,7 +23,7 @@ create table mysqltest.t (a int) with system versioning;
...
@@ -23,7 +23,7 @@ create table mysqltest.t (a int) with system versioning;
connection
user1
;
connection
user1
;
show
grants
;
show
grants
;
--
error
ER_TABLEACCESS_DENIED_ERROR
--
error
ER_TABLEACCESS_DENIED_ERROR
truncate
mysqltest
.
t
to
system_time
now
();
delete
history
from
mysqltest
.
t
before
system_time
now
();
connection
root
;
connection
root
;
grant
delete
history
on
mysqltest
.*
to
mysqltest_1
@
localhost
;
grant
delete
history
on
mysqltest
.*
to
mysqltest_1
@
localhost
;
...
@@ -31,7 +31,7 @@ grant delete history on mysqltest.t to mysqltest_1@localhost;
...
@@ -31,7 +31,7 @@ grant delete history on mysqltest.t to mysqltest_1@localhost;
connection
user1
;
connection
user1
;
show
grants
;
show
grants
;
truncate
mysqltest
.
t
to
system_time
now
();
delete
history
from
mysqltest
.
t
before
system_time
now
();
connection
root
;
connection
root
;
grant
all
on
*.*
to
mysqltest_1
@
localhost
;
grant
all
on
*.*
to
mysqltest_1
@
localhost
;
...
...
sql/sql_parse.cc
View file @
617e108f
...
@@ -9409,10 +9409,18 @@ bool update_precheck(THD *thd, TABLE_LIST *tables)
...
@@ -9409,10 +9409,18 @@ bool update_precheck(THD *thd, TABLE_LIST *tables)
bool
delete_precheck
(
THD
*
thd
,
TABLE_LIST
*
tables
)
bool
delete_precheck
(
THD
*
thd
,
TABLE_LIST
*
tables
)
{
{
DBUG_ENTER
(
"delete_precheck"
);
DBUG_ENTER
(
"delete_precheck"
);
if
(
check_one_table_access
(
thd
,
DELETE_ACL
,
tables
))
if
(
tables
->
vers_conditions
)
DBUG_RETURN
(
TRUE
);
{
/* Set privilege for the WHERE clause */
if
(
check_one_table_access
(
thd
,
DELETE_HISTORY_ACL
,
tables
))
tables
->
grant
.
want_privilege
=
(
SELECT_ACL
&
~
tables
->
grant
.
privilege
);
DBUG_RETURN
(
TRUE
);
}
else
{
if
(
check_one_table_access
(
thd
,
DELETE_ACL
,
tables
))
DBUG_RETURN
(
TRUE
);
/* Set privilege for the WHERE clause */
tables
->
grant
.
want_privilege
=
(
SELECT_ACL
&
~
tables
->
grant
.
privilege
);
}
DBUG_RETURN
(
FALSE
);
DBUG_RETURN
(
FALSE
);
}
}
...
...
sql/sql_truncate.cc
View file @
617e108f
...
@@ -496,13 +496,6 @@ bool Sql_cmd_truncate_table::execute(THD *thd)
...
@@ -496,13 +496,6 @@ bool Sql_cmd_truncate_table::execute(THD *thd)
TABLE_LIST
*
table
=
thd
->
lex
->
select_lex
.
table_list
.
first
;
TABLE_LIST
*
table
=
thd
->
lex
->
select_lex
.
table_list
.
first
;
DBUG_ENTER
(
"Sql_cmd_truncate_table::execute"
);
DBUG_ENTER
(
"Sql_cmd_truncate_table::execute"
);
if
(
table
->
vers_conditions
)
{
if
(
check_one_table_access
(
thd
,
DELETE_HISTORY_ACL
,
table
))
DBUG_RETURN
(
res
);
DBUG_RETURN
(
mysql_delete
(
thd
,
table
,
NULL
,
NULL
,
-
1
,
0
,
NULL
));
}
if
(
check_one_table_access
(
thd
,
DROP_ACL
,
table
))
if
(
check_one_table_access
(
thd
,
DROP_ACL
,
table
))
DBUG_RETURN
(
res
);
DBUG_RETURN
(
res
);
...
...
sql/sql_yacc.yy
View file @
617e108f
...
@@ -892,10 +892,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
...
@@ -892,10 +892,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%parse-param { THD *thd }
%parse-param { THD *thd }
%lex-param { THD *thd }
%lex-param { THD *thd }
/*
/*
Currently there are 12
2
shift/reduce conflicts.
Currently there are 12
3
shift/reduce conflicts.
We should not introduce new conflicts any more.
We should not introduce new conflicts any more.
*/
*/
%expect 12
2
%expect 12
3
/*
/*
Comments for TOKENS.
Comments for TOKENS.
...
@@ -13404,10 +13404,20 @@ delete:
...
@@ -13404,10 +13404,20 @@ delete:
lex->ignore= 0;
lex->ignore= 0;
lex->select_lex.init_order();
lex->select_lex.init_order();
}
}
opt_delete_options single_multi
delete_part2
;
delete_part2:
opt_delete_options single_multi {}
| HISTORY_SYM delete_single_table
BEFORE_SYM SYSTEM_TIME_SYM opt_trans_or_timestamp simple_expr
{
Lex->vers_conditions.init(SYSTEM_TIME_BEFORE, $5, $6);
Lex->last_table()->vers_conditions= Lex->vers_conditions;
}
;
;
single_multi
:
delete_single_table
:
FROM table_ident opt_use_partition
FROM table_ident opt_use_partition
{
{
if (!Select->add_table_to_list(thd, $2, NULL, TL_OPTION_UPDATING,
if (!Select->add_table_to_list(thd, $2, NULL, TL_OPTION_UPDATING,
...
@@ -13419,8 +13429,13 @@ single_multi:
...
@@ -13419,8 +13429,13 @@ single_multi:
YYPS->m_lock_type= TL_READ_DEFAULT;
YYPS->m_lock_type= TL_READ_DEFAULT;
YYPS->m_mdl_type= MDL_SHARED_READ;
YYPS->m_mdl_type= MDL_SHARED_READ;
}
}
opt_where_clause opt_order_clause
;
delete_limit_clause {}
single_multi:
delete_single_table
opt_where_clause
opt_order_clause
delete_limit_clause
opt_select_expressions {}
opt_select_expressions {}
| table_wild_list
| table_wild_list
{
{
...
@@ -13501,15 +13516,6 @@ opt_delete_option:
...
@@ -13501,15 +13516,6 @@ opt_delete_option:
| IGNORE_SYM { Lex->ignore= 1; }
| IGNORE_SYM { Lex->ignore= 1; }
;
;
truncate_end:
opt_lock_wait_timeout
| TO_SYM SYSTEM_TIME_SYM opt_trans_or_timestamp simple_expr
{
Lex->vers_conditions.init(SYSTEM_TIME_BEFORE, $3, $4);
Lex->last_table()->vers_conditions= Lex->vers_conditions;
}
;
truncate:
truncate:
TRUNCATE_SYM
TRUNCATE_SYM
{
{
...
@@ -13522,7 +13528,7 @@ truncate:
...
@@ -13522,7 +13528,7 @@ truncate:
YYPS->m_lock_type= TL_WRITE;
YYPS->m_lock_type= TL_WRITE;
YYPS->m_mdl_type= MDL_EXCLUSIVE;
YYPS->m_mdl_type= MDL_EXCLUSIVE;
}
}
opt_table_sym table_name
truncate_end
opt_table_sym table_name
opt_lock_wait_timeout
{
{
LEX* lex= thd->lex;
LEX* lex= thd->lex;
DBUG_ASSERT(!lex->m_sql_cmd);
DBUG_ASSERT(!lex->m_sql_cmd);
...
...
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