mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
SQL: compare TRX_ID fields against timestamps [closes #231]
This commit is contained in:
@@ -28,7 +28,7 @@ insert into emp (emp_id, name, salary, dept_id, mgr) values
|
||||
(20, "john", 500, 10, 1),
|
||||
(30, "jane", 750, 10,1 );
|
||||
|
||||
select vtq_commit_ts(max(sys_trx_start)) into @ts_1 from emp;
|
||||
select vtq_commit_ts(max(sys_trx_start + 0)) into @ts_1 from emp;
|
||||
|
||||
update emp set mgr=30 where name ="john";
|
||||
select vtq_commit_ts(sys_trx_start) into @ts_2 from emp where name="john";
|
||||
|
@@ -1,119 +1,106 @@
|
||||
-- source suite/versioning/common.inc
|
||||
|
||||
delimiter ~~;
|
||||
create procedure test_01()
|
||||
begin
|
||||
declare engine varchar(255) default default_engine();
|
||||
declare sys_type varchar(255) default sys_datatype();
|
||||
declare fields varchar(255) default sys_commit_ts('sys_start');
|
||||
# test_01
|
||||
|
||||
set @str= concat('
|
||||
create table t1(
|
||||
x int unsigned,
|
||||
y int unsigned,
|
||||
sys_start ', sys_type, ' generated always as row start,
|
||||
sys_end ', sys_type, ' generated always as row end,
|
||||
period for system_time (sys_start, sys_end))
|
||||
with system versioning
|
||||
engine ', engine);
|
||||
prepare stmt from @str; execute stmt; drop prepare stmt;
|
||||
insert into t1 (x, y) values
|
||||
(0, 100),
|
||||
(1, 101),
|
||||
(2, 102),
|
||||
(3, 103),
|
||||
(4, 104),
|
||||
(5, 105),
|
||||
(6, 106),
|
||||
(7, 107),
|
||||
(8, 108),
|
||||
(9, 109);
|
||||
set @t0= now(6);
|
||||
if engine = 'innodb' then
|
||||
select sys_start from t1 limit 1 into @x0;
|
||||
end if;
|
||||
create or replace table t1 (
|
||||
x int unsigned,
|
||||
y int unsigned
|
||||
) with system versioning;
|
||||
|
||||
delete from t1 where x = 3;
|
||||
delete from t1 where x > 7;
|
||||
insert into t1 (x, y) values
|
||||
(0, 100),
|
||||
(1, 101),
|
||||
(2, 102),
|
||||
(3, 103),
|
||||
(4, 104),
|
||||
(5, 105),
|
||||
(6, 106),
|
||||
(7, 107),
|
||||
(8, 108),
|
||||
(9, 109);
|
||||
|
||||
insert into t1(x, y) values(3, 33);
|
||||
select sys_start from t1 where x = 3 and y = 33 into @t1;
|
||||
if engine = 'innodb' then
|
||||
set @x1= @t1;
|
||||
select vtq_commit_ts(@x1) into @t1;
|
||||
end if;
|
||||
set @t0= now(6);
|
||||
if ($default_engine == 'innodb')
|
||||
{
|
||||
--disable_query_log
|
||||
select sys_trx_start from t1 limit 1 into @x0;
|
||||
--enable_query_log
|
||||
}
|
||||
|
||||
select x, y from t1;
|
||||
select x as ASOF_x, y from t1 for system_time as of timestamp @t0;
|
||||
select x as FROMTO_x, y from t1 for system_time from timestamp '0-0-0 0:0:0' to timestamp @t1;
|
||||
select x as BETWAND_x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp @t1;
|
||||
select x as FROMTO_ext_x, y from t1 for system_time from timestamp '0-0-0 0:0:0' to timestamp @t1;
|
||||
select x as BETWAND_ext_x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp @t1;
|
||||
select x as ALL_x, y from t1 for system_time all;
|
||||
delete from t1 where x = 3;
|
||||
delete from t1 where x > 7;
|
||||
|
||||
if engine = 'innodb' then
|
||||
select x as ASOF2_x, y from t1 for system_time as of transaction @x0;
|
||||
select x as FROMTO2_x, y from t1 for system_time from transaction 0 to transaction @x1;
|
||||
select x as BETWAND2_x, y from t1 for system_time between transaction 0 and transaction @x1;
|
||||
select x as FROMTO2_ext_x, y from t1 for system_time transaction from 0 to @x1;
|
||||
select x as BETWAND2_ext_x, y from t1 for system_time transaction between 0 and @x1;
|
||||
else
|
||||
select x as ASOF2_x, y from t1 for system_time as of timestamp @t0;
|
||||
select x as FROMTO2_x, y from t1 for system_time from timestamp '0-0-0 0:0:0' to timestamp @t1;
|
||||
select x as BETWAND2_x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp @t1;
|
||||
select x as FROMTO2_ext_x, y from t1 for system_time from timestamp '0-0-0 0:0:0' to timestamp @t1;
|
||||
select x as BETWAND2_ext_x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp @t1;
|
||||
end if;
|
||||
insert into t1(x, y) values(3, 33);
|
||||
select sys_trx_start from t1 where x = 3 and y = 33 into @t1;
|
||||
if ($default_engine == 'innodb')
|
||||
{
|
||||
--disable_query_log
|
||||
set @x1= @t1;
|
||||
select vtq_commit_ts(@x1) into @t1;
|
||||
--enable_query_log
|
||||
}
|
||||
|
||||
drop table t1;
|
||||
end~~
|
||||
select x, y from t1;
|
||||
select x as ASOF_x, y from t1 for system_time as of timestamp @t0;
|
||||
select x as FROMTO_x, y from t1 for system_time from timestamp '0-0-0 0:0:0' to timestamp @t1;
|
||||
select x as BETWAND_x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp @t1;
|
||||
select x as FROMTO_ext_x, y from t1 for system_time from timestamp '0-0-0 0:0:0' to timestamp @t1;
|
||||
select x as BETWAND_ext_x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp @t1;
|
||||
select x as ALL_x, y from t1 for system_time all;
|
||||
|
||||
create or replace procedure test_02()
|
||||
begin
|
||||
declare engine varchar(255) default default_engine();
|
||||
declare sys_type varchar(255) default sys_datatype();
|
||||
declare fields varchar(255) default sys_commit_ts('sys_start');
|
||||
--disable_query_log
|
||||
if ($default_engine == 'innodb')
|
||||
{
|
||||
select x as ASOF2_x, y from t1 for system_time as of transaction @x0;
|
||||
select x as FROMTO2_x, y from t1 for system_time from transaction @x0 to transaction @x1;
|
||||
select x as BETWAND2_x, y from t1 for system_time between transaction @x0 and transaction @x1;
|
||||
select x as FROMTO2_ext_x, y from t1 for system_time transaction from @x0 to @x1;
|
||||
select x as BETWAND2_ext_x, y from t1 for system_time transaction between @x0 and @x1;
|
||||
}
|
||||
if ($default_engine != 'innodb')
|
||||
{
|
||||
select x as ASOF2_x, y from t1 for system_time as of timestamp @t0;
|
||||
select x as FROMTO2_x, y from t1 for system_time from timestamp '0-0-0 0:0:0' to timestamp @t1;
|
||||
select x as BETWAND2_x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp @t1;
|
||||
select x as FROMTO2_ext_x, y from t1 for system_time from timestamp '0-0-0 0:0:0' to timestamp @t1;
|
||||
select x as BETWAND2_ext_x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp @t1;
|
||||
}
|
||||
--enable_query_log
|
||||
|
||||
set @str0= concat('(
|
||||
x int,
|
||||
y int,
|
||||
sys_start ', sys_type, ' generated always as row start,
|
||||
sys_end ', sys_type, ' generated always as row end,
|
||||
period for system_time (sys_start, sys_end))
|
||||
with system versioning
|
||||
engine ', engine);
|
||||
set @str= concat('create or replace table t1', @str0);
|
||||
prepare stmt from @str; execute stmt; drop prepare stmt;
|
||||
set @str= concat('create or replace table t2', @str0);
|
||||
prepare stmt from @str; execute stmt; drop prepare stmt;
|
||||
# test_02
|
||||
|
||||
insert into t1 values (1, 1), (1, 2), (1, 3), (4, 4), (5, 5);
|
||||
insert into t2 values (1, 2), (2, 1), (3, 1);
|
||||
set @t0= now(6);
|
||||
create or replace table t1 (
|
||||
x int unsigned,
|
||||
y int unsigned
|
||||
) with system versioning;
|
||||
create or replace table t2 (
|
||||
x int unsigned,
|
||||
y int unsigned
|
||||
) with system versioning;
|
||||
|
||||
select t1.x as IJ1_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 inner join t2 on t1.x = t2.x;
|
||||
select t1.x as LJ1_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 left join t2 on t1.x = t2.x;
|
||||
select t1.x as RJ1_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 right join t2 on t1.x = t2.x;
|
||||
insert into t1 values (1, 1), (1, 2), (1, 3), (4, 4), (5, 5);
|
||||
insert into t2 values (1, 2), (2, 1), (3, 1);
|
||||
set @t0= now(6);
|
||||
|
||||
delete from t1;
|
||||
delete from t2;
|
||||
select t1.x as IJ1_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 inner join t2 on t1.x = t2.x;
|
||||
select t1.x as LJ1_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 left join t2 on t1.x = t2.x;
|
||||
select t1.x as RJ1_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 right join t2 on t1.x = t2.x;
|
||||
|
||||
select t1.x as IJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 inner join t2 on t1.x = t2.x
|
||||
system_time as of timestamp @t0;
|
||||
select t1.x as LJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 left join t2 on t1.x = t2.x
|
||||
system_time as of timestamp @t0;
|
||||
select t1.x as RJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 right join t2 on t1.x = t2.x
|
||||
system_time as of timestamp @t0;
|
||||
delete from t1;
|
||||
delete from t2;
|
||||
|
||||
drop table t1;
|
||||
drop table t2;
|
||||
end~~
|
||||
delimiter ;~~
|
||||
select t1.x as IJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 inner join t2 on t1.x = t2.x
|
||||
system_time as of timestamp @t0;
|
||||
select t1.x as LJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 left join t2 on t1.x = t2.x
|
||||
system_time as of timestamp @t0;
|
||||
select t1.x as RJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 right join t2 on t1.x = t2.x
|
||||
system_time as of timestamp @t0;
|
||||
|
||||
call test_01();
|
||||
call test_02();
|
||||
drop table t1;
|
||||
drop table t2;
|
||||
|
||||
# Wildcard expansion on hidden fields
|
||||
|
||||
# wildcard expansion on hidden fields.
|
||||
create table t1(
|
||||
A int
|
||||
) with system versioning;
|
||||
@@ -205,7 +192,4 @@ drop table t1, t2;
|
||||
|
||||
call innodb_verify_vtq(27);
|
||||
|
||||
drop procedure test_01;
|
||||
drop procedure test_02;
|
||||
|
||||
-- source suite/versioning/common_finish.inc
|
||||
|
5
mysql-test/suite/versioning/t/select_sp.combinations
Normal file
5
mysql-test/suite/versioning/t/select_sp.combinations
Normal file
@@ -0,0 +1,5 @@
|
||||
[innodb]
|
||||
default-storage-engine=innodb
|
||||
|
||||
[myisam]
|
||||
default-storage-engine=myisam
|
211
mysql-test/suite/versioning/t/select_sp.test
Normal file
211
mysql-test/suite/versioning/t/select_sp.test
Normal file
@@ -0,0 +1,211 @@
|
||||
-- source suite/versioning/common.inc
|
||||
|
||||
delimiter ~~;
|
||||
create procedure test_01()
|
||||
begin
|
||||
declare engine varchar(255) default default_engine();
|
||||
declare sys_type varchar(255) default sys_datatype();
|
||||
declare fields varchar(255) default sys_commit_ts('sys_start');
|
||||
|
||||
set @str= concat('
|
||||
create table t1(
|
||||
x int unsigned,
|
||||
y int unsigned,
|
||||
sys_start ', sys_type, ' generated always as row start,
|
||||
sys_end ', sys_type, ' generated always as row end,
|
||||
period for system_time (sys_start, sys_end))
|
||||
with system versioning
|
||||
engine ', engine);
|
||||
prepare stmt from @str; execute stmt; drop prepare stmt;
|
||||
insert into t1 (x, y) values
|
||||
(0, 100),
|
||||
(1, 101),
|
||||
(2, 102),
|
||||
(3, 103),
|
||||
(4, 104),
|
||||
(5, 105),
|
||||
(6, 106),
|
||||
(7, 107),
|
||||
(8, 108),
|
||||
(9, 109);
|
||||
set @t0= now(6);
|
||||
if engine = 'innodb' then
|
||||
select sys_start from t1 limit 1 into @x0;
|
||||
end if;
|
||||
|
||||
delete from t1 where x = 3;
|
||||
delete from t1 where x > 7;
|
||||
|
||||
insert into t1(x, y) values(3, 33);
|
||||
select sys_start from t1 where x = 3 and y = 33 into @t1;
|
||||
if engine = 'innodb' then
|
||||
set @x1= @t1;
|
||||
select vtq_commit_ts(@x1) into @t1;
|
||||
end if;
|
||||
|
||||
select x, y from t1;
|
||||
select x as ASOF_x, y from t1 for system_time as of timestamp @t0;
|
||||
select x as FROMTO_x, y from t1 for system_time from timestamp '0-0-0 0:0:0' to timestamp @t1;
|
||||
select x as BETWAND_x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp @t1;
|
||||
select x as FROMTO_ext_x, y from t1 for system_time from timestamp '0-0-0 0:0:0' to timestamp @t1;
|
||||
select x as BETWAND_ext_x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp @t1;
|
||||
select x as ALL_x, y from t1 for system_time all;
|
||||
|
||||
if engine = 'innodb' then
|
||||
select x as ASOF2_x, y from t1 for system_time as of transaction @x0;
|
||||
select x as FROMTO2_x, y from t1 for system_time from transaction @x0 to transaction @x1;
|
||||
select x as BETWAND2_x, y from t1 for system_time between transaction @x0 and transaction @x1;
|
||||
select x as FROMTO2_ext_x, y from t1 for system_time transaction from @x0 to @x1;
|
||||
select x as BETWAND2_ext_x, y from t1 for system_time transaction between @x0 and @x1;
|
||||
else
|
||||
select x as ASOF2_x, y from t1 for system_time as of timestamp @t0;
|
||||
select x as FROMTO2_x, y from t1 for system_time from timestamp '0-0-0 0:0:0' to timestamp @t1;
|
||||
select x as BETWAND2_x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp @t1;
|
||||
select x as FROMTO2_ext_x, y from t1 for system_time from timestamp '0-0-0 0:0:0' to timestamp @t1;
|
||||
select x as BETWAND2_ext_x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp @t1;
|
||||
end if;
|
||||
|
||||
drop table t1;
|
||||
end~~
|
||||
|
||||
create or replace procedure test_02()
|
||||
begin
|
||||
declare engine varchar(255) default default_engine();
|
||||
declare sys_type varchar(255) default sys_datatype();
|
||||
declare fields varchar(255) default sys_commit_ts('sys_start');
|
||||
|
||||
set @str0= concat('(
|
||||
x int,
|
||||
y int,
|
||||
sys_start ', sys_type, ' generated always as row start,
|
||||
sys_end ', sys_type, ' generated always as row end,
|
||||
period for system_time (sys_start, sys_end))
|
||||
with system versioning
|
||||
engine ', engine);
|
||||
set @str= concat('create or replace table t1', @str0);
|
||||
prepare stmt from @str; execute stmt; drop prepare stmt;
|
||||
set @str= concat('create or replace table t2', @str0);
|
||||
prepare stmt from @str; execute stmt; drop prepare stmt;
|
||||
|
||||
insert into t1 values (1, 1), (1, 2), (1, 3), (4, 4), (5, 5);
|
||||
insert into t2 values (1, 2), (2, 1), (3, 1);
|
||||
set @t0= now(6);
|
||||
|
||||
select t1.x as IJ1_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 inner join t2 on t1.x = t2.x;
|
||||
select t1.x as LJ1_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 left join t2 on t1.x = t2.x;
|
||||
select t1.x as RJ1_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 right join t2 on t1.x = t2.x;
|
||||
|
||||
delete from t1;
|
||||
delete from t2;
|
||||
|
||||
select t1.x as IJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 inner join t2 on t1.x = t2.x
|
||||
system_time as of timestamp @t0;
|
||||
select t1.x as LJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 left join t2 on t1.x = t2.x
|
||||
system_time as of timestamp @t0;
|
||||
select t1.x as RJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 right join t2 on t1.x = t2.x
|
||||
system_time as of timestamp @t0;
|
||||
|
||||
drop table t1;
|
||||
drop table t2;
|
||||
end~~
|
||||
delimiter ;~~
|
||||
|
||||
call test_01();
|
||||
call test_02();
|
||||
|
||||
# wildcard expansion on hidden fields.
|
||||
create table t1(
|
||||
A int
|
||||
) with system versioning;
|
||||
insert into t1 values(1);
|
||||
select * from t1;
|
||||
|
||||
create or replace table t1 (x int);
|
||||
insert into t1 values (1);
|
||||
--error ER_VERSIONING_REQUIRED
|
||||
select * from t1 for system_time all;
|
||||
|
||||
create or replace table t1 (x int) with system versioning;
|
||||
insert into t1 values (1);
|
||||
--error ER_VERS_HISTORY_LOCK
|
||||
select * from t1 for system_time all for update;
|
||||
|
||||
create or replace table t1 (a int not null auto_increment primary key) with system versioning;
|
||||
select * from (t1 as t2 left join t1 as t3 using (a)) natural left join t1;
|
||||
|
||||
create or replace table t1 (a int) with system versioning;
|
||||
create or replace table t2 (a int) with system versioning;
|
||||
insert into t1 values(1);
|
||||
insert into t2 values(1);
|
||||
create view v1 as select * from t2 inner join t1 using (a);
|
||||
select * from v1;
|
||||
drop view v1;
|
||||
|
||||
create or replace table t1 (a int) with system versioning;
|
||||
insert into t1 values (1);
|
||||
create view vt1 as select a from t1;
|
||||
select * from t1 natural join vt1;
|
||||
drop view vt1;
|
||||
|
||||
create or replace table t1(x int) with system versioning;
|
||||
select * from (t1 as r left join t1 as u using (x)), t1;
|
||||
|
||||
# @end should be max
|
||||
create or replace table t1 (a int) with system versioning;
|
||||
insert into t1 values (1);
|
||||
create trigger read_end after update on t1
|
||||
for each row set @end = old.sys_trx_end;
|
||||
update t1 set a=2;
|
||||
--replace_result 18446744073709551615 MAX_RESULT "2038-01-19 03:14:07.000000" MAX_RESULT
|
||||
select @end;
|
||||
|
||||
create or replace table t1 (a int) with system versioning;
|
||||
create or replace table t2 (b int) with system versioning;
|
||||
insert into t1 values (1);
|
||||
insert into t2 values (2);
|
||||
select * from (select * from t1 cross join t2) as tmp;
|
||||
select * from (select * from (select * from t1 cross join t2) as tmp1) as tmp2;
|
||||
select * from (select * from t1 cross join t2 for system_time as of timestamp '0-0-0') as tmp;
|
||||
|
||||
create or replace table t1(a1 int) with system versioning;
|
||||
create or replace table t2(a2 int) with system versioning;
|
||||
insert into t1 values(1),(2);
|
||||
insert into t2 values(1),(2);
|
||||
select * from t1 for system_time all natural left join t2 for system_time all;
|
||||
|
||||
# natural join of a view and table
|
||||
create or replace table t1(a1 int) with system versioning;
|
||||
create or replace table t2(a2 int) with system versioning;
|
||||
insert into t1 values(1),(2);
|
||||
insert into t2 values(1),(2);
|
||||
create or replace view v1 as select a1 from t1;
|
||||
|
||||
select * from v1 natural join t2;
|
||||
select * from v1 natural left join t2;
|
||||
select * from v1 natural right join t2;
|
||||
|
||||
create or replace table t1 (a int) with system versioning;
|
||||
insert into t1 values (1);
|
||||
insert into t1 values (2);
|
||||
insert into t1 values (3);
|
||||
select * from t1 left outer join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
|
||||
|
||||
create or replace table t1 (x int) with system versioning;
|
||||
create or replace table t2 (y int) with system versioning;
|
||||
insert into t1 values (1), (2), (3);
|
||||
delete from t1 where x = 3;
|
||||
insert into t2 values (1);
|
||||
select * from t1, t2 system_time all;
|
||||
|
||||
--error ER_VERS_UNUSED_CLAUSE
|
||||
select * from t1 for system_time all, t2 for system_time all system_time all;
|
||||
|
||||
drop view v1;
|
||||
drop table t1, t2;
|
||||
|
||||
call innodb_verify_vtq(27);
|
||||
|
||||
drop procedure test_01;
|
||||
drop procedure test_02;
|
||||
|
||||
-- source suite/versioning/common_finish.inc
|
@@ -110,7 +110,7 @@ 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) from t into @tx;
|
||||
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;
|
||||
|
@@ -1,4 +1,5 @@
|
||||
-- source include/have_innodb.inc
|
||||
-- source suite/versioning/common.inc
|
||||
|
||||
create table t1 (x int) with system versioning engine innodb;
|
||||
insert into t1 values (1);
|
||||
@@ -89,3 +90,5 @@ create or replace view vvt1 as select * from t1, t2, vt1;
|
||||
|
||||
drop view vt1, vt12;
|
||||
drop table t1, t2, t3;
|
||||
|
||||
-- source suite/versioning/common_finish.inc
|
||||
|
@@ -46,7 +46,7 @@ begin
|
||||
select start from tmp_vtmd for system_time all order by start limit 1 into @start;
|
||||
select @start > 0 and @start < @inf;
|
||||
select
|
||||
start = @start as A_start,
|
||||
start + 0 = @start as A_start,
|
||||
(@start:= end) and end = @inf as B_end,
|
||||
name,
|
||||
substr(archive_name, 1, instr(archive_name, '_')) as C_archive_name
|
||||
|
Reference in New Issue
Block a user