~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table_share.cc

  • Committer: Monty Taylor
  • Date: 2010-07-31 21:37:09 UTC
  • mto: (1680.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1681.
  • Revision ID: mordred@inaugust.com-20100731213709-p2tlj3txhwdi9339
Removed our unordered wrappers. We use Boost now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; i/dent-tabs-mode: nil; -*-
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
4
 *  Copyright (C) 2010 Brian Aker
44
44
#include "drizzled/internal/my_pthread.h"
45
45
#include "drizzled/plugin/event_observer.h"
46
46
 
47
 
#include "drizzled/table.h"
48
 
#include "drizzled/table/shell.h"
49
 
 
50
47
#include "drizzled/session.h"
51
48
 
52
49
#include "drizzled/charset.h"
70
67
#include "drizzled/field/decimal.h"
71
68
#include "drizzled/field/real.h"
72
69
#include "drizzled/field/double.h"
73
 
#include "drizzled/field/int32.h"
74
 
#include "drizzled/field/int64.h"
 
70
#include "drizzled/field/long.h"
 
71
#include "drizzled/field/int64_t.h"
75
72
#include "drizzled/field/num.h"
76
73
#include "drizzled/field/timestamp.h"
77
74
#include "drizzled/field/datetime.h"
78
75
#include "drizzled/field/varstring.h"
79
 
#include "drizzled/field/uuid.h"
80
 
 
81
 
#include "drizzled/definition/cache.h"
82
76
 
83
77
using namespace std;
84
78
 
86
80
{
87
81
 
88
82
extern size_t table_def_size;
 
83
static TableDefinitionCache table_def_cache;
 
84
static pthread_mutex_t LOCK_table_share;
 
85
bool table_def_inited= false;
89
86
 
90
87
/*****************************************************************************
91
88
  Functions to handle table definition cach (TableShare)
92
89
 *****************************************************************************/
93
90
 
 
91
 
 
92
void TableShare::cacheStart(void)
 
93
{
 
94
  pthread_mutex_init(&LOCK_table_share, MY_MUTEX_INIT_FAST);
 
95
  table_def_inited= true;
 
96
  /* 
 
97
   * This is going to overalloc a bit - as rehash sets the number of
 
98
   * buckets, not the number of elements. BUT, it'll allow us to not need
 
99
   * to rehash later on as the unordered_map grows.
 
100
 */
 
101
  table_def_cache.rehash(table_def_size);
 
102
}
 
103
 
 
104
 
 
105
void TableShare::cacheStop(void)
 
106
{
 
107
  if (table_def_inited)
 
108
  {
 
109
    table_def_inited= false;
 
110
    pthread_mutex_destroy(&LOCK_table_share);
 
111
  }
 
112
}
 
113
 
 
114
 
 
115
/**
 
116
 * @TODO: This should return size_t
 
117
 */
 
118
uint32_t cached_table_definitions(void)
 
119
{
 
120
  return static_cast<uint32_t>(table_def_cache.size());
 
121
}
 
122
 
 
123
 
94
124
/*
95
125
  Mark that we are not using table share anymore.
96
126
 
106
136
void TableShare::release(TableShare *share)
107
137
{
108
138
  bool to_be_deleted= false;
109
 
  safe_mutex_assert_owner(table::Cache::singleton().mutex().native_handle);
110
 
 
111
 
  share->lock();
112
 
  if (!--share->ref_count)
113
 
  {
114
 
    to_be_deleted= true;
115
 
  }
116
 
  share->unlock();
117
 
 
118
 
  if (to_be_deleted)
119
 
  {
120
 
    definition::Cache::singleton().erase(share->getCacheKey());
121
 
  }
122
 
}
123
 
 
124
 
void TableShare::release(TableShare::shared_ptr &share)
125
 
{
126
 
  bool to_be_deleted= false;
127
 
  safe_mutex_assert_owner(table::Cache::singleton().mutex().native_handle);
128
 
 
129
 
  share->lock();
130
 
  if (!--share->ref_count)
131
 
  {
132
 
    to_be_deleted= true;
133
 
  }
134
 
  share->unlock();
135
 
 
136
 
  if (to_be_deleted)
137
 
  {
138
 
    definition::Cache::singleton().erase(share->getCacheKey());
139
 
  }
140
 
}
141
 
 
142
 
void TableShare::release(const TableIdentifier &identifier)
143
 
{
144
 
  TableShare::shared_ptr share= definition::Cache::singleton().find(identifier.getKey());
145
 
  if (share)
146
 
  {
 
139
  safe_mutex_assert_owner(&LOCK_open);
 
140
 
 
141
  pthread_mutex_lock(&share->mutex);
 
142
  if (!--share->ref_count)
 
143
  {
 
144
    to_be_deleted= true;
 
145
  }
 
146
 
 
147
  if (to_be_deleted)
 
148
  {
 
149
    TableIdentifier identifier(share->getSchemaName(), share->getTableName());
 
150
    plugin::EventObserver::deregisterTableEvents(*share);
 
151
   
 
152
    TableDefinitionCache::iterator iter= table_def_cache.find(identifier.getKey());
 
153
    if (iter != table_def_cache.end())
 
154
    {
 
155
      table_def_cache.erase(iter);
 
156
      delete share;
 
157
    }
 
158
    return;
 
159
  }
 
160
  pthread_mutex_unlock(&share->mutex);
 
161
}
 
162
 
 
163
void TableShare::release(TableIdentifier &identifier)
 
164
{
 
165
  TableDefinitionCache::iterator iter= table_def_cache.find(identifier.getKey());
 
166
  if (iter != table_def_cache.end())
 
167
  {
 
168
    TableShare *share= (*iter).second;
147
169
    share->version= 0;                          // Mark for delete
148
170
    if (share->ref_count == 0)
149
171
    {
150
 
      definition::Cache::singleton().erase(identifier.getKey());
 
172
      pthread_mutex_lock(&share->mutex);
 
173
      plugin::EventObserver::deregisterTableEvents(*share);
 
174
      table_def_cache.erase(identifier.getKey());
 
175
      delete share;
151
176
    }
152
177
  }
153
178
}
154
179
 
155
180
 
156
 
static TableShare::shared_ptr foundTableShare(TableShare::shared_ptr share)
 
181
static TableShare *foundTableShare(TableShare *share)
157
182
{
158
183
  /*
159
184
    We found an existing table definition. Return it if we didn't get
161
186
  */
162
187
 
163
188
  /* We must do a lock to ensure that the structure is initialized */
 
189
  (void) pthread_mutex_lock(&share->mutex);
164
190
  if (share->error)
165
191
  {
166
192
    /* Table definition contained an error */
167
193
    share->open_table_error(share->error, share->open_errno, share->errarg);
 
194
    (void) pthread_mutex_unlock(&share->mutex);
168
195
 
169
 
    return TableShare::shared_ptr();
 
196
    return NULL;
170
197
  }
171
198
 
172
199
  share->incrementTableCount();
 
200
  (void) pthread_mutex_unlock(&share->mutex);
173
201
 
174
202
  return share;
175
203
}
189
217
  If it doesn't exist, create a new from the table definition file.
190
218
 
191
219
  NOTES
192
 
  We must have wrlock on table::Cache::singleton().mutex() when we come here
 
220
  We must have wrlock on LOCK_open when we come here
193
221
  (To be changed later)
194
222
 
195
223
  RETURN
197
225
#  Share for table
198
226
*/
199
227
 
200
 
TableShare::shared_ptr TableShare::getShareCreate(Session *session, 
201
 
                                                  const TableIdentifier &identifier,
202
 
                                                  int &in_error)
 
228
TableShare *TableShare::getShareCreate(Session *session, 
 
229
                                       TableIdentifier &identifier,
 
230
                                       int *error)
203
231
{
204
 
  TableShare::shared_ptr share;
 
232
  TableShare *share= NULL;
205
233
 
206
 
  in_error= 0;
 
234
  *error= 0;
207
235
 
208
236
  /* Read table definition from cache */
209
 
  if ((share= definition::Cache::singleton().find(identifier.getKey())))
 
237
  TableDefinitionCache::iterator iter= table_def_cache.find(identifier.getKey());
 
238
  if (iter != table_def_cache.end())
 
239
  {
 
240
    share= (*iter).second;
210
241
    return foundTableShare(share);
211
 
 
212
 
  share.reset(new TableShare(message::Table::STANDARD, identifier));
213
 
  
 
242
  }
 
243
 
 
244
  if (not (share= new TableShare(message::Table::STANDARD, identifier)))
 
245
  {
 
246
    return NULL;
 
247
  }
 
248
 
 
249
  /*
 
250
    Lock mutex to be able to read table definition from file without
 
251
    conflicts
 
252
  */
 
253
  (void) pthread_mutex_lock(&share->mutex);
 
254
 
 
255
  /**
 
256
   * @TODO: we need to eject something if we exceed table_def_size
 
257
 */
 
258
  pair<TableDefinitionCache::iterator, bool> ret=
 
259
    table_def_cache.insert(make_pair(identifier.getKey(), share));
 
260
  if (ret.second == false)
 
261
  {
 
262
    delete share;
 
263
 
 
264
    return NULL;
 
265
  }
 
266
 
214
267
  if (share->open_table_def(*session, identifier))
215
268
  {
216
 
    in_error= share->error;
 
269
    *error= share->error;
 
270
    table_def_cache.erase(identifier.getKey());
 
271
    delete share;
217
272
 
218
 
    return TableShare::shared_ptr();
 
273
    return NULL;
219
274
  }
220
275
  share->ref_count++;                           // Mark in use
221
276
  
222
277
  plugin::EventObserver::registerTableEvents(*share);
223
 
 
224
 
  bool ret= definition::Cache::singleton().insert(identifier.getKey(), share);
225
 
 
226
 
  if (not ret)
227
 
    return TableShare::shared_ptr();
 
278
  
 
279
  (void) pthread_mutex_unlock(&share->mutex);
228
280
 
229
281
  return share;
230
282
}
231
283
 
 
284
 
 
285
/*
 
286
  Check if table definition exits in cache
 
287
 
 
288
  SYNOPSIS
 
289
  get_cached_table_share()
 
290
  db                    Database name
 
291
  table_name            Table name
 
292
 
 
293
  RETURN
 
294
  0  Not cached
 
295
#  TableShare for table
 
296
*/
 
297
TableShare *TableShare::getShare(TableIdentifier &identifier)
 
298
{
 
299
  safe_mutex_assert_owner(&LOCK_open);
 
300
 
 
301
  TableDefinitionCache::iterator iter= table_def_cache.find(identifier.getKey());
 
302
  if (iter != table_def_cache.end())
 
303
  {
 
304
    return (*iter).second;
 
305
  }
 
306
  else
 
307
  {
 
308
    return NULL;
 
309
  }
 
310
}
 
311
 
232
312
static enum_field_types proto_field_type_to_drizzle_type(uint32_t proto_field_type)
233
313
{
234
314
  enum_field_types field_type;
265
345
  case message::Table::Field::BLOB:
266
346
    field_type= DRIZZLE_TYPE_BLOB;
267
347
    break;
268
 
  case message::Table::Field::UUID:
269
 
    field_type= DRIZZLE_TYPE_UUID;
270
 
    break;
271
348
  default:
272
 
    assert(0);
273
 
    abort(); // Programming error
 
349
    field_type= DRIZZLE_TYPE_LONG; /* Set value to kill GCC warning */
 
350
    assert(1);
274
351
  }
275
352
 
276
353
  return field_type;
304
381
                                 default_value->length());
305
382
    break;
306
383
  case DRIZZLE_TYPE_NULL:
307
 
    assert(0);
308
 
    abort();
 
384
    assert(false);
309
385
  case DRIZZLE_TYPE_TIMESTAMP:
310
386
  case DRIZZLE_TYPE_DATETIME:
311
387
  case DRIZZLE_TYPE_DATE:
312
388
  case DRIZZLE_TYPE_ENUM:
313
 
  case DRIZZLE_TYPE_UUID:
314
389
    default_item= new Item_string(default_value->c_str(),
315
390
                                  default_value->length(),
316
391
                                  system_charset_info);
361
436
      size_t num_parts= index.index_part_size();
362
437
      for (size_t y= 0; y < num_parts; ++y)
363
438
      {
364
 
        if (index.index_part(y).fieldnr() == in_field->position())
 
439
        if (index.index_part(y).fieldnr() == in_field->field_index)
365
440
          return true;
366
441
      }
367
442
    }
369
444
  return false;
370
445
}
371
446
 
372
 
TableShare::TableShare(const TableIdentifier::Type type_arg) :
 
447
const TableDefinitionCache &TableShare::getCache()
 
448
{
 
449
  return table_def_cache;
 
450
}
 
451
 
 
452
TableShare::TableShare(TableIdentifier::Type type_arg) :
373
453
  table_category(TABLE_UNKNOWN_CATEGORY),
 
454
  open_count(0),
374
455
  found_next_number_field(NULL),
375
456
  timestamp_field(NULL),
376
457
  key_info(NULL),
377
 
  mem_root(TABLE_ALLOC_BLOCK_SIZE),
378
 
  all_set(),
 
458
  blob_field(NULL),
379
459
  block_size(0),
380
460
  version(0),
381
461
  timestamp_offset(0),
398
478
  uniques(0),
399
479
  null_fields(0),
400
480
  blob_fields(0),
401
 
  has_variable_width(false),
 
481
  timestamp_field_offset(0),
 
482
  varchar_fields(0),
402
483
  db_create_options(0),
403
484
  db_options_in_use(0),
404
485
  db_record_offset(0),
410
491
  error(0),
411
492
  open_errno(0),
412
493
  errarg(0),
 
494
  column_bitmap_size(0),
413
495
  blob_ptr_size(0),
414
496
  db_low_byte_first(false),
 
497
  name_lock(false),
 
498
  replace_with_name_lock(false),
 
499
  waiting_on_cond(false),
415
500
  keys_in_use(0),
416
501
  keys_for_keyread(0),
417
502
  event_observers(NULL)
425
510
 
426
511
  if (type_arg == message::Table::INTERNAL)
427
512
  {
428
 
    TableIdentifier::build_tmptable_filename(private_key_for_cache.vectorPtr());
429
 
    init(private_key_for_cache.vector(), private_key_for_cache.vector());
 
513
    TableIdentifier::build_tmptable_filename(private_key_for_cache);
 
514
    init(&private_key_for_cache[0], &private_key_for_cache[0]);
430
515
  }
431
516
  else
432
517
  {
434
519
  }
435
520
}
436
521
 
437
 
TableShare::TableShare(const TableIdentifier &identifier, const TableIdentifier::Key &key) :// Used by placeholder
 
522
TableShare::TableShare(TableIdentifier &identifier, const TableIdentifier::Key &key) :// Used by placeholder
438
523
  table_category(TABLE_UNKNOWN_CATEGORY),
 
524
  open_count(0),
439
525
  found_next_number_field(NULL),
440
526
  timestamp_field(NULL),
441
527
  key_info(NULL),
442
 
  mem_root(TABLE_ALLOC_BLOCK_SIZE),
443
 
  all_set(),
 
528
  blob_field(NULL),
444
529
  block_size(0),
445
530
  version(0),
446
531
  timestamp_offset(0),
463
548
  uniques(0),
464
549
  null_fields(0),
465
550
  blob_fields(0),
466
 
  has_variable_width(false),
 
551
  timestamp_field_offset(0),
 
552
  varchar_fields(0),
467
553
  db_create_options(0),
468
554
  db_options_in_use(0),
469
555
  db_record_offset(0),
475
561
  error(0),
476
562
  open_errno(0),
477
563
  errarg(0),
 
564
  column_bitmap_size(0),
478
565
  blob_ptr_size(0),
479
566
  db_low_byte_first(false),
 
567
  name_lock(false),
 
568
  replace_with_name_lock(false),
 
569
  waiting_on_cond(false),
480
570
  keys_in_use(0),
481
571
  keys_for_keyread(0),
482
572
  event_observers(NULL)
489
579
 
490
580
  private_key_for_cache= key;
491
581
 
 
582
  memory::init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
492
583
  table_category=         TABLE_CATEGORY_TEMPORARY;
493
584
  tmp_table=              message::Table::INTERNAL;
494
585
 
495
 
  db.str= const_cast<char *>(private_key_for_cache.vector());
496
 
  db.length= strlen(private_key_for_cache.vector());
 
586
  db.str= &private_key_for_cache[0];
 
587
  db.length= strlen(&private_key_for_cache[0]);
497
588
 
498
 
  table_name.str= const_cast<char *>(private_key_for_cache.vector()) + strlen(private_key_for_cache.vector()) + 1;
 
589
  table_name.str= &private_key_for_cache[0] + strlen(&private_key_for_cache[0]) + 1;
499
590
  table_name.length= strlen(table_name.str);
500
591
  path.str= (char *)"";
501
592
  normalized_path.str= path.str;
502
593
  path.length= normalized_path.length= 0;
503
 
 
504
 
  std::string tb_name(identifier.getTableName());
505
 
  std::transform(tb_name.begin(), tb_name.end(), tb_name.begin(), ::tolower);
506
 
  assert(strcmp(tb_name.c_str(), table_name.str) == 0);
507
 
 
 
594
  assert(strcmp(identifier.getTableName().c_str(), table_name.str) == 0);
508
595
  assert(strcmp(identifier.getSchemaName().c_str(), db.str) == 0);
509
596
}
510
597
 
511
598
 
512
599
TableShare::TableShare(const TableIdentifier &identifier) : // Just used during createTable()
513
600
  table_category(TABLE_UNKNOWN_CATEGORY),
 
601
  open_count(0),
514
602
  found_next_number_field(NULL),
515
603
  timestamp_field(NULL),
516
604
  key_info(NULL),
517
 
  mem_root(TABLE_ALLOC_BLOCK_SIZE),
518
 
  all_set(),
 
605
  blob_field(NULL),
519
606
  block_size(0),
520
607
  version(0),
521
608
  timestamp_offset(0),
538
625
  uniques(0),
539
626
  null_fields(0),
540
627
  blob_fields(0),
541
 
  has_variable_width(false),
 
628
  timestamp_field_offset(0),
 
629
  varchar_fields(0),
542
630
  db_create_options(0),
543
631
  db_options_in_use(0),
544
632
  db_record_offset(0),
550
638
  error(0),
551
639
  open_errno(0),
552
640
  errarg(0),
 
641
  column_bitmap_size(0),
553
642
  blob_ptr_size(0),
554
643
  db_low_byte_first(false),
 
644
  name_lock(false),
 
645
  replace_with_name_lock(false),
 
646
  waiting_on_cond(false),
555
647
  keys_in_use(0),
556
648
  keys_for_keyread(0),
557
649
  event_observers(NULL)
568
660
  memcpy(&private_normalized_path[0], identifier.getPath().c_str(), identifier.getPath().size());
569
661
 
570
662
  {
 
663
    memory::init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
571
664
    table_category=         TABLE_CATEGORY_TEMPORARY;
572
665
    tmp_table=              message::Table::INTERNAL;
573
 
    db.str= const_cast<char *>(private_key_for_cache.vector());
574
 
    db.length= strlen(private_key_for_cache.vector());
 
666
    db.str= &private_key_for_cache[0];
 
667
    db.length= strlen(&private_key_for_cache[0]);
575
668
    table_name.str= db.str + 1;
576
669
    table_name.length= strlen(table_name.str);
577
670
    path.str= &private_normalized_path[0];
584
677
/*
585
678
  Used for shares that will go into the cache.
586
679
*/
587
 
TableShare::TableShare(const TableIdentifier::Type type_arg,
588
 
                       const TableIdentifier &identifier,
 
680
TableShare::TableShare(TableIdentifier::Type type_arg,
 
681
                       TableIdentifier &identifier,
589
682
                       char *path_arg,
590
683
                       uint32_t path_length_arg) :
591
684
  table_category(TABLE_UNKNOWN_CATEGORY),
 
685
  open_count(0),
592
686
  found_next_number_field(NULL),
593
687
  timestamp_field(NULL),
594
688
  key_info(NULL),
595
 
  mem_root(TABLE_ALLOC_BLOCK_SIZE),
596
 
  all_set(),
 
689
  blob_field(NULL),
597
690
  block_size(0),
598
691
  version(0),
599
692
  timestamp_offset(0),
616
709
  uniques(0),
617
710
  null_fields(0),
618
711
  blob_fields(0),
619
 
  has_variable_width(false),
 
712
  timestamp_field_offset(0),
 
713
  varchar_fields(0),
620
714
  db_create_options(0),
621
715
  db_options_in_use(0),
622
716
  db_record_offset(0),
628
722
  error(0),
629
723
  open_errno(0),
630
724
  errarg(0),
 
725
  column_bitmap_size(0),
631
726
  blob_ptr_size(0),
632
727
  db_low_byte_first(false),
 
728
  name_lock(false),
 
729
  replace_with_name_lock(false),
 
730
  waiting_on_cond(false),
633
731
  keys_in_use(0),
634
732
  keys_for_keyread(0),
635
733
  event_observers(NULL)
640
738
  memset(&path, 0, sizeof(LEX_STRING));
641
739
  memset(&normalized_path, 0, sizeof(LEX_STRING));
642
740
 
 
741
  mem_root.init_alloc_root(TABLE_ALLOC_BLOCK_SIZE);
643
742
  char *path_buff;
644
743
  std::string _path;
645
744
 
648
747
    Let us use the fact that the key is "db/0/table_name/0" + optional
649
748
    part for temporary tables.
650
749
  */
651
 
  db.str= const_cast<char *>(private_key_for_cache.vector());
 
750
  db.str= &private_key_for_cache[0];
652
751
  db.length=         strlen(db.str);
653
752
  table_name.str=    db.str + db.length + 1;
654
753
  table_name.length= strlen(table_name.str);
662
761
    TableIdentifier::build_table_filename(_path, db.str, table_name.str, false);
663
762
  }
664
763
 
665
 
  if ((path_buff= (char *)mem_root.alloc_root(_path.length() + 1)))
 
764
  if (mem_root.multi_alloc_root(0,
 
765
                                &path_buff, _path.length() + 1,
 
766
                                NULL))
666
767
  {
667
768
    setPath(path_buff, _path.length());
668
769
    strcpy(path_buff, _path.c_str());
669
770
    setNormalizedPath(path_buff, _path.length());
670
771
 
671
772
    version= refresh_version;
 
773
 
 
774
    pthread_mutex_init(&mutex, MY_MUTEX_INIT_FAST);
 
775
    pthread_cond_init(&cond, NULL);
672
776
  }
673
777
  else
674
778
  {
675
779
    assert(0); // We should throw here.
676
 
    abort();
677
780
  }
678
781
}
679
782
 
681
784
                      const char *new_path)
682
785
{
683
786
 
 
787
  memory::init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
684
788
  table_category=         TABLE_CATEGORY_TEMPORARY;
685
789
  tmp_table=              message::Table::INTERNAL;
686
790
  db.str= (char *)"";
696
800
{
697
801
  assert(ref_count == 0);
698
802
 
 
803
  /*
 
804
    If someone is waiting for this to be deleted, inform it about this.
 
805
    Don't do a delete until we know that no one is refering to this anymore.
 
806
  */
 
807
  if (tmp_table == message::Table::STANDARD)
 
808
  {
 
809
    /* share->mutex is locked in release_table_share() */
 
810
    while (waiting_on_cond)
 
811
    {
 
812
      pthread_cond_broadcast(&cond);
 
813
      pthread_cond_wait(&cond, &mutex);
 
814
    }
 
815
    /* No thread refers to this anymore */
 
816
    pthread_mutex_unlock(&mutex);
 
817
    pthread_mutex_destroy(&mutex);
 
818
    pthread_cond_destroy(&cond);
 
819
  }
 
820
 
699
821
  storage_engine= NULL;
700
822
 
701
823
  delete table_proto;
702
824
  table_proto= NULL;
703
825
 
704
 
  plugin::EventObserver::deregisterTableEvents(*this);
705
 
 
706
826
  mem_root.free_root(MYF(0));                 // Free's share
707
827
}
708
828
 
709
 
void TableShare::setIdentifier(const TableIdentifier &identifier_arg)
 
829
void TableShare::setIdentifier(TableIdentifier &identifier_arg)
710
830
{
 
831
  private_key_for_cache.clear();
711
832
  private_key_for_cache= identifier_arg.getKey();
712
833
 
713
834
  /*
714
835
    Let us use the fact that the key is "db/0/table_name/0" + optional
715
836
    part for temporary tables.
716
837
  */
717
 
  db.str= const_cast<char *>(private_key_for_cache.vector());
 
838
  db.str= &private_key_for_cache[0];
718
839
  db.length=         strlen(db.str);
719
840
  table_name.str=    db.str + db.length + 1;
720
841
  table_name.length= strlen(table_name.str);
759
880
 
760
881
  table_charset= get_charset(table_options.collation_id());
761
882
 
762
 
  if (! table_charset)
 
883
  if (!table_charset)
763
884
  {
764
885
    char errmsg[100];
765
886
    snprintf(errmsg, sizeof(errmsg),
882
1003
 
883
1004
      key_part->length= part.compare_length();
884
1005
 
885
 
      int mbmaxlen= 1;
886
 
 
887
 
      if (table.field(part.fieldnr()).type() == message::Table::Field::VARCHAR
888
 
          || table.field(part.fieldnr()).type() == message::Table::Field::BLOB)
889
 
      {
890
 
        uint32_t collation_id;
891
 
 
892
 
        if (table.field(part.fieldnr()).string_options().has_collation_id())
893
 
          collation_id= table.field(part.fieldnr()).string_options().collation_id();
894
 
        else
895
 
          collation_id= table.options().collation_id();
896
 
 
897
 
        const CHARSET_INFO *cs= get_charset(collation_id);
898
 
 
899
 
        mbmaxlen= cs->mbmaxlen;
900
 
      }
901
 
      key_part->length*= mbmaxlen;
902
 
 
903
1006
      key_part->store_length= key_part->length;
904
1007
 
905
1008
      /* key_part->offset is set later */
934
1037
  uint32_t local_null_fields= 0;
935
1038
  reclength= 0;
936
1039
 
937
 
  std::vector<uint32_t> field_offsets;
938
 
  std::vector<uint32_t> field_pack_length;
 
1040
  vector<uint32_t> field_offsets;
 
1041
  vector<uint32_t> field_pack_length;
939
1042
 
940
1043
  field_offsets.resize(fields);
941
1044
  field_pack_length.resize(fields);
981
1084
      {
982
1085
        message::Table::Field::EnumerationValues field_options= pfield.enumeration_values();
983
1086
 
984
 
        field_pack_length[fieldnr]= 4;
 
1087
        field_pack_length[fieldnr]=
 
1088
          get_enum_pack_length(field_options.field_value_size());
985
1089
 
986
1090
        interval_count++;
987
1091
        interval_parts+= field_options.field_value_size();
1123
1227
 
1124
1228
    if (pfield.has_options() &&
1125
1229
        pfield.options().has_default_expression() &&
1126
 
        pfield.options().default_expression().compare("CURRENT_TIMESTAMP") == 0)
 
1230
        pfield.options().default_expression().compare("NOW()") == 0)
1127
1231
    {
1128
1232
      if (pfield.options().has_update_expression() &&
1129
 
          pfield.options().update_expression().compare("CURRENT_TIMESTAMP") == 0)
 
1233
          pfield.options().update_expression().compare("NOW()") == 0)
1130
1234
      {
1131
1235
        unireg_type= Field::TIMESTAMP_DNUN_FIELD;
1132
1236
      }
1135
1239
        unireg_type= Field::TIMESTAMP_DN_FIELD;
1136
1240
      }
1137
1241
      else
1138
 
      {
1139
 
        assert(0); // Invalid update value.
1140
 
        abort();
1141
 
      }
 
1242
        assert(1); // Invalid update value.
1142
1243
    }
1143
1244
    else if (pfield.has_options() &&
1144
1245
             pfield.options().has_update_expression() &&
1145
 
             pfield.options().update_expression().compare("CURRENT_TIMESTAMP") == 0)
 
1246
             pfield.options().update_expression().compare("NOW()") == 0)
1146
1247
    {
1147
1248
      unireg_type= Field::TIMESTAMP_UN_FIELD;
1148
1249
    }
1220
1321
    Item *default_value= NULL;
1221
1322
 
1222
1323
    if (pfield.options().has_default_value() ||
1223
 
        pfield.options().default_null()  ||
 
1324
        pfield.options().has_default_null()  ||
1224
1325
        pfield.options().has_default_bin_value())
1225
1326
    {
1226
1327
      default_value= default_value_item(field_type,
1231
1332
    }
1232
1333
 
1233
1334
 
1234
 
    blob_ptr_size= portable_sizeof_char_ptr;
 
1335
    Table temp_table; /* Use this so that BLOB DEFAULT '' works */
 
1336
    memset(&temp_table, 0, sizeof(temp_table));
 
1337
    temp_table.setShare(this);
 
1338
    temp_table.in_use= &session;
 
1339
    temp_table.getMutableShare()->db_low_byte_first= true; //Cursor->low_byte_first();
 
1340
    temp_table.getMutableShare()->blob_ptr_size= portable_sizeof_char_ptr;
1235
1341
 
1236
1342
    uint32_t field_length= 0; //Assignment is for compiler complaint.
1237
1343
 
1315
1421
    case DRIZZLE_TYPE_LONGLONG:
1316
1422
      field_length= MAX_BIGINT_WIDTH;
1317
1423
      break;
1318
 
    case DRIZZLE_TYPE_UUID:
1319
 
      field_length= field::Uuid::max_string_length();
1320
 
      break;
1321
1424
    case DRIZZLE_TYPE_NULL:
1322
1425
      abort(); // Programming error
1323
1426
    }
1324
1427
 
1325
 
    assert(enum_field_types_size == 12);
1326
 
 
1327
1428
    Field* f= make_field(record + field_offsets[fieldnr] + data_offset,
1328
 
                         field_length,
1329
 
                         pfield.constraints().is_nullable(),
1330
 
                         null_pos,
1331
 
                         null_bit_pos,
1332
 
                         decimals,
1333
 
                         field_type,
1334
 
                         charset,
1335
 
                         MTYP_TYPENR(unireg_type),
1336
 
                         ((field_type == DRIZZLE_TYPE_ENUM) ?  &intervals[interval_nr++] : (TYPELIB*) 0),
1337
 
                         getTableProto()->field(fieldnr).name().c_str());
 
1429
                                field_length,
 
1430
                                pfield.constraints().is_nullable(),
 
1431
                                null_pos,
 
1432
                                null_bit_pos,
 
1433
                                decimals,
 
1434
                                field_type,
 
1435
                                charset,
 
1436
                                (Field::utype) MTYP_TYPENR(unireg_type),
 
1437
                                ((field_type == DRIZZLE_TYPE_ENUM) ?
 
1438
                                 &intervals[interval_nr++]
 
1439
                                 : (TYPELIB*) 0),
 
1440
                                getTableProto()->field(fieldnr).name().c_str());
1338
1441
 
1339
1442
    field[fieldnr]= f;
1340
1443
 
1341
 
    // Insert post make_field code here.
1342
 
    switch (field_type)
1343
 
    {
1344
 
    case DRIZZLE_TYPE_BLOB:
1345
 
    case DRIZZLE_TYPE_VARCHAR:
1346
 
    case DRIZZLE_TYPE_DOUBLE:
1347
 
    case DRIZZLE_TYPE_DECIMAL:
1348
 
    case DRIZZLE_TYPE_TIMESTAMP:
1349
 
    case DRIZZLE_TYPE_DATETIME:
1350
 
    case DRIZZLE_TYPE_DATE:
1351
 
    case DRIZZLE_TYPE_ENUM:
1352
 
    case DRIZZLE_TYPE_LONG:
1353
 
    case DRIZZLE_TYPE_LONGLONG:
1354
 
    case DRIZZLE_TYPE_NULL:
1355
 
    case DRIZZLE_TYPE_UUID:
1356
 
      break;
1357
 
    }
1358
 
 
1359
 
    // This needs to go, we should be setting the "use" on the field so that
1360
 
    // it does not reference the share/table.
1361
 
    table::Shell temp_table(*this); /* Use this so that BLOB DEFAULT '' works */
1362
 
    temp_table.in_use= &session;
1363
 
 
1364
1444
    f->init(&temp_table); /* blob default values need table obj */
1365
1445
 
1366
1446
    if (! (f->flags & NOT_NULL_FLAG))
1385
1465
        return local_error;
1386
1466
      }
1387
1467
    }
1388
 
    else if (f->real_type() == DRIZZLE_TYPE_ENUM && (f->flags & NOT_NULL_FLAG))
 
1468
    else if (f->real_type() == DRIZZLE_TYPE_ENUM &&
 
1469
             (f->flags & NOT_NULL_FLAG))
1389
1470
    {
1390
1471
      f->set_notnull();
1391
1472
      f->store((int64_t) 1, true);
1399
1480
    f->setTable(NULL);
1400
1481
    f->orig_table= NULL;
1401
1482
 
1402
 
    f->setPosition(fieldnr);
 
1483
    f->field_index= fieldnr;
1403
1484
    f->comment= comment;
1404
1485
    if (! default_value &&
1405
1486
        ! (f->unireg_check==Field::NEXT_NUMBER) &&
1412
1493
    if (f->unireg_check == Field::NEXT_NUMBER)
1413
1494
      found_next_number_field= &(field[fieldnr]);
1414
1495
 
 
1496
    if (timestamp_field == f)
 
1497
      timestamp_field_offset= fieldnr;
 
1498
 
1415
1499
    if (use_hash) /* supposedly this never fails... but comments lie */
1416
1500
    {
1417
1501
      const char *local_field_name= field[fieldnr]->field_name;
1418
1502
      name_hash.insert(make_pair(local_field_name, &(field[fieldnr])));
1419
1503
    }
 
1504
 
1420
1505
  }
1421
1506
 
1422
1507
  keyinfo= key_info;
1441
1526
    We need to set the unused bits to 1. If the number of bits is a multiple
1442
1527
    of 8 there are no unused bits.
1443
1528
  */
 
1529
 
1444
1530
  if (null_count & 7)
1445
1531
    *(record + null_count / 8)|= ~(((unsigned char) 1 << (null_count & 7)) - 1);
1446
1532
 
1606
1692
 
1607
1693
  if (blob_fields)
1608
1694
  {
 
1695
    uint32_t k, *save;
 
1696
 
1609
1697
    /* Store offsets to blob fields to find them fast */
1610
1698
    blob_field.resize(blob_fields);
1611
 
    uint32_t *save= &blob_field[0];
1612
 
    uint32_t k= 0;
 
1699
    save= &blob_field[0];
 
1700
    k= 0;
1613
1701
    for (Fields::iterator iter= field.begin(); iter != field.end()-1; iter++, k++)
1614
1702
    {
1615
1703
      if ((*iter)->flags & BLOB_FLAG)
1617
1705
    }
1618
1706
  }
1619
1707
 
1620
 
  all_set.clear();
1621
 
  all_set.resize(fields);
1622
 
  all_set.set();
 
1708
  db_low_byte_first= true; // @todo Question this.
 
1709
  column_bitmap_size= bitmap_buffer_size(fields);
 
1710
 
 
1711
  all_bitmap.resize(column_bitmap_size);
 
1712
  all_set.init(&all_bitmap[0], fields);
 
1713
  all_set.setAll();
1623
1714
 
1624
1715
  return local_error;
1625
1716
}
1650
1741
 
1651
1742
  NOTES
1652
1743
  This function is called when the table definition is not cached in
1653
 
  definition::Cache::singleton().getCache()
 
1744
  table_def_cache
1654
1745
  The data is returned in 'share', which is alloced by
1655
1746
  alloc_table_share().. The code assumes that share is initialized.
1656
1747
 
1664
1755
  6    Unknown .frm version
1665
1756
*/
1666
1757
 
1667
 
int TableShare::open_table_def(Session& session, const TableIdentifier &identifier)
 
1758
int TableShare::open_table_def(Session& session, TableIdentifier &identifier)
1668
1759
{
1669
1760
  int local_error;
1670
1761
  bool error_given;
1672
1763
  local_error= 1;
1673
1764
  error_given= 0;
1674
1765
 
1675
 
  message::table::shared_ptr table;
 
1766
  message::Table table;
1676
1767
 
1677
1768
  local_error= plugin::StorageEngine::getTableDefinition(session, identifier, table);
1678
1769
 
1685
1776
    }
1686
1777
    else
1687
1778
    {
1688
 
      if (not table->IsInitialized())
 
1779
      if (not table.IsInitialized())
1689
1780
      {
1690
1781
        local_error= 4;
1691
1782
      }
1693
1784
    goto err_not_open;
1694
1785
  }
1695
1786
 
1696
 
  local_error= parse_table_proto(session, *table);
 
1787
  local_error= parse_table_proto(session, table);
1697
1788
 
1698
1789
  setTableCategory(TABLE_CATEGORY_USER);
1699
1790
 
1731
1822
  5    Error (see open_table_error: charset unavailable)
1732
1823
  7    Table definition has changed in engine
1733
1824
*/
 
1825
 
1734
1826
int TableShare::open_table_from_share(Session *session,
1735
1827
                                      const TableIdentifier &identifier,
1736
1828
                                      const char *alias,
1737
1829
                                      uint32_t db_stat, uint32_t ha_open_flags,
1738
1830
                                      Table &outparam)
1739
1831
{
 
1832
  int local_error;
 
1833
  uint32_t records, bitmap_size;
1740
1834
  bool error_reported= false;
1741
 
  int ret= open_table_from_share_inner(session, alias, db_stat, outparam);
1742
 
 
1743
 
  if (not ret)
1744
 
    ret= open_table_cursor_inner(identifier, db_stat, ha_open_flags, outparam, error_reported);
1745
 
 
1746
 
  if (not ret)
1747
 
    return ret;
1748
 
 
1749
 
  if (not error_reported)
1750
 
    open_table_error(ret, errno, 0);
1751
 
 
1752
 
  delete outparam.cursor;
1753
 
  outparam.cursor= 0;                           // For easier error checking
1754
 
  outparam.db_stat= 0;
1755
 
  outparam.getMemRoot()->free_root(MYF(0));       // Safe to call on zeroed root
1756
 
  outparam.clearAlias();
1757
 
 
1758
 
  return ret;
1759
 
}
1760
 
 
1761
 
int TableShare::open_table_from_share_inner(Session *session,
1762
 
                                            const char *alias,
1763
 
                                            uint32_t db_stat,
1764
 
                                            Table &outparam)
1765
 
{
1766
 
  int local_error;
1767
 
  uint32_t records;
1768
 
  unsigned char *record= NULL;
 
1835
  unsigned char *record, *bitmaps;
1769
1836
  Field **field_ptr;
1770
1837
 
1771
1838
  /* Parsing of partitioning information from .frm needs session->lex set up. */
1774
1841
  local_error= 1;
1775
1842
  outparam.resetTable(session, this, db_stat);
1776
1843
 
1777
 
  outparam.setAlias(alias);
 
1844
  if (not (outparam.alias= strdup(alias)))
 
1845
    goto err;
1778
1846
 
1779
1847
  /* Allocate Cursor */
1780
 
  if (not (outparam.cursor= db_type()->getCursor(outparam)))
1781
 
    return local_error;
 
1848
  if (not (outparam.cursor= db_type()->getCursor(*this, outparam.getMemRoot())))
 
1849
    goto err;
1782
1850
 
1783
1851
  local_error= 4;
1784
1852
  records= 0;
1788
1856
  records++;
1789
1857
 
1790
1858
  if (!(record= (unsigned char*) outparam.alloc_root(rec_buff_length * records)))
1791
 
    return local_error;
 
1859
    goto err;
1792
1860
 
1793
1861
  if (records == 0)
1794
1862
  {
1801
1869
    if (records > 1)
1802
1870
      outparam.record[1]= record+ rec_buff_length;
1803
1871
    else
1804
 
      outparam.record[1]= outparam.getInsertRecord();   // Safety
 
1872
      outparam.record[1]= outparam.record[0];   // Safety
1805
1873
  }
1806
1874
 
1807
 
#ifdef HAVE_VALGRIND
 
1875
#ifdef HAVE_purify
1808
1876
  /*
1809
1877
    We need this because when we read var-length rows, we are not updating
1810
1878
    bytes after end of varchar
1811
1879
  */
1812
1880
  if (records > 1)
1813
1881
  {
1814
 
    memcpy(outparam.getInsertRecord(), getDefaultValues(), rec_buff_length);
1815
 
    memcpy(outparam.getUpdateRecord(), getDefaultValues(), null_bytes);
 
1882
    memcpy(outparam.record[0], getDefaultValues(), rec_buff_length);
 
1883
    memcpy(outparam.record[1], getDefaultValues(), null_bytes);
1816
1884
    if (records > 2)
1817
 
      memcpy(outparam.getUpdateRecord(), getDefaultValues(), rec_buff_length);
 
1885
      memcpy(outparam.record[1], getDefaultValues(), rec_buff_length);
1818
1886
  }
1819
1887
#endif
1820
1888
  if (records > 1)
1821
1889
  {
1822
 
    memcpy(outparam.getUpdateRecord(), getDefaultValues(), null_bytes);
 
1890
    memcpy(outparam.record[1], getDefaultValues(), null_bytes);
1823
1891
  }
1824
1892
 
1825
1893
  if (!(field_ptr = (Field **) outparam.alloc_root( (uint32_t) ((fields+1)* sizeof(Field*)))))
1826
1894
  {
1827
 
    return local_error;
 
1895
    goto err;
1828
1896
  }
1829
1897
 
1830
1898
  outparam.setFields(field_ptr);
1831
1899
 
1832
 
  record= (unsigned char*) outparam.getInsertRecord()-1;        /* Fieldstart = 1 */
 
1900
  record= (unsigned char*) outparam.record[0]-1;        /* Fieldstart = 1 */
1833
1901
 
1834
1902
  outparam.null_flags= (unsigned char*) record+1;
1835
1903
 
1837
1905
  for (uint32_t i= 0 ; i < fields; i++, field_ptr++)
1838
1906
  {
1839
1907
    if (!((*field_ptr)= field[i]->clone(outparam.getMemRoot(), &outparam)))
1840
 
      return local_error;
 
1908
      goto err;
1841
1909
  }
1842
1910
  (*field_ptr)= 0;                              // End marker
1843
1911
 
1845
1913
    outparam.found_next_number_field=
1846
1914
      outparam.getField(positionFields(found_next_number_field));
1847
1915
  if (timestamp_field)
1848
 
    outparam.timestamp_field= (Field_timestamp*) outparam.getField(timestamp_field->position());
 
1916
    outparam.timestamp_field= (Field_timestamp*) outparam.getField(timestamp_field_offset);
 
1917
 
1849
1918
 
1850
1919
  /* Fix key->name and key_part->field */
1851
1920
  if (key_parts)
1855
1924
    uint32_t n_length;
1856
1925
    n_length= keys*sizeof(KeyInfo) + key_parts*sizeof(KeyPartInfo);
1857
1926
    if (!(local_key_info= (KeyInfo*) outparam.alloc_root(n_length)))
1858
 
      return local_error;
 
1927
      goto err;
1859
1928
    outparam.key_info= local_key_info;
1860
1929
    key_part= (reinterpret_cast<KeyPartInfo*> (local_key_info+keys));
1861
1930
 
1894
1963
 
1895
1964
  /* Allocate bitmaps */
1896
1965
 
1897
 
  outparam.def_read_set.resize(fields);
1898
 
  outparam.def_write_set.resize(fields);
1899
 
  outparam.tmp_set.resize(fields);
 
1966
  bitmap_size= column_bitmap_size;
 
1967
  if (!(bitmaps= (unsigned char*) outparam.alloc_root(bitmap_size*3)))
 
1968
  {
 
1969
    goto err;
 
1970
  }
 
1971
  outparam.def_read_set.init((my_bitmap_map*) bitmaps, fields);
 
1972
  outparam.def_write_set.init((my_bitmap_map*) (bitmaps+bitmap_size), fields);
 
1973
  outparam.tmp_set.init((my_bitmap_map*) (bitmaps+bitmap_size*2), fields);
1900
1974
  outparam.default_column_bitmaps();
1901
1975
 
1902
 
  return 0;
1903
 
}
1904
 
 
1905
 
int TableShare::open_table_cursor_inner(const TableIdentifier &identifier,
1906
 
                                        uint32_t db_stat, uint32_t ha_open_flags,
1907
 
                                        Table &outparam,
1908
 
                                        bool &error_reported)
1909
 
{
1910
1976
  /* The table struct is now initialized;  Open the table */
1911
 
  int local_error= 2;
 
1977
  local_error= 2;
1912
1978
  if (db_stat)
1913
1979
  {
1914
1980
    assert(!(db_stat & HA_WAIT_IF_LOCKED));
1915
1981
    int ha_err;
1916
1982
 
1917
 
    if ((ha_err= (outparam.cursor->ha_open(identifier,
1918
 
                                           (db_stat & HA_READ_ONLY ? O_RDONLY : O_RDWR),
1919
 
                                           (db_stat & HA_OPEN_TEMPORARY ? HA_OPEN_TMP_TABLE : HA_OPEN_IGNORE_IF_LOCKED) | ha_open_flags))))
 
1983
    if ((ha_err= (outparam.cursor->ha_open(identifier, &outparam, getNormalizedPath(),
 
1984
                          (db_stat & HA_READ_ONLY ? O_RDONLY : O_RDWR),
 
1985
                          (db_stat & HA_OPEN_TEMPORARY ? HA_OPEN_TMP_TABLE : HA_OPEN_IGNORE_IF_LOCKED) | ha_open_flags))))
1920
1986
    {
1921
1987
      switch (ha_err)
1922
1988
      {
1943
2009
          local_error= 7;
1944
2010
        break;
1945
2011
      }
1946
 
      return local_error;
 
2012
      goto err;
1947
2013
    }
1948
2014
  }
1949
2015
 
 
2016
#if defined(HAVE_purify)
 
2017
  memset(bitmaps, 0, bitmap_size*3);
 
2018
#endif
 
2019
 
1950
2020
  return 0;
 
2021
 
 
2022
err:
 
2023
  if (!error_reported)
 
2024
    open_table_error(local_error, errno, 0);
 
2025
 
 
2026
  delete outparam.cursor;
 
2027
  outparam.cursor= 0;                           // For easier error checking
 
2028
  outparam.db_stat= 0;
 
2029
  outparam.getMemRoot()->free_root(MYF(0));       // Safe to call on zeroed root
 
2030
  free((char*) outparam.alias);
 
2031
 
 
2032
  return (local_error);
1951
2033
}
1952
2034
 
1953
2035
/* error message when opening a form cursor */
2037
2119
  case DRIZZLE_TYPE_DATE:
2038
2120
  case DRIZZLE_TYPE_DATETIME:
2039
2121
  case DRIZZLE_TYPE_TIMESTAMP:
2040
 
  case DRIZZLE_TYPE_UUID:
2041
2122
    field_charset= &my_charset_bin;
2042
2123
  default: break;
2043
2124
  }
2050
2131
                                 null_pos,
2051
2132
                                 null_bit,
2052
2133
                                 field_name,
 
2134
                                 get_enum_pack_length(interval->count),
2053
2135
                                 interval,
2054
2136
                                 field_charset);
2055
2137
  case DRIZZLE_TYPE_VARCHAR:
2056
 
    setVariableWidth();
2057
2138
    return new (&mem_root) Field_varstring(ptr,field_length,
2058
 
                                      ha_varchar_packlength(field_length),
 
2139
                                      HA_VARCHAR_PACKLENGTH(field_length),
2059
2140
                                      null_pos,null_bit,
2060
2141
                                      field_name,
 
2142
                                      this,
2061
2143
                                      field_charset);
2062
2144
  case DRIZZLE_TYPE_BLOB:
2063
2145
    return new (&mem_root) Field_blob(ptr,
2065
2147
                                 null_bit,
2066
2148
                                 field_name,
2067
2149
                                 this,
 
2150
                                 calc_pack_length(DRIZZLE_TYPE_LONG, 0),
2068
2151
                                 field_charset);
2069
2152
  case DRIZZLE_TYPE_DECIMAL:
2070
2153
    return new (&mem_root) Field_decimal(ptr,
2086
2169
                                   decimals,
2087
2170
                                   false,
2088
2171
                                   false /* is_unsigned */);
2089
 
  case DRIZZLE_TYPE_UUID:
2090
 
    return new (&mem_root) field::Uuid(ptr,
2091
 
                                       field_length,
2092
 
                                       null_pos,
2093
 
                                       null_bit,
2094
 
                                       field_name);
2095
2172
  case DRIZZLE_TYPE_LONG:
2096
 
    return new (&mem_root) field::Int32(ptr,
2097
 
                                        field_length,
2098
 
                                        null_pos,
2099
 
                                        null_bit,
2100
 
                                        unireg_check,
2101
 
                                        field_name);
 
2173
    return new (&mem_root) Field_long(ptr,
 
2174
                                 field_length,
 
2175
                                 null_pos,
 
2176
                                 null_bit,
 
2177
                                 unireg_check,
 
2178
                                 field_name,
 
2179
                                 false,
 
2180
                                 false /* is_unsigned */);
2102
2181
  case DRIZZLE_TYPE_LONGLONG:
2103
 
    return new (&mem_root) field::Int64(ptr,
2104
 
                                        field_length,
2105
 
                                        null_pos,
2106
 
                                        null_bit,
2107
 
                                        unireg_check,
2108
 
                                        field_name);
 
2182
    return new (&mem_root) Field_int64_t(ptr,
 
2183
                                    field_length,
 
2184
                                    null_pos,
 
2185
                                    null_bit,
 
2186
                                    unireg_check,
 
2187
                                    field_name,
 
2188
                                    false,
 
2189
                                    false /* is_unsigned */);
2109
2190
  case DRIZZLE_TYPE_TIMESTAMP:
2110
2191
    return new (&mem_root) Field_timestamp(ptr,
2111
2192
                                      field_length,
2132
2213
                                 field_length,
2133
2214
                                 field_name,
2134
2215
                                 field_charset);
 
2216
  default: // Impossible (Wrong version)
 
2217
    break;
2135
2218
  }
2136
 
  assert(0);
2137
 
  abort();
 
2219
  return 0;
2138
2220
}
2139
2221
 
2140
2222