~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000-2006 MySQL AB
2
3
   This program is free software; you can redistribute it and/or modify
4
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
6
7
   This program is distributed in the hope that it will be useful,
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
   GNU General Public License for more details.
11
12
   You should have received a copy of the GNU General Public License
13
   along with this program; if not, write to the Free Software
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
16
17
/* Some general useful functions */
18
1241.9.36 by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h.
19
#include "config.h"
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
20
21
#include <float.h>
22
#include <fcntl.h>
23
24
#include <string>
25
#include <vector>
26
#include <algorithm>
27
549 by Monty Taylor
Took gettext.h out of header files.
28
#include <drizzled/error.h>
29
#include <drizzled/gettext.h>
1 by brian
clean slate
30
1273.1.15 by Jay Pipes
This patch completes the first step in the splitting of
31
#include "drizzled/plugin/transactional_storage_engine.h"
1317.2.7 by Monty Taylor
Prevent users from attempting to access schemas that he is not authorized to
32
#include "drizzled/plugin/authorization.h"
553.1.3 by Monty Taylor
Split out nested_join.h.
33
#include <drizzled/nested_join.h>
520.8.2 by Monty Taylor
Moved sql_parse.h and sql_error.h out of common_includes.
34
#include <drizzled/sql_parse.h>
584.4.7 by Monty Taylor
Removed a big bank of includes from item.h.
35
#include <drizzled/item/sum.h>
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
36
#include <drizzled/table_list.h>
37
#include <drizzled/session.h>
38
#include <drizzled/sql_base.h>
1085.1.2 by Monty Taylor
Fixed -Wmissing-declarations
39
#include <drizzled/sql_select.h>
584.5.1 by Monty Taylor
Removed field includes from field.h.
40
#include <drizzled/field/blob.h>
41
#include <drizzled/field/varstring.h>
42
#include <drizzled/field/double.h>
820.1.8 by Stewart Smith
start reading table definition from proto instead of FRM.
43
#include <drizzled/unireg.h>
988.1.1 by Jay Pipes
Changes libserialize to libdrizzledmessage per ML discussion. All GPB messages are now in the drizzled::message namespace.
44
#include <drizzled/message/table.pb.h>
1241.9.23 by Monty Taylor
Removed sql_table.h from server_includes.h.
45
#include "drizzled/sql_table.h"
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
46
#include "drizzled/charset.h"
1241.9.64 by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal.
47
#include "drizzled/internal/m_string.h"
1241.9.63 by Monty Taylor
zomg. I think drizzled/ is clean now.
48
#include "plugin/myisam/myisam.h"
820.1.8 by Stewart Smith
start reading table definition from proto instead of FRM.
49
896.3.3 by Stewart Smith
Start generating a record buffer with default values in proto read path instead of FRM write path.
50
#include <drizzled/item/string.h>
51
#include <drizzled/item/int.h>
52
#include <drizzled/item/decimal.h>
53
#include <drizzled/item/float.h>
54
#include <drizzled/item/null.h>
1215.1.6 by stewart at flamingspork
[patch 06/17] Dont store TIMESTAMP length in proto. Always the same (max string length), so just set it on load instead.
55
#include <drizzled/temporal.h>
982.1.11 by Padraig O'Sullivan
Reverted my changes for replacing Bitmap<> for the moment. Going to fix up
56
1532.1.1 by Brian Aker
Merge of change to flip table instance to be share instance
57
#include "drizzled/table_share_instance.h"
1502.1.19 by Brian Aker
Adds concept of table owned TableShare.
58
1130.3.9 by Monty Taylor
Wrapped table_proto_write.cc code in namespace drizzled.
59
#include "drizzled/table_proto.h"
1095.3.3 by Stewart Smith
move drizzle_proto_exists and drizzle_read_table_proto out of unireg.h and into table_proto.h
60
534 by Monty Taylor
Removed stxnmov. Also deleted strstr which had already been removed.
61
using namespace std;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
62
63
namespace drizzled
64
{
534 by Monty Taylor
Removed stxnmov. Also deleted strstr which had already been removed.
65
1241.9.31 by Monty Taylor
Moved global pthread variables into their own header.
66
extern pid_t current_pid;
1241.9.32 by Monty Taylor
Moved global myisam and heap pointers out of server_includes.
67
extern plugin::StorageEngine *heap_engine;
68
extern plugin::StorageEngine *myisam_engine;
1241.9.31 by Monty Taylor
Moved global pthread variables into their own header.
69
1208.3.2 by brian
Update for Cursor renaming.
70
/* Functions defined in this cursor */
1 by brian
clean slate
71
1000.1.3 by Brian Aker
Renamed TABLE_SHARE to TableShare
72
void open_table_error(TableShare *share, int error, int db_errno,
1 by brian
clean slate
73
                      myf errortype, int errarg);
74
75
/*************************************************************************/
76
1502.1.3 by Brian Aker
Cleanup to use references.
77
// @note this should all be the destructor
78
int Table::delete_table(bool free_share)
1 by brian
clean slate
79
{
1046.1.6 by Brian Aker
Formatting/style cleanup.
80
  int error= 0;
1 by brian
clean slate
81
793 by Brian Aker
Pass through on refactoring functions to clases.
82
  if (db_stat)
1208.3.2 by brian
Update for Cursor renaming.
83
    error= cursor->close();
793 by Brian Aker
Pass through on refactoring functions to clases.
84
  free((char*) alias);
85
  alias= NULL;
86
  if (field)
1 by brian
clean slate
87
  {
793 by Brian Aker
Pass through on refactoring functions to clases.
88
    for (Field **ptr=field ; *ptr ; ptr++)
1502.1.13 by Brian Aker
Next bit of TableShare to c++.
89
    {
1 by brian
clean slate
90
      delete *ptr;
1502.1.13 by Brian Aker
Next bit of TableShare to c++.
91
    }
793 by Brian Aker
Pass through on refactoring functions to clases.
92
    field= 0;
1 by brian
clean slate
93
  }
1208.3.2 by brian
Update for Cursor renaming.
94
  delete cursor;
95
  cursor= 0;				/* For easier errorchecking */
1532.1.14 by Brian Aker
We no longer use alloc for placeholders (due to HASH I didn't use a
96
1 by brian
clean slate
97
  if (free_share)
98
  {
1608.2.3 by Brian Aker
Encapsulate type for TableShare.
99
    if (s->getType() == message::Table::STANDARD)
1502.1.13 by Brian Aker
Next bit of TableShare to c++.
100
    {
1093.6.1 by Brian Aker
Refactor TableShare has to be behind class.
101
      TableShare::release(s);
1502.1.13 by Brian Aker
Next bit of TableShare to c++.
102
    }
1 by brian
clean slate
103
    else
1502.1.13 by Brian Aker
Next bit of TableShare to c++.
104
    {
1502.1.20 by Brian Aker
Folding the destructor into the object.
105
      delete s;
1502.1.13 by Brian Aker
Next bit of TableShare to c++.
106
    }
107
108
    s= NULL;
1 by brian
clean slate
109
  }
1487 by Brian Aker
More updates for memory::Root
110
  mem_root.free_root(MYF(0));
793 by Brian Aker
Pass through on refactoring functions to clases.
111
112
  return error;
1 by brian
clean slate
113
}
114
115
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
116
void Table::resetTable(Session *session,
117
                       TableShare *share,
118
                       uint32_t db_stat_arg)
119
{
120
  s= share;
121
  field= NULL;
122
123
  cursor= NULL;
124
  next= NULL;
125
  prev= NULL;
126
127
  read_set= NULL;
128
  write_set= NULL;
129
130
  tablenr= 0;
131
  db_stat= db_stat_arg;
132
133
  in_use= session;
134
  record[0]= (unsigned char *) NULL;
135
  record[1]= (unsigned char *) NULL;
136
1672.3.5 by Brian Aker
This replaces the allocation we do for insert/update.
137
  insert_values.clear();
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
138
  key_info= NULL;
139
  next_number_field= NULL;
140
  found_next_number_field= NULL;
141
  timestamp_field= NULL;
142
143
  pos_in_table_list= NULL;
144
  group= NULL;
145
  alias= NULL;
146
  null_flags= NULL;
147
148
  lock_position= 0;
149
  lock_data_start= 0;
150
  lock_count= 0;
151
  used_fields= 0;
152
  status= 0;
153
  derived_select_number= 0;
154
  current_lock= F_UNLCK;
155
  copy_blobs= false;
156
157
  maybe_null= false;
158
159
  null_row= false;
160
161
  force_index= false;
162
  distinct= false;
163
  const_table= false;
164
  no_rows= false;
165
  key_read= false;
166
  no_keyread= false;
167
168
  open_placeholder= false;
169
  locked_by_name= false;
170
  no_cache= false;
171
172
  auto_increment_field_not_null= false;
173
  alias_name_used= false;
174
175
  query_id= 0;
176
  quick_condition_rows= 0;
177
178
  timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
179
  map= 0;
180
181
  reginfo.reset();
182
183
  covering_keys.reset();
184
185
  quick_keys.reset();
186
  merge_keys.reset();
187
188
  keys_in_use_for_query.reset();
189
  keys_in_use_for_group_by.reset();
190
  keys_in_use_for_order_by.reset();
191
1273.1.1 by Jay Pipes
* Changes Session::warn_id to Session::warn_query_id
192
  memset(quick_rows, 0, sizeof(ha_rows) * MAX_KEY);
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
193
  memset(const_key_parts, 0, sizeof(ha_rows) * MAX_KEY);
194
195
  memset(quick_key_parts, 0, sizeof(unsigned int) * MAX_KEY);
196
  memset(quick_n_ranges, 0, sizeof(unsigned int) * MAX_KEY);
197
1253.1.6 by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace.
198
  memory::init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
199
}
200
201
202
1 by brian
clean slate
203
/* Deallocate temporary blob storage */
204
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
205
void free_blobs(register Table *table)
1 by brian
clean slate
206
{
482 by Brian Aker
Remove uint.
207
  uint32_t *ptr, *end;
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
208
  for (ptr= table->getBlobField(), end=ptr + table->sizeBlobFields();
1 by brian
clean slate
209
       ptr != end ;
210
       ptr++)
1578.2.16 by Brian Aker
Merge in change to getTable() to private the field objects.
211
  {
212
    ((Field_blob*) table->getField(*ptr))->free();
213
  }
1 by brian
clean slate
214
}
215
216
1253.1.3 by Monty Taylor
MEM_ROOT == memory::Root
217
TYPELIB *typelib(memory::Root *mem_root, List<String> &strings)
1 by brian
clean slate
218
{
1485 by Brian Aker
Updates to confine memroot
219
  TYPELIB *result= (TYPELIB*) mem_root->alloc_root(sizeof(TYPELIB));
1 by brian
clean slate
220
  if (!result)
221
    return 0;
1101.3.1 by Nathan Williams
Reverted CreateField::interval_list to a List<String>. Fixes memory leaks I introduced by converting it to a vector in branch listed below.
222
  result->count= strings.elements;
1052.2.1 by Nathan Williams
Converted Create_field::interval_list to a std::list<String*>.
223
  result->name= "";
895 by Brian Aker
Completion (?) of uint conversion.
224
  uint32_t nbytes= (sizeof(char*) + sizeof(uint32_t)) * (result->count + 1);
1052.2.1 by Nathan Williams
Converted Create_field::interval_list to a std::list<String*>.
225
  
1485 by Brian Aker
Updates to confine memroot
226
  if (!(result->type_names= (const char**) mem_root->alloc_root(nbytes)))
1 by brian
clean slate
227
    return 0;
1052.2.1 by Nathan Williams
Converted Create_field::interval_list to a std::list<String*>.
228
    
1 by brian
clean slate
229
  result->type_lengths= (uint*) (result->type_names + result->count + 1);
1052.2.1 by Nathan Williams
Converted Create_field::interval_list to a std::list<String*>.
230
1101.3.1 by Nathan Williams
Reverted CreateField::interval_list to a List<String>. Fixes memory leaks I introduced by converting it to a vector in branch listed below.
231
  List_iterator<String> it(strings);
232
  String *tmp;
233
  for (uint32_t i= 0; (tmp= it++); i++)
1 by brian
clean slate
234
  {
1101.3.1 by Nathan Williams
Reverted CreateField::interval_list to a List<String>. Fixes memory leaks I introduced by converting it to a vector in branch listed below.
235
    result->type_names[i]= tmp->ptr();
236
    result->type_lengths[i]= tmp->length();
1 by brian
clean slate
237
  }
1052.2.1 by Nathan Williams
Converted Create_field::interval_list to a std::list<String*>.
238
239
  result->type_names[result->count]= 0;   // End marker
1 by brian
clean slate
240
  result->type_lengths[result->count]= 0;
1052.2.1 by Nathan Williams
Converted Create_field::interval_list to a std::list<String*>.
241
1 by brian
clean slate
242
  return result;
243
}
244
245
	/* Check that the integer is in the internal */
246
247
int set_zone(register int nr, int min_zone, int max_zone)
248
{
249
  if (nr<=min_zone)
250
    return (min_zone);
251
  if (nr>=max_zone)
252
    return (max_zone);
253
  return (nr);
254
} /* set_zone */
255
256
	/* Adjust number to next larger disk buffer */
257
258
ulong next_io_size(register ulong pos)
259
{
260
  register ulong offset;
261
  if ((offset= pos & (IO_SIZE-1)))
262
    return pos-offset+IO_SIZE;
263
  return pos;
264
} /* next_io_size */
265
266
267
/*
268
  Store an SQL quoted string.
269
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
270
  SYNOPSIS
1 by brian
clean slate
271
    append_unescaped()
272
    res		result String
273
    pos		string to be quoted
274
    length	it's length
275
276
  NOTE
277
    This function works correctly with utf8 or single-byte charset strings.
278
    May fail with some multibyte charsets though.
279
*/
280
482 by Brian Aker
Remove uint.
281
void append_unescaped(String *res, const char *pos, uint32_t length)
1 by brian
clean slate
282
{
283
  const char *end= pos+length;
284
  res->append('\'');
285
286
  for (; pos != end ; pos++)
287
  {
482 by Brian Aker
Remove uint.
288
    uint32_t mblen;
1 by brian
clean slate
289
    if (use_mb(default_charset_info) &&
290
        (mblen= my_ismbchar(default_charset_info, pos, end)))
291
    {
292
      res->append(pos, mblen);
1638.6.2 by Stewart Smith
fix multibyte comments in SHOW CREATE TABLE. Was a simple off-by-one bug.
293
      pos+= mblen - 1;
814.1.1 by Jay Pipes
Fix for Bug 314502 "show create table crashes with multi-byte character in enum description"
294
      if (pos >= end)
295
        break;
814.1.2 by Jay Pipes
Forgot to add back the continue in case of multi-byte character not exceeding the end of string buffer.
296
      continue;
1 by brian
clean slate
297
    }
298
299
    switch (*pos) {
300
    case 0:				/* Must be escaped for 'mysql' */
301
      res->append('\\');
302
      res->append('0');
303
      break;
304
    case '\n':				/* Must be escaped for logs */
305
      res->append('\\');
306
      res->append('n');
307
      break;
308
    case '\r':
309
      res->append('\\');		/* This gives better readability */
310
      res->append('r');
311
      break;
312
    case '\\':
313
      res->append('\\');		/* Because of the sql syntax */
314
      res->append('\\');
315
      break;
316
    case '\'':
317
      res->append('\'');		/* Because of the sql syntax */
318
      res->append('\'');
319
      break;
320
    default:
321
      res->append(*pos);
322
      break;
323
    }
324
  }
325
  res->append('\'');
326
}
327
328
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
329
/*
330
  Set up column usage bitmaps for a temporary table
331
332
  IMPLEMENTATION
333
    For temporary tables, we need one bitmap with all columns set and
334
    a tmp_set bitmap to be used by things like filesort.
335
*/
336
1005.2.3 by Monty Taylor
Further reversion of P.
337
void Table::setup_tmp_table_column_bitmaps(unsigned char *bitmaps)
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
338
{
1578.2.10 by Brian Aker
keys and fields partial encapsulation.
339
  uint32_t field_count= s->sizeFields();
1005.2.3 by Monty Taylor
Further reversion of P.
340
1103.6.3 by Padraig O'Sullivan
Fixing up more calls to the old bitmap API.
341
  this->def_read_set.init((my_bitmap_map*) bitmaps, field_count);
342
  this->tmp_set.init((my_bitmap_map*) (bitmaps+ bitmap_buffer_size(field_count)), field_count);
1005.2.3 by Monty Taylor
Further reversion of P.
343
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
344
  /* write_set and all_set are copies of read_set */
345
  def_write_set= def_read_set;
346
  s->all_set= def_read_set;
1574 by Brian Aker
Rollup patch for hiding tableshare.
347
  this->getMutableShare()->all_set.setAll();
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
348
  default_column_bitmaps();
349
}
350
351
673.2.1 by Toru Maesaka
First pass of replacing MySQL's strxmov with libc alternatives
352
int rename_file_ext(const char * from,const char * to,const char * ext)
1 by brian
clean slate
353
{
673.2.1 by Toru Maesaka
First pass of replacing MySQL's strxmov with libc alternatives
354
  string from_s, to_s;
355
356
  from_s.append(from);
357
  from_s.append(ext);
358
  to_s.append(to);
359
  to_s.append(ext);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
360
  return (internal::my_rename(from_s.c_str(),to_s.c_str(),MYF(MY_WME)));
1 by brian
clean slate
361
}
362
363
/*
1273 by Brian Aker
Revert db patch.
364
  Check if database name is valid
365
366
  SYNPOSIS
367
    check_db_name()
368
    org_name		Name of database and length
369
370
  RETURN
1415 by Brian Aker
Mass overhaul to use schema_identifier.
371
    false error
372
    true ok
1273 by Brian Aker
Revert db patch.
373
*/
374
1578.4.11 by Brian Aker
PAss through the code removing current_session
375
bool check_db_name(Session *session, SchemaIdentifier &schema_identifier)
1273 by Brian Aker
Revert db patch.
376
{
1578.4.11 by Brian Aker
PAss through the code removing current_session
377
  if (not plugin::Authorization::isAuthorized(session->getSecurityContext(), schema_identifier))
1317.2.7 by Monty Taylor
Prevent users from attempting to access schemas that he is not authorized to
378
  {
1415 by Brian Aker
Mass overhaul to use schema_identifier.
379
    return false;
1317.2.7 by Monty Taylor
Prevent users from attempting to access schemas that he is not authorized to
380
  }
381
1415 by Brian Aker
Mass overhaul to use schema_identifier.
382
  return schema_identifier.isValid();
1273 by Brian Aker
Revert db patch.
383
}
384
385
/*
1 by brian
clean slate
386
  Allow anything as a table name, as long as it doesn't contain an
387
  ' ' at the end
388
  returns 1 on error
389
*/
482 by Brian Aker
Remove uint.
390
bool check_table_name(const char *name, uint32_t length)
1 by brian
clean slate
391
{
392
  if (!length || length > NAME_LEN || name[length - 1] == ' ')
393
    return 1;
394
  LEX_STRING ident;
395
  ident.str= (char*) name;
396
  ident.length= length;
397
  return check_identifier_name(&ident);
398
}
399
400
401
/*
402
  Eventually, a "length" argument should be added
403
  to this function, and the inner loop changed to
404
  check_identifier_name() call.
405
*/
406
bool check_column_name(const char *name)
407
{
482 by Brian Aker
Remove uint.
408
  uint32_t name_length= 0;  // name length in symbols
51.1.70 by Jay Pipes
Removed/replaced DBUG symbols and removed sql_test.cc from Makefile
409
  bool last_char_is_space= true;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
410
1 by brian
clean slate
411
  while (*name)
412
  {
413
    last_char_is_space= my_isspace(system_charset_info, *name);
414
    if (use_mb(system_charset_info))
415
    {
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
416
      int len=my_ismbchar(system_charset_info, name,
1 by brian
clean slate
417
                          name+system_charset_info->mbmaxlen);
418
      if (len)
419
      {
420
        if (len > 3) /* Disallow non-BMP characters */
421
          return 1;
422
        name += len;
423
        name_length++;
424
        continue;
425
      }
426
    }
427
    /*
428
      NAMES_SEP_CHAR is used in FRM format to separate SET and ENUM values.
429
      It is defined as 0xFF, which is a not valid byte in utf8.
430
      This assert is to catch use of this byte if we decide to
431
      use non-utf8 as system_character_set.
432
    */
51.2.1 by Patrick Galbraith
Removed DBUG_PRINTs, DBUG_ASSERTs, DBUG_EXECUTE_IFs from
433
    assert(*name != NAMES_SEP_CHAR);
1 by brian
clean slate
434
    name++;
435
    name_length++;
436
  }
437
  /* Error if empty or too long column name */
895 by Brian Aker
Completion (?) of uint conversion.
438
  return last_char_is_space || (uint32_t) name_length > NAME_CHAR_LEN;
1 by brian
clean slate
439
}
440
441
442
/*****************************************************************************
443
  Functions to handle column usage bitmaps (read_set, write_set etc...)
444
*****************************************************************************/
445
446
/* Reset all columns bitmaps */
447
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
448
void Table::clear_column_bitmaps()
1 by brian
clean slate
449
{
450
  /*
1005.2.3 by Monty Taylor
Further reversion of P.
451
    Reset column read/write usage. It's identical to:
452
    bitmap_clear_all(&table->def_read_set);
453
    bitmap_clear_all(&table->def_write_set);
1 by brian
clean slate
454
  */
1103.6.3 by Padraig O'Sullivan
Fixing up more calls to the old bitmap API.
455
  def_read_set.clearAll();
456
  def_write_set.clearAll();
1 by brian
clean slate
457
  column_bitmaps_set(&def_read_set, &def_write_set);
458
}
459
460
461
/*
1183.1.2 by Brian Aker
Rename of handler to Cursor. You would not believe how long I have wanted
462
  Tell Cursor we are going to call position() and rnd_pos() later.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
463
1 by brian
clean slate
464
  NOTES:
465
  This is needed for handlers that uses the primary key to find the
466
  row. In this case we have to extend the read bitmap with the primary
467
  key fields.
468
*/
469
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
470
void Table::prepare_for_position()
1 by brian
clean slate
471
{
1005.2.1 by Monty Taylor
Reverted a crap-ton of padraig's work.
472
1233.1.4 by Brian Aker
Added:
473
  if ((cursor->getEngine()->check_flag(HTON_BIT_PRIMARY_KEY_IN_READ_INDEX)) &&
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
474
      s->hasPrimaryKey())
1 by brian
clean slate
475
  {
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
476
    mark_columns_used_by_index_no_reset(s->getPrimaryKey());
1 by brian
clean slate
477
  }
51.1.1 by Jay Pipes
Merged PatG's removal of various DBUG stuff with still keeping DBUG_ASSERT calls since they seem to be breaking test runs
478
  return;
1 by brian
clean slate
479
}
480
481
482
/*
483
  Mark that only fields from one key is used
484
485
  NOTE:
486
    This changes the bitmap to use the tmp bitmap
487
    After this, you can't access any other columns in the table until
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
488
    bitmaps are reset, for example with Table::clear_column_bitmaps()
489
    or Table::restore_column_maps_after_mark_index()
1 by brian
clean slate
490
*/
491
482 by Brian Aker
Remove uint.
492
void Table::mark_columns_used_by_index(uint32_t index)
1 by brian
clean slate
493
{
1103.6.2 by Padraig O'Sullivan
Removing references to MY_BITMAP throughout the code base and updating calls
494
  MyBitmap *bitmap= &tmp_set;
1 by brian
clean slate
495
1208.3.2 by brian
Update for Cursor renaming.
496
  (void) cursor->extra(HA_EXTRA_KEYREAD);
1103.6.2 by Padraig O'Sullivan
Removing references to MY_BITMAP throughout the code base and updating calls
497
  bitmap->clearAll();
1 by brian
clean slate
498
  mark_columns_used_by_index_no_reset(index, bitmap);
499
  column_bitmaps_set(bitmap, bitmap);
51.1.1 by Jay Pipes
Merged PatG's removal of various DBUG stuff with still keeping DBUG_ASSERT calls since they seem to be breaking test runs
500
  return;
1 by brian
clean slate
501
}
502
503
504
/*
505
  Restore to use normal column maps after key read
506
507
  NOTES
508
    This reverse the change done by mark_columns_used_by_index
509
510
  WARNING
511
    For this to work, one must have the normal table maps in place
512
    when calling mark_columns_used_by_index
513
*/
514
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
515
void Table::restore_column_maps_after_mark_index()
1 by brian
clean slate
516
{
517
518
  key_read= 0;
1208.3.2 by brian
Update for Cursor renaming.
519
  (void) cursor->extra(HA_EXTRA_NO_KEYREAD);
1 by brian
clean slate
520
  default_column_bitmaps();
1005.2.1 by Monty Taylor
Reverted a crap-ton of padraig's work.
521
  return;
1 by brian
clean slate
522
}
523
524
525
/*
526
  mark columns used by key, but don't reset other fields
527
*/
528
1003.1.7 by Brian Aker
Add mark_columns_used_by_index_no_reset() with just index (assumes read_set
529
void Table::mark_columns_used_by_index_no_reset(uint32_t index)
530
{
531
    mark_columns_used_by_index_no_reset(index, read_set);
532
}
533
482 by Brian Aker
Remove uint.
534
void Table::mark_columns_used_by_index_no_reset(uint32_t index,
1103.6.2 by Padraig O'Sullivan
Removing references to MY_BITMAP throughout the code base and updating calls
535
                                                MyBitmap *bitmap)
1 by brian
clean slate
536
{
1534 by Brian Aker
Remove of KeyPartInfo
537
  KeyPartInfo *key_part= key_info[index].key_part;
538
  KeyPartInfo *key_part_end= (key_part +
1 by brian
clean slate
539
                                key_info[index].key_parts);
540
  for (;key_part != key_part_end; key_part++)
1103.6.2 by Padraig O'Sullivan
Removing references to MY_BITMAP throughout the code base and updating calls
541
    bitmap->setBit(key_part->fieldnr-1);
1 by brian
clean slate
542
}
543
544
545
/*
546
  Mark auto-increment fields as used fields in both read and write maps
547
548
  NOTES
549
    This is needed in insert & update as the auto-increment field is
550
    always set and sometimes read.
551
*/
552
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
553
void Table::mark_auto_increment_column()
1 by brian
clean slate
554
{
51.2.1 by Patrick Galbraith
Removed DBUG_PRINTs, DBUG_ASSERTs, DBUG_EXECUTE_IFs from
555
  assert(found_next_number_field);
1 by brian
clean slate
556
  /*
557
    We must set bit in read set as update_auto_increment() is using the
558
    store() to check overflow of auto_increment values
559
  */
1005.2.12 by Monty Taylor
Moved some things to the API.
560
  setReadSet(found_next_number_field->field_index);
561
  setWriteSet(found_next_number_field->field_index);
1 by brian
clean slate
562
  if (s->next_number_keypart)
1003.1.7 by Brian Aker
Add mark_columns_used_by_index_no_reset() with just index (assumes read_set
563
    mark_columns_used_by_index_no_reset(s->next_number_index);
1 by brian
clean slate
564
}
565
566
567
/*
568
  Mark columns needed for doing an delete of a row
569
570
  DESCRIPTON
571
    Some table engines don't have a cursor on the retrieve rows
572
    so they need either to use the primary key or all columns to
573
    be able to delete a row.
574
575
    If the engine needs this, the function works as follows:
576
    - If primary key exits, mark the primary key columns to be read.
577
    - If not, mark all columns to be read
578
579
    If the engine has HA_REQUIRES_KEY_COLUMNS_FOR_DELETE, we will
580
    mark all key columns as 'to-be-read'. This allows the engine to
581
    loop over the given record to find all keys and doesn't have to
582
    retrieve the row again.
583
*/
584
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
585
void Table::mark_columns_needed_for_delete()
1 by brian
clean slate
586
{
1003.1.8 by Brian Aker
The call for setting columns was backwards (engines with certain callers
587
  /*
1183.1.2 by Brian Aker
Rename of handler to Cursor. You would not believe how long I have wanted
588
    If the Cursor has no cursor capabilites, or we have row-based
1003.1.8 by Brian Aker
The call for setting columns was backwards (engines with certain callers
589
    replication active for the current statement, we have to read
590
    either the primary key, the hidden primary key or all columns to
591
    be able to do an delete
592
593
  */
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
594
  if (not s->hasPrimaryKey())
1003.1.8 by Brian Aker
The call for setting columns was backwards (engines with certain callers
595
  {
596
    /* fallback to use all columns in the table to identify row */
597
    use_all_columns();
598
    return;
599
  }
600
  else
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
601
    mark_columns_used_by_index_no_reset(s->getPrimaryKey());
1003.1.8 by Brian Aker
The call for setting columns was backwards (engines with certain callers
602
603
  /* If we the engine wants all predicates we mark all keys */
1233.1.7 by Brian Aker
Final table flag removal.
604
  if (cursor->getEngine()->check_flag(HTON_BIT_REQUIRES_KEY_COLUMNS_FOR_DELETE))
1 by brian
clean slate
605
  {
606
    Field **reg_field;
607
    for (reg_field= field ; *reg_field ; reg_field++)
608
    {
609
      if ((*reg_field)->flags & PART_KEY_FLAG)
1005.2.12 by Monty Taylor
Moved some things to the API.
610
        setReadSet((*reg_field)->field_index);
1 by brian
clean slate
611
    }
612
  }
613
}
614
615
616
/*
617
  Mark columns needed for doing an update of a row
618
619
  DESCRIPTON
620
    Some engines needs to have all columns in an update (to be able to
621
    build a complete row). If this is the case, we mark all not
622
    updated columns to be read.
623
624
    If this is no the case, we do like in the delete case and mark
625
    if neeed, either the primary key column or all columns to be read.
626
    (see mark_columns_needed_for_delete() for details)
627
1233.1.7 by Brian Aker
Final table flag removal.
628
    If the engine has HTON_BIT_REQUIRES_KEY_COLUMNS_FOR_DELETE, we will
1 by brian
clean slate
629
    mark all USED key columns as 'to-be-read'. This allows the engine to
630
    loop over the given record to find all changed keys and doesn't have to
631
    retrieve the row again.
632
*/
633
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
634
void Table::mark_columns_needed_for_update()
1 by brian
clean slate
635
{
1003.1.8 by Brian Aker
The call for setting columns was backwards (engines with certain callers
636
  /*
1183.1.2 by Brian Aker
Rename of handler to Cursor. You would not believe how long I have wanted
637
    If the Cursor has no cursor capabilites, or we have row-based
1003.1.8 by Brian Aker
The call for setting columns was backwards (engines with certain callers
638
    logging active for the current statement, we have to read either
639
    the primary key, the hidden primary key or all columns to be
640
    able to do an update
641
  */
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
642
  if (not s->hasPrimaryKey())
1003.1.8 by Brian Aker
The call for setting columns was backwards (engines with certain callers
643
  {
644
    /* fallback to use all columns in the table to identify row */
645
    use_all_columns();
646
    return;
647
  }
648
  else
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
649
    mark_columns_used_by_index_no_reset(s->getPrimaryKey());
1003.1.8 by Brian Aker
The call for setting columns was backwards (engines with certain callers
650
1233.1.7 by Brian Aker
Final table flag removal.
651
  if (cursor->getEngine()->check_flag(HTON_BIT_REQUIRES_KEY_COLUMNS_FOR_DELETE))
1 by brian
clean slate
652
  {
653
    /* Mark all used key columns for read */
654
    Field **reg_field;
655
    for (reg_field= field ; *reg_field ; reg_field++)
656
    {
657
      /* Merge keys is all keys that had a column refered to in the query */
1005.2.6 by Monty Taylor
Re-added bitset<> as a replacement for Bitmap<>
658
      if (is_overlapping(merge_keys, (*reg_field)->part_of_key))
1005.2.12 by Monty Taylor
Moved some things to the API.
659
        setReadSet((*reg_field)->field_index);
1 by brian
clean slate
660
    }
661
  }
798.2.21 by Brian Aker
More work on binlog.poen
662
1 by brian
clean slate
663
}
664
665
666
/*
1183.1.2 by Brian Aker
Rename of handler to Cursor. You would not believe how long I have wanted
667
  Mark columns the Cursor needs for doing an insert
1 by brian
clean slate
668
669
  For now, this is used to mark fields used by the trigger
670
  as changed.
671
*/
672
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
673
void Table::mark_columns_needed_for_insert()
1 by brian
clean slate
674
{
675
  if (found_next_number_field)
676
    mark_auto_increment_column();
383.7.1 by Andrey Zhakov
Initial submit of code and tests
677
}
678
1 by brian
clean slate
679
680
481 by Brian Aker
Remove all of uchar.
681
size_t Table::max_row_length(const unsigned char *data)
1 by brian
clean slate
682
{
354 by Brian Aker
Refactor of Table methods.
683
  size_t length= getRecordLength() + 2 * sizeFields();
482 by Brian Aker
Remove uint.
684
  uint32_t *const beg= getBlobField();
685
  uint32_t *const end= beg + sizeBlobFields();
1 by brian
clean slate
686
482 by Brian Aker
Remove uint.
687
  for (uint32_t *ptr= beg ; ptr != end ; ++ptr)
1 by brian
clean slate
688
  {
354 by Brian Aker
Refactor of Table methods.
689
    Field_blob* const blob= (Field_blob*) field[*ptr];
481 by Brian Aker
Remove all of uchar.
690
    length+= blob->get_length((const unsigned char*)
1672.3.6 by Brian Aker
First pass in encapsulating row
691
                              (data + blob->offset(getInsertRecord()))) +
1 by brian
clean slate
692
      HA_KEY_BLOB_LENGTH;
693
  }
694
  return length;
695
}
696
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
697
/****************************************************************************
698
 Functions for creating temporary tables.
699
****************************************************************************/
700
/**
701
  Create field for temporary table from given field.
702
1183.1.2 by Brian Aker
Rename of handler to Cursor. You would not believe how long I have wanted
703
  @param session	       Thread Cursor
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
704
  @param org_field    field from which new field will be created
705
  @param name         New field name
706
  @param table	       Temporary table
707
  @param item	       !=NULL if item->result_field should point to new field.
708
                      This is relevant for how fill_record() is going to work:
709
                      If item != NULL then fill_record() will update
710
                      the record in the original table.
711
                      If item == NULL then fill_record() will update
712
                      the temporary table
713
  @param convert_blob_length   If >0 create a varstring(convert_blob_length)
714
                               field instead of blob.
715
716
  @retval
717
    NULL		on error
718
  @retval
719
    new_created field
720
*/
721
520.1.22 by Brian Aker
Second pass of thd cleanup
722
Field *create_tmp_field_from_field(Session *session, Field *org_field,
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
723
                                   const char *name, Table *table,
482 by Brian Aker
Remove uint.
724
                                   Item_field *item, uint32_t convert_blob_length)
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
725
{
726
  Field *new_field;
727
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
728
  /*
729
    Make sure that the blob fits into a Field_varstring which has
730
    2-byte lenght.
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
731
  */
732
  if (convert_blob_length && convert_blob_length <= Field_varstring::MAX_SIZE &&
733
      (org_field->flags & BLOB_FLAG))
734
    new_field= new Field_varstring(convert_blob_length,
735
                                   org_field->maybe_null(),
1574 by Brian Aker
Rollup patch for hiding tableshare.
736
                                   org_field->field_name, table->getMutableShare(),
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
737
                                   org_field->charset());
738
  else
520.1.22 by Brian Aker
Second pass of thd cleanup
739
    new_field= org_field->new_field(session->mem_root, table,
1660.1.3 by Brian Aker
Encapsulate Table in field
740
                                    table == org_field->getTable());
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
741
  if (new_field)
742
  {
743
    new_field->init(table);
744
    new_field->orig_table= org_field->orig_table;
745
    if (item)
746
      item->result_field= new_field;
747
    else
748
      new_field->field_name= name;
749
    new_field->flags|= (org_field->flags & NO_DEFAULT_VALUE_FLAG);
750
    if (org_field->maybe_null() || (item && item->maybe_null))
751
      new_field->flags&= ~NOT_NULL_FLAG;	// Because of outer join
752
    if (org_field->type() == DRIZZLE_TYPE_VARCHAR)
1574 by Brian Aker
Rollup patch for hiding tableshare.
753
      table->getMutableShare()->db_create_options|= HA_OPTION_PACK_RECORD;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
754
    else if (org_field->type() == DRIZZLE_TYPE_DOUBLE)
755
      ((Field_double *) new_field)->not_fixed= true;
756
  }
757
  return new_field;
758
}
759
760
761
/**
762
  Create a temp table according to a field list.
763
764
  Given field pointers are changed to point at tmp_table for
765
  send_fields. The table object is self contained: it's
766
  allocated in its own memory root, as well as Field objects
767
  created for table columns.
768
  This function will replace Item_sum items in 'fields' list with
769
  corresponding Item_field items, pointing at the fields in the
770
  temporary table, unless this was prohibited by true
771
  value of argument save_sum_fields. The Item_field objects
520.1.21 by Brian Aker
THD -> Session rename
772
  are created in Session memory root.
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
773
520.1.22 by Brian Aker
Second pass of thd cleanup
774
  @param session                  thread handle
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
775
  @param param                a description used as input to create the table
776
  @param fields               list of items that will be used to define
777
                              column types of the table (also see NOTES)
778
  @param group                TODO document
779
  @param distinct             should table rows be distinct
780
  @param save_sum_fields      see NOTES
781
  @param select_options
782
  @param rows_limit
783
  @param table_alias          possible name of the temporary table that can
784
                              be used for name resolving; can be "".
785
*/
786
787
#define STRING_TOTAL_LENGTH_TO_PACK_ROWS 128
788
#define AVG_STRING_LENGTH_TO_PACK_ROWS   64
789
#define RATIO_TO_PACK_ROWS	       2
790
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
791
Table *
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
792
create_tmp_table(Session *session,Tmp_Table_Param *param,List<Item> &fields,
327.2.3 by Brian Aker
Refactoring of class Table
793
		 order_st *group, bool distinct, bool save_sum_fields,
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
794
		 uint64_t select_options, ha_rows rows_limit,
1039.1.4 by Brian Aker
Modified alias to being const.
795
		 const char *table_alias)
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
796
{
1532.1.1 by Brian Aker
Merge of change to flip table instance to be share instance
797
  memory::Root *mem_root_save;
798
  Table *table;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
799
  uint	i,field_count,null_count,null_pack_length;
482 by Brian Aker
Remove uint.
800
  uint32_t  copy_func_count= param->func_count;
801
  uint32_t  hidden_null_count, hidden_null_pack_length, hidden_field_count;
802
  uint32_t  blob_count,group_null_items, string_count;
803
  uint32_t fieldnr= 0;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
804
  ulong reclength, string_total_length;
1277.2.1 by Brian Aker
Remove open tables, other assorted code bits (cleanup on style)
805
  bool  using_unique_constraint= false;
806
  bool  use_packed_rows= true;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
807
  bool  not_all_columns= !(select_options & TMP_TABLE_ALL_COLUMNS);
1005.2.1 by Monty Taylor
Reverted a crap-ton of padraig's work.
808
  unsigned char	*pos, *group_buff, *bitmaps;
481 by Brian Aker
Remove all of uchar.
809
  unsigned char *null_flags;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
810
  Field **reg_field, **from_field, **default_field;
1052.2.2 by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards.
811
  CopyField *copy= 0;
1535 by Brian Aker
Rename of KEY to KeyInfo
812
  KeyInfo *keyinfo;
1534 by Brian Aker
Remove of KeyPartInfo
813
  KeyPartInfo *key_part_info;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
814
  Item **copy_func;
815
  MI_COLUMNDEF *recinfo;
482 by Brian Aker
Remove uint.
816
  uint32_t total_uneven_bit_length= 0;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
817
  bool force_copy_fields= param->force_copy_fields;
1116.1.1 by Brian Aker
Fix for Stewart's patch (includes hack to solve MAX rows problem).
818
  uint64_t max_rows= 0;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
819
1689.5.1 by Joseph Daly
remove increment calls
820
  session->status_var.created_tmp_tables++;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
821
822
  if (group)
823
  {
1277.2.1 by Brian Aker
Remove open tables, other assorted code bits (cleanup on style)
824
    if (! param->quick_group)
1487.1.1 by Brian Aker
There is room for improvement around this. We should be using rows as well
825
    {
1046.1.6 by Brian Aker
Formatting/style cleanup.
826
      group= 0;					// Can't use group key
1487.1.1 by Brian Aker
There is room for improvement around this. We should be using rows as well
827
    }
327.2.3 by Brian Aker
Refactoring of class Table
828
    else for (order_st *tmp=group ; tmp ; tmp=tmp->next)
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
829
    {
830
      /*
831
        marker == 4 means two things:
832
        - store NULLs in the key, and
833
        - convert BIT fields to 64-bit long, needed because MEMORY tables
834
          can't index BIT fields.
835
      */
836
      (*tmp->item)->marker= 4;
837
      if ((*tmp->item)->max_length >= CONVERT_IF_BIGGER_TO_BLOB)
1277.2.1 by Brian Aker
Remove open tables, other assorted code bits (cleanup on style)
838
	using_unique_constraint= true;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
839
    }
840
    if (param->group_length >= MAX_BLOB_WIDTH)
1277.2.1 by Brian Aker
Remove open tables, other assorted code bits (cleanup on style)
841
      using_unique_constraint= true;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
842
    if (group)
1046.1.6 by Brian Aker
Formatting/style cleanup.
843
      distinct= 0;				// Can't use distinct
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
844
  }
845
846
  field_count=param->field_count+param->func_count+param->sum_func_count;
847
  hidden_field_count=param->hidden_field_count;
848
849
  /*
850
    When loose index scan is employed as access method, it already
851
    computes all groups and the result of all aggregate functions. We
852
    make space for the items of the aggregate function in the list of
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
853
    functions Tmp_Table_Param::items_to_copy, so that the values of
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
854
    these items are stored in the temporary table.
855
  */
856
  if (param->precomputed_group_by)
1532.1.7 by Brian Aker
Fix for non-portable vastart usage.
857
  {
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
858
    copy_func_count+= param->sum_func_count;
1532.1.7 by Brian Aker
Fix for non-portable vastart usage.
859
  }
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
860
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
861
  TableShareInstance *share= session->getTemporaryShare(message::Table::INTERNAL); // This will not go into the tableshare cache, so no key is used.
1532.1.1 by Brian Aker
Merge of change to flip table instance to be share instance
862
1578.2.11 by Brian Aker
Use the Fields generated from share for Table.
863
  if (not share->getMemRoot()->multi_alloc_root(0,
1532.1.7 by Brian Aker
Fix for non-portable vastart usage.
864
                                                &default_field, sizeof(Field*) * (field_count),
865
                                                &from_field, sizeof(Field*)*field_count,
866
                                                &copy_func, sizeof(*copy_func)*(copy_func_count+1),
867
                                                &param->keyinfo, sizeof(*param->keyinfo),
868
                                                &key_part_info, sizeof(*key_part_info)*(param->group_parts+1),
869
                                                &param->start_recinfo, sizeof(*param->recinfo)*(field_count*2+4),
870
                                                &group_buff, (group && ! using_unique_constraint ?
871
                                                              param->group_length : 0),
872
                                                &bitmaps, bitmap_buffer_size(field_count)*2,
873
                                                NULL))
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
874
  {
971.6.11 by Eric Day
Removed purecov messages.
875
    return NULL;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
876
  }
1052.2.2 by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards.
877
  /* CopyField belongs to Tmp_Table_Param, allocate it in Session mem_root */
878
  if (!(param->copy_field= copy= new (session->mem_root) CopyField[field_count]))
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
879
  {
971.6.11 by Eric Day
Removed purecov messages.
880
    return NULL;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
881
  }
882
  param->items_to_copy= copy_func;
883
  /* make table according to fields */
884
1532.1.1 by Brian Aker
Merge of change to flip table instance to be share instance
885
  table= share->getTable();
886
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
887
  memset(default_field, 0, sizeof(Field*) * (field_count));
888
  memset(from_field, 0, sizeof(Field*)*field_count);
889
520.1.22 by Brian Aker
Second pass of thd cleanup
890
  mem_root_save= session->mem_root;
1532.1.10 by Brian Aker
Encapsulation of mem_root for session/this switches the creation of new_path
891
  session->mem_root= table->getMemRoot();
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
892
1578.2.11 by Brian Aker
Use the Fields generated from share for Table.
893
  share->setFields(field_count+1);
1578.2.16 by Brian Aker
Merge in change to getTable() to private the field objects.
894
  table->setFields(share->getFields(true));
895
  reg_field= share->getFields(true);
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
896
  table->alias= table_alias;
897
  table->reginfo.lock_type=TL_WRITE;	/* Will be updated */
898
  table->db_stat=HA_OPEN_KEYFILE+HA_OPEN_RNDFILE;
899
  table->map=1;
900
  table->copy_blobs= 1;
1578.6.2 by Brian Aker
Remove ha_session.
901
  assert(session);
520.1.22 by Brian Aker
Second pass of thd cleanup
902
  table->in_use= session;
1005.2.6 by Monty Taylor
Re-added bitset<> as a replacement for Bitmap<>
903
  table->quick_keys.reset();
904
  table->covering_keys.reset();
905
  table->keys_in_use_for_query.reset();
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
906
907
  table->setShare(share);
1574.1.8 by Brian Aker
Blob now allocated via vector
908
  share->blob_field.resize(field_count+1);
909
  uint32_t *blob_field= &share->blob_field[0];
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
910
  share->blob_ptr_size= portable_sizeof_char_ptr;
911
  share->db_low_byte_first=1;                // True for HEAP and MyISAM
912
  share->table_charset= param->table_charset;
1005.2.6 by Monty Taylor
Re-added bitset<> as a replacement for Bitmap<>
913
  share->keys_for_keyread.reset();
914
  share->keys_in_use.reset();
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
915
916
  /* Calculate which type of fields we will store in the temporary table */
917
918
  reclength= string_total_length= 0;
919
  blob_count= string_count= null_count= hidden_null_count= group_null_items= 0;
1046.1.6 by Brian Aker
Formatting/style cleanup.
920
  param->using_indirect_summary_function= 0;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
921
922
  List_iterator_fast<Item> li(fields);
923
  Item *item;
924
  Field **tmp_from_field=from_field;
925
  while ((item=li++))
926
  {
927
    Item::Type type=item->type();
928
    if (not_all_columns)
929
    {
930
      if (item->with_sum_func && type != Item::SUM_FUNC_ITEM)
931
      {
932
        if (item->used_tables() & OUTER_REF_TABLE_BIT)
933
          item->update_used_tables();
934
        if (type == Item::SUBSELECT_ITEM ||
935
            (item->used_tables() & ~OUTER_REF_TABLE_BIT))
936
        {
937
	  /*
938
	    Mark that the we have ignored an item that refers to a summary
939
	    function. We need to know this if someone is going to use
940
	    DISTINCT on the result.
941
	  */
942
	  param->using_indirect_summary_function=1;
943
	  continue;
944
        }
945
      }
946
      if (item->const_item() && (int) hidden_field_count <= 0)
947
        continue; // We don't have to store this
948
    }
949
    if (type == Item::SUM_FUNC_ITEM && !group && !save_sum_fields)
950
    {						/* Can't calc group yet */
1046.1.6 by Brian Aker
Formatting/style cleanup.
951
      ((Item_sum*) item)->result_field= 0;
952
      for (i= 0 ; i < ((Item_sum*) item)->arg_count ; i++)
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
953
      {
954
	Item **argp= ((Item_sum*) item)->args + i;
955
	Item *arg= *argp;
956
	if (!arg->const_item())
957
	{
958
	  Field *new_field=
520.1.22 by Brian Aker
Second pass of thd cleanup
959
            create_tmp_field(session, table, arg, arg->type(), &copy_func,
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
960
                             tmp_from_field, &default_field[fieldnr],
961
                             group != 0,not_all_columns,
1273.2.4 by Stewart Smith
remove unused parameter to create_tmp_field() - was table_cant_handle_bit_fields which was around for HEAP based temp tables.
962
                             false,
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
963
                             param->convert_blob_length);
964
	  if (!new_field)
965
	    goto err;					// Should be OOM
966
	  tmp_from_field++;
967
	  reclength+=new_field->pack_length();
968
	  if (new_field->flags & BLOB_FLAG)
969
	  {
970
	    *blob_field++= fieldnr;
971
	    blob_count++;
972
	  }
973
	  *(reg_field++)= new_field;
974
          if (new_field->real_type() == DRIZZLE_TYPE_VARCHAR)
975
          {
976
            string_count++;
977
            string_total_length+= new_field->pack_length();
978
          }
520.1.22 by Brian Aker
Second pass of thd cleanup
979
          session->mem_root= mem_root_save;
980
          session->change_item_tree(argp, new Item_field(new_field));
1532.1.15 by Brian Aker
Partial encapsulation of TableShare from Table.
981
          session->mem_root= table->getMemRoot();
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
982
	  if (!(new_field->flags & NOT_NULL_FLAG))
983
          {
984
	    null_count++;
985
            /*
986
              new_field->maybe_null() is still false, it will be
987
              changed below. But we have to setup Item_field correctly
988
            */
989
            (*argp)->maybe_null=1;
990
          }
991
          new_field->field_index= fieldnr++;
992
	}
993
      }
994
    }
995
    else
996
    {
997
      /*
998
	The last parameter to create_tmp_field() is a bit tricky:
999
1000
	We need to set it to 0 in union, to get fill_record() to modify the
1001
	temporary table.
1002
	We need to set it to 1 on multi-table-update and in select to
1003
	write rows to the temporary table.
1004
	We here distinguish between UNION and multi-table-updates by the fact
1005
	that in the later case group is set to the row pointer.
1006
      */
1273.2.4 by Stewart Smith
remove unused parameter to create_tmp_field() - was table_cant_handle_bit_fields which was around for HEAP based temp tables.
1007
      Field *new_field=
520.1.22 by Brian Aker
Second pass of thd cleanup
1008
        create_tmp_field(session, table, item, type, &copy_func,
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1009
                         tmp_from_field, &default_field[fieldnr],
1010
                         group != 0,
1011
                         !force_copy_fields &&
1046.1.6 by Brian Aker
Formatting/style cleanup.
1012
                           (not_all_columns || group != 0),
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1013
                         force_copy_fields,
1014
                         param->convert_blob_length);
1015
1016
      if (!new_field)
1017
      {
520.1.22 by Brian Aker
Second pass of thd cleanup
1018
	if (session->is_fatal_error)
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1019
	  goto err;				// Got OOM
1020
	continue;				// Some kindf of const item
1021
      }
1022
      if (type == Item::SUM_FUNC_ITEM)
1023
	((Item_sum *) item)->result_field= new_field;
1024
      tmp_from_field++;
1025
      reclength+=new_field->pack_length();
1026
      if (!(new_field->flags & NOT_NULL_FLAG))
1027
	null_count++;
1028
      if (new_field->flags & BLOB_FLAG)
1029
      {
1030
        *blob_field++= fieldnr;
1031
	blob_count++;
1032
      }
1033
      if (item->marker == 4 && item->maybe_null)
1034
      {
1035
	group_null_items++;
1036
	new_field->flags|= GROUP_FLAG;
1037
      }
1038
      new_field->field_index= fieldnr++;
1039
      *(reg_field++)= new_field;
1040
    }
1041
    if (!--hidden_field_count)
1042
    {
1043
      /*
1044
        This was the last hidden field; Remember how many hidden fields could
1045
        have null
1046
      */
1047
      hidden_null_count=null_count;
1048
      /*
1049
	We need to update hidden_field_count as we may have stored group
1050
	functions with constant arguments
1051
      */
1052
      param->hidden_field_count= fieldnr;
1053
      null_count= 0;
1054
    }
1055
  }
1578.2.16 by Brian Aker
Merge in change to getTable() to private the field objects.
1056
  assert(fieldnr == (uint32_t) (reg_field - table->getFields()));
1057
  assert(field_count >= (uint32_t) (reg_field - table->getFields()));
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1058
  field_count= fieldnr;
1059
  *reg_field= 0;
1060
  *blob_field= 0;				// End marker
1061
  share->fields= field_count;
1062
1063
  /* If result table is small; use a heap */
1064
  /* future: storage engine selection can be made dynamic? */
1487.1.1 by Brian Aker
There is room for improvement around this. We should be using rows as well
1065
  if (blob_count || using_unique_constraint || 
1066
      (session->lex->select_lex.options & SELECT_BIG_RESULT) ||
1067
      (session->lex->current_select->olap == ROLLUP_TYPE) ||
1277.2.1 by Brian Aker
Remove open tables, other assorted code bits (cleanup on style)
1068
      (select_options & (OPTION_BIG_TABLES | SELECT_SMALL_RESULT)) == OPTION_BIG_TABLES)
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1069
  {
971.1.21 by Monty Taylor
Store StorageEngine in system variables, rather than storage engine plugin.
1070
    share->storage_engine= myisam_engine;
1680.6.1 by Brian Aker
Remove call for using special new for a cursor.
1071
    table->cursor= share->db_type()->getCursor(*share);
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1072
    if (group &&
1233.1.9 by Brian Aker
Move max key stuff up to engine.
1073
	(param->group_parts > table->cursor->getEngine()->max_key_parts() ||
1074
	 param->group_length > table->cursor->getEngine()->max_key_length()))
1487.1.1 by Brian Aker
There is room for improvement around this. We should be using rows as well
1075
    {
1277.2.1 by Brian Aker
Remove open tables, other assorted code bits (cleanup on style)
1076
      using_unique_constraint= true;
1487.1.1 by Brian Aker
There is room for improvement around this. We should be using rows as well
1077
    }
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1078
  }
1079
  else
1080
  {
971.1.21 by Monty Taylor
Store StorageEngine in system variables, rather than storage engine plugin.
1081
    share->storage_engine= heap_engine;
1680.6.1 by Brian Aker
Remove call for using special new for a cursor.
1082
    table->cursor= share->db_type()->getCursor(*share);
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1083
  }
1277.2.1 by Brian Aker
Remove open tables, other assorted code bits (cleanup on style)
1084
  if (! table->cursor)
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1085
    goto err;
1086
1087
1277.2.1 by Brian Aker
Remove open tables, other assorted code bits (cleanup on style)
1088
  if (! using_unique_constraint)
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1089
    reclength+= group_null_items;	// null flag is stored separately
1090
1091
  share->blob_fields= blob_count;
1092
  if (blob_count == 0)
1093
  {
1094
    /* We need to ensure that first byte is not 0 for the delete link */
1095
    if (param->hidden_field_count)
1096
      hidden_null_count++;
1097
    else
1098
      null_count++;
1099
  }
1100
  hidden_null_pack_length=(hidden_null_count+7)/8;
1101
  null_pack_length= (hidden_null_pack_length +
1102
                     (null_count + total_uneven_bit_length + 7) / 8);
1103
  reclength+=null_pack_length;
1104
  if (!reclength)
1105
    reclength=1;				// Dummy select
1106
  /* Use packed rows if there is blobs or a lot of space to gain */
1107
  if (blob_count || ((string_total_length >= STRING_TOTAL_LENGTH_TO_PACK_ROWS) && (reclength / string_total_length <= RATIO_TO_PACK_ROWS || (string_total_length / string_count) >= AVG_STRING_LENGTH_TO_PACK_ROWS)))
1108
    use_packed_rows= 1;
1109
1578.2.8 by Brian Aker
Encapsulate record length.
1110
  share->setRecordLength(reclength);
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1111
  {
482 by Brian Aker
Remove uint.
1112
    uint32_t alloc_length=ALIGN_SIZE(reclength+MI_UNIQUE_HASH_LENGTH+1);
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1113
    share->rec_buff_length= alloc_length;
1672.3.6 by Brian Aker
First pass in encapsulating row
1114
    if (!(table->record[0]= (unsigned char*) table->alloc_root(alloc_length*2)))
1485 by Brian Aker
Updates to confine memroot
1115
    {
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1116
      goto err;
1485 by Brian Aker
Updates to confine memroot
1117
    }
1672.3.6 by Brian Aker
First pass in encapsulating row
1118
    table->record[1]= table->getInsertRecord()+alloc_length;
1574 by Brian Aker
Rollup patch for hiding tableshare.
1119
    share->resizeDefaultValues(alloc_length);
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1120
  }
1046.1.6 by Brian Aker
Formatting/style cleanup.
1121
  copy_func[0]= 0;				// End marker
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1122
  param->func_count= copy_func - param->items_to_copy;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1123
1005.2.3 by Monty Taylor
Further reversion of P.
1124
  table->setup_tmp_table_column_bitmaps(bitmaps);
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1125
1126
  recinfo=param->start_recinfo;
1672.3.6 by Brian Aker
First pass in encapsulating row
1127
  null_flags=(unsigned char*) table->getInsertRecord();
1128
  pos=table->getInsertRecord()+ null_pack_length;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1129
  if (null_pack_length)
1130
  {
1131
    memset(recinfo, 0, sizeof(*recinfo));
1132
    recinfo->type=FIELD_NORMAL;
1133
    recinfo->length=null_pack_length;
1134
    recinfo++;
1135
    memset(null_flags, 255, null_pack_length);	// Set null fields
1136
1672.3.6 by Brian Aker
First pass in encapsulating row
1137
    table->null_flags= (unsigned char*) table->getInsertRecord();
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1138
    share->null_fields= null_count+ hidden_null_count;
1139
    share->null_bytes= null_pack_length;
1140
  }
1141
  null_count= (blob_count == 0) ? 1 : 0;
1142
  hidden_field_count=param->hidden_field_count;
1578.2.16 by Brian Aker
Merge in change to getTable() to private the field objects.
1143
  for (i= 0,reg_field= table->getFields(); i < field_count; i++,reg_field++,recinfo++)
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1144
  {
1145
    Field *field= *reg_field;
482 by Brian Aker
Remove uint.
1146
    uint32_t length;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1147
    memset(recinfo, 0, sizeof(*recinfo));
1148
1149
    if (!(field->flags & NOT_NULL_FLAG))
1150
    {
1151
      if (field->flags & GROUP_FLAG && !using_unique_constraint)
1152
      {
1153
	/*
1154
	  We have to reserve one byte here for NULL bits,
1155
	  as this is updated by 'end_update()'
1156
	*/
1063.5.1 by Patrick
Fix for Centos 5.2
1157
	*pos++= '\0';				// Null is stored here
1046.1.6 by Brian Aker
Formatting/style cleanup.
1158
	recinfo->length= 1;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1159
	recinfo->type=FIELD_NORMAL;
1160
	recinfo++;
1161
	memset(recinfo, 0, sizeof(*recinfo));
1162
      }
1163
      else
1164
      {
1165
	recinfo->null_bit= 1 << (null_count & 7);
1166
	recinfo->null_pos= null_count/8;
1167
      }
1168
      field->move_field(pos,null_flags+null_count/8,
1169
			1 << (null_count & 7));
1170
      null_count++;
1171
    }
1172
    else
481 by Brian Aker
Remove all of uchar.
1173
      field->move_field(pos,(unsigned char*) 0,0);
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1174
    field->reset();
1175
1176
    /*
1177
      Test if there is a default field value. The test for ->ptr is to skip
1178
      'offset' fields generated by initalize_tables
1179
    */
1180
    if (default_field[i] && default_field[i]->ptr)
1181
    {
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1182
      /*
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1183
         default_field[i] is set only in the cases  when 'field' can
1184
         inherit the default value that is defined for the field referred
1185
         by the Item_field object from which 'field' has been created.
1186
      */
1122.2.12 by Monty Taylor
Removed the silly my_ptrdiff_t typedef.
1187
      ptrdiff_t diff;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1188
      Field *orig_field= default_field[i];
1189
      /* Get the value from default_values */
1672.3.6 by Brian Aker
First pass in encapsulating row
1190
      diff= (ptrdiff_t) (orig_field->getTable()->getDefaultValues() - orig_field->getTable()->getInsertRecord());
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1191
      orig_field->move_field_offset(diff);      // Points now at default_values
1192
      if (orig_field->is_real_null())
1193
        field->set_null();
1194
      else
1195
      {
1196
        field->set_notnull();
1197
        memcpy(field->ptr, orig_field->ptr, field->pack_length());
1198
      }
1672.3.6 by Brian Aker
First pass in encapsulating row
1199
      orig_field->move_field_offset(-diff);     // Back to getInsertRecord()
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1200
    }
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1201
1202
    if (from_field[i])
1203
    {						/* Not a table Item */
1204
      copy->set(field,from_field[i],save_sum_fields);
1205
      copy++;
1206
    }
1207
    length=field->pack_length();
1208
    pos+= length;
1209
1210
    /* Make entry for create table */
1211
    recinfo->length=length;
1212
    if (field->flags & BLOB_FLAG)
1213
      recinfo->type= (int) FIELD_BLOB;
1214
    else
1215
      recinfo->type=FIELD_NORMAL;
1216
    if (!--hidden_field_count)
1217
      null_count=(null_count+7) & ~7;		// move to next byte
1218
  }
1219
1220
  param->copy_field_end=copy;
1221
  param->recinfo=recinfo;
997.5.1 by chris
Replace macros around unireg.h, store_record,restore_record,cmp_record,empty_record
1222
  table->storeRecordAsDefault();        // Make empty default record
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1223
520.1.22 by Brian Aker
Second pass of thd cleanup
1224
  if (session->variables.tmp_table_size == ~ (uint64_t) 0)		// No limit
1578.2.8 by Brian Aker
Encapsulate record length.
1225
  {
1116.1.1 by Brian Aker
Fix for Stewart's patch (includes hack to solve MAX rows problem).
1226
    max_rows= ~(uint64_t) 0;
1578.2.8 by Brian Aker
Encapsulate record length.
1227
  }
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1228
  else
1578.2.8 by Brian Aker
Encapsulate record length.
1229
  {
1116.1.1 by Brian Aker
Fix for Stewart's patch (includes hack to solve MAX rows problem).
1230
    max_rows= (uint64_t) (((share->db_type() == heap_engine) ?
1578.2.8 by Brian Aker
Encapsulate record length.
1231
                           min(session->variables.tmp_table_size,
1232
                               session->variables.max_heap_table_size) :
1233
                           session->variables.tmp_table_size) /
1234
                          share->getRecordLength());
1235
  }
1067.4.1 by Nathan Williams
First few changes at converting cmin to std::min.
1236
1116.1.1 by Brian Aker
Fix for Stewart's patch (includes hack to solve MAX rows problem).
1237
  set_if_bigger(max_rows, (uint64_t)1);	// For dummy start options
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1238
  /*
1239
    Push the LIMIT clause to the temporary table creation, so that we
1240
    materialize only up to 'rows_limit' records instead of all result records.
1241
  */
1116.1.1 by Brian Aker
Fix for Stewart's patch (includes hack to solve MAX rows problem).
1242
  set_if_smaller(max_rows, rows_limit);
1243
1244
  share->setMaxRows(max_rows);
1245
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1246
  param->end_write_records= rows_limit;
1247
1248
  keyinfo= param->keyinfo;
1249
1250
  if (group)
1251
  {
1252
    table->group=group;				/* Table is grouped by key */
1253
    param->group_buff=group_buff;
1254
    share->keys=1;
1255
    share->uniques= test(using_unique_constraint);
1256
    table->key_info=keyinfo;
1257
    keyinfo->key_part=key_part_info;
1258
    keyinfo->flags=HA_NOSAME;
1259
    keyinfo->usable_key_parts=keyinfo->key_parts= param->group_parts;
1046.1.6 by Brian Aker
Formatting/style cleanup.
1260
    keyinfo->key_length= 0;
1261
    keyinfo->rec_per_key= 0;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1262
    keyinfo->algorithm= HA_KEY_ALG_UNDEF;
1263
    keyinfo->name= (char*) "group_key";
327.2.3 by Brian Aker
Refactoring of class Table
1264
    order_st *cur_group= group;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1265
    for (; cur_group ; cur_group= cur_group->next, key_part_info++)
1266
    {
1267
      Field *field=(*cur_group->item)->get_tmp_table_field();
1268
      bool maybe_null=(*cur_group->item)->maybe_null;
1046.1.6 by Brian Aker
Formatting/style cleanup.
1269
      key_part_info->null_bit= 0;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1270
      key_part_info->field=  field;
1672.3.6 by Brian Aker
First pass in encapsulating row
1271
      key_part_info->offset= field->offset(table->getInsertRecord());
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1272
      key_part_info->length= (uint16_t) field->key_length();
1273
      key_part_info->type=   (uint8_t) field->key_type();
1119.9.7 by Jay Pipes
Removes FIELDFLAG_BINARY and the useless f_is_binary() macro.
1274
      key_part_info->key_type= 
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1275
	((ha_base_keytype) key_part_info->type == HA_KEYTYPE_TEXT ||
1276
	 (ha_base_keytype) key_part_info->type == HA_KEYTYPE_VARTEXT1 ||
1277
	 (ha_base_keytype) key_part_info->type == HA_KEYTYPE_VARTEXT2) ?
1119.9.7 by Jay Pipes
Removes FIELDFLAG_BINARY and the useless f_is_binary() macro.
1278
	0 : 1;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1279
      if (!using_unique_constraint)
1280
      {
1281
	cur_group->buff=(char*) group_buff;
520.1.22 by Brian Aker
Second pass of thd cleanup
1282
	if (!(cur_group->field= field->new_key_field(session->mem_root,table,
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1283
                                                     group_buff +
1284
                                                     test(maybe_null),
1285
                                                     field->null_ptr,
1286
                                                     field->null_bit)))
971.6.11 by Eric Day
Removed purecov messages.
1287
	  goto err;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1288
	if (maybe_null)
1289
	{
1290
	  /*
1291
	    To be able to group on NULL, we reserved place in group_buff
1292
	    for the NULL flag just before the column. (see above).
1293
	    The field data is after this flag.
1294
	    The NULL flag is updated in 'end_update()' and 'end_write()'
1295
	  */
1296
	  keyinfo->flags|= HA_NULL_ARE_EQUAL;	// def. that NULL == NULL
1297
	  key_part_info->null_bit=field->null_bit;
895 by Brian Aker
Completion (?) of uint conversion.
1298
	  key_part_info->null_offset= (uint32_t) (field->null_ptr -
1672.3.6 by Brian Aker
First pass in encapsulating row
1299
					      (unsigned char*) table->getInsertRecord());
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1300
          cur_group->buff++;                        // Pointer to field data
1301
	  group_buff++;                         // Skipp null flag
1302
	}
1303
        /* In GROUP BY 'a' and 'a ' are equal for VARCHAR fields */
1304
        key_part_info->key_part_flag|= HA_END_SPACE_ARE_EQUAL;
1305
	group_buff+= cur_group->field->pack_length();
1306
      }
1307
      keyinfo->key_length+=  key_part_info->length;
1308
    }
1309
  }
1310
1311
  if (distinct && field_count != param->hidden_field_count)
1312
  {
1313
    /*
1314
      Create an unique key or an unique constraint over all columns
1315
      that should be in the result.  In the temporary table, there are
1316
      'param->hidden_field_count' extra columns, whose null bits are stored
1317
      in the first 'hidden_null_pack_length' bytes of the row.
1318
    */
1319
    if (blob_count)
1320
    {
1321
      /*
1322
        Special mode for index creation in MyISAM used to support unique
1323
        indexes on blobs with arbitrary length. Such indexes cannot be
1324
        used for lookups.
1325
      */
1326
      share->uniques= 1;
1327
    }
1328
    null_pack_length-=hidden_null_pack_length;
1329
    keyinfo->key_parts= ((field_count-param->hidden_field_count)+
1330
			 (share->uniques ? test(null_pack_length) : 0));
1331
    table->distinct= 1;
1332
    share->keys= 1;
1534 by Brian Aker
Remove of KeyPartInfo
1333
    if (!(key_part_info= (KeyPartInfo*)
1532.1.8 by Brian Aker
Yet more movement/encapsulation of mem_root in table.
1334
         table->alloc_root(keyinfo->key_parts * sizeof(KeyPartInfo))))
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1335
      goto err;
1534 by Brian Aker
Remove of KeyPartInfo
1336
    memset(key_part_info, 0, keyinfo->key_parts * sizeof(KeyPartInfo));
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1337
    table->key_info=keyinfo;
1338
    keyinfo->key_part=key_part_info;
1339
    keyinfo->flags=HA_NOSAME | HA_NULL_ARE_EQUAL;
1340
    keyinfo->key_length=(uint16_t) reclength;
1341
    keyinfo->name= (char*) "distinct_key";
1342
    keyinfo->algorithm= HA_KEY_ALG_UNDEF;
1046.1.6 by Brian Aker
Formatting/style cleanup.
1343
    keyinfo->rec_per_key= 0;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1344
1345
    /*
1346
      Create an extra field to hold NULL bits so that unique indexes on
1347
      blobs can distinguish NULL from 0. This extra field is not needed
1348
      when we do not use UNIQUE indexes for blobs.
1349
    */
1350
    if (null_pack_length && share->uniques)
1351
    {
1046.1.6 by Brian Aker
Formatting/style cleanup.
1352
      key_part_info->null_bit= 0;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1353
      key_part_info->offset=hidden_null_pack_length;
1354
      key_part_info->length=null_pack_length;
1672.3.6 by Brian Aker
First pass in encapsulating row
1355
      key_part_info->field= new Field_varstring(table->getInsertRecord(),
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1356
                                                (uint32_t) key_part_info->length,
1357
                                                0,
481 by Brian Aker
Remove all of uchar.
1358
                                                (unsigned char*) 0,
895 by Brian Aker
Completion (?) of uint conversion.
1359
                                                (uint32_t) 0,
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1360
                                                NULL,
1574 by Brian Aker
Rollup patch for hiding tableshare.
1361
                                                table->getMutableShare(),
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1362
                                                &my_charset_bin);
1363
      if (!key_part_info->field)
1364
        goto err;
1365
      key_part_info->field->init(table);
1119.9.7 by Jay Pipes
Removes FIELDFLAG_BINARY and the useless f_is_binary() macro.
1366
      key_part_info->key_type= 1; /* binary comparison */
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1367
      key_part_info->type=    HA_KEYTYPE_BINARY;
1368
      key_part_info++;
1369
    }
1370
    /* Create a distinct key over the columns we are going to return */
1578.2.16 by Brian Aker
Merge in change to getTable() to private the field objects.
1371
    for (i=param->hidden_field_count, reg_field=table->getFields() + i ;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1372
	 i < field_count;
1373
	 i++, reg_field++, key_part_info++)
1374
    {
1046.1.6 by Brian Aker
Formatting/style cleanup.
1375
      key_part_info->null_bit= 0;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1376
      key_part_info->field=    *reg_field;
1672.3.6 by Brian Aker
First pass in encapsulating row
1377
      key_part_info->offset=   (*reg_field)->offset(table->getInsertRecord());
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1378
      key_part_info->length=   (uint16_t) (*reg_field)->pack_length();
1672.3.4 by Brian Aker
This change the style on a few TODO, and fixes an error path to correctly
1379
      /* @todo The below method of computing the key format length of the
1237.9.2 by Padraig O'Sullivan
Moved opt_range.[cc,h] into the optimizer directory and namespace and renamed the files to
1380
        key part is a copy/paste from optimizer/range.cc, and table.cc.
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1381
        This should be factored out, e.g. as a method of Field.
1382
        In addition it is not clear if any of the Field::*_length
1383
        methods is supposed to compute the same length. If so, it
1384
        might be reused.
1385
      */
1386
      key_part_info->store_length= key_part_info->length;
1387
1388
      if ((*reg_field)->real_maybe_null())
1389
        key_part_info->store_length+= HA_KEY_NULL_LENGTH;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1390
      if ((*reg_field)->type() == DRIZZLE_TYPE_BLOB ||
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1391
          (*reg_field)->real_type() == DRIZZLE_TYPE_VARCHAR)
1392
        key_part_info->store_length+= HA_KEY_BLOB_LENGTH;
1393
1394
      key_part_info->type=     (uint8_t) (*reg_field)->key_type();
1395
      key_part_info->key_type =
1396
	((ha_base_keytype) key_part_info->type == HA_KEYTYPE_TEXT ||
1397
	 (ha_base_keytype) key_part_info->type == HA_KEYTYPE_VARTEXT1 ||
1398
	 (ha_base_keytype) key_part_info->type == HA_KEYTYPE_VARTEXT2) ?
1119.9.7 by Jay Pipes
Removes FIELDFLAG_BINARY and the useless f_is_binary() macro.
1399
	0 : 1;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1400
    }
1401
  }
1402
520.1.22 by Brian Aker
Second pass of thd cleanup
1403
  if (session->is_fatal_error)				// If end of memory
971.6.11 by Eric Day
Removed purecov messages.
1404
    goto err;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1405
  share->db_record_offset= 1;
960.2.25 by Monty Taylor
First step of hton rename.
1406
  if (share->db_type() == myisam_engine)
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1407
  {
1408
    if (table->create_myisam_tmp_table(param->keyinfo, param->start_recinfo,
1409
				       &param->recinfo, select_options))
1410
      goto err;
1411
  }
1578.6.2 by Brian Aker
Remove ha_session.
1412
  assert(table->in_use);
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1413
  if (table->open_tmp_table())
1414
    goto err;
1415
520.1.22 by Brian Aker
Second pass of thd cleanup
1416
  session->mem_root= mem_root_save;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1417
1418
  return(table);
1419
1420
err:
520.1.22 by Brian Aker
Second pass of thd cleanup
1421
  session->mem_root= mem_root_save;
1532.1.1 by Brian Aker
Merge of change to flip table instance to be share instance
1422
  table= NULL;
1423
971.6.11 by Eric Day
Removed purecov messages.
1424
  return NULL;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1425
}
1426
1427
/****************************************************************************/
1428
1429
/**
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
1430
  Create a reduced Table object with properly set up Field list from a
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1431
  list of field definitions.
1432
1183.1.2 by Brian Aker
Rename of handler to Cursor. You would not believe how long I have wanted
1433
    The created table doesn't have a table Cursor associated with
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1434
    it, has no keys, no group/distinct, no copy_funcs array.
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
1435
    The sole purpose of this Table object is to use the power of Field
1672.3.6 by Brian Aker
First pass in encapsulating row
1436
    class to read/write data to/from table->getInsertRecord(). Then one can store
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1437
    the record in any container (RB tree, hash, etc).
520.1.21 by Brian Aker
THD -> Session rename
1438
    The table is created in Session mem_root, so are the table's fields.
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1439
    Consequently, if you don't BLOB fields, you don't need to free it.
1440
520.1.22 by Brian Aker
Second pass of thd cleanup
1441
  @param session         connection handle
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1442
  @param field_list  list of column definitions
1443
1444
  @return
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
1445
    0 if out of memory, Table object in case of success
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1446
*/
1447
1502.1.6 by Brian Aker
Further shift TableShare to private strucute.
1448
Table *Session::create_virtual_tmp_table(List<CreateField> &field_list)
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1449
{
482 by Brian Aker
Remove uint.
1450
  uint32_t field_count= field_list.elements;
1451
  uint32_t blob_count= 0;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1452
  Field **field;
1052.2.3 by Nathan Williams
No actual code changes. Changed Create_field to CreateField to be consistent with coding standards.
1453
  CreateField *cdef;                           /* column definition */
482 by Brian Aker
Remove uint.
1454
  uint32_t record_length= 0;
1455
  uint32_t null_count= 0;                 /* number of columns which may be null */
1456
  uint32_t null_pack_length;              /* NULL representation array length */
1005.2.1 by Monty Taylor
Reverted a crap-ton of padraig's work.
1457
  unsigned char *bitmaps;
1532.1.1 by Brian Aker
Merge of change to flip table instance to be share instance
1458
  Table *table;
1459
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
1460
  TableShareInstance *share= getTemporaryShare(message::Table::INTERNAL); // This will not go into the tableshare cache, so no key is used.
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1461
1578.2.11 by Brian Aker
Use the Fields generated from share for Table.
1462
  if (! share->getMemRoot()->multi_alloc_root(0,
1532.1.6 by Brian Aker
Encapsulate the ownership of the table members to the table (so not in
1463
                                              &bitmaps, bitmap_buffer_size(field_count)*2,
1464
                                              NULL))
1465
  {
1046.1.7 by Brian Aker
Style cleanup.
1466
    return NULL;
1532.1.6 by Brian Aker
Encapsulate the ownership of the table members to the table (so not in
1467
  }
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1468
1532.1.1 by Brian Aker
Merge of change to flip table instance to be share instance
1469
  table= share->getTable();
1578.2.11 by Brian Aker
Use the Fields generated from share for Table.
1470
  share->setFields(field_count + 1);
1578.2.16 by Brian Aker
Merge in change to getTable() to private the field objects.
1471
  table->setFields(share->getFields(true));
1472
  field= share->getFields(true);
1574.1.8 by Brian Aker
Blob now allocated via vector
1473
  share->blob_field.resize(field_count+1);
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1474
  share->fields= field_count;
1475
  share->blob_ptr_size= portable_sizeof_char_ptr;
1005.2.3 by Monty Taylor
Further reversion of P.
1476
  table->setup_tmp_table_column_bitmaps(bitmaps);
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1477
1578.2.16 by Brian Aker
Merge in change to getTable() to private the field objects.
1478
  table->in_use= this;           /* field->reset() may access table->in_use */
1479
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1480
  /* Create all fields and calculate the total length of record */
1052.2.3 by Nathan Williams
No actual code changes. Changed Create_field to CreateField to be consistent with coding standards.
1481
  List_iterator_fast<CreateField> it(field_list);
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1482
  while ((cdef= it++))
1483
  {
1532.1.6 by Brian Aker
Encapsulate the ownership of the table members to the table (so not in
1484
    *field= share->make_field(NULL,
1502.1.18 by Brian Aker
Encapsulate mem_root in TableShare
1485
                              cdef->length,
1486
                              (cdef->flags & NOT_NULL_FLAG) ? false : true,
1487
                              (unsigned char *) ((cdef->flags & NOT_NULL_FLAG) ? 0 : ""),
1488
                              (cdef->flags & NOT_NULL_FLAG) ? 0 : 1,
1489
                              cdef->decimals,
1490
                              cdef->sql_type,
1491
                              cdef->charset,
1492
                              cdef->unireg_check,
1493
                              cdef->interval,
1494
                              cdef->field_name);
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1495
    if (!*field)
1496
      goto error;
1497
    (*field)->init(table);
1498
    record_length+= (*field)->pack_length();
1499
    if (! ((*field)->flags & NOT_NULL_FLAG))
1500
      null_count++;
1501
1502
    if ((*field)->flags & BLOB_FLAG)
1578.2.16 by Brian Aker
Merge in change to getTable() to private the field objects.
1503
      share->blob_field[blob_count++]= (uint32_t) (field - table->getFields());
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1504
1505
    field++;
1506
  }
1507
  *field= NULL;                             /* mark the end of the list */
1508
  share->blob_field[blob_count]= 0;            /* mark the end of the list */
1509
  share->blob_fields= blob_count;
1510
1511
  null_pack_length= (null_count + 7)/8;
1578.2.8 by Brian Aker
Encapsulate record length.
1512
  share->setRecordLength(record_length + null_pack_length);
1513
  share->rec_buff_length= ALIGN_SIZE(share->getRecordLength() + 1);
1532.1.8 by Brian Aker
Yet more movement/encapsulation of mem_root in table.
1514
  table->record[0]= (unsigned char*)alloc(share->rec_buff_length);
1672.3.6 by Brian Aker
First pass in encapsulating row
1515
  if (not table->getInsertRecord())
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1516
    goto error;
1517
1518
  if (null_pack_length)
1519
  {
1672.3.6 by Brian Aker
First pass in encapsulating row
1520
    table->null_flags= (unsigned char*) table->getInsertRecord();
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1521
    share->null_fields= null_count;
1522
    share->null_bytes= null_pack_length;
1523
  }
1524
  {
1525
    /* Set up field pointers */
1672.3.6 by Brian Aker
First pass in encapsulating row
1526
    unsigned char *null_pos= table->getInsertRecord();
481 by Brian Aker
Remove all of uchar.
1527
    unsigned char *field_pos= null_pos + share->null_bytes;
482 by Brian Aker
Remove uint.
1528
    uint32_t null_bit= 1;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1529
1578.2.16 by Brian Aker
Merge in change to getTable() to private the field objects.
1530
    for (field= table->getFields(); *field; ++field)
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1531
    {
1532
      Field *cur_field= *field;
1533
      if ((cur_field->flags & NOT_NULL_FLAG))
1534
        cur_field->move_field(field_pos);
1535
      else
1536
      {
481 by Brian Aker
Remove all of uchar.
1537
        cur_field->move_field(field_pos, (unsigned char*) null_pos, null_bit);
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1538
        null_bit<<= 1;
1539
        if (null_bit == (1 << 8))
1540
        {
1541
          ++null_pos;
1542
          null_bit= 1;
1543
        }
1544
      }
1545
      cur_field->reset();
1546
1547
      field_pos+= cur_field->pack_length();
1548
    }
1549
  }
1578.2.16 by Brian Aker
Merge in change to getTable() to private the field objects.
1550
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1551
  return table;
1578.2.16 by Brian Aker
Merge in change to getTable() to private the field objects.
1552
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1553
error:
1578.2.16 by Brian Aker
Merge in change to getTable() to private the field objects.
1554
  for (field= table->getFields(); *field; ++field)
1555
  {
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1556
    delete *field;                         /* just invokes field destructor */
1578.2.16 by Brian Aker
Merge in change to getTable() to private the field objects.
1557
  }
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1558
  return 0;
1559
}
1560
1561
bool Table::open_tmp_table()
1562
{
1563
  int error;
1626.3.1 by Brian Aker
Adding in TableIdentifier for ha_open; (first pass)
1564
  
1565
  TableIdentifier identifier(s->getSchemaName(), s->getTableName(), s->getPath());
1566
  if ((error=cursor->ha_open(identifier,
1567
                             this,
1568
                             O_RDWR,
1578.2.10 by Brian Aker
keys and fields partial encapsulation.
1569
                             HA_OPEN_TMP_TABLE | HA_OPEN_INTERNAL_TABLE)))
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1570
  {
1216.1.1 by Brian Aker
Move print_error up to Engine.
1571
    print_error(error, MYF(0));
1046.1.6 by Brian Aker
Formatting/style cleanup.
1572
    db_stat= 0;
1573
    return true;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1574
  }
1208.3.2 by brian
Update for Cursor renaming.
1575
  (void) cursor->extra(HA_EXTRA_QUICK);		/* Faster */
1046.1.6 by Brian Aker
Formatting/style cleanup.
1576
  return false;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1577
}
1578
1579
1580
/*
1581
  Create MyISAM temporary table
1582
1583
  SYNOPSIS
1584
    create_myisam_tmp_table()
1585
      keyinfo         Description of the index (there is always one index)
1586
      start_recinfo   MyISAM's column descriptions
1587
      recinfo INOUT   End of MyISAM's column descriptions
1588
      options         Option bits
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1589
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1590
  DESCRIPTION
1591
    Create a MyISAM temporary table according to passed description. The is
1592
    assumed to have one unique index or constraint.
1593
1594
    The passed array or MI_COLUMNDEF structures must have this form:
1595
1596
      1. 1-byte column (afaiu for 'deleted' flag) (note maybe not 1-byte
1597
         when there are many nullable columns)
1598
      2. Table columns
1599
      3. One free MI_COLUMNDEF element (*recinfo points here)
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1600
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1601
    This function may use the free element to create hash column for unique
1602
    constraint.
1603
1604
   RETURN
1605
     false - OK
1606
     true  - Error
1607
*/
1608
1535 by Brian Aker
Rename of KEY to KeyInfo
1609
bool Table::create_myisam_tmp_table(KeyInfo *keyinfo,
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1610
                                    MI_COLUMNDEF *start_recinfo,
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1611
                                    MI_COLUMNDEF **recinfo,
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1612
				    uint64_t options)
1613
{
1614
  int error;
1615
  MI_KEYDEF keydef;
1616
  MI_UNIQUEDEF uniquedef;
1000.1.3 by Brian Aker
Renamed TABLE_SHARE to TableShare
1617
  TableShare *share= s;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1618
1578.2.10 by Brian Aker
keys and fields partial encapsulation.
1619
  if (share->sizeKeys())
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1620
  {						// Get keys for ni_create
1277.2.1 by Brian Aker
Remove open tables, other assorted code bits (cleanup on style)
1621
    bool using_unique_constraint= false;
1485 by Brian Aker
Updates to confine memroot
1622
    HA_KEYSEG *seg= (HA_KEYSEG*) this->mem_root.alloc_root(sizeof(*seg) * keyinfo->key_parts);
1711.6.5 by Brian Aker
Updating so that structures have constructor (removed memset calls).
1623
    if (not seg)
1624
      return true;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1625
1626
    memset(seg, 0, sizeof(*seg) * keyinfo->key_parts);
1233.1.9 by Brian Aker
Move max key stuff up to engine.
1627
    if (keyinfo->key_length >= cursor->getEngine()->max_key_length() ||
1628
	keyinfo->key_parts > cursor->getEngine()->max_key_parts() ||
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1629
	share->uniques)
1630
    {
1631
      /* Can't create a key; Make a unique constraint instead of a key */
1632
      share->keys=    0;
1633
      share->uniques= 1;
1277.2.1 by Brian Aker
Remove open tables, other assorted code bits (cleanup on style)
1634
      using_unique_constraint= true;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1635
      memset(&uniquedef, 0, sizeof(uniquedef));
1636
      uniquedef.keysegs=keyinfo->key_parts;
1637
      uniquedef.seg=seg;
1638
      uniquedef.null_are_equal=1;
1639
1640
      /* Create extra column for hash value */
1641
      memset(*recinfo, 0, sizeof(**recinfo));
1642
      (*recinfo)->type= FIELD_CHECK;
1643
      (*recinfo)->length=MI_UNIQUE_HASH_LENGTH;
1644
      (*recinfo)++;
1578.2.8 by Brian Aker
Encapsulate record length.
1645
      share->setRecordLength(share->getRecordLength() + MI_UNIQUE_HASH_LENGTH);
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1646
    }
1647
    else
1648
    {
1649
      /* Create an unique key */
1650
      memset(&keydef, 0, sizeof(keydef));
1651
      keydef.flag=HA_NOSAME | HA_BINARY_PACK_KEY | HA_PACK_KEY;
1652
      keydef.keysegs=  keyinfo->key_parts;
1653
      keydef.seg= seg;
1654
    }
1046.1.6 by Brian Aker
Formatting/style cleanup.
1655
    for (uint32_t i= 0; i < keyinfo->key_parts ; i++,seg++)
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1656
    {
779.3.10 by Monty Taylor
Turned on -Wshadow.
1657
      Field *key_field=keyinfo->key_part[i].field;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1658
      seg->flag=     0;
779.3.10 by Monty Taylor
Turned on -Wshadow.
1659
      seg->language= key_field->charset()->number;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1660
      seg->length=   keyinfo->key_part[i].length;
1661
      seg->start=    keyinfo->key_part[i].offset;
779.3.10 by Monty Taylor
Turned on -Wshadow.
1662
      if (key_field->flags & BLOB_FLAG)
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1663
      {
1119.9.7 by Jay Pipes
Removes FIELDFLAG_BINARY and the useless f_is_binary() macro.
1664
	seg->type= ((keyinfo->key_part[i].key_type & 1 /* binary */) ?
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1665
	 HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2);
779.3.10 by Monty Taylor
Turned on -Wshadow.
1666
	seg->bit_start= (uint8_t)(key_field->pack_length()
1667
                                  - share->blob_ptr_size);
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1668
	seg->flag= HA_BLOB_PART;
1046.1.6 by Brian Aker
Formatting/style cleanup.
1669
	seg->length= 0;			// Whole blob in unique constraint
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1670
      }
1671
      else
1672
      {
1673
	seg->type= keyinfo->key_part[i].type;
1674
      }
779.3.10 by Monty Taylor
Turned on -Wshadow.
1675
      if (!(key_field->flags & NOT_NULL_FLAG))
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1676
      {
779.3.10 by Monty Taylor
Turned on -Wshadow.
1677
	seg->null_bit= key_field->null_bit;
1672.3.6 by Brian Aker
First pass in encapsulating row
1678
	seg->null_pos= (uint32_t) (key_field->null_ptr - (unsigned char*) getInsertRecord());
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1679
	/*
1680
	  We are using a GROUP BY on something that contains NULL
1681
	  In this case we have to tell MyISAM that two NULL should
1682
	  on INSERT be regarded at the same value
1683
	*/
1277.2.1 by Brian Aker
Remove open tables, other assorted code bits (cleanup on style)
1684
	if (! using_unique_constraint)
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1685
	  keydef.flag|= HA_NULL_ARE_EQUAL;
1686
      }
1687
    }
1688
  }
1689
  MI_CREATE_INFO create_info;
1690
1691
  if ((options & (OPTION_BIG_TABLES | SELECT_SMALL_RESULT)) ==
1692
      OPTION_BIG_TABLES)
1693
    create_info.data_file_length= ~(uint64_t) 0;
1694
1711.6.5 by Brian Aker
Updating so that structures have constructor (removed memset calls).
1695
  if ((error= mi_create(share->getTableName(), share->sizeKeys(), &keydef,
1696
                        (uint32_t) (*recinfo-start_recinfo),
1697
                        start_recinfo,
1698
                        share->uniques, &uniquedef,
1699
                        &create_info,
1700
                        HA_CREATE_TMP_TABLE)))
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1701
  {
1216.1.1 by Brian Aker
Move print_error up to Engine.
1702
    print_error(error, MYF(0));
1046.1.6 by Brian Aker
Formatting/style cleanup.
1703
    db_stat= 0;
1711.6.5 by Brian Aker
Updating so that structures have constructor (removed memset calls).
1704
1705
    return true;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1706
  }
1689.5.1 by Joseph Daly
remove increment calls
1707
  in_use->status_var.created_tmp_disk_tables++;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1708
  share->db_record_offset= 1;
1709
  return false;
1710
}
1711
1712
520.1.22 by Brian Aker
Second pass of thd cleanup
1713
void Table::free_tmp_table(Session *session)
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1714
{
1253.1.3 by Monty Taylor
MEM_ROOT == memory::Root
1715
  memory::Root own_root= mem_root;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1716
  const char *save_proc_info;
1717
1532.1.1 by Brian Aker
Merge of change to flip table instance to be share instance
1718
  save_proc_info= session->get_proc_info();
520.1.22 by Brian Aker
Second pass of thd cleanup
1719
  session->set_proc_info("removing tmp table");
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1720
873.2.11 by Monty Taylor
call ha_release_temporary_latches
1721
  // Release latches since this can take a long time
1273.1.15 by Jay Pipes
This patch completes the first step in the splitting of
1722
  plugin::TransactionalStorageEngine::releaseTemporaryLatches(session);
873.2.11 by Monty Taylor
call ha_release_temporary_latches
1723
1208.3.2 by brian
Update for Cursor renaming.
1724
  if (cursor)
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1725
  {
1726
    if (db_stat)
1532.1.1 by Brian Aker
Merge of change to flip table instance to be share instance
1727
    {
1502.1.10 by Brian Aker
Encapsulate table name in TableShare.
1728
      cursor->closeMarkForDelete(s->getTableName());
1532.1.1 by Brian Aker
Merge of change to flip table instance to be share instance
1729
    }
1166.3.2 by Brian Aker
Remove ha_drop_table and modify it just to be a signal for the one case
1730
1502.1.10 by Brian Aker
Encapsulate table name in TableShare.
1731
    TableIdentifier identifier(s->getSchemaName(), s->getTableName(), s->getTableName());
1370 by Brian Aker
Remove dead call.
1732
    s->db_type()->doDropTable(*session, identifier);
1166.3.2 by Brian Aker
Remove ha_drop_table and modify it just to be a signal for the one case
1733
1208.3.2 by brian
Update for Cursor renaming.
1734
    delete cursor;
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1735
  }
1736
1737
  /* free blobs */
1738
  for (Field **ptr= field ; *ptr ; ptr++)
1578.2.16 by Brian Aker
Merge in change to getTable() to private the field objects.
1739
  {
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1740
    (*ptr)->free();
1578.2.16 by Brian Aker
Merge in change to getTable() to private the field objects.
1741
  }
1109.1.4 by Brian Aker
More Table refactor
1742
  free_io_cache();
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1743
1487 by Brian Aker
More updates for memory::Root
1744
  own_root.free_root(MYF(0)); /* the table is allocated in its own root */
520.1.22 by Brian Aker
Second pass of thd cleanup
1745
  session->set_proc_info(save_proc_info);
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
1746
}
1747
1103.6.2 by Padraig O'Sullivan
Removing references to MY_BITMAP throughout the code base and updating calls
1748
my_bitmap_map *Table::use_all_columns(MyBitmap *bitmap)
354 by Brian Aker
Refactor of Table methods.
1749
{
1103.6.2 by Padraig O'Sullivan
Removing references to MY_BITMAP throughout the code base and updating calls
1750
  my_bitmap_map *old= bitmap->getBitmap();
1103.6.4 by Padraig O'Sullivan
Correct all remaining references to the old bitmap interface in the code
1751
  bitmap->setBitmap(s->all_set.getBitmap());
354 by Brian Aker
Refactor of Table methods.
1752
  return old;
1753
}
1754
1005.2.3 by Monty Taylor
Further reversion of P.
1755
void Table::restore_column_map(my_bitmap_map *old)
354 by Brian Aker
Refactor of Table methods.
1756
{
1103.6.4 by Padraig O'Sullivan
Correct all remaining references to the old bitmap interface in the code
1757
  read_set->setBitmap(old);
354 by Brian Aker
Refactor of Table methods.
1758
}
1759
482 by Brian Aker
Remove uint.
1760
uint32_t Table::find_shortest_key(const key_map *usable_keys)
355 by Brian Aker
More Table cleanup
1761
{
365.2.6 by Monty Taylor
Undid some stupid int->int16_t conversions.
1762
  uint32_t min_length= UINT32_MAX;
1763
  uint32_t best= MAX_KEY;
1005.2.6 by Monty Taylor
Re-added bitset<> as a replacement for Bitmap<>
1764
  if (usable_keys->any())
355 by Brian Aker
More Table cleanup
1765
  {
1578.2.10 by Brian Aker
keys and fields partial encapsulation.
1766
    for (uint32_t nr= 0; nr < s->sizeKeys() ; nr++)
355 by Brian Aker
More Table cleanup
1767
    {
1005.2.6 by Monty Taylor
Re-added bitset<> as a replacement for Bitmap<>
1768
      if (usable_keys->test(nr))
355 by Brian Aker
More Table cleanup
1769
      {
1770
        if (key_info[nr].key_length < min_length)
1771
        {
1772
          min_length= key_info[nr].key_length;
1773
          best=nr;
1774
        }
1775
      }
1776
    }
1777
  }
1778
  return best;
1779
}
1780
1781
/*****************************************************************************
1782
  Remove duplicates from tmp table
1783
  This should be recoded to add a unique index to the table and remove
1784
  duplicates
1785
  Table is a locked single thread table
1786
  fields is the number of fields to check (from the end)
1787
*****************************************************************************/
1788
1789
bool Table::compare_record(Field **ptr)
1790
{
1791
  for (; *ptr ; ptr++)
1792
  {
1793
    if ((*ptr)->cmp_offset(s->rec_buff_length))
1794
      return true;
1795
  }
1796
  return false;
1797
}
1798
1799
/* Return false if row hasn't changed */
1800
1801
bool Table::compare_record()
1802
{
1803
  if (s->blob_fields + s->varchar_fields == 0)
1672.3.6 by Brian Aker
First pass in encapsulating row
1804
    return memcmp(this->getInsertRecord(), this->getUpdateRecord(), (size_t) s->getRecordLength());
1221.1.1 by Jay Pipes
Fixes some valgrind warnings regarding conditionals depending on unintialized variables. Use initializer lists properly, dang it. :) Also, removed the new_Cached_item() function's use_result_field, as this was only used for views and was producing a valgrind warning unnecessarily.
1805
  
355 by Brian Aker
More Table cleanup
1806
  /* Compare null bits */
1221.1.1 by Jay Pipes
Fixes some valgrind warnings regarding conditionals depending on unintialized variables. Use initializer lists properly, dang it. :) Also, removed the new_Cached_item() function's use_result_field, as this was only used for views and was producing a valgrind warning unnecessarily.
1807
  if (memcmp(null_flags, null_flags + s->rec_buff_length, s->null_bytes))
1808
    return true; /* Diff in NULL value */
1809
355 by Brian Aker
More Table cleanup
1810
  /* Compare updated fields */
1811
  for (Field **ptr= field ; *ptr ; ptr++)
1812
  {
1005.2.12 by Monty Taylor
Moved some things to the API.
1813
    if (isWriteSet((*ptr)->field_index) &&
355 by Brian Aker
More Table cleanup
1814
	(*ptr)->cmp_binary_offset(s->rec_buff_length))
1815
      return true;
1816
  }
1817
  return false;
1818
}
1819
997.5.1 by chris
Replace macros around unireg.h, store_record,restore_record,cmp_record,empty_record
1820
/*
1821
 * Store a record from previous record into next
1822
 *
1823
 */
1824
void Table::storeRecord()
1825
{
1672.3.6 by Brian Aker
First pass in encapsulating row
1826
  memcpy(getUpdateRecord(), getInsertRecord(), (size_t) s->getRecordLength());
997.5.1 by chris
Replace macros around unireg.h, store_record,restore_record,cmp_record,empty_record
1827
}
1828
1829
/*
1830
 * Store a record as an insert
1831
 *
1832
 */
1833
void Table::storeRecordAsInsert()
1834
{
1672.3.5 by Brian Aker
This replaces the allocation we do for insert/update.
1835
  assert(insert_values.size() >= s->getRecordLength());
1672.3.6 by Brian Aker
First pass in encapsulating row
1836
  memcpy(&insert_values[0], getInsertRecord(), (size_t) s->getRecordLength());
997.5.1 by chris
Replace macros around unireg.h, store_record,restore_record,cmp_record,empty_record
1837
}
1838
1839
/*
1840
 * Store a record with default values
1841
 *
1842
 */
1843
void Table::storeRecordAsDefault()
1844
{
1672.3.6 by Brian Aker
First pass in encapsulating row
1845
  memcpy(s->getDefaultValues(), getInsertRecord(), (size_t) s->getRecordLength());
997.5.1 by chris
Replace macros around unireg.h, store_record,restore_record,cmp_record,empty_record
1846
}
1847
1848
/*
1849
 * Restore a record from previous record into next
1850
 *
1851
 */
1852
void Table::restoreRecord()
1853
{
1672.3.6 by Brian Aker
First pass in encapsulating row
1854
  memcpy(getInsertRecord(), getUpdateRecord(), (size_t) s->getRecordLength());
997.5.1 by chris
Replace macros around unireg.h, store_record,restore_record,cmp_record,empty_record
1855
}
1856
1857
/*
1858
 * Restore a record with default values
1859
 *
1860
 */
1861
void Table::restoreRecordAsDefault()
1862
{
1672.3.6 by Brian Aker
First pass in encapsulating row
1863
  memcpy(getInsertRecord(), s->getDefaultValues(), (size_t) s->getRecordLength());
997.5.1 by chris
Replace macros around unireg.h, store_record,restore_record,cmp_record,empty_record
1864
}
1865
1866
/*
1867
 * Empty a record
1868
 *
1869
 */
1870
void Table::emptyRecord()
1871
{
997.5.2 by chris
Remove comments, do/while, spaces per Monty review
1872
  restoreRecordAsDefault();
1873
  memset(null_flags, 255, s->null_bytes);
997.5.1 by chris
Replace macros around unireg.h, store_record,restore_record,cmp_record,empty_record
1874
}
354 by Brian Aker
Refactor of Table methods.
1875
1532.1.2 by Brian Aker
Remove need for memset on Table object.
1876
Table::Table() : 
1877
  s(NULL),
1878
  field(NULL),
1879
  cursor(NULL),
1880
  next(NULL),
1881
  prev(NULL),
1882
  read_set(NULL),
1883
  write_set(NULL),
1884
  tablenr(0),
1885
  db_stat(0),
1886
  in_use(NULL),
1887
  key_info(NULL),
1888
  next_number_field(NULL),
1889
  found_next_number_field(NULL),
1890
  timestamp_field(NULL),
1891
  pos_in_table_list(NULL),
1892
  group(NULL),
1893
  alias(NULL),
1894
  null_flags(NULL),
1895
  lock_position(0),
1896
  lock_data_start(0),
1897
  lock_count(0),
1898
  used_fields(0),
1899
  status(0),
1900
  derived_select_number(0),
1901
  current_lock(F_UNLCK),
1902
  copy_blobs(false),
1903
  maybe_null(false),
1904
  null_row(false),
1905
  force_index(false),
1906
  distinct(false),
1907
  const_table(false),
1908
  no_rows(false),
1909
  key_read(false),
1910
  no_keyread(false),
1911
  open_placeholder(false),
1912
  locked_by_name(false),
1913
  no_cache(false),
1914
  auto_increment_field_not_null(false),
1915
  alias_name_used(false),
1916
  query_id(0),
1917
  quick_condition_rows(0),
1918
  timestamp_field_type(TIMESTAMP_NO_AUTO_SET),
1532.1.14 by Brian Aker
We no longer use alloc for placeholders (due to HASH I didn't use a
1919
  map(0),
1920
  is_placeholder_created(0)
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
1921
{
1532.1.2 by Brian Aker
Remove need for memset on Table object.
1922
  memset(&def_read_set, 0, sizeof(MyBitmap)); /**< Default read set of columns */
1923
  memset(&def_write_set, 0, sizeof(MyBitmap)); /**< Default write set of columns */
1924
  memset(&tmp_set, 0, sizeof(MyBitmap)); /* Not sure about this... */
1925
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
1926
  record[0]= (unsigned char *) 0;
1927
  record[1]= (unsigned char *) 0;
1928
1532.1.2 by Brian Aker
Remove need for memset on Table object.
1929
  reginfo.reset();
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
1930
  covering_keys.reset();
1931
  quick_keys.reset();
1932
  merge_keys.reset();
1933
1934
  keys_in_use_for_query.reset();
1935
  keys_in_use_for_group_by.reset();
1936
  keys_in_use_for_order_by.reset();
1937
1273.1.1 by Jay Pipes
* Changes Session::warn_id to Session::warn_query_id
1938
  memset(quick_rows, 0, sizeof(ha_rows) * MAX_KEY);
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
1939
  memset(const_key_parts, 0, sizeof(ha_rows) * MAX_KEY);
1940
1941
  memset(quick_key_parts, 0, sizeof(unsigned int) * MAX_KEY);
1942
  memset(quick_n_ranges, 0, sizeof(unsigned int) * MAX_KEY);
1943
}
1944
354 by Brian Aker
Refactor of Table methods.
1945
/*****************************************************************************
1946
  The different ways to read a record
1947
  Returns -1 if row was not found, 0 if row was found and 1 on errors
1948
*****************************************************************************/
1949
1183.1.2 by Brian Aker
Rename of handler to Cursor. You would not believe how long I have wanted
1950
/** Help function when we get some an error from the table Cursor. */
354 by Brian Aker
Refactor of Table methods.
1951
1952
int Table::report_error(int error)
1953
{
1954
  if (error == HA_ERR_END_OF_FILE || error == HA_ERR_KEY_NOT_FOUND)
1955
  {
1956
    status= STATUS_GARBAGE;
1957
    return -1;					// key not found; ok
1958
  }
1959
  /*
1960
    Locking reads can legally return also these errors, do not
1961
    print them to the .err log
1962
  */
1963
  if (error != HA_ERR_LOCK_DEADLOCK && error != HA_ERR_LOCK_WAIT_TIMEOUT)
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
1964
    errmsg_printf(ERRMSG_LVL_ERROR, _("Got error %d when reading table '%s'"),
1502.1.7 by Brian Aker
Partial encapsulation of table_share
1965
                  error, s->getPath());
1216.1.1 by Brian Aker
Move print_error up to Engine.
1966
  print_error(error, MYF(0));
354 by Brian Aker
Refactor of Table methods.
1967
1968
  return 1;
1969
}
1970
1 by brian
clean slate
1971
934.1.1 by Brian Aker
Moved two functions in classes.
1972
void Table::setup_table_map(TableList *table_list, uint32_t table_number)
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
1973
{
934.1.1 by Brian Aker
Moved two functions in classes.
1974
  used_fields= 0;
1975
  const_table= 0;
1976
  null_row= 0;
1977
  status= STATUS_NO_RECORD;
1978
  maybe_null= table_list->outer_join;
1637.2.7 by Vijay Samuel
Merge encapsulate TableList-2.
1979
  TableList *embedding= table_list->getEmbedding();
934.1.1 by Brian Aker
Moved two functions in classes.
1980
  while (!maybe_null && embedding)
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
1981
  {
934.1.1 by Brian Aker
Moved two functions in classes.
1982
    maybe_null= embedding->outer_join;
1637.2.7 by Vijay Samuel
Merge encapsulate TableList-2.
1983
    embedding= embedding->getEmbedding();
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
1984
  }
934.1.1 by Brian Aker
Moved two functions in classes.
1985
  tablenr= table_number;
1986
  map= (table_map) 1 << table_number;
1987
  force_index= table_list->force_index;
1988
  covering_keys= s->keys_for_keyread;
1005.2.6 by Monty Taylor
Re-added bitset<> as a replacement for Bitmap<>
1989
  merge_keys.reset();
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
1990
}
1991
1109.1.1 by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be
1992
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1993
bool Table::fill_item_list(List<Item> *item_list) const
1994
{
1995
  /*
1996
    All Item_field's created using a direct pointer to a field
1997
    are fixed in Item_field constructor.
1998
  */
1999
  for (Field **ptr= field; *ptr; ptr++)
2000
  {
2001
    Item_field *item= new Item_field(*ptr);
2002
    if (!item || item_list->push_back(item))
2003
      return true;
2004
  }
2005
  return false;
2006
}
2007
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
2008
} /* namespace drizzled */