~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/drop_table.cc

  • Committer: Monty Taylor
  • Date: 2009-09-22 23:50:12 UTC
  • mto: This revision was merged to the branch mainline in revision 1184.
  • Revision ID: mordred@inaugust.com-20090922235012-i0a3bs91f6krqduc
Fixed multi_malloc.h include guard.
Added include guard checking script.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include "config.h"
 
21
#include <drizzled/server_includes.h>
22
22
#include <drizzled/show.h>
23
23
#include <drizzled/session.h>
24
 
#include <drizzled/lock.h>
25
24
#include <drizzled/statement/drop_table.h>
26
 
#include "drizzled/sql_table.h"
27
 
 
28
 
namespace drizzled
29
 
{
30
 
 
31
 
 
32
 
/*
33
 
 delete (drop) tables.
34
 
 
35
 
  SYNOPSIS
36
 
   mysql_rm_table()
37
 
   session                      Thread handle
38
 
   tables               List of tables to delete
39
 
   if_exists            If 1, don't give error if one table doesn't exists
40
 
 
41
 
  NOTES
42
 
    Will delete all tables that can be deleted and give a compact error
43
 
    messages for tables that could not be deleted.
44
 
    If a table is in use, we will wait for all users to free the table
45
 
    before dropping it
46
 
 
47
 
    Wait if global_read_lock (FLUSH TABLES WITH READ LOCK) is set, but
48
 
    not if under LOCK TABLES.
49
 
 
50
 
  RETURN
51
 
    false OK.  In this case ok packet is sent to user
52
 
    true  Error
53
 
 
54
 
*/
55
 
 
56
 
static bool mysql_rm_table(Session *session, TableList *tables, bool if_exists, bool drop_temporary)
57
 
{
58
 
  bool error, need_start_waiting= false;
59
 
 
60
 
  /* mark for close and remove all cached entries */
61
 
 
62
 
  if (not drop_temporary)
63
 
  {
64
 
    if (not (need_start_waiting= not session->wait_if_global_read_lock(false, true)))
65
 
      return true;
66
 
  }
67
 
 
68
 
  /*
69
 
    Acquire table::Cache::singleton().mutex() after wait_if_global_read_lock(). If we would hold
70
 
    table::Cache::singleton().mutex() during wait_if_global_read_lock(), other threads could not
71
 
    close their tables. This would make a pretty deadlock.
72
 
  */
73
 
  error= mysql_rm_table_part2(session, tables, if_exists, drop_temporary);
74
 
 
75
 
  if (need_start_waiting)
76
 
  {
77
 
    session->startWaitingGlobalReadLock();
78
 
  }
79
 
 
80
 
  if (error)
81
 
    return true;
82
 
 
83
 
  session->my_ok();
84
 
 
85
 
  return false;
86
 
}
 
25
 
 
26
using namespace drizzled;
87
27
 
88
28
bool statement::DropTable::execute()
89
29
{
90
30
  TableList *first_table= (TableList *) session->lex->select_lex.table_list.first;
91
31
  TableList *all_tables= session->lex->query_tables;
92
32
  assert(first_table == all_tables && first_table != 0);
93
 
 
94
 
  if (not drop_temporary)
 
33
  if (! session->lex->drop_temporary)
95
34
  {
96
 
    if (not session->endActiveTransaction())
 
35
    if (! session->endActiveTransaction())
97
36
    {
98
37
      return true;
99
38
    }
100
39
  }
101
 
 
102
 
  /* DDL and binlog write order protected by table::Cache::singleton().mutex() */
103
 
  bool res= mysql_rm_table(session,
104
 
                           first_table,
105
 
                           drop_if_exists,
106
 
                           drop_temporary);
 
40
  else
 
41
  {
 
42
    /* So that DROP TEMPORARY TABLE gets to binlog at commit/rollback */
 
43
    session->options|= OPTION_KEEP_LOG;
 
44
  }
 
45
  /* DDL and binlog write order protected by LOCK_open */
 
46
  bool res= mysql_rm_table(session, 
 
47
                           first_table, 
 
48
                           session->lex->drop_if_exists, 
 
49
                           session->lex->drop_temporary);
107
50
  return res;
108
51
}
109
 
 
110
 
} /* namespace drizzled */