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
20
1
#include "sj_tmp_table.h"
27
create_duplicate_weedout_tmp_table()
8
create_duplicate_weedout_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().
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().
55
Table *create_duplicate_weedout_tmp_table(THD *thd,
56
uint32_t uniq_tuple_length_arg,
36
Table *create_duplicate_weedout_tmp_table(THD *thd,
37
uint uniq_tuple_length_arg,
59
40
MEM_ROOT *mem_root_save, own_root;
61
42
TABLE_SHARE *share;
62
uint32_t temp_pool_slot=MY_BIT_NONE;
63
char *tmpname,path[FN_REFLEN];
43
uint temp_pool_slot=MY_BIT_NONE;
44
char *tmpname,path[FN_REFLEN];
65
46
KEY_PART_INFO *key_part_info;
67
unsigned char *group_buff;
68
unsigned char *bitmaps;
70
51
MI_COLUMNDEF *recinfo, *start_recinfo;
71
52
bool using_unique_constraint=false;
72
53
Field *field, *key_field;
73
uint32_t blob_count, null_pack_length, null_count;
74
unsigned char *null_flags;
54
uint blob_count, null_pack_length, null_count;
78
59
STEP 1: Get temporary table name
102
83
&table, sizeof(*table),
103
84
&share, sizeof(*share),
104
85
®_field, sizeof(Field*) * (1+1),
105
&blob_field, sizeof(uint32_t)*2,
86
&blob_field, sizeof(uint)*2,
106
87
&keyinfo, sizeof(*keyinfo),
107
88
&key_part_info, sizeof(*key_part_info) * 2,
109
90
sizeof(*recinfo)*(1*2+4),
110
&tmpname, (uint32_t) strlen(path)+1,
91
&tmpname, (uint) strlen(path)+1,
111
92
&group_buff, (!using_unique_constraint ?
112
93
uniq_tuple_length_arg : 0),
113
94
&bitmaps, bitmap_buffer_size(1)*2,
116
97
if (temp_pool_slot != MY_BIT_NONE)
117
98
bitmap_lock_clear_bit(&temp_pool, temp_pool_slot);
120
my_stpcpy(tmpname,path);
101
stpcpy(tmpname,path);
122
104
/* STEP 4: Create Table description */
123
105
memset(table, 0, sizeof(*table));
180
162
share->blob_fields= 0;
183
uint32_t reclength= field->pack_length();
165
uint reclength= field->pack_length();
184
166
if (using_unique_constraint)
186
168
share->db_plugin= ha_lock_engine(0, myisam_hton);
187
169
table->file= get_new_handler(share, &table->mem_root,
188
170
share->db_type());
202
184
null_pack_length= 1;
203
185
reclength += null_pack_length;
205
187
share->reclength= reclength;
207
uint32_t alloc_length=ALIGN_SIZE(share->reclength + MI_UNIQUE_HASH_LENGTH+1);
189
uint alloc_length=ALIGN_SIZE(share->reclength + MI_UNIQUE_HASH_LENGTH+1);
208
190
share->rec_buff_length= alloc_length;
209
if (!(table->record[0]= (unsigned char*)
210
alloc_root(&table->mem_root, alloc_length*3)))
191
if (!(table->record[0]= (uchar*)
192
alloc_root(&table->mem_root, alloc_length*3)))
212
194
table->record[1]= table->record[0]+alloc_length;
213
195
share->default_values= table->record[1]+alloc_length;
223
205
recinfo->type=FIELD_NORMAL;
224
206
recinfo->length=null_pack_length;
226
memset(null_flags, 255, null_pack_length); // Set null fields
208
memset(null_flags, 255, null_pack_length); // Set null fields
228
table->null_flags= (unsigned char*) table->record[0];
210
table->null_flags= (uchar*) table->record[0];
229
211
share->null_fields= null_count;
230
212
share->null_bytes= null_pack_length;
235
217
//Field *field= *reg_field;
237
219
memset(recinfo, 0, sizeof(*recinfo));
238
field->move_field(pos,(unsigned char*) 0,0);
220
field->move_field(pos,(uchar*) 0,0);
261
243
//param->recinfo=recinfo;
262
244
//store_record(table,s->default_values); // Make empty default record
264
if (thd->variables.tmp_table_size == ~ (uint64_t) 0) // No limit
246
if (thd->variables.tmp_table_size == ~ (uint64_t) 0) // No limit
265
247
share->max_rows= ~(ha_rows) 0;
267
249
share->max_rows= (ha_rows) (((share->db_type() == heap_hton) ?
268
cmin(thd->variables.tmp_table_size,
269
thd->variables.max_heap_table_size) :
250
min(thd->variables.tmp_table_size,
251
thd->variables.max_heap_table_size) :
270
252
thd->variables.tmp_table_size) /
272
set_if_bigger(share->max_rows,1); // For dummy start options
254
set_if_bigger(share->max_rows,1); // For dummy start options
275
257
//// keyinfo= param->keyinfo;
294
276
key_part_info->key_type = FIELDFLAG_BINARY;
295
277
if (!using_unique_constraint)
297
if (!(key_field= field->new_key_field(thd->mem_root, table,
279
if (!(key_field= field->new_key_field(thd->mem_root, table,
300
282
field->null_bit)))
302
284
key_part_info->key_part_flag|= HA_END_SPACE_ARE_EQUAL; //todo need this?
304
286
keyinfo->key_length+= key_part_info->length;
308
if (thd->is_fatal_error) // If end of memory
290
if (thd->is_fatal_error) // If end of memory
310
292
share->db_record_offset= 1;
311
293
if (share->db_type() == myisam_hton)