~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_handler.cc

  • Committer: Brian Aker
  • Date: 2008-08-18 22:20:43 UTC
  • mto: This revision was merged to the branch mainline in revision 352.
  • Revision ID: brian@tangent.org-20080818222043-et6zf93ogrgx1cz9
Refactoring table.h

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
  It is used like 'thd->open_tables' in the table cache. The trick is to
39
39
  exchange these two lists during open and lock of tables. Thus the normal
40
40
  table cache code can be used.
41
 
  The second container is a HASH. It holds objects of the type TABLE_LIST.
 
41
  The second container is a HASH. It holds objects of the type TableList.
42
42
  Despite its name, no lists of tables but only single structs are hashed
43
43
  (the 'next' pointer is always NULL). The reason for theis second container
44
44
  is, that we want handler tables to survive FLUSH Table commands. A table
47
47
  functions with 'thd->handler_tables', the closed tables are removed from
48
48
  this list. Hence we need the original open information for the handler
49
49
  table in the case that it is used again. This information is handed over
50
 
  to mysql_ha_open() as a TABLE_LIST. So we store this information in the
 
50
  to mysql_ha_open() as a TableList. So we store this information in the
51
51
  second container, where it is not affected by FLUSH Table. The second
52
52
  container is implemented as a hash for performance reasons. Consequently,
53
53
  we use it not only for re-opening a handler table, but also for the
73
73
  @note Broadcasts refresh if it closed a table with old version.
74
74
*/
75
75
 
76
 
static void mysql_ha_close_table(THD *thd, TABLE_LIST *tables,
 
76
static void mysql_ha_close_table(THD *thd, TableList *tables,
77
77
                                 bool is_locked)
78
78
{
79
79
  Table **table_ptr;
130
130
    true  error
131
131
*/
132
132
 
133
 
bool mysql_ha_close(THD *thd, TABLE_LIST *tables)
 
133
bool mysql_ha_close(THD *thd, TableList *tables)
134
134
{
135
 
  TABLE_LIST    *hash_tables;
 
135
  TableList    *hash_tables;
136
136
 
137
 
  if ((hash_tables= (TABLE_LIST*) hash_search(&thd->handler_tables_hash,
 
137
  if ((hash_tables= (TableList*) hash_search(&thd->handler_tables_hash,
138
138
                                              (uchar*) tables->alias,
139
139
                                              strlen(tables->alias) + 1)))
140
140
  {
158
158
  @param thd Thread identifier.
159
159
  @param tables The list of tables to remove.
160
160
 
161
 
  @return Pointer to head of linked list (TABLE_LIST::next_local) of matching
162
 
          TABLE_LIST elements from handler_tables_hash. Otherwise, NULL if no
 
161
  @return Pointer to head of linked list (TableList::next_local) of matching
 
162
          TableList elements from handler_tables_hash. Otherwise, NULL if no
163
163
          table was matched.
164
164
*/
165
165
 
166
 
static TABLE_LIST *mysql_ha_find(THD *thd, TABLE_LIST *tables)
 
166
static TableList *mysql_ha_find(THD *thd, TableList *tables)
167
167
{
168
 
  TABLE_LIST *hash_tables, *head= NULL, *first= tables;
 
168
  TableList *hash_tables, *head= NULL, *first= tables;
169
169
 
170
170
  /* search for all handlers with matching table names */
171
171
  for (uint i= 0; i < thd->handler_tables_hash.records; i++)
172
172
  {
173
 
    hash_tables= (TABLE_LIST*) hash_element(&thd->handler_tables_hash, i);
 
173
    hash_tables= (TableList*) hash_element(&thd->handler_tables_hash, i);
174
174
    for (tables= first; tables; tables= tables->next_local)
175
175
    {
176
176
      if ((! *tables->db ||
200
200
  @note Broadcasts refresh if it closed a table with old version.
201
201
*/
202
202
 
203
 
void mysql_ha_rm_tables(THD *thd, TABLE_LIST *tables, bool is_locked)
 
203
void mysql_ha_rm_tables(THD *thd, TableList *tables, bool is_locked)
204
204
{
205
 
  TABLE_LIST *hash_tables, *next;
 
205
  TableList *hash_tables, *next;
206
206
 
207
207
  assert(tables);
208
208
 
232
232
 
233
233
void mysql_ha_flush(THD *thd)
234
234
{
235
 
  TABLE_LIST *hash_tables;
 
235
  TableList *hash_tables;
236
236
 
237
237
  safe_mutex_assert_owner(&LOCK_open);
238
238
 
239
239
  for (uint i= 0; i < thd->handler_tables_hash.records; i++)
240
240
  {
241
 
    hash_tables= (TABLE_LIST*) hash_element(&thd->handler_tables_hash, i);
 
241
    hash_tables= (TableList*) hash_element(&thd->handler_tables_hash, i);
242
242
    if (hash_tables->table && hash_tables->table->needs_reopen_or_name_lock())
243
243
    {
244
244
      mysql_ha_close_table(thd, hash_tables, true);
261
261
 
262
262
void mysql_ha_cleanup(THD *thd)
263
263
{
264
 
  TABLE_LIST *hash_tables;
 
264
  TableList *hash_tables;
265
265
 
266
266
  for (uint i= 0; i < thd->handler_tables_hash.records; i++)
267
267
  {
268
 
    hash_tables= (TABLE_LIST*) hash_element(&thd->handler_tables_hash, i);
 
268
    hash_tables= (TableList*) hash_element(&thd->handler_tables_hash, i);
269
269
    if (hash_tables->table)
270
270
      mysql_ha_close_table(thd, hash_tables, false);
271
271
   }