285
int parse_table_proto(Session *session, drizzle::Table &table, TABLE_SHARE *share)
288
LEX_STRING engine_name= { (char*)table.engine().name().c_str(),
289
strlen(table.engine().name().c_str()) };
290
share->db_plugin= ha_resolve_by_name(session, &engine_name);
293
// share->db_create_options FAIL
294
// share->db_options_in_use FAIL
295
share->mysql_version= DRIZZLE_VERSION_ID; // TODO: remove
296
share->null_field_first= 0;
298
drizzle::Table::TableOptions table_options;
300
if(table.has_options())
301
table_options= table.options();
303
share->avg_row_length= table_options.has_avg_row_length() ?
304
table_options.avg_row_length() : 0;
306
share->page_checksum= table_options.has_page_checksum() ?
307
(table_options.page_checksum()?HA_CHOICE_YES:HA_CHOICE_NO)
310
share->row_type= table_options.has_row_type() ?
311
(enum row_type) table_options.row_type() : ROW_TYPE_DEFAULT;
313
share->block_size= table_options.has_block_size() ?
314
table_options.block_size() : 0;
316
share->table_charset= get_charset(table_options.has_collation_id()?
317
table_options.collation_id() : 0);
319
if (!share->table_charset)
321
/* unknown charset in head[38] or pre-3.23 frm */
322
if (use_mb(default_charset_info))
324
/* Warn that we may be changing the size of character columns */
325
errmsg_printf(ERRMSG_LVL_WARN,
326
_("'%s' had no or invalid character set, "
327
"and default character set is multi-byte, "
328
"so character column sizes may have changed"),
331
share->table_charset= default_charset_info;
334
share->null_field_first= 1;
336
share->db_record_offset= 1;
338
share->blob_ptr_size= portable_sizeof_char_ptr; // more bonghits.
340
share->db_low_byte_first= true;
342
share->max_rows= table_options.has_max_rows() ?
343
table_options.max_rows() : 0;
345
share->min_rows= table_options.has_min_rows() ?
346
table_options.min_rows() : 0;
348
share->keys= table.indexes_size();
351
for(int indx= 0; indx < table.indexes_size(); indx++)
352
share->key_parts+= table.indexes(indx).index_part_size();
354
share->key_info= (KEY*) alloc_root(&share->mem_root,
355
table.indexes_size() * sizeof(KEY)
356
+share->key_parts*sizeof(KEY_PART_INFO));
358
KEY_PART_INFO *key_part;
360
key_part= reinterpret_cast<KEY_PART_INFO*>
361
(share->key_info+table.indexes_size());
364
ulong *rec_per_key= (ulong*) alloc_root(&share->mem_root,
365
sizeof(ulong*)*share->key_parts);
367
share->keynames.count= table.indexes_size();
368
share->keynames.name= NULL;
369
share->keynames.type_names= (const char**)
370
alloc_root(&share->mem_root, sizeof(char*) * (table.indexes_size()+1));
372
share->keynames.type_lengths= (unsigned int*)
373
alloc_root(&share->mem_root,
374
sizeof(unsigned int) * (table.indexes_size()+1));
376
share->keynames.type_names[share->keynames.count]= NULL;
377
share->keynames.type_lengths[share->keynames.count]= 0;
379
KEY* keyinfo= share->key_info;
380
for (int keynr=0; keynr < table.indexes_size(); keynr++, keyinfo++)
382
drizzle::Table::Index indx= table.indexes(keynr);
388
keyinfo->flags|= HA_NOSAME;
390
if(indx.has_options())
392
drizzle::Table::Index::IndexOptions indx_options= indx.options();
393
if(indx_options.pack_key())
394
keyinfo->flags|= HA_PACK_KEY;
396
if(indx_options.var_length_key())
397
keyinfo->flags|= HA_VAR_LENGTH_PART;
399
if(indx_options.null_part_key())
400
keyinfo->flags|= HA_NULL_PART_KEY;
402
if(indx_options.binary_pack_key())
403
keyinfo->flags|= HA_BINARY_PACK_KEY;
405
if(indx_options.has_partial_segments())
406
keyinfo->flags|= HA_KEY_HAS_PART_KEY_SEG;
408
if(indx_options.auto_generated_key())
409
keyinfo->flags|= HA_GENERATED_KEY;
411
if(indx_options.has_key_block_size())
413
keyinfo->flags|= HA_USES_BLOCK_SIZE;
414
keyinfo->block_size= indx_options.key_block_size();
418
keyinfo->block_size= 0;
425
case drizzle::Table::Index::UNKNOWN_INDEX:
426
keyinfo->algorithm= HA_KEY_ALG_UNDEF;
428
case drizzle::Table::Index::BTREE:
429
keyinfo->algorithm= HA_KEY_ALG_BTREE;
431
case drizzle::Table::Index::RTREE:
432
keyinfo->algorithm= HA_KEY_ALG_RTREE;
434
case drizzle::Table::Index::HASH:
435
keyinfo->algorithm= HA_KEY_ALG_HASH;
437
case drizzle::Table::Index::FULLTEXT:
438
keyinfo->algorithm= HA_KEY_ALG_FULLTEXT;
441
/* TODO: suitable warning ? */
442
keyinfo->algorithm= HA_KEY_ALG_UNDEF;
446
keyinfo->key_length= indx.key_length();
448
keyinfo->key_parts= indx.index_part_size();
450
keyinfo->key_part= key_part;
451
keyinfo->rec_per_key= rec_per_key;
453
for(unsigned int partnr= 0;
454
partnr < keyinfo->key_parts;
455
partnr++, key_part++)
457
drizzle::Table::Index::IndexPart part;
458
part= indx.index_part(partnr);
462
key_part->field= NULL;
463
key_part->fieldnr= part.fieldnr();
464
key_part->null_bit= 0;
465
/* key_part->offset= ASS ASS ASS. Set later in the frm code */
466
/* key_part->null_offset is only set if null_bit (see later) */
467
/* key_part->key_type= */ /* I *THINK* this may be okay.... */
468
/* key_part->type ???? */
469
key_part->key_part_flag= 0;
470
if(part.has_in_reverse_order())
471
key_part->key_part_flag= part.in_reverse_order()? HA_REVERSE_SORT : 0;
473
key_part->length= part.compare_length();
475
key_part->store_length= key_part->length;
478
if(!indx.has_comment())
480
keyinfo->comment.length= 0;
481
keyinfo->comment.str= NULL;
485
keyinfo->flags|= HA_USES_COMMENT;
486
keyinfo->comment.length= indx.comment().length();
487
keyinfo->comment.str= strmake_root(&share->mem_root,
488
indx.comment().c_str(),
489
keyinfo->comment.length);
492
keyinfo->name= strmake_root(&share->mem_root,
494
indx.name().length());
496
share->keynames.type_names[keynr]= keyinfo->name;
497
share->keynames.type_lengths[keynr]= indx.name().length();
500
share->keys_for_keyread.init(0);
501
share->keys_in_use.init(share->keys);
503
if(table_options.has_connect_string())
505
size_t len= table_options.connect_string().length();
506
const char* str= table_options.connect_string().c_str();
508
share->connect_string.length= len;
509
share->connect_string.str= strmake_root(&share->mem_root, str, len);
512
if(table_options.has_comment())
514
size_t len= table_options.comment().length();
515
const char* str= table_options.comment().c_str();
517
share->comment.length= len;
518
share->comment.str= strmake_root(&share->mem_root, str, len);
521
share->key_block_size= table_options.has_key_block_size() ?
522
table_options.key_block_size() : 0;
286
528
Read table definition from a binary / text based .frm file
332
574
drizzle::Table table;
334
if(drizzle_read_table_proto(proto_path.c_str(), &table)==0)
576
if((error= drizzle_read_table_proto(proto_path.c_str(), &table)))
337
LEX_STRING engine_name= { (char*)table.engine().name().c_str(),
338
strlen(table.engine().name().c_str()) };
339
share->db_plugin= ha_resolve_by_name(session, &engine_name);
342
// share->db_create_options FAIL
343
// share->db_options_in_use FAIL
344
share->mysql_version= DRIZZLE_VERSION_ID; // TODO: remove
345
share->null_field_first= 0;
347
drizzle::Table::TableOptions table_options;
349
if(table.has_options())
350
table_options= table.options();
352
share->avg_row_length= table_options.has_avg_row_length() ?
353
table_options.avg_row_length() : 0;
355
share->page_checksum= table_options.has_page_checksum() ?
356
(table_options.page_checksum()?HA_CHOICE_YES:HA_CHOICE_NO)
359
share->row_type= table_options.has_row_type() ?
360
(enum row_type) table_options.row_type() : ROW_TYPE_DEFAULT;
362
share->block_size= table_options.has_block_size() ?
363
table_options.block_size() : 0;
365
share->table_charset= get_charset(table_options.has_collation_id()?
366
table_options.collation_id() : 0);
368
if (!share->table_charset)
370
/* unknown charset in head[38] or pre-3.23 frm */
371
if (use_mb(default_charset_info))
373
/* Warn that we may be changing the size of character columns */
374
errmsg_printf(ERRMSG_LVL_WARN,
375
_("'%s' had no or invalid character set, "
376
"and default character set is multi-byte, "
377
"so character column sizes may have changed"),
380
share->table_charset= default_charset_info;
383
share->null_field_first= 1;
385
share->db_record_offset= 1;
387
share->blob_ptr_size= portable_sizeof_char_ptr; // more bonghits.
389
share->db_low_byte_first= true;
391
share->max_rows= table_options.has_max_rows() ?
392
table_options.max_rows() : 0;
394
share->min_rows= table_options.has_min_rows() ?
395
table_options.min_rows() : 0;
397
share->keys= table.indexes_size();
400
for(int indx= 0; indx < table.indexes_size(); indx++)
401
share->key_parts+= table.indexes(indx).index_part_size();
403
share->key_info= (KEY*) alloc_root(&share->mem_root,
404
table.indexes_size() * sizeof(KEY)
405
+share->key_parts*sizeof(KEY_PART_INFO));
407
KEY_PART_INFO *key_part;
409
key_part= reinterpret_cast<KEY_PART_INFO*>
410
(share->key_info+table.indexes_size());
413
ulong *rec_per_key= (ulong*) alloc_root(&share->mem_root,
414
sizeof(ulong*)*share->key_parts);
416
share->keynames.count= table.indexes_size();
417
share->keynames.name= NULL;
418
share->keynames.type_names= (const char**)
419
alloc_root(&share->mem_root, sizeof(char*) * (table.indexes_size()+1));
421
share->keynames.type_lengths= (unsigned int*)
422
alloc_root(&share->mem_root,
423
sizeof(unsigned int) * (table.indexes_size()+1));
425
share->keynames.type_names[share->keynames.count]= NULL;
426
share->keynames.type_lengths[share->keynames.count]= 0;
428
KEY* keyinfo= share->key_info;
429
for (int keynr=0; keynr < table.indexes_size(); keynr++, keyinfo++)
431
drizzle::Table::Index indx= table.indexes(keynr);
437
keyinfo->flags|= HA_NOSAME;
439
if(indx.has_options())
441
drizzle::Table::Index::IndexOptions indx_options= indx.options();
442
if(indx_options.pack_key())
443
keyinfo->flags|= HA_PACK_KEY;
445
if(indx_options.var_length_key())
446
keyinfo->flags|= HA_VAR_LENGTH_PART;
448
if(indx_options.null_part_key())
449
keyinfo->flags|= HA_NULL_PART_KEY;
451
if(indx_options.binary_pack_key())
452
keyinfo->flags|= HA_BINARY_PACK_KEY;
454
if(indx_options.has_partial_segments())
455
keyinfo->flags|= HA_KEY_HAS_PART_KEY_SEG;
457
if(indx_options.auto_generated_key())
458
keyinfo->flags|= HA_GENERATED_KEY;
460
if(indx_options.has_key_block_size())
462
keyinfo->flags|= HA_USES_BLOCK_SIZE;
463
keyinfo->block_size= indx_options.key_block_size();
467
keyinfo->block_size= 0;
474
case drizzle::Table::Index::UNKNOWN_INDEX:
475
keyinfo->algorithm= HA_KEY_ALG_UNDEF;
477
case drizzle::Table::Index::BTREE:
478
keyinfo->algorithm= HA_KEY_ALG_BTREE;
480
case drizzle::Table::Index::RTREE:
481
keyinfo->algorithm= HA_KEY_ALG_RTREE;
483
case drizzle::Table::Index::HASH:
484
keyinfo->algorithm= HA_KEY_ALG_HASH;
486
case drizzle::Table::Index::FULLTEXT:
487
keyinfo->algorithm= HA_KEY_ALG_FULLTEXT;
490
/* TODO: suitable warning ? */
491
keyinfo->algorithm= HA_KEY_ALG_UNDEF;
495
keyinfo->key_length= indx.key_length();
497
keyinfo->key_parts= indx.index_part_size();
499
keyinfo->key_part= key_part;
500
keyinfo->rec_per_key= rec_per_key;
502
for(unsigned int partnr= 0;
503
partnr < keyinfo->key_parts;
504
partnr++, key_part++)
506
drizzle::Table::Index::IndexPart part;
507
part= indx.index_part(partnr);
511
key_part->field= NULL;
512
key_part->fieldnr= part.fieldnr();
513
key_part->null_bit= 0;
514
/* key_part->offset= ASS ASS ASS. Set later in the frm code */
515
/* key_part->null_offset is only set if null_bit (see later) */
516
/* key_part->key_type= */ /* I *THINK* this may be okay.... */
517
/* key_part->type ???? */
518
key_part->key_part_flag= 0;
519
if(part.has_in_reverse_order())
520
key_part->key_part_flag= part.in_reverse_order()? HA_REVERSE_SORT : 0;
522
key_part->length= part.compare_length();
524
key_part->store_length= key_part->length;
527
if(!indx.has_comment())
529
keyinfo->comment.length= 0;
530
keyinfo->comment.str= NULL;
534
keyinfo->flags|= HA_USES_COMMENT;
535
keyinfo->comment.length= indx.comment().length();
536
keyinfo->comment.str= strmake_root(&share->mem_root,
537
indx.comment().c_str(),
538
keyinfo->comment.length);
541
keyinfo->name= strmake_root(&share->mem_root,
543
indx.name().length());
545
share->keynames.type_names[keynr]= keyinfo->name;
546
share->keynames.type_lengths[keynr]= indx.name().length();
549
share->keys_for_keyread.init(0);
550
share->keys_in_use.init(share->keys);
552
if(table_options.has_connect_string())
554
size_t len= table_options.connect_string().length();
555
const char* str= table_options.connect_string().c_str();
557
share->connect_string.length= len;
558
share->connect_string.str= strmake_root(&share->mem_root, str, len);
561
if(table_options.has_comment())
563
size_t len= table_options.comment().length();
564
const char* str= table_options.comment().c_str();
566
share->comment.length= len;
567
share->comment.str= strmake_root(&share->mem_root, str, len);
570
share->key_block_size= table_options.has_key_block_size() ?
571
table_options.key_block_size() : 0;
585
if(!table.IsInitialized())
593
parse_table_proto(session, table, share);
595
/* end of proto code... now to get some scraps from FRM */
578
597
if ((file= open(path.c_str(), O_RDONLY)) < 0)