1
/* - mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
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.
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.
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
1
20
#include "sj_tmp_table.h"
8
create_duplicate_weedout_tmp_table()
27
create_duplicate_weedout_tmp_table()
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
18
Depending on the needed length, there are two cases:
20
1. When the length of the column < max_key_length:
22
CREATE TABLE tmp (col VARBINARY(n) NOT NULL, UNIQUE KEY(col));
24
2. Otherwise (not a valid SQL syntax but internally supported):
26
CREATE TABLE tmp (col VARBINARY NOT NULL, UNIQUE CONSTRAINT(col));
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
37
Depending on the needed length, there are two cases:
39
1. When the length of the column < max_key_length:
41
CREATE TABLE tmp (col VARBINARY(n) NOT NULL, UNIQUE KEY(col));
43
2. Otherwise (not a valid SQL syntax but internally supported):
45
CREATE TABLE tmp (col VARBINARY NOT NULL, UNIQUE CONSTRAINT(col));
47
The code in this function was produced by extraction of relevant parts
48
from create_tmp_table().
36
Table *create_duplicate_weedout_tmp_table(THD *thd,
37
uint uniq_tuple_length_arg,
55
Table *create_duplicate_weedout_tmp_table(THD *thd,
56
uint uniq_tuple_length_arg,
40
59
MEM_ROOT *mem_root_save, own_root;
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];
46
65
KEY_PART_INFO *key_part_info;
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;
117
136
table->temp_pool_slot = temp_pool_slot;
165
184
uint reclength= field->pack_length();
166
185
if (using_unique_constraint)
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());
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)))
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;
208
memset(null_flags, 255, null_pack_length); // Set null fields
227
memset(null_flags, 255, null_pack_length); // Set null fields
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
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;
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) /
254
set_if_bigger(share->max_rows,1); // For dummy start options
273
set_if_bigger(share->max_rows,1); // For dummy start options
257
276
//// keyinfo= param->keyinfo;
276
295
key_part_info->key_type = FIELDFLAG_BINARY;
277
296
if (!using_unique_constraint)
279
if (!(key_field= field->new_key_field(thd->mem_root, table,
298
if (!(key_field= field->new_key_field(thd->mem_root, table,
282
301
field->null_bit)))
284
303
key_part_info->key_part_flag|= HA_END_SPACE_ARE_EQUAL; //todo need this?
286
305
keyinfo->key_length+= key_part_info->length;
290
if (thd->is_fatal_error) // If end of memory
309
if (thd->is_fatal_error) // If end of memory
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 */