Tidb: `select for update` doesn't seem to work on views in some cases

Created on 26 Nov 2020  路  2Comments  路  Source: pingcap/tidb

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

/* init */ drop table if exists t;
/* init */ drop view if exists v;
/* init */ create table t(a int primary key, b int);
/* init */ create view v as select a, b from t;
/* init */ insert into t values(1,2),(2,3);

/* t1 */ begin;
/* t2 */ begin;
/* t1 */ update t set b = 12 where a = 1;
/* t2 */ select * from v where a < 2 for update; -- range-scan on view, not blocked
# /* t2 */ select * from v where a = 1 for update; -- point-get on view, blocked
# /* t2 */ select * from t where a < 2 for update; -- range-scan on table, blocked
# /* t2 */ select * from t where a = 1 for update; -- point-get on table, blocked
/* t1 */ commit;
/* t2 */ commit;

2. What did you expect to see? (Required)

select * from v where a < 2 for update; should be blocked by t1.

3. What did you see instead (Required)

It's not blocked.

4. What is your TiDB version? (Required)

release-4.0 (1e73c51515e123e3066fa5abeb14430551d00758)

severitmajor sitransaction typbug

Most helpful comment

Because views are non-writeable in TiDB, the expected behavior should be an error when trying FOR UPDATE or LOCK IN SHARE MODE.

All 2 comments

Because views are non-writeable in TiDB, the expected behavior should be an error when trying FOR UPDATE or LOCK IN SHARE MODE.

PTAL @cfzjywxk @lysu

Was this page helpful?
0 / 5 - 0 ratings