~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sj_tmp_table.cc

  • Committer: Stewart Smith
  • Date: 2009-06-16 03:02:59 UTC
  • mto: This revision was merged to the branch mainline in revision 1065.
  • Revision ID: stewart@flamingspork.com-20090616030259-tn2thqrajk6cappd
ER_NISAMCHK is unused, mark it as so. Thanks to Paul DuBois for researching this for MySQL.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "sj_tmp_table.h"
 
20
#include <drizzled/global.h>
 
21
#include <drizzled/sj_tmp_table.h>
 
22
#include <drizzled/session.h>
 
23
#include <drizzled/field/varstring.h>
21
24
 
22
25
/*
23
26
  Create a temporary table to weed out duplicate rowid combinations
25
28
  SYNOPSIS
26
29
 
27
30
  create_duplicate_weedout_tmp_table()
28
 
  thd
 
31
  session
29
32
  uniq_tuple_length_arg
30
33
  SJ_TMP_TABLE
31
34
 
52
55
  NULL on error
53
56
*/
54
57
 
55
 
Table *create_duplicate_weedout_tmp_table(THD *thd,
 
58
Table *create_duplicate_weedout_tmp_table(Session *session,
56
59
                                          uint32_t uniq_tuple_length_arg,
57
60
                                          SJ_TMP_TABLE *sjtbl)
58
61
{
59
62
  MEM_ROOT *mem_root_save, own_root;
60
63
  Table *table;
61
 
  TABLE_SHARE *share;
62
 
  uint32_t  temp_pool_slot=MY_BIT_NONE;
 
64
  TableShare *share;
63
65
  char  *tmpname,path[FN_REFLEN];
64
66
  Field **reg_field;
65
67
  KEY_PART_INFO *key_part_info;
73
75
  uint32_t blob_count, null_pack_length, null_count;
74
76
  unsigned char *null_flags;
75
77
  unsigned char *pos;
76
 
  
 
78
 
77
79
  /*
78
80
    STEP 1: Get temporary table name
79
81
  */
80
 
  statistic_increment(thd->status_var.created_tmp_tables, &LOCK_status);
81
 
  if (use_temp_pool && !(test_flags & TEST_KEEP_TMP_TABLES))
82
 
    temp_pool_slot = bitmap_lock_set_next(&temp_pool);
 
82
  statistic_increment(session->status_var.created_tmp_tables, &LOCK_status);
83
83
 
84
 
  if (temp_pool_slot != MY_BIT_NONE) // we got a slot
85
 
    sprintf(path, "%s_%lx_%i", tmp_file_prefix,
86
 
            current_pid, temp_pool_slot);
87
 
  else
88
 
  {
89
 
    /* if we run out of slots or we are not using tempool */
90
 
    sprintf(path,"%s%lx_%lx_%x", tmp_file_prefix,current_pid,
91
 
            thd->thread_id, thd->tmp_table++);
92
 
  }
93
 
  fn_format(path, path, mysql_tmpdir, "", MY_REPLACE_EXT|MY_UNPACK_FILENAME);
 
84
  /* if we run out of slots or we are not using tempool */
 
85
  sprintf(path,"%s%lx_%"PRIx64"_%x", TMP_FILE_PREFIX, (unsigned long)current_pid,
 
86
          session->thread_id, session->tmp_table++);
 
87
  fn_format(path, path, drizzle_tmpdir, "", MY_REPLACE_EXT|MY_UNPACK_FILENAME);
94
88
 
95
89
  /* STEP 2: Figure if we'll be using a key or blob+constraint */
96
90
  if (uniq_tuple_length_arg >= CONVERT_IF_BIGGER_TO_BLOB)
113
107
                        &bitmaps, bitmap_buffer_size(1)*2,
114
108
                        NULL))
115
109
  {
116
 
    if (temp_pool_slot != MY_BIT_NONE)
117
 
      bitmap_lock_clear_bit(&temp_pool, temp_pool_slot);
118
 
    return(NULL);
 
110
    return NULL;
119
111
  }
120
 
  my_stpcpy(tmpname,path);
 
112
  strcpy(tmpname,path);
121
113
 
122
114
  /* STEP 4: Create Table description */
123
115
  memset(table, 0, sizeof(*table));
124
116
  memset(reg_field, 0, sizeof(Field*)*2);
125
117
 
126
118
  table->mem_root= own_root;
127
 
  mem_root_save= thd->mem_root;
128
 
  thd->mem_root= &table->mem_root;
 
119
  mem_root_save= session->mem_root;
 
120
  session->mem_root= &table->mem_root;
129
121
 
130
122
  table->field=reg_field;
131
123
  table->alias= "weedout-tmp";
132
124
  table->reginfo.lock_type=TL_WRITE;  /* Will be updated */
133
125
  table->db_stat=HA_OPEN_KEYFILE+HA_OPEN_RNDFILE;
134
126
  table->map=1;
135
 
  table->temp_pool_slot = temp_pool_slot;
136
127
  table->copy_blobs= 1;
137
 
  table->in_use= thd;
138
 
  table->quick_keys.init();
139
 
  table->covering_keys.init();
140
 
  table->keys_in_use_for_query.init();
 
128
  table->in_use= session;
 
129
  table->quick_keys.reset();
 
130
  table->covering_keys.reset();
 
131
  table->keys_in_use_for_query.reset();
141
132
 
142
133
  table->s= share;
143
 
  init_tmp_table_share(thd, share, "", 0, tmpname, tmpname);
 
134
  share->init(tmpname, tmpname);
144
135
  share->blob_field= blob_field;
145
136
  share->blob_ptr_size= portable_sizeof_char_ptr;
146
137
  share->db_low_byte_first=1;                // True for HEAP and MyISAM
147
138
  share->table_charset= NULL;
148
139
  share->primary_key= MAX_KEY;               // Indicate no primary key
149
 
  share->keys_for_keyread.init();
150
 
  share->keys_in_use.init();
 
140
  share->keys_for_keyread.reset();
 
141
  share->keys_in_use.reset();
151
142
 
152
143
  blob_count= 0;
153
144
 
161
152
    if (!field)
162
153
      return(0);
163
154
    field->table= table;
164
 
    field->key_start.init(0);
165
 
    field->part_of_key.init(0);
166
 
    field->part_of_sortkey.init(0);
 
155
    field->key_start.reset();
 
156
    field->part_of_key.reset();
 
157
    field->part_of_sortkey.reset();
167
158
    field->unireg_check= Field::NONE;
168
159
    field->flags= (NOT_NULL_FLAG | BINARY_FLAG | NO_DEFAULT_VALUE_FLAG);
169
160
    field->reset_fields();
183
174
  uint32_t reclength= field->pack_length();
184
175
  if (using_unique_constraint)
185
176
  {
186
 
    share->db_plugin= ha_lock_engine(0, myisam_hton);
 
177
    share->storage_engine= myisam_engine;
187
178
    table->file= get_new_handler(share, &table->mem_root,
188
179
                                 share->db_type());
189
180
    assert(uniq_tuple_length_arg <= table->file->max_key_length());
190
181
  }
191
182
  else
192
183
  {
193
 
    share->db_plugin= ha_lock_engine(0, heap_hton);
 
184
    share->storage_engine= heap_engine;
194
185
    table->file= get_new_handler(share, &table->mem_root,
195
186
                                 share->db_type());
196
187
  }
259
250
  }
260
251
 
261
252
  //param->recinfo=recinfo;
262
 
  //store_record(table,s->default_values);        // Make empty default record
 
253
  //table->storeRecordAsDefault();        // Make empty default record
263
254
 
264
 
  if (thd->variables.tmp_table_size == ~ (uint64_t) 0)    // No limit
 
255
  if (session->variables.tmp_table_size == ~ (uint64_t) 0)    // No limit
265
256
    share->max_rows= ~(ha_rows) 0;
266
257
  else
267
 
    share->max_rows= (ha_rows) (((share->db_type() == heap_hton) ?
268
 
                                 cmin(thd->variables.tmp_table_size,
269
 
                                      thd->variables.max_heap_table_size) :
270
 
                                 thd->variables.tmp_table_size) /
 
258
    share->max_rows= (ha_rows) (((share->db_type() == heap_engine) ?
 
259
                                 cmin(session->variables.tmp_table_size,
 
260
                                      session->variables.max_heap_table_size) :
 
261
                                 session->variables.tmp_table_size) /
271
262
                                share->reclength);
272
 
  set_if_bigger(share->max_rows,1);    // For dummy start options
 
263
  set_if_bigger(share->max_rows,(ha_rows)1);    // For dummy start options
273
264
 
274
265
 
275
266
  //// keyinfo= param->keyinfo;
294
285
      key_part_info->key_type = FIELDFLAG_BINARY;
295
286
      if (!using_unique_constraint)
296
287
      {
297
 
        if (!(key_field= field->new_key_field(thd->mem_root, table,
 
288
        if (!(key_field= field->new_key_field(session->mem_root, table,
298
289
                                              group_buff,
299
290
                                              field->null_ptr,
300
291
                                              field->null_bit)))
305
296
    }
306
297
  }
307
298
 
308
 
  if (thd->is_fatal_error)        // If end of memory
 
299
  if (session->is_fatal_error)        // If end of memory
309
300
    goto err;
310
301
  share->db_record_offset= 1;
311
 
  if (share->db_type() == myisam_hton)
 
302
  if (share->db_type() == myisam_engine)
312
303
  {
313
304
    recinfo++;
314
305
    if (table->create_myisam_tmp_table(keyinfo, start_recinfo, &recinfo, 0))
319
310
  if (table->open_tmp_table())
320
311
    goto err;
321
312
 
322
 
  thd->mem_root= mem_root_save;
 
313
  session->mem_root= mem_root_save;
323
314
  return(table);
324
315
 
325
316
err:
326
 
  thd->mem_root= mem_root_save;
327
 
  table->free_tmp_table(thd);                    /* purecov: inspected */
328
 
  if (temp_pool_slot != MY_BIT_NONE)
329
 
    bitmap_lock_clear_bit(&temp_pool, temp_pool_slot);
330
 
  return(NULL);        /* purecov: inspected */
 
317
  session->mem_root= mem_root_save;
 
318
  table->free_tmp_table(session);                    /* purecov: inspected */
 
319
  return NULL;        /* purecov: inspected */
331
320
}