1422
1422
/****************************************************************************/
1425
Create a reduced Table object with properly set up Field list from a
1426
list of field definitions.
1428
The created table doesn't have a table Cursor associated with
1429
it, has no keys, no group/distinct, no copy_funcs array.
1430
The sole purpose of this Table object is to use the power of Field
1431
class to read/write data to/from table->getInsertRecord(). Then one can store
1432
the record in any container (RB tree, hash, etc).
1433
The table is created in Session mem_root, so are the table's fields.
1434
Consequently, if you don't BLOB fields, you don't need to free it.
1436
@param session connection handle
1437
@param field_list list of column definitions
1440
0 if out of memory, Table object in case of success
1443
Table *Session::create_virtual_tmp_table(List<CreateField> &field_list)
1445
uint32_t field_count= field_list.elements;
1446
uint32_t blob_count= 0;
1448
CreateField *cdef; /* column definition */
1449
uint32_t record_length= 0;
1450
uint32_t null_count= 0; /* number of columns which may be null */
1451
uint32_t null_pack_length; /* NULL representation array length */
1453
table::Instance *table= getInstanceTable(); // This will not go into the tableshare cache, so no key is used.
1454
table->getMutableShare()->setFields(field_count + 1);
1455
table->setFields(table->getMutableShare()->getFields(true));
1456
field= table->getMutableShare()->getFields(true);
1457
table->getMutableShare()->blob_field.resize(field_count+1);
1458
table->getMutableShare()->fields= field_count;
1459
table->getMutableShare()->blob_ptr_size= portable_sizeof_char_ptr;
1460
table->setup_tmp_table_column_bitmaps();
1462
table->in_use= this; /* field->reset() may access table->in_use */
1464
/* Create all fields and calculate the total length of record */
1465
List_iterator_fast<CreateField> it(field_list);
1466
while ((cdef= it++))
1468
*field= table->getMutableShare()->make_field(NULL,
1470
(cdef->flags & NOT_NULL_FLAG) ? false : true,
1471
(unsigned char *) ((cdef->flags & NOT_NULL_FLAG) ? 0 : ""),
1472
(cdef->flags & NOT_NULL_FLAG) ? 0 : 1,
1481
(*field)->init(table);
1482
record_length+= (*field)->pack_length();
1483
if (! ((*field)->flags & NOT_NULL_FLAG))
1486
if ((*field)->flags & BLOB_FLAG)
1487
table->getMutableShare()->blob_field[blob_count++]= (uint32_t) (field - table->getFields());
1491
*field= NULL; /* mark the end of the list */
1492
table->getMutableShare()->blob_field[blob_count]= 0; /* mark the end of the list */
1493
table->getMutableShare()->blob_fields= blob_count;
1495
null_pack_length= (null_count + 7)/8;
1496
table->getMutableShare()->setRecordLength(record_length + null_pack_length);
1497
table->getMutableShare()->rec_buff_length= ALIGN_SIZE(table->getMutableShare()->getRecordLength() + 1);
1498
table->record[0]= (unsigned char*)alloc(table->getMutableShare()->rec_buff_length);
1499
if (not table->getInsertRecord())
1502
if (null_pack_length)
1504
table->null_flags= (unsigned char*) table->getInsertRecord();
1505
table->getMutableShare()->null_fields= null_count;
1506
table->getMutableShare()->null_bytes= null_pack_length;
1509
/* Set up field pointers */
1510
unsigned char *null_pos= table->getInsertRecord();
1511
unsigned char *field_pos= null_pos + table->getMutableShare()->null_bytes;
1512
uint32_t null_bit= 1;
1514
for (field= table->getFields(); *field; ++field)
1516
Field *cur_field= *field;
1517
if ((cur_field->flags & NOT_NULL_FLAG))
1518
cur_field->move_field(field_pos);
1521
cur_field->move_field(field_pos, (unsigned char*) null_pos, null_bit);
1523
if (null_bit == (1 << 8))
1531
field_pos+= cur_field->pack_length();
1538
for (field= table->getFields(); *field; ++field)
1540
delete *field; /* just invokes field destructor */
1545
1424
void Table::column_bitmaps_set(boost::dynamic_bitset<>& read_set_arg,
1546
1425
boost::dynamic_bitset<>& write_set_arg)