a real table can be created even read_only = 1

Bug #997879 reported by yinfeng
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MySQL Server
Unknown
Unknown
Percona Server moved to https://jira.percona.com/projects/PS
Status tracked in 5.7
5.1
Won't Fix
Low
Unassigned
5.5
Triaged
Low
Unassigned
5.6
Triaged
Low
Unassigned
5.7
Fix Released
Low
Unassigned

Bug Description

this bug has been reported here: http://bugs.mysql.com/bug.php?id=64992

I've written my analyses there (user: zhai weixiang) based on percona5.5.18, here just copy it

test case:

xx@test 09:59:54>show variables like 'read_only%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| read_only | ON |
+---------------+-------+
1 row in set (0.00 sec)

xx@test 09:59:58>select @@version;
+------------+
| @@version |
+------------+
| 5.5.22-log |
+------------+
1 row in set (0.00 sec)

xx@test 10:00:22>create table t(foo varchar(12), bar varchar(24));
ERROR 1290 (HY000): The MySQL server is running with the --read-only option so it cannot execute this statement
xx@test 10:02:38>create temporary table t(id bigint unsigned not null primary key);
Query OK, 0 rows affected (0.04 sec)

xx@test 10:02:43>create table t(foo varchar(12), bar varchar(24));
Query OK, 0 rows affected (0.00 sec)

------------------------

deny_updates_if_read_only_option() was used to check if a query was allowed to excute. if we first create a temporary table and then create a real table, the later operation will be allowed.

i guess there must be some problem with the following code in deny_updates_if_read_only_option()

  const my_bool update_real_tables=
    some_non_temp_table_to_be_updated(thd, all_tables) &&
    !(create_temp_tables || drop_temp_tables);

Generally some_non_temp_table_to_be_updated() should return true and create_temp_tables equals zero while we are creating a real table.

but actully the return value of some_non_temp_table_to_be_updated() is 0, because the same table name was found in temporary table list.

function some_non_temp_table_to_be_updated:

static bool some_non_temp_table_to_be_updated(THD *thd, TABLE_LIST *tables)
{
  for (TABLE_LIST *table= tables; table; table= table->next_global)
  {
    DBUG_ASSERT(table->db && table->table_name);
    if (table->updating && !find_temporary_table(thd, table))
      return 1;
  }
  return 0;
}

so i think the value of update_real_tables should be calculated like this :

  const my_bool update_real_tables=
    (lex->sql_command == SQLCOM_CREATE_TABLE || some_non_temp_table_to_be_updated(thd, all_tables)) &&
    !(create_temp_tables || drop_temp_tables);

I don't know my guess is correct , but this small change really works

Tags: upstream
Changed in percona-server:
status: New → Confirmed
Stewart Smith (stewart)
Changed in percona-server:
importance: Undecided → Low
status: Confirmed → Triaged
Revision history for this message
yinfeng (yinfeng-zwx) wrote :

from the comment of http://bugs.mysql.com/bug.php?id=64992, this bug was fixed in 5.7.0.
But I can't find any information about 5.7.0 and I don't know how they fix this bug.

tags: added: upstream
Revision history for this message
Shahriyar Rzayev (rzayev-sehriyar) wrote :

Percona now uses JIRA for bug reports so this bug report is migrated to: https://jira.percona.com/browse/PS-1914

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.