From 617e108fb6e2bc24e5c9badb94e7d8eaa65d8851 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sat, 16 Dec 2017 21:33:43 +0100 Subject: [PATCH] s/TRUNCATE ... TO/DELETE HISTORY FROM ... BEFORE/ --- mysql-test/suite/versioning/r/truncate.result | 21 +++++----- .../versioning/r/truncate_privilege.result | 4 +- mysql-test/suite/versioning/t/truncate.test | 18 ++++----- .../versioning/t/truncate_privilege.test | 4 +- sql/sql_parse.cc | 16 ++++++-- sql/sql_truncate.cc | 7 ---- sql/sql_yacc.yy | 38 +++++++++++-------- 7 files changed, 59 insertions(+), 49 deletions(-) diff --git a/mysql-test/suite/versioning/r/truncate.result b/mysql-test/suite/versioning/r/truncate.result index 63388f85d60..36ac4fe5ed3 100644 --- a/mysql-test/suite/versioning/r/truncate.result +++ b/mysql-test/suite/versioning/r/truncate.result @@ -1,5 +1,5 @@ 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 create or replace table t (a int) with system versioning; insert into t values (1); @@ -7,7 +7,7 @@ update t set a=2; set @test = 'correct'; 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'; -truncate t to system_time now(6); +delete history from t before system_time now(6); select @test from t; @test correct @@ -23,17 +23,20 @@ a 22 1 2 -truncate t to system_time timestamp @ts1; +delete history from t before system_time timestamp @ts1; select * from t for system_time all; a 11 22 +1 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; a 11 22 +1 +2 ### Issue #399, truncate partitioned table is now unimplemented create or replace table t (a int) with system versioning @@ -41,18 +44,18 @@ engine myisam partition by system_time ( partition p0 history, 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 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; -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 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 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 drop table t; drop view v; diff --git a/mysql-test/suite/versioning/r/truncate_privilege.result b/mysql-test/suite/versioning/r/truncate_privilege.result index 9590d93809a..e378407afde 100644 --- a/mysql-test/suite/versioning/r/truncate_privilege.result +++ b/mysql-test/suite/versioning/r/truncate_privilege.result @@ -10,7 +10,7 @@ connection user1; show grants; Grants for 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' connection root; grant delete history on mysqltest.* to mysqltest_1@localhost; @@ -21,7 +21,7 @@ Grants for 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`.`t` TO 'mysqltest_1'@'localhost' -truncate mysqltest.t to system_time now(); +delete history from mysqltest.t before system_time now(); connection root; grant all on *.* to mysqltest_1@localhost; show grants for mysqltest_1@localhost; diff --git a/mysql-test/suite/versioning/t/truncate.test b/mysql-test/suite/versioning/t/truncate.test index e732414f826..72da15b56d9 100644 --- a/mysql-test/suite/versioning/t/truncate.test +++ b/mysql-test/suite/versioning/t/truncate.test @@ -2,7 +2,7 @@ create table t (a int); --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. create or replace table t (a int) with system versioning; @@ -11,7 +11,7 @@ update t set a=2; set @test = 'correct'; 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'; -truncate t to system_time now(6); +delete history from t before system_time now(6); select @test from t; drop table t; @@ -23,9 +23,9 @@ set @ts1=now(6); --real_sleep 0.01 update t set a=22 where a=2; 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; -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; --echo ### Issue #399, truncate partitioned table is now unimplemented @@ -38,20 +38,20 @@ partition by system_time ( partition pn current); --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; -truncate t to system_time now(); +delete history from t before system_time now(); create or replace view v as select * from t; --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); --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; --error ER_VERS_TRUNCATE_TO_VIEW -truncate v to system_time now(); +delete history from v before system_time now(); drop table t; drop view v; diff --git a/mysql-test/suite/versioning/t/truncate_privilege.test b/mysql-test/suite/versioning/t/truncate_privilege.test index c2212570555..dcdad59039a 100644 --- a/mysql-test/suite/versioning/t/truncate_privilege.test +++ b/mysql-test/suite/versioning/t/truncate_privilege.test @@ -23,7 +23,7 @@ create table mysqltest.t (a int) with system versioning; connection user1; show grants; --error ER_TABLEACCESS_DENIED_ERROR -truncate mysqltest.t to system_time now(); +delete history from mysqltest.t before system_time now(); connection root; grant delete history on mysqltest.* to mysqltest_1@localhost; @@ -31,7 +31,7 @@ grant delete history on mysqltest.t to mysqltest_1@localhost; connection user1; show grants; -truncate mysqltest.t to system_time now(); +delete history from mysqltest.t before system_time now(); connection root; grant all on *.* to mysqltest_1@localhost; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 3c245eea92b..01b77f49b7d 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -9409,10 +9409,18 @@ bool update_precheck(THD *thd, TABLE_LIST *tables) bool delete_precheck(THD *thd, TABLE_LIST *tables) { DBUG_ENTER("delete_precheck"); - 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); + if (tables->vers_conditions) + { + if (check_one_table_access(thd, DELETE_HISTORY_ACL, tables)) + 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); } diff --git a/sql/sql_truncate.cc b/sql/sql_truncate.cc index 9286143e259..bd3f1fdc111 100644 --- a/sql/sql_truncate.cc +++ b/sql/sql_truncate.cc @@ -496,13 +496,6 @@ bool Sql_cmd_truncate_table::execute(THD *thd) TABLE_LIST *table= thd->lex->select_lex.table_list.first; 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)) DBUG_RETURN(res); diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index f68ce213a2c..dfc82a70784 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -892,10 +892,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %parse-param { THD *thd } %lex-param { THD *thd } /* - Currently there are 122 shift/reduce conflicts. + Currently there are 123 shift/reduce conflicts. We should not introduce new conflicts any more. */ -%expect 122 +%expect 123 /* Comments for TOKENS. @@ -13404,10 +13404,20 @@ delete: lex->ignore= 0; 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 { if (!Select->add_table_to_list(thd, $2, NULL, TL_OPTION_UPDATING, @@ -13419,8 +13429,13 @@ single_multi: YYPS->m_lock_type= TL_READ_DEFAULT; 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 {} | table_wild_list { @@ -13501,15 +13516,6 @@ opt_delete_option: | 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_SYM { @@ -13522,7 +13528,7 @@ truncate: YYPS->m_lock_type= TL_WRITE; 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; DBUG_ASSERT(!lex->m_sql_cmd);