mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
SQL: truncate syntax and privilege [closes #229]
This commit is contained in:
5
mysql-test/suite/versioning/t/truncate.combinations
Normal file
5
mysql-test/suite/versioning/t/truncate.combinations
Normal file
@@ -0,0 +1,5 @@
|
||||
[innodb]
|
||||
default-storage-engine=innodb
|
||||
|
||||
[myisam]
|
||||
default-storage-engine=myisam
|
@@ -2,120 +2,28 @@
|
||||
|
||||
create table t (a int);
|
||||
--error ER_VERSIONING_REQUIRED
|
||||
truncate t for system_time all;
|
||||
|
||||
delimiter ~~;
|
||||
create procedure truncate_history_of_t()
|
||||
begin
|
||||
prepare stmt from 'truncate t for system_time between \'1-1-1\' and now(6)';
|
||||
execute stmt;
|
||||
drop prepare stmt;
|
||||
end~~
|
||||
delimiter ;~~
|
||||
truncate t to system_time now();
|
||||
|
||||
# TRUNCATE is not DELETE and trigger must not be called.
|
||||
create or replace table t (a int) with system versioning;
|
||||
insert into t values (1);
|
||||
update t set a=2;
|
||||
select * from t for system_time all;
|
||||
|
||||
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 for system_time all;
|
||||
select * from t for system_time all;
|
||||
|
||||
truncate t to system_time now(6);
|
||||
select @test from t;
|
||||
drop trigger trg_before;
|
||||
drop trigger trg_after;
|
||||
drop table t;
|
||||
|
||||
update t set a=3;
|
||||
update t set a=4;
|
||||
truncate t for system_time as of timestamp now(6);
|
||||
select * from t for system_time all;
|
||||
|
||||
truncate t for system_time between '1-1-1' and now(6);
|
||||
select * from t for system_time all;
|
||||
|
||||
update t set a=5;
|
||||
truncate t for system_time from '1-1-1' to now(6);
|
||||
select * from t for system_time all;
|
||||
|
||||
update t set a=6;
|
||||
call truncate_history_of_t();
|
||||
select * from t for system_time all;
|
||||
|
||||
set @ts1 = now(6);
|
||||
update t set a=7;
|
||||
set @ts2 = now(6);
|
||||
update t set a=8;
|
||||
truncate t for system_time from '1-1-1' to @ts1;
|
||||
select * from t for system_time all;
|
||||
update t set a=9;
|
||||
truncate t for system_time between '1-1-1' and @ts2;
|
||||
select * from t for system_time all;
|
||||
|
||||
|
||||
create or replace table t (a int) with system versioning engine=innodb;
|
||||
insert into t values (1);
|
||||
update t set a=2;
|
||||
select * from t for system_time all;
|
||||
|
||||
truncate t for system_time all;
|
||||
select * from t for system_time all;
|
||||
|
||||
update t set a=3;
|
||||
update t set a=4;
|
||||
truncate t for system_time as of timestamp now(6);
|
||||
select * from t for system_time all;
|
||||
|
||||
truncate t for system_time between '1-1-1' and now(6);
|
||||
select * from t for system_time all;
|
||||
|
||||
update t set a=5;
|
||||
truncate t for system_time from '1-1-1' to now(6);
|
||||
select * from t for system_time all;
|
||||
|
||||
update t set a=6;
|
||||
call truncate_history_of_t();
|
||||
select * from t for system_time all;
|
||||
|
||||
set @ts1 = now(6);
|
||||
update t set a=7;
|
||||
set @ts2 = now(6);
|
||||
update t set a=8;
|
||||
truncate t for system_time from '1-1-1' to timestamp @ts1;
|
||||
select * from t for system_time all;
|
||||
update t set a=9;
|
||||
truncate t for system_time between '1-1-1' and timestamp @ts2;
|
||||
select * from t for system_time all;
|
||||
|
||||
create or replace table t (a int) with system versioning;
|
||||
create table t (a int) with system versioning;
|
||||
insert into t values (1), (2);
|
||||
update t set a=11 where a=1;
|
||||
set @ts1=now(6);
|
||||
update t set a=22 where a=2;
|
||||
select * from t for system_time all;
|
||||
select * from t for system_time before timestamp @ts1;
|
||||
truncate t for system_time before timestamp @ts1;
|
||||
truncate t to system_time timestamp @ts1;
|
||||
select * from t for system_time all;
|
||||
truncate t for system_time before timestamp now(6);
|
||||
select * from t for system_time all;
|
||||
|
||||
create or replace table t (a int) with system versioning engine=innodb;
|
||||
insert into t values (1), (2);
|
||||
update t set a=11 where a=1;
|
||||
set @ts1=now(6);
|
||||
update t set a=22 where a=2;
|
||||
select * from t for system_time all;
|
||||
select * from t for system_time before timestamp @ts1;
|
||||
insert into t values (33);
|
||||
select max(sys_trx_start + 0) from t into @tx;
|
||||
select * from t for system_time before transaction @tx;
|
||||
truncate t for system_time before timestamp @ts1;
|
||||
select * from t for system_time all;
|
||||
truncate t for system_time before timestamp now(6);
|
||||
truncate table t to system_time timestamp now(6);
|
||||
select * from t for system_time all;
|
||||
|
||||
drop table t;
|
||||
drop procedure truncate_history_of_t;
|
||||
|
41
mysql-test/suite/versioning/t/truncate_privilege.test
Normal file
41
mysql-test/suite/versioning/t/truncate_privilege.test
Normal file
@@ -0,0 +1,41 @@
|
||||
# Can't test with embedded server
|
||||
-- source include/not_embedded.inc
|
||||
|
||||
--source include/have_innodb.inc
|
||||
|
||||
# Save the initial number of concurrent sessions
|
||||
--source include/count_sessions.inc
|
||||
|
||||
connect (root,localhost,root,,test);
|
||||
connection root;
|
||||
|
||||
--disable_warnings
|
||||
create database mysqltest;
|
||||
--enable_warnings
|
||||
|
||||
create user mysqltest_1@localhost;
|
||||
connect (user1,localhost,mysqltest_1,,test);
|
||||
connection user1;
|
||||
|
||||
connection root;
|
||||
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();
|
||||
|
||||
connection root;
|
||||
grant delete versioning rows on mysqltest.* to mysqltest_1@localhost;
|
||||
grant delete versioning rows on mysqltest.t to mysqltest_1@localhost;
|
||||
|
||||
connection user1;
|
||||
show grants;
|
||||
truncate mysqltest.t to system_time now();
|
||||
|
||||
connection root;
|
||||
grant all on *.* to mysqltest_1@localhost;
|
||||
show grants for mysqltest_1@localhost;
|
||||
|
||||
drop user mysqltest_1@localhost;
|
||||
drop database mysqltest;
|
@@ -75,8 +75,6 @@ create or replace table t (a int) with system versioning;
|
||||
show create table t for system_time between timestamp @tm1 and timestamp @tm1;
|
||||
--error ER_VERS_RANGE_PROHIBITED
|
||||
show create table t for system_time from timestamp @tm1 to timestamp @tm1;
|
||||
--error ER_VERS_RANGE_PROHIBITED
|
||||
show create table t for system_time before timestamp @tm1;
|
||||
--error ER_VERS_VTMD_ERROR
|
||||
show create table t for system_time as of timestamp '01-01-1990';
|
||||
--error ER_VERS_VTMD_ERROR
|
||||
|
Reference in New Issue
Block a user