~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

  • Committer: Monty Taylor
  • Date: 2010-10-08 17:32:00 UTC
  • mto: This revision was merged to the branch mainline in revision 1833.
  • Revision ID: mordred@inaugust.com-20101008173200-iq22jo2nic48noa3
Updated pandora-build files to version 0.157

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
#include "drizzled/global_charset_info.h"
42
42
#include "drizzled/charset.h"
43
43
 
44
 
#include "drizzled/definition/cache.h"
45
 
 
46
44
 
47
45
#include "drizzled/statement/alter_table.h"
48
46
#include "drizzled/sql_table.h"
107
105
    cursor
108
106
*/
109
107
 
110
 
void write_bin_log(Session *session, const std::string &query)
 
108
void write_bin_log(Session *session,
 
109
                   char const *query)
111
110
{
112
111
  TransactionServices &transaction_services= TransactionServices::singleton();
113
112
  transaction_services.rawStatement(session, query);
148
147
  int error= 0;
149
148
  bool foreign_key_error= false;
150
149
 
151
 
  {
152
 
    table::Cache::singleton().mutex().lock(); /* Part 2 of rm a table */
153
 
 
154
 
    if (not drop_temporary && session->lock_table_names_exclusively(tables))
155
 
    {
156
 
      table::Cache::singleton().mutex().unlock();
157
 
      return 1;
158
 
    }
159
 
 
160
 
    /* Don't give warnings for not found errors, as we already generate notes */
161
 
    session->no_warnings_for_error= 1;
162
 
 
163
 
    for (table= tables; table; table= table->next_local)
164
 
    {
165
 
      TableIdentifier tmp_identifier(table->getSchemaName(), table->getTableName());
166
 
 
167
 
      error= session->drop_temporary_table(tmp_identifier);
168
 
 
169
 
      switch (error) {
170
 
      case  0:
171
 
        // removed temporary table
172
 
        continue;
173
 
      case -1:
 
150
  LOCK_open.lock(); /* Part 2 of rm a table */
 
151
 
 
152
  if (not drop_temporary && lock_table_names_exclusively(session, tables))
 
153
  {
 
154
    LOCK_open.unlock();
 
155
    return 1;
 
156
  }
 
157
 
 
158
  /* Don't give warnings for not found errors, as we already generate notes */
 
159
  session->no_warnings_for_error= 1;
 
160
 
 
161
  for (table= tables; table; table= table->next_local)
 
162
  {
 
163
    char *db=table->db;
 
164
 
 
165
    error= session->drop_temporary_table(table);
 
166
 
 
167
    switch (error) {
 
168
    case  0:
 
169
      // removed temporary table
 
170
      continue;
 
171
    case -1:
 
172
      error= 1;
 
173
      goto err_with_placeholders;
 
174
    default:
 
175
      // temporary table not found
 
176
      error= 0;
 
177
    }
 
178
 
 
179
    if (drop_temporary == false)
 
180
    {
 
181
      Table *locked_table;
 
182
      TableIdentifier identifier(db, table->table_name);
 
183
      abort_locked_tables(session, identifier);
 
184
      remove_table_from_cache(session, identifier,
 
185
                              RTFC_WAIT_OTHER_THREAD_FLAG |
 
186
                              RTFC_CHECK_KILLED_FLAG);
 
187
      /*
 
188
        If the table was used in lock tables, remember it so that
 
189
        unlock_table_names can free it
 
190
      */
 
191
      if ((locked_table= drop_locked_tables(session, identifier)))
 
192
        table->table= locked_table;
 
193
 
 
194
      if (session->killed)
 
195
      {
 
196
        error= -1;
 
197
        goto err_with_placeholders;
 
198
      }
 
199
    }
 
200
    TableIdentifier identifier(db, table->table_name, table->getInternalTmpTable() ? message::Table::INTERNAL : message::Table::STANDARD);
 
201
 
 
202
    if (drop_temporary || not plugin::StorageEngine::doesTableExist(*session, identifier))
 
203
    {
 
204
      // Table was not found on disk and table can't be created from engine
 
205
      if (if_exists)
 
206
        push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
 
207
                            ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR),
 
208
                            table->table_name);
 
209
      else
174
210
        error= 1;
175
 
        goto err_with_placeholders;
176
 
      default:
177
 
        // temporary table not found
 
211
    }
 
212
    else
 
213
    {
 
214
      error= plugin::StorageEngine::dropTable(*session, identifier);
 
215
 
 
216
      if ((error == ENOENT || error == HA_ERR_NO_SUCH_TABLE) && if_exists)
 
217
      {
178
218
        error= 0;
179
 
      }
180
 
 
181
 
      if (drop_temporary == false)
182
 
      {
183
 
        Table *locked_table;
184
 
        abort_locked_tables(session, tmp_identifier);
185
 
        table::Cache::singleton().removeTable(session, tmp_identifier,
186
 
                                              RTFC_WAIT_OTHER_THREAD_FLAG |
187
 
                                              RTFC_CHECK_KILLED_FLAG);
188
 
        /*
189
 
          If the table was used in lock tables, remember it so that
190
 
          unlock_table_names can free it
191
 
        */
192
 
        if ((locked_table= drop_locked_tables(session, tmp_identifier)))
193
 
          table->table= locked_table;
194
 
 
195
 
        if (session->getKilled())
196
 
        {
197
 
          error= -1;
198
 
          goto err_with_placeholders;
199
 
        }
200
 
      }
201
 
      TableIdentifier identifier(table->getSchemaName(), table->getTableName(), table->getInternalTmpTable() ? message::Table::INTERNAL : message::Table::STANDARD);
202
 
 
203
 
      if (drop_temporary || not plugin::StorageEngine::doesTableExist(*session, identifier))
204
 
      {
205
 
        // Table was not found on disk and table can't be created from engine
206
 
        if (if_exists)
207
 
          push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
208
 
                              ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR),
209
 
                              table->getTableName());
210
 
        else
211
 
          error= 1;
212
 
      }
213
 
      else
214
 
      {
215
 
        error= plugin::StorageEngine::dropTable(*session, identifier);
216
 
 
217
 
        if ((error == ENOENT || error == HA_ERR_NO_SUCH_TABLE) && if_exists)
218
 
        {
219
 
          error= 0;
220
 
          session->clear_error();
221
 
        }
222
 
 
223
 
        if (error == HA_ERR_ROW_IS_REFERENCED)
224
 
        {
225
 
          /* the table is referenced by a foreign key constraint */
226
 
          foreign_key_error= true;
227
 
        }
228
 
      }
229
 
 
230
 
      if (error == 0 || (if_exists && foreign_key_error == false))
231
 
      {
232
 
        TransactionServices &transaction_services= TransactionServices::singleton();
233
 
        transaction_services.dropTable(session, string(table->getSchemaName()), string(table->getTableName()), if_exists);
234
 
      }
235
 
 
236
 
      if (error)
237
 
      {
238
 
        if (wrong_tables.length())
239
 
          wrong_tables.append(',');
240
 
        wrong_tables.append(String(table->getTableName(), system_charset_info));
241
 
      }
242
 
    }
243
 
    /*
244
 
      It's safe to unlock table::Cache::singleton().mutex(): we have an exclusive lock
245
 
      on the table name.
246
 
    */
247
 
    table::Cache::singleton().mutex().unlock();
 
219
        session->clear_error();
 
220
      }
 
221
 
 
222
      if (error == HA_ERR_ROW_IS_REFERENCED)
 
223
      {
 
224
        /* the table is referenced by a foreign key constraint */
 
225
        foreign_key_error= true;
 
226
      }
 
227
    }
 
228
 
 
229
    if (error == 0 || (if_exists && foreign_key_error == false))
 
230
    {
 
231
      TransactionServices &transaction_services= TransactionServices::singleton();
 
232
      transaction_services.dropTable(session, string(db), string(table->table_name), if_exists);
 
233
    }
 
234
 
 
235
    if (error)
 
236
    {
 
237
      if (wrong_tables.length())
 
238
        wrong_tables.append(',');
 
239
      wrong_tables.append(String(table->table_name,system_charset_info));
 
240
    }
248
241
  }
 
242
  /*
 
243
    It's safe to unlock LOCK_open: we have an exclusive lock
 
244
    on the table name.
 
245
  */
 
246
  LOCK_open.unlock();
249
247
  error= 0;
250
248
 
251
249
  if (wrong_tables.length())
262
260
    error= 1;
263
261
  }
264
262
 
265
 
  table::Cache::singleton().mutex().lock(); /* final bit in rm table lock */
 
263
  LOCK_open.lock(); /* final bit in rm table lock */
266
264
 
267
265
err_with_placeholders:
268
 
  tables->unlock_table_names();
269
 
  table::Cache::singleton().mutex().unlock();
 
266
  unlock_table_names(tables, NULL);
 
267
  LOCK_open.unlock();
270
268
  session->no_warnings_for_error= 0;
271
269
 
272
270
  return error;
273
271
}
274
272
 
 
273
 
 
274
/*
 
275
  Quickly remove a table.
 
276
 
 
277
  SYNOPSIS
 
278
    quick_rm_table()
 
279
      base                      The plugin::StorageEngine handle.
 
280
      db                        The database name.
 
281
      table_name                The table name.
 
282
      is_tmp                    If the table is temp.
 
283
 
 
284
  RETURN
 
285
    0           OK
 
286
    != 0        Error
 
287
*/
 
288
bool quick_rm_table(Session& session,
 
289
                    TableIdentifier &identifier)
 
290
{
 
291
  return (plugin::StorageEngine::dropTable(session, identifier));
 
292
}
 
293
 
275
294
/*
276
295
  Sort keys in the following order:
277
296
  - PRIMARY KEY
1265
1284
}
1266
1285
 
1267
1286
static bool locked_create_event(Session *session,
1268
 
                                const TableIdentifier &identifier,
 
1287
                                TableIdentifier &identifier,
1269
1288
                                HA_CREATE_INFO *create_info,
1270
1289
                                message::Table &table_proto,
1271
1290
                                AlterInfo *alter_info,
1300
1319
        return error;
1301
1320
      }
1302
1321
 
1303
 
      std::string path;
1304
 
      identifier.getSQLPath(path);
1305
 
      my_error(ER_TABLE_EXISTS_ERROR, MYF(0), path.c_str());
1306
 
 
 
1322
      my_error(ER_TABLE_EXISTS_ERROR, MYF(0), identifier.getSQLPath().c_str());
1307
1323
      return error;
1308
1324
    }
1309
1325
 
1320
1336
      /*
1321
1337
        @todo improve this error condition.
1322
1338
      */
1323
 
      if (definition::Cache::singleton().find(identifier.getKey()))
 
1339
      if (TableShare::getShare(identifier))
1324
1340
      {
1325
 
        std::string path;
1326
 
        identifier.getSQLPath(path);
1327
 
        my_error(ER_TABLE_EXISTS_ERROR, MYF(0), path.c_str());
1328
 
 
 
1341
        my_error(ER_TABLE_EXISTS_ERROR, MYF(0), identifier.getSQLPath().c_str());
1329
1342
        return error;
1330
1343
      }
1331
1344
    }
1401
1414
*/
1402
1415
 
1403
1416
bool mysql_create_table_no_lock(Session *session,
1404
 
                                const TableIdentifier &identifier,
 
1417
                                TableIdentifier &identifier,
1405
1418
                                HA_CREATE_INFO *create_info,
1406
1419
                                message::Table &table_proto,
1407
1420
                                AlterInfo *alter_info,
1427
1440
 
1428
1441
  /* Build a Table object to pass down to the engine, and the do the actual create. */
1429
1442
  if (not mysql_prepare_create_table(session, create_info, table_proto, alter_info,
1430
 
                                     internal_tmp_table,
1431
 
                                     &db_options,
1432
 
                                     &key_info_buffer, &key_count,
1433
 
                                     select_field_count))
 
1443
                                 internal_tmp_table,
 
1444
                                 &db_options,
 
1445
                                 &key_info_buffer, &key_count,
 
1446
                                 select_field_count))
1434
1447
  {
1435
 
    boost_unique_lock_t lock(table::Cache::singleton().mutex()); /* CREATE TABLE (some confussion on naming, double check) */
 
1448
    boost::mutex::scoped_lock lock(LOCK_open); /* CREATE TABLE (some confussion on naming, double check) */
1436
1449
    error= locked_create_event(session,
1437
1450
                               identifier,
1438
1451
                               create_info,
1453
1466
  @note the following two methods implement create [temporary] table.
1454
1467
*/
1455
1468
static bool drizzle_create_table(Session *session,
1456
 
                                 const TableIdentifier &identifier,
 
1469
                                 TableIdentifier &identifier,
1457
1470
                                 HA_CREATE_INFO *create_info,
1458
1471
                                 message::Table &table_proto,
1459
1472
                                 AlterInfo *alter_info,
1480
1493
    }
1481
1494
    else
1482
1495
    {
1483
 
      std::string path;
1484
 
      identifier.getSQLPath(path);
1485
 
      my_error(ER_TABLE_EXISTS_ERROR, MYF(0), path.c_str());
 
1496
      my_error(ER_TABLE_EXISTS_ERROR, MYF(0), identifier.getSQLPath().c_str());
1486
1497
      result= true;
1487
1498
    }
1488
1499
  }
1500
1511
 
1501
1512
  if (name_lock)
1502
1513
  {
1503
 
    boost_unique_lock_t lock(table::Cache::singleton().mutex()); /* Lock for removing name_lock during table create */
 
1514
    boost::mutex::scoped_lock lock(LOCK_open); /* Lock for removing name_lock during table create */
1504
1515
    session->unlink_open_table(name_lock);
1505
1516
  }
1506
1517
 
1512
1523
  Database locking aware wrapper for mysql_create_table_no_lock(),
1513
1524
*/
1514
1525
bool mysql_create_table(Session *session,
1515
 
                        const TableIdentifier &identifier,
 
1526
                        TableIdentifier &identifier,
1516
1527
                        HA_CREATE_INFO *create_info,
1517
1528
                        message::Table &table_proto,
1518
1529
                        AlterInfo *alter_info,
1608
1619
bool
1609
1620
mysql_rename_table(Session &session,
1610
1621
                   plugin::StorageEngine *base,
1611
 
                   const TableIdentifier &from,
1612
 
                   const TableIdentifier &to)
 
1622
                   TableIdentifier &from,
 
1623
                   TableIdentifier &to)
1613
1624
{
1614
1625
  int error= 0;
1615
1626
 
1629
1640
  }
1630
1641
  else if (error)
1631
1642
  {
1632
 
    std::string from_path;
1633
 
    std::string to_path;
1634
 
 
1635
 
    from.getSQLPath(from_path);
1636
 
    to.getSQLPath(to_path);
1637
 
 
1638
 
    const char *from_identifier= from.isTmp() ? "#sql-temporary" : from_path.c_str();
1639
 
    const char *to_identifier= to.isTmp() ? "#sql-temporary" : to_path.c_str();
 
1643
    const char *from_identifier= from.isTmp() ? "#sql-temporary" : from.getSQLPath().c_str();
 
1644
    const char *to_identifier= to.isTmp() ? "#sql-temporary" : to.getSQLPath().c_str();
1640
1645
 
1641
1646
    my_error(ER_ERROR_ON_RENAME, MYF(0), from_identifier, to_identifier, error);
1642
1647
  }
1660
1665
   the table is closed.
1661
1666
 
1662
1667
  PREREQUISITES
1663
 
    Lock on table::Cache::singleton().mutex()
 
1668
    Lock on LOCK_open
1664
1669
    Win32 clients must also have a WRITE LOCK on the table !
1665
1670
*/
1666
1671
 
1668
1673
                              enum ha_extra_function function)
1669
1674
{
1670
1675
 
1671
 
  safe_mutex_assert_owner(table::Cache::singleton().mutex().native_handle());
 
1676
  safe_mutex_assert_owner(LOCK_open.native_handle());
1672
1677
 
1673
1678
  table->cursor->extra(function);
1674
1679
  /* Mark all tables that are in use as 'old' */
1675
 
  session->abortLock(table);    /* end threads waiting on lock */
 
1680
  mysql_lock_abort(session, table);     /* end threads waiting on lock */
1676
1681
 
1677
1682
  /* Wait until all there are no other threads that has this table open */
1678
 
  TableIdentifier identifier(table->getShare()->getSchemaName(), table->getShare()->getTableName());
1679
 
  table::Cache::singleton().removeTable(session, identifier, RTFC_WAIT_OTHER_THREAD_FLAG);
 
1683
  TableIdentifier identifier(table->getMutableShare()->getSchemaName(), table->getMutableShare()->getTableName());
 
1684
  remove_table_from_cache(session, identifier, RTFC_WAIT_OTHER_THREAD_FLAG);
1680
1685
}
1681
1686
 
1682
1687
/*
1692
1697
    reopen the table.
1693
1698
 
1694
1699
  PREREQUISITES
1695
 
    Lock on table::Cache::singleton().mutex()
 
1700
    Lock on LOCK_open
1696
1701
    Win32 clients must also have a WRITE LOCK on the table !
1697
1702
*/
1698
1703
 
1703
1708
  /* Close lock if this is not got with LOCK TABLES */
1704
1709
  if (lock)
1705
1710
  {
1706
 
    unlockTables(lock);
 
1711
    mysql_unlock_tables(this, lock);
1707
1712
    lock= NULL;                 // Start locked threads
1708
1713
  }
1709
1714
  /* Close all copies of 'table'.  This also frees all LOCK TABLES lock */
1710
1715
  unlink_open_table(table);
1711
1716
 
1712
 
  /* When lock on table::Cache::singleton().mutex() is freed other threads can continue */
1713
 
  locking::broadcast_refresh();
 
1717
  /* When lock on LOCK_open is freed other threads can continue */
 
1718
  broadcast_refresh();
1714
1719
}
1715
1720
 
1716
1721
/*
1754
1759
  for (table= tables; table; table= table->next_local)
1755
1760
  {
1756
1761
    char table_name[NAME_LEN*2+2];
 
1762
    char* db = table->db;
1757
1763
    bool fatal_error=0;
1758
1764
 
1759
 
    snprintf(table_name, sizeof(table_name), "%s.%s", table->getSchemaName(), table->getTableName());
 
1765
    snprintf(table_name, sizeof(table_name), "%s.%s",db,table->table_name);
1760
1766
    table->lock_type= lock_type;
1761
1767
    /* open only one table from local list of command */
1762
1768
    {
1822
1828
    /* Close all instances of the table to allow repair to rename files */
1823
1829
    if (lock_type == TL_WRITE && table->table->getShare()->getVersion())
1824
1830
    {
1825
 
      table::Cache::singleton().mutex().lock(); /* Lock type is TL_WRITE and we lock to repair the table */
1826
 
      const char *old_message=session->enter_cond(COND_refresh, table::Cache::singleton().mutex(),
 
1831
      LOCK_open.lock(); /* Lock type is TL_WRITE and we lock to repair the table */
 
1832
      const char *old_message=session->enter_cond(COND_refresh, LOCK_open,
1827
1833
                                                  "Waiting to get writelock");
1828
 
      session->abortLock(table->table);
1829
 
      TableIdentifier identifier(table->table->getShare()->getSchemaName(), table->table->getShare()->getTableName());
1830
 
      table::Cache::singleton().removeTable(session, identifier, RTFC_WAIT_OTHER_THREAD_FLAG | RTFC_CHECK_KILLED_FLAG);
 
1834
      mysql_lock_abort(session,table->table);
 
1835
      TableIdentifier identifier(table->table->getMutableShare()->getSchemaName(), table->table->getMutableShare()->getTableName());
 
1836
      remove_table_from_cache(session, identifier,
 
1837
                              RTFC_WAIT_OTHER_THREAD_FLAG |
 
1838
                              RTFC_CHECK_KILLED_FLAG);
1831
1839
      session->exit_cond(old_message);
1832
 
      if (session->getKilled())
 
1840
      if (session->killed)
1833
1841
        goto err;
1834
1842
      open_for_modify= 0;
1835
1843
    }
1927
1935
        }
1928
1936
        else
1929
1937
        {
1930
 
          boost::unique_lock<boost::mutex> lock(table::Cache::singleton().mutex());
1931
 
          TableIdentifier identifier(table->table->getShare()->getSchemaName(), table->table->getShare()->getTableName());
1932
 
          table::Cache::singleton().removeTable(session, identifier, RTFC_NO_FLAG);
 
1938
          boost::mutex::scoped_lock lock(LOCK_open);
 
1939
          TableIdentifier identifier(table->table->getMutableShare()->getSchemaName(), table->table->getMutableShare()->getTableName());
 
1940
          remove_table_from_cache(session, identifier, RTFC_NO_FLAG);
1933
1941
        }
1934
1942
      }
1935
1943
    }
1959
1967
    Altough exclusive name-lock on target table protects us from concurrent
1960
1968
    DML and DDL operations on it we still want to wrap .FRM creation and call
1961
1969
    to plugin::StorageEngine::createTable() in critical section protected by
1962
 
    table::Cache::singleton().mutex() in order to provide minimal atomicity against operations which
 
1970
    LOCK_open in order to provide minimal atomicity against operations which
1963
1971
    disregard name-locks, like I_S implementation, for example. This is a
1964
1972
    temporary and should not be copied. Instead we should fix our code to
1965
1973
    always honor name-locks.
1966
1974
 
1967
 
    Also some engines (e.g. NDB cluster) require that table::Cache::singleton().mutex() should be held
 
1975
    Also some engines (e.g. NDB cluster) require that LOCK_open should be held
1968
1976
    during the call to plugin::StorageEngine::createTable().
1969
1977
    See bug #28614 for more info.
1970
1978
  */
1971
1979
static bool create_table_wrapper(Session &session, const message::Table& create_table_proto,
1972
 
                                 const TableIdentifier &destination_identifier,
1973
 
                                 const TableIdentifier &src_table,
 
1980
                                 TableIdentifier &destination_identifier,
 
1981
                                 TableIdentifier &src_table,
1974
1982
                                 bool is_engine_set)
1975
1983
{
1976
1984
  int protoerr= EEXIST;
1977
1985
  message::Table new_proto;
1978
 
  message::table::shared_ptr src_proto;
 
1986
  message::Table src_proto;
1979
1987
 
1980
1988
  protoerr= plugin::StorageEngine::getTableDefinition(session,
1981
1989
                                                      src_table,
1982
1990
                                                      src_proto);
1983
 
  new_proto.CopyFrom(*src_proto);
 
1991
  new_proto.CopyFrom(src_proto);
1984
1992
 
1985
1993
  if (destination_identifier.isTmp())
1986
1994
  {
2046
2054
*/
2047
2055
 
2048
2056
bool mysql_create_like_table(Session* session,
2049
 
                             const TableIdentifier &destination_identifier,
 
2057
                             TableIdentifier &destination_identifier,
2050
2058
                             TableList* table, TableList* src_table,
2051
2059
                             message::Table &create_table_proto,
2052
2060
                             bool is_if_not_exists,
2053
2061
                             bool is_engine_set)
2054
2062
{
 
2063
  char *db= table->db;
 
2064
  char *table_name= table->table_name;
2055
2065
  bool res= true;
2056
2066
  uint32_t not_used;
2057
2067
 
2067
2077
  if (session->open_tables_from_list(&src_table, &not_used))
2068
2078
    return true;
2069
2079
 
2070
 
  TableIdentifier src_identifier(src_table->table->getShare()->getSchemaName(),
2071
 
                                 src_table->table->getShare()->getTableName(), src_table->table->getShare()->getType());
 
2080
  TableIdentifier src_identifier(src_table->table->getMutableShare()->getSchemaName(),
 
2081
                                 src_table->table->getMutableShare()->getTableName(), src_table->table->getMutableShare()->getType());
2072
2082
 
2073
2083
 
2074
2084
 
2081
2091
  bool table_exists= false;
2082
2092
  if (destination_identifier.isTmp())
2083
2093
  {
2084
 
    if (session->find_temporary_table(destination_identifier))
 
2094
    if (session->find_temporary_table(db, table_name))
2085
2095
    {
2086
2096
      table_exists= true;
2087
2097
    }
2112
2122
    {
2113
2123
      if (name_lock)
2114
2124
      {
2115
 
        boost_unique_lock_t lock(table::Cache::singleton().mutex()); /* unlink open tables for create table like*/
 
2125
        boost::mutex::scoped_lock lock(LOCK_open); /* unlink open tables for create table like*/
2116
2126
        session->unlink_open_table(name_lock);
2117
2127
      }
2118
2128
 
2131
2141
    {
2132
2142
      bool was_created;
2133
2143
      {
2134
 
        boost_unique_lock_t lock(table::Cache::singleton().mutex()); /* We lock for CREATE TABLE LIKE to copy table definition */
 
2144
        boost::mutex::scoped_lock lock(LOCK_open); /* We lock for CREATE TABLE LIKE to copy table definition */
2135
2145
        was_created= create_table_wrapper(*session, create_table_proto, destination_identifier,
2136
2146
                                               src_identifier, is_engine_set);
2137
2147
      }
2140
2150
      // anything that might have been created (read... it is a hack)
2141
2151
      if (not was_created)
2142
2152
      {
2143
 
        plugin::StorageEngine::dropTable(*session, destination_identifier);
 
2153
        quick_rm_table(*session, destination_identifier);
2144
2154
      } 
2145
2155
      else
2146
2156
      {
2150
2160
 
2151
2161
    if (name_lock)
2152
2162
    {
2153
 
      boost_unique_lock_t lock(table::Cache::singleton().mutex()); /* unlink open tables for create table like*/
 
2163
      boost::mutex::scoped_lock lock(LOCK_open); /* unlink open tables for create table like*/
2154
2164
      session->unlink_open_table(name_lock);
2155
2165
    }
2156
2166
  }
2161
2171
    {
2162
2172
      char warn_buff[DRIZZLE_ERRMSG_SIZE];
2163
2173
      snprintf(warn_buff, sizeof(warn_buff),
2164
 
               ER(ER_TABLE_EXISTS_ERROR), table->getTableName());
 
2174
               ER(ER_TABLE_EXISTS_ERROR), table_name);
2165
2175
      push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
2166
2176
                   ER_TABLE_EXISTS_ERROR,warn_buff);
2167
2177
      res= false;
2168
2178
    }
2169
2179
    else
2170
2180
    {
2171
 
      my_error(ER_TABLE_EXISTS_ERROR, MYF(0), table->getTableName());
 
2181
      my_error(ER_TABLE_EXISTS_ERROR, MYF(0), table_name);
2172
2182
    }
2173
2183
  }
2174
2184