~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/open_tables_state.h

mergeĀ mainline

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#ifndef DRIZZLED_OPEN_TABLES_STATE_H
22
22
#define DRIZZLED_OPEN_TABLES_STATE_H
23
23
 
24
 
#include "drizzled/lock.h"
25
 
 
26
 
namespace drizzled
27
 
{
28
24
 
29
25
/**
30
26
  Class that holds information about tables which were opened and locked
40
36
    base tables that were opened with @see open_tables().
41
37
  */
42
38
  Table *open_tables;
43
 
 
44
39
  /**
45
40
    List of temporary tables used by this thread. Contains user-level
46
41
    temporary tables, created with CREATE TEMPORARY TABLE, and
48
43
    or for an intermediate table used in ALTER.
49
44
    XXX Why are internal temporary tables added to this list?
50
45
  */
51
 
private:
52
46
  Table *temporary_tables;
53
 
public:
54
 
 
55
 
  Table *getTemporaryTables()
56
 
  {
57
 
    return temporary_tables;
58
 
  }
59
 
 
60
47
  /**
61
 
    Mark all temporary tables which were used by the current statement or
62
 
    substatement as free for reuse, but only if the query_id can be cleared.
63
 
 
64
 
    @param session thread context
65
 
 
66
 
    @remark For temp tables associated with a open SQL HANDLER the query_id
67
 
            is not reset until the HANDLER is closed.
 
48
    List of tables that were opened with HANDLER OPEN and are
 
49
    still in use by this thread.
68
50
  */
69
 
  void mark_temp_tables_as_free_for_reuse();
70
 
 
71
 
protected:
72
 
  void close_temporary_tables();
73
 
public:
74
 
  void close_temporary_table(Table *table);
75
 
  // The method below just handles the de-allocation of the table. In
76
 
  // a better memory type world, this would not be needed.
77
 
private:
78
 
  void nukeTable(Table *table);
79
 
public:
80
 
 
81
 
  /* Work with temporary tables */
82
 
  Table *find_temporary_table(const TableIdentifier &identifier);
83
 
 
84
 
  void dumpTemporaryTableNames(const char *id);
85
 
  int drop_temporary_table(const drizzled::TableIdentifier &identifier);
86
 
  bool rm_temporary_table(plugin::StorageEngine *base, const TableIdentifier &identifier);
87
 
  bool rm_temporary_table(const drizzled::TableIdentifier &identifier, bool best_effort= false);
88
 
  Table *open_temporary_table(const drizzled::TableIdentifier &identifier,
89
 
                              bool link_in_list= true);
90
 
 
91
 
  virtual query_id_t getQueryId()  const= 0;
92
 
 
93
 
private:
 
51
  Table *handler_tables;
94
52
  Table *derived_tables;
95
 
public:
96
 
 
97
 
 
98
 
  Table *getDerivedTables()
99
 
  {
100
 
    return derived_tables;
101
 
  }
102
 
 
103
 
  void setDerivedTables(Table *arg)
104
 
  {
105
 
    derived_tables= arg;
106
 
  }
107
 
 
108
 
  void clearDerivedTables()
109
 
  {
110
 
    if (derived_tables)
111
 
      derived_tables= NULL; // They should all be invalid by this point
112
 
  }
113
 
 
114
53
  /*
115
54
    During a MySQL session, one can lock tables in two modes: automatic
116
55
    or manual. In automatic mode all necessary tables are locked just before
124
63
    the 'LOCK_TABLES' chapter of the MySQL manual.
125
64
    See also lock_tables() for details.
126
65
  */
127
 
  DrizzleLock *lock;
 
66
  DRIZZLE_LOCK *lock;
 
67
  /*
 
68
    Tables that were locked with explicit or implicit LOCK TABLES.
 
69
    (Implicit LOCK TABLES happens when we are prelocking tables for
 
70
     execution of statement which uses stored routines. See description
 
71
     Session::prelocked_mode for more info.)
 
72
  */
 
73
  DRIZZLE_LOCK *locked_tables;
128
74
 
129
75
  /*
130
76
    CREATE-SELECT keeps an extra lock for the table being
131
77
    created. This field is used to keep the extra lock available for
132
78
    lower level routines, which would otherwise miss that lock.
133
79
   */
134
 
  DrizzleLock *extra_lock;
 
80
  DRIZZLE_LOCK *extra_lock;
135
81
 
136
 
  uint64_t version;
 
82
  ulong version;
137
83
  uint32_t current_tablenr;
138
84
 
 
85
  enum enum_flags {
 
86
    BACKUPS_AVAIL = (1U << 0)     /* There are backups available */
 
87
  };
 
88
 
 
89
  /*
 
90
    Flags with information about the open tables state.
 
91
  */
 
92
  uint32_t state_flags;
 
93
 
139
94
  /*
140
95
    This constructor serves for creation of Open_tables_state instances
141
96
    which are used as backup storage.
142
97
  */
143
 
  Open_tables_state() :
144
 
    open_tables(0),
145
 
    temporary_tables(0),
146
 
    derived_tables(0),
147
 
    lock(0),
148
 
    extra_lock(0),
149
 
    version(0),
150
 
    current_tablenr(0)
151
 
  { }
152
 
  virtual ~Open_tables_state() {}
153
 
 
154
 
  void doGetTableNames(CachedDirectory &directory,
155
 
                       const SchemaIdentifier &schema_identifier,
156
 
                       std::set<std::string>& set_of_names);
157
 
  void doGetTableNames(const SchemaIdentifier &schema_identifier,
158
 
                       std::set<std::string>& set_of_names);
159
 
 
160
 
  void doGetTableIdentifiers(CachedDirectory &directory,
161
 
                             const SchemaIdentifier &schema_identifier,
162
 
                             TableIdentifier::vector &set_of_identifiers);
163
 
  void doGetTableIdentifiers(const SchemaIdentifier &schema_identifier,
164
 
                             TableIdentifier::vector &set_of_identifiers);
165
 
 
166
 
  int doGetTableDefinition(const drizzled::TableIdentifier &identifier,
167
 
                           message::Table &table_proto);
168
 
  bool doDoesTableExist(const drizzled::TableIdentifier &identifier);
169
 
 
170
 
 
171
 
  Open_tables_state(uint64_t version_arg);
 
98
  Open_tables_state() : state_flags(0U) { }
 
99
 
 
100
  Open_tables_state(ulong version_arg);
 
101
 
 
102
  void set_open_tables_state(Open_tables_state *state)
 
103
  {
 
104
    *this= *state;
 
105
  }
 
106
 
 
107
  void reset_open_tables_state()
 
108
  {
 
109
    open_tables= temporary_tables= handler_tables= derived_tables= 0;
 
110
    extra_lock= lock= locked_tables= 0;
 
111
    state_flags= 0U;
 
112
  }
172
113
};
173
114
 
174
 
} /* namespace drizzled */
175
 
 
176
115
#endif /* DRIZZLED_OPEN_TABLES_STATE_H */