~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sj_tmp_table.cc

Moved the last of the libdrizzleclient calls into Protocol.

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
{
73
76
  uint32_t blob_count, null_pack_length, null_count;
74
77
  unsigned char *null_flags;
75
78
  unsigned char *pos;
76
 
  
 
79
 
77
80
  /*
78
81
    STEP 1: Get temporary table name
79
82
  */
80
 
  statistic_increment(thd->status_var.created_tmp_tables, &LOCK_status);
 
83
  statistic_increment(session->status_var.created_tmp_tables, &LOCK_status);
81
84
  if (use_temp_pool && !(test_flags & TEST_KEEP_TMP_TABLES))
82
85
    temp_pool_slot = bitmap_lock_set_next(&temp_pool);
83
86
 
84
87
  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);
 
88
    sprintf(path, "%s_%lx_%i", TMP_FILE_PREFIX,
 
89
            (unsigned long)current_pid, temp_pool_slot);
87
90
  else
88
91
  {
89
92
    /* 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++);
 
93
    sprintf(path,"%s%lx_%"PRIx64"_%x", TMP_FILE_PREFIX, (unsigned long)current_pid,
 
94
            session->thread_id, session->tmp_table++);
92
95
  }
93
 
  fn_format(path, path, mysql_tmpdir, "", MY_REPLACE_EXT|MY_UNPACK_FILENAME);
 
96
  fn_format(path, path, drizzle_tmpdir, "", MY_REPLACE_EXT|MY_UNPACK_FILENAME);
94
97
 
95
98
  /* STEP 2: Figure if we'll be using a key or blob+constraint */
96
99
  if (uniq_tuple_length_arg >= CONVERT_IF_BIGGER_TO_BLOB)
117
120
      bitmap_lock_clear_bit(&temp_pool, temp_pool_slot);
118
121
    return(NULL);
119
122
  }
120
 
  my_stpcpy(tmpname,path);
 
123
  strcpy(tmpname,path);
121
124
 
122
125
  /* STEP 4: Create Table description */
123
126
  memset(table, 0, sizeof(*table));
124
127
  memset(reg_field, 0, sizeof(Field*)*2);
125
128
 
126
129
  table->mem_root= own_root;
127
 
  mem_root_save= thd->mem_root;
128
 
  thd->mem_root= &table->mem_root;
 
130
  mem_root_save= session->mem_root;
 
131
  session->mem_root= &table->mem_root;
129
132
 
130
133
  table->field=reg_field;
131
134
  table->alias= "weedout-tmp";
134
137
  table->map=1;
135
138
  table->temp_pool_slot = temp_pool_slot;
136
139
  table->copy_blobs= 1;
137
 
  table->in_use= thd;
 
140
  table->in_use= session;
138
141
  table->quick_keys.init();
139
142
  table->covering_keys.init();
140
143
  table->keys_in_use_for_query.init();
141
144
 
142
145
  table->s= share;
143
 
  init_tmp_table_share(thd, share, "", 0, tmpname, tmpname);
 
146
  init_tmp_table_share(session, share, "", 0, tmpname, tmpname);
144
147
  share->blob_field= blob_field;
145
148
  share->blob_ptr_size= portable_sizeof_char_ptr;
146
149
  share->db_low_byte_first=1;                // True for HEAP and MyISAM
183
186
  uint32_t reclength= field->pack_length();
184
187
  if (using_unique_constraint)
185
188
  {
186
 
    share->db_plugin= ha_lock_engine(0, myisam_hton);
 
189
    share->db_plugin= ha_lock_engine(0, myisam_engine);
187
190
    table->file= get_new_handler(share, &table->mem_root,
188
191
                                 share->db_type());
189
192
    assert(uniq_tuple_length_arg <= table->file->max_key_length());
190
193
  }
191
194
  else
192
195
  {
193
 
    share->db_plugin= ha_lock_engine(0, heap_hton);
 
196
    share->db_plugin= ha_lock_engine(0, heap_engine);
194
197
    table->file= get_new_handler(share, &table->mem_root,
195
198
                                 share->db_type());
196
199
  }
261
264
  //param->recinfo=recinfo;
262
265
  //store_record(table,s->default_values);        // Make empty default record
263
266
 
264
 
  if (thd->variables.tmp_table_size == ~ (uint64_t) 0)    // No limit
 
267
  if (session->variables.tmp_table_size == ~ (uint64_t) 0)    // No limit
265
268
    share->max_rows= ~(ha_rows) 0;
266
269
  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) /
 
270
    share->max_rows= (ha_rows) (((share->db_type() == heap_engine) ?
 
271
                                 cmin(session->variables.tmp_table_size,
 
272
                                      session->variables.max_heap_table_size) :
 
273
                                 session->variables.tmp_table_size) /
271
274
                                share->reclength);
272
 
  set_if_bigger(share->max_rows,1);    // For dummy start options
 
275
  set_if_bigger(share->max_rows,(ha_rows)1);    // For dummy start options
273
276
 
274
277
 
275
278
  //// keyinfo= param->keyinfo;
294
297
      key_part_info->key_type = FIELDFLAG_BINARY;
295
298
      if (!using_unique_constraint)
296
299
      {
297
 
        if (!(key_field= field->new_key_field(thd->mem_root, table,
 
300
        if (!(key_field= field->new_key_field(session->mem_root, table,
298
301
                                              group_buff,
299
302
                                              field->null_ptr,
300
303
                                              field->null_bit)))
305
308
    }
306
309
  }
307
310
 
308
 
  if (thd->is_fatal_error)        // If end of memory
 
311
  if (session->is_fatal_error)        // If end of memory
309
312
    goto err;
310
313
  share->db_record_offset= 1;
311
 
  if (share->db_type() == myisam_hton)
 
314
  if (share->db_type() == myisam_engine)
312
315
  {
313
316
    recinfo++;
314
317
    if (table->create_myisam_tmp_table(keyinfo, start_recinfo, &recinfo, 0))
319
322
  if (table->open_tmp_table())
320
323
    goto err;
321
324
 
322
 
  thd->mem_root= mem_root_save;
 
325
  session->mem_root= mem_root_save;
323
326
  return(table);
324
327
 
325
328
err:
326
 
  thd->mem_root= mem_root_save;
327
 
  table->free_tmp_table(thd);                    /* purecov: inspected */
 
329
  session->mem_root= mem_root_save;
 
330
  table->free_tmp_table(session);                    /* purecov: inspected */
328
331
  if (temp_pool_slot != MY_BIT_NONE)
329
332
    bitmap_lock_clear_bit(&temp_pool, temp_pool_slot);
330
333
  return(NULL);        /* purecov: inspected */