~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table_share.h

  • Committer: Brian Aker
  • Date: 2009-07-10 00:39:24 UTC
  • mto: (1090.1.1 staging)
  • mto: This revision was merged to the branch mainline in revision 1091.
  • Revision ID: brian@gaz-20090710003924-4k89lygqakxyf76g
Optimization for createKey(). Removes the need to initialize some
structures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
  This class is shared between different table objects. There is one
23
23
  instance of table share per one table in the database.
24
24
*/
 
25
 
 
26
#include <string>
 
27
 
 
28
using namespace std;
 
29
 
25
30
class TableShare
26
31
{
27
32
public:
67
72
  /*
68
73
    Key which is used for looking-up table in table cache and in the list
69
74
    of thread's temporary tables. Has the form of:
70
 
      "database_name\0table_name\0" + optional part for temporary tables.
 
75
    "database_name\0table_name\0" + optional part for temporary tables.
71
76
 
72
77
    Note that all three 'table_cache_key', 'db' and 'table_name' members
73
78
    must be set (and be non-zero) for tables in table cache. They also
133
138
  bool waiting_on_cond;                 /* Protection against free */
134
139
 
135
140
  /*
136
 
     Set of keys in use, implemented as a Bitmap.
137
 
     Excludes keys disabled by ALTER Table ... DISABLE KEYS.
 
141
    Set of keys in use, implemented as a Bitmap.
 
142
    Excludes keys disabled by ALTER Table ... DISABLE KEYS.
138
143
  */
139
144
  key_map keys_in_use;
140
145
  key_map keys_for_keyread;
143
148
    Set share's table cache key and update its db and table name appropriately.
144
149
 
145
150
    SYNOPSIS
146
 
      set_table_cache_key()
147
 
        key_buff    Buffer with already built table cache key to be
148
 
                    referenced from share.
149
 
        key_length  Key length.
 
151
    set_table_cache_key()
 
152
    key_buff    Buffer with already built table cache key to be
 
153
    referenced from share.
 
154
    key_length  Key length.
150
155
 
151
156
    NOTES
152
 
      Since 'key_buff' buffer will be referenced from share it should has same
153
 
      life-time as share itself.
154
 
      This method automatically ensures that TableShare::table_name/db have
155
 
      appropriate values by using table cache key as their source.
 
157
    Since 'key_buff' buffer will be referenced from share it should has same
 
158
    life-time as share itself.
 
159
    This method automatically ensures that TableShare::table_name/db have
 
160
    appropriate values by using table cache key as their source.
156
161
  */
157
162
 
158
163
  void set_table_cache_key(char *key_buff, uint32_t key_length)
174
179
    Set share's table cache key and update its db and table name appropriately.
175
180
 
176
181
    SYNOPSIS
177
 
      set_table_cache_key()
178
 
        key_buff    Buffer to be used as storage for table cache key
179
 
                    (should be at least key_length bytes).
180
 
        key         Value for table cache key.
181
 
        key_length  Key length.
 
182
    set_table_cache_key()
 
183
    key_buff    Buffer to be used as storage for table cache key
 
184
    (should be at least key_length bytes).
 
185
    key         Value for table cache key.
 
186
    key_length  Key length.
182
187
 
183
188
    NOTE
184
 
      Since 'key_buff' buffer will be used as storage for table cache key
185
 
      it should has same life-time as share itself.
 
189
    Since 'key_buff' buffer will be used as storage for table cache key
 
190
    it should has same life-time as share itself.
186
191
  */
187
192
 
188
193
  void set_table_cache_key(char *key_buff, const char *key, uint32_t key_length)
294
299
  }
295
300
 
296
301
  void open_table_error(int pass_error, int db_errno, int pass_errarg);
 
302
 
 
303
 
 
304
 
 
305
  /*
 
306
    Create a table cache key
 
307
 
 
308
    SYNOPSIS
 
309
    createKey()
 
310
    key                 Create key here (must be of size MAX_DBKEY_LENGTH)
 
311
    table_list          Table definition
 
312
 
 
313
    IMPLEMENTATION
 
314
    The table cache_key is created from:
 
315
    db_name + \0
 
316
    table_name + \0
 
317
 
 
318
    if the table is a tmp table, we add the following to make each tmp table
 
319
    unique on the slave:
 
320
 
 
321
    4 bytes for master thread id
 
322
    4 bytes pseudo thread id
 
323
 
 
324
    RETURN
 
325
    Length of key
 
326
  */
 
327
 
 
328
  static inline uint32_t createKey(char *key, string& db_arg, string& table_name_arg)
 
329
  {
 
330
    return createKey(key, db_arg.c_str(), table_name_arg.c_str());
 
331
  }
 
332
 
 
333
  static inline uint32_t createKey(char *key, const char *db_arg, const char *table_name_arg)
 
334
  {
 
335
    uint32_t key_length;
 
336
    char *key_pos= key;
 
337
 
 
338
    key_pos= strcpy(key_pos, db_arg) + strlen(db_arg);
 
339
    key_pos= strcpy(key_pos+1, table_name_arg) +
 
340
      strlen(table_name_arg);
 
341
    key_length= (uint32_t)(key_pos-key)+1;
 
342
 
 
343
    return key_length;
 
344
  }
297
345
};