Bug #27907 Misleading error message when opening/locking tables
Submitted: 18 Apr 2007 0:25 Modified: 18 Jun 2007 16:43
Reporter: Marc Alff Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Stored Routines Severity:S3 (Non-critical)
Version:5.0, 5.1 OS:Any
Assigned to: Konstantin Osipov CPU Architecture:Any

[18 Apr 2007 0:25] Marc Alff
Description:
When opening a table that does not exist,
the server sometime reports:
  ER_TABLE_NOT_LOCKED
where the expected result is
  ER_NO_SUCH_TABLE

How to repeat:
drop table if exists logs;
drop table if exists t1;

create table logs (a int);
create table t1 (a int);

delimiter $$;

create trigger t1_ai after insert on t1
for each row
begin
  insert into logs(a) values (1);
end
$$

delimiter ;$$

drop table logs;

## fails with ER_TABLE_NOT_LOCKED, instead of ER_NO_SUCH_TABLE
insert into t1(a) values (1);

drop table t1;

Suggested fix:
The root cause is related to the following code:

in sql/sql_base.cc, function open_table():

    if ((thd->locked_tables) && (thd->locked_tables->lock_count > 0))
      my_error(ER_TABLE_NOT_LOCKED, MYF(0), alias);
    else
      my_error(ER_NO_SUCH_TABLE, MYF(0), table_list->db, table_list->alias);

The problem seems to be that thd->locked_tables is set,
even when no tables are locked by a LOCK TABLE statement,
making the logic report confusing errors.
[18 Apr 2007 6:42] Sveta Smirnova
Thank you for the report.

Verified as described.
[18 May 2007 8:45] Konstantin Osipov
Queued into 5.0 and 5.1 -runtime
[18 May 2007 12:12] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/26975

ChangeSet@1.2489, 2007-05-18 12:29:06+04:00, kostja@vajra.(none) +7 -0
  Bug #27907 "Misleading error message when opening/locking tables"
  
  Adjust the check that defines the error message to be returned.
[1 Jun 2007 19:21] Bugs System
Pushed into 5.0.44
[1 Jun 2007 19:24] Bugs System
Pushed into 5.1.20-beta
[18 Jun 2007 16:43] Paul Dubois
Noted in 5.0.44, 5.1.20 changelogs.

For attempts to open a non-existent table, the server should report
ER_NO_SUCH_TABLE but sometimes reported ER_TABLE_NOT_LOCKED.