CREATE OR REPLACE TABLE (MDEV-5491)

[MDEV-5601] Strange error on CREATE OR REPLACE .. SELECT under lock Created: 2014-02-02  Updated: 2014-02-06  Resolved: 2014-02-06

Status: Closed
Project: MariaDB Server
Component/s: None
Affects Version/s: None
Fix Version/s: 10.0.8

Type: Technical task Priority: Minor
Reporter: Elena Stepanova Assignee: Michael Widenius
Resolution: Won't Fix Votes: 0
Labels: None

Issue Links:
Relates

 Description   

The following set of commands ends with the error "ERROR 1100 (HY000): Table 't1' was not locked with LOCK TABLES" which is untrue and hence confusing:

MariaDB [test]> create table t1 (i int);
Query OK, 0 rows affected (0.68 sec)
 
MariaDB [test]> lock table t1 write;
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [test]> create or replace table t1 as select * from t1;
ERROR 1100 (HY000): Table 't1' was not locked with LOCK TABLES

Test case:

drop table if exists t1;
create table t1 (i int);
lock table t1 write;
create or replace table t1 as select * from t1;

revision-id: monty@askmonty.org-20140202093802-a6jtuy6ni29biigz
revno: 3968
branch-nick: mariadb-monty



 Comments   
Comment by Michael Widenius [ 2014-02-06 ]

I don't think I can do much about this
This happens because we try to use t1 twice. If succeed first for the SELECT part, but when we try to lock it again for the create part, it will fail.

This is the same error that you would get from:

create table t1 (a int) engine = myisam;
lock table t1 write;
select * from t1 where a in (select * from t1);

This gives the error "Table 't1' was not locked with LOCK TABLES"

Comment by Michael Widenius [ 2014-02-06 ]

Same error as with other similar usage of locked tables.

Generated at Thu Feb 08 07:05:37 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.