~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sj_tmp_table.cc

  • Committer: Monty Taylor
  • Date: 2008-09-23 00:10:39 UTC
  • mto: This revision was merged to the branch mainline in revision 417.
  • Revision ID: monty@inaugust.com-20080923001039-cv4ve8om1kk5mgit
Removed __alpha__ references.
Removed VOID().

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* - mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
1
20
#include "sj_tmp_table.h"
2
21
 
3
22
/*
5
24
 
6
25
  SYNOPSIS
7
26
 
8
 
    create_duplicate_weedout_tmp_table()
9
 
      thd
10
 
      uniq_tuple_length_arg
11
 
      SJ_TMP_TABLE 
 
27
  create_duplicate_weedout_tmp_table()
 
28
  thd
 
29
  uniq_tuple_length_arg
 
30
  SJ_TMP_TABLE
12
31
 
13
32
  DESCRIPTION
14
 
    Create a temporary table to weed out duplicate rowid combinations. The
15
 
    table has a single column that is a concatenation of all rowids in the
16
 
    combination. 
17
 
 
18
 
    Depending on the needed length, there are two cases:
19
 
 
20
 
    1. When the length of the column < max_key_length:
21
 
 
22
 
      CREATE TABLE tmp (col VARBINARY(n) NOT NULL, UNIQUE KEY(col));
23
 
 
24
 
    2. Otherwise (not a valid SQL syntax but internally supported):
25
 
 
26
 
      CREATE TABLE tmp (col VARBINARY NOT NULL, UNIQUE CONSTRAINT(col));
27
 
 
28
 
    The code in this function was produced by extraction of relevant parts
29
 
    from create_tmp_table().
 
33
  Create a temporary table to weed out duplicate rowid combinations. The
 
34
  table has a single column that is a concatenation of all rowids in the
 
35
  combination.
 
36
 
 
37
  Depending on the needed length, there are two cases:
 
38
 
 
39
  1. When the length of the column < max_key_length:
 
40
 
 
41
  CREATE TABLE tmp (col VARBINARY(n) NOT NULL, UNIQUE KEY(col));
 
42
 
 
43
  2. Otherwise (not a valid SQL syntax but internally supported):
 
44
 
 
45
  CREATE TABLE tmp (col VARBINARY NOT NULL, UNIQUE CONSTRAINT(col));
 
46
 
 
47
  The code in this function was produced by extraction of relevant parts
 
48
  from create_tmp_table().
30
49
 
31
50
  RETURN
32
 
    created table
33
 
    NULL on error
 
51
  created table
 
52
  NULL on error
34
53
*/
35
54
 
36
 
Table *create_duplicate_weedout_tmp_table(THD *thd, 
37
 
                                          uint uniq_tuple_length_arg,
38
 
                                          SJ_TMP_TABLE *sjtbl)
 
55
Table *create_duplicate_weedout_tmp_table(THD *thd,
 
56
                                          uint uniq_tuple_length_arg,
 
57
                                          SJ_TMP_TABLE *sjtbl)
39
58
{
40
59
  MEM_ROOT *mem_root_save, own_root;
41
60
  Table *table;
42
61
  TABLE_SHARE *share;
43
62
  uint  temp_pool_slot=MY_BIT_NONE;
44
 
  char  *tmpname,path[FN_REFLEN];
 
63
  char  *tmpname,path[FN_REFLEN];
45
64
  Field **reg_field;
46
65
  KEY_PART_INFO *key_part_info;
47
66
  KEY *keyinfo;
99
118
    return(NULL);
100
119
  }
101
120
  stpcpy(tmpname,path);
102
 
  
 
121
 
103
122
 
104
123
  /* STEP 4: Create Table description */
105
124
  memset(table, 0, sizeof(*table));
111
130
 
112
131
  table->field=reg_field;
113
132
  table->alias= "weedout-tmp";
114
 
  table->reginfo.lock_type=TL_WRITE;    /* Will be updated */
 
133
  table->reginfo.lock_type=TL_WRITE;  /* Will be updated */
115
134
  table->db_stat=HA_OPEN_KEYFILE+HA_OPEN_RNDFILE;
116
135
  table->map=1;
117
136
  table->temp_pool_slot = temp_pool_slot;
151
170
    field->reset_fields();
152
171
    field->init(table);
153
172
    field->orig_table= NULL;
154
 
     
 
173
 
155
174
    field->field_index= 0;
156
 
    
 
175
 
157
176
    *(reg_field++)= field;
158
177
    *blob_field= 0;
159
178
    *reg_field= 0;
164
183
 
165
184
  uint reclength= field->pack_length();
166
185
  if (using_unique_constraint)
167
 
  { 
 
186
  {
168
187
    share->db_plugin= ha_lock_engine(0, myisam_hton);
169
188
    table->file= get_new_handler(share, &table->mem_root,
170
189
                                 share->db_type());
180
199
    goto err;
181
200
 
182
201
  null_count=1;
183
 
  
 
202
 
184
203
  null_pack_length= 1;
185
204
  reclength += null_pack_length;
186
205
 
189
208
    uint alloc_length=ALIGN_SIZE(share->reclength + MI_UNIQUE_HASH_LENGTH+1);
190
209
    share->rec_buff_length= alloc_length;
191
210
    if (!(table->record[0]= (uchar*)
192
 
                            alloc_root(&table->mem_root, alloc_length*3)))
 
211
          alloc_root(&table->mem_root, alloc_length*3)))
193
212
      goto err;
194
213
    table->record[1]= table->record[0]+alloc_length;
195
214
    share->default_values= table->record[1]+alloc_length;
205
224
    recinfo->type=FIELD_NORMAL;
206
225
    recinfo->length=null_pack_length;
207
226
    recinfo++;
208
 
    memset(null_flags, 255, null_pack_length);  // Set null fields
 
227
    memset(null_flags, 255, null_pack_length);  // Set null fields
209
228
 
210
229
    table->null_flags= (uchar*) table->record[0];
211
230
    share->null_fields= null_count;
243
262
  //param->recinfo=recinfo;
244
263
  //store_record(table,s->default_values);        // Make empty default record
245
264
 
246
 
  if (thd->variables.tmp_table_size == ~ (uint64_t) 0)          // No limit
 
265
  if (thd->variables.tmp_table_size == ~ (uint64_t) 0)    // No limit
247
266
    share->max_rows= ~(ha_rows) 0;
248
267
  else
249
268
    share->max_rows= (ha_rows) (((share->db_type() == heap_hton) ?
250
269
                                 cmin(thd->variables.tmp_table_size,
251
 
                                     thd->variables.max_heap_table_size) :
 
270
                                      thd->variables.max_heap_table_size) :
252
271
                                 thd->variables.tmp_table_size) /
253
 
                                 share->reclength);
254
 
  set_if_bigger(share->max_rows,1);             // For dummy start options
 
272
                                share->reclength);
 
273
  set_if_bigger(share->max_rows,1);    // For dummy start options
255
274
 
256
275
 
257
276
  //// keyinfo= param->keyinfo;
276
295
      key_part_info->key_type = FIELDFLAG_BINARY;
277
296
      if (!using_unique_constraint)
278
297
      {
279
 
        if (!(key_field= field->new_key_field(thd->mem_root, table,
 
298
        if (!(key_field= field->new_key_field(thd->mem_root, table,
280
299
                                              group_buff,
281
300
                                              field->null_ptr,
282
301
                                              field->null_bit)))
283
 
          goto err;
 
302
          goto err;
284
303
        key_part_info->key_part_flag|= HA_END_SPACE_ARE_EQUAL; //todo need this?
285
304
      }
286
305
      keyinfo->key_length+=  key_part_info->length;
287
306
    }
288
307
  }
289
308
 
290
 
  if (thd->is_fatal_error)                              // If end of memory
 
309
  if (thd->is_fatal_error)        // If end of memory
291
310
    goto err;
292
311
  share->db_record_offset= 1;
293
312
  if (share->db_type() == myisam_hton)
309
328
  table->free_tmp_table(thd);                    /* purecov: inspected */
310
329
  if (temp_pool_slot != MY_BIT_NONE)
311
330
    bitmap_lock_clear_bit(&temp_pool, temp_pool_slot);
312
 
  return(NULL);                         /* purecov: inspected */
 
331
  return(NULL);        /* purecov: inspected */
313
332
}