40
#include <drizzled/error.h>
41
#include <drizzled/gettext.h>
42
#include <drizzled/sql_base.h>
43
#include <drizzled/pthread_globals.h>
44
#include <drizzled/internal/my_pthread.h>
46
#include <drizzled/table.h>
47
#include <drizzled/table/shell.h>
49
#include <drizzled/session.h>
51
#include <drizzled/charset.h>
52
#include <drizzled/internal/m_string.h>
53
#include <drizzled/internal/my_sys.h>
55
#include <drizzled/item/string.h>
56
#include <drizzled/item/int.h>
57
#include <drizzled/item/decimal.h>
58
#include <drizzled/item/float.h>
59
#include <drizzled/item/null.h>
60
#include <drizzled/temporal.h>
62
#include <drizzled/field.h>
63
#include <drizzled/field/str.h>
64
#include <drizzled/field/num.h>
65
#include <drizzled/field/blob.h>
66
#include <drizzled/field/boolean.h>
67
#include <drizzled/field/enum.h>
68
#include <drizzled/field/null.h>
69
#include <drizzled/field/date.h>
70
#include <drizzled/field/decimal.h>
71
#include <drizzled/field/real.h>
72
#include <drizzled/field/double.h>
73
#include <drizzled/field/int32.h>
74
#include <drizzled/field/int64.h>
75
#include <drizzled/field/size.h>
76
#include <drizzled/field/num.h>
77
#include <drizzled/field/time.h>
78
#include <drizzled/field/epoch.h>
79
#include <drizzled/field/datetime.h>
80
#include <drizzled/field/microtime.h>
81
#include <drizzled/field/varstring.h>
82
#include <drizzled/field/uuid.h>
84
#include <drizzled/plugin/storage_engine.h>
86
#include <drizzled/definition/cache.h>
87
#include <drizzled/typelib.h>
89
#include <drizzled/refresh_version.h>
40
#include "drizzled/error.h"
41
#include "drizzled/gettext.h"
42
#include "drizzled/sql_base.h"
43
#include "drizzled/pthread_globals.h"
44
#include "drizzled/internal/my_pthread.h"
45
#include "drizzled/plugin/event_observer.h"
47
#include "drizzled/session.h"
49
#include "drizzled/charset.h"
50
#include "drizzled/internal/m_string.h"
51
#include "drizzled/internal/my_sys.h"
53
#include "drizzled/item/string.h"
54
#include "drizzled/item/int.h"
55
#include "drizzled/item/decimal.h"
56
#include "drizzled/item/float.h"
57
#include "drizzled/item/null.h"
58
#include "drizzled/temporal.h"
60
#include "drizzled/field.h"
61
#include "drizzled/field/str.h"
62
#include "drizzled/field/num.h"
63
#include "drizzled/field/blob.h"
64
#include "drizzled/field/enum.h"
65
#include "drizzled/field/null.h"
66
#include "drizzled/field/date.h"
67
#include "drizzled/field/decimal.h"
68
#include "drizzled/field/real.h"
69
#include "drizzled/field/double.h"
70
#include "drizzled/field/long.h"
71
#include "drizzled/field/int64_t.h"
72
#include "drizzled/field/num.h"
73
#include "drizzled/field/timestamp.h"
74
#include "drizzled/field/datetime.h"
75
#include "drizzled/field/varstring.h"
91
77
using namespace std;
96
82
extern size_t table_def_size;
99
static enum_field_types proto_field_type_to_drizzle_type(const message::Table::Field &field)
83
static TableDefinitionCache table_def_cache;
84
static pthread_mutex_t LOCK_table_share;
85
bool table_def_inited= false;
87
/*****************************************************************************
88
Functions to handle table definition cach (TableShare)
89
*****************************************************************************/
92
void TableShare::cacheStart(void)
94
pthread_mutex_init(&LOCK_table_share, MY_MUTEX_INIT_FAST);
95
table_def_inited= true;
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.
101
table_def_cache.rehash(table_def_size);
105
void TableShare::cacheStop(void)
107
if (table_def_inited)
109
table_def_inited= false;
110
pthread_mutex_destroy(&LOCK_table_share);
116
* @TODO: This should return size_t
118
uint32_t cached_table_definitions(void)
120
return static_cast<uint32_t>(table_def_cache.size());
125
Mark that we are not using table share anymore.
132
If ref_count goes to zero and (we have done a refresh or if we have
133
already too many open table shares) then delete the definition.
136
void TableShare::release(TableShare *share)
138
bool to_be_deleted= false;
139
safe_mutex_assert_owner(&LOCK_open);
141
pthread_mutex_lock(&share->mutex);
142
if (!--share->ref_count)
149
TableIdentifier identifier(share->getSchemaName(), share->getTableName());
150
plugin::EventObserver::deregisterTableEvents(*share);
152
TableDefinitionCache::iterator iter= table_def_cache.find(identifier.getKey());
153
if (iter != table_def_cache.end())
155
table_def_cache.erase(iter);
160
pthread_mutex_unlock(&share->mutex);
163
void TableShare::release(TableIdentifier &identifier)
165
TableDefinitionCache::iterator iter= table_def_cache.find(identifier.getKey());
166
if (iter != table_def_cache.end())
168
TableShare *share= (*iter).second;
169
share->version= 0; // Mark for delete
170
if (share->ref_count == 0)
172
pthread_mutex_lock(&share->mutex);
173
plugin::EventObserver::deregisterTableEvents(*share);
174
table_def_cache.erase(identifier.getKey());
181
static TableShare *foundTableShare(TableShare *share)
184
We found an existing table definition. Return it if we didn't get
185
an error when reading the table definition from file.
188
/* We must do a lock to ensure that the structure is initialized */
189
(void) pthread_mutex_lock(&share->mutex);
192
/* Table definition contained an error */
193
share->open_table_error(share->error, share->open_errno, share->errarg);
194
(void) pthread_mutex_unlock(&share->mutex);
199
share->incrementTableCount();
200
(void) pthread_mutex_unlock(&share->mutex);
206
Get TableShare for a table.
209
session Thread handle
210
table_list Table that should be opened
212
key_length Length of key
213
error out: Error code from open_table_def()
216
Get a table definition from the table definition cache.
217
If it doesn't exist, create a new from the table definition file.
220
We must have wrlock on LOCK_open when we come here
221
(To be changed later)
228
TableShare *TableShare::getShareCreate(Session *session,
229
TableIdentifier &identifier,
232
TableShare *share= NULL;
236
/* Read table definition from cache */
237
TableDefinitionCache::iterator iter= table_def_cache.find(identifier.getKey());
238
if (iter != table_def_cache.end())
240
share= (*iter).second;
241
return foundTableShare(share);
244
if (not (share= new TableShare(message::Table::STANDARD, identifier)))
250
Lock mutex to be able to read table definition from file without
253
(void) pthread_mutex_lock(&share->mutex);
256
* @TODO: we need to eject something if we exceed table_def_size
258
pair<TableDefinitionCache::iterator, bool> ret=
259
table_def_cache.insert(make_pair(identifier.getKey(), share));
260
if (ret.second == false)
267
if (share->open_table_def(*session, identifier))
269
*error= share->error;
270
table_def_cache.erase(identifier.getKey());
275
share->ref_count++; // Mark in use
277
plugin::EventObserver::registerTableEvents(*share);
279
(void) pthread_mutex_unlock(&share->mutex);
286
Check if table definition exits in cache
289
get_cached_table_share()
291
table_name Table name
295
# TableShare for table
297
TableShare *TableShare::getShare(TableIdentifier &identifier)
299
safe_mutex_assert_owner(&LOCK_open);
301
TableDefinitionCache::iterator iter= table_def_cache.find(identifier.getKey());
302
if (iter != table_def_cache.end())
304
return (*iter).second;
312
static enum_field_types proto_field_type_to_drizzle_type(uint32_t proto_field_type)
314
enum_field_types field_type;
316
switch(proto_field_type)
103
318
case message::Table::Field::INTEGER:
104
return DRIZZLE_TYPE_LONG;
319
field_type= DRIZZLE_TYPE_LONG;
106
321
case message::Table::Field::DOUBLE:
107
return DRIZZLE_TYPE_DOUBLE;
109
case message::Table::Field::EPOCH:
110
if (field.has_time_options() and field.time_options().microseconds())
111
return DRIZZLE_TYPE_MICROTIME;
113
return DRIZZLE_TYPE_TIMESTAMP;
322
field_type= DRIZZLE_TYPE_DOUBLE;
324
case message::Table::Field::TIMESTAMP:
325
field_type= DRIZZLE_TYPE_TIMESTAMP;
115
327
case message::Table::Field::BIGINT:
116
return DRIZZLE_TYPE_LONGLONG;
328
field_type= DRIZZLE_TYPE_LONGLONG;
118
330
case message::Table::Field::DATETIME:
119
return DRIZZLE_TYPE_DATETIME;
331
field_type= DRIZZLE_TYPE_DATETIME;
121
333
case message::Table::Field::DATE:
122
return DRIZZLE_TYPE_DATE;
334
field_type= DRIZZLE_TYPE_DATE;
124
336
case message::Table::Field::VARCHAR:
125
return DRIZZLE_TYPE_VARCHAR;
337
field_type= DRIZZLE_TYPE_VARCHAR;
127
339
case message::Table::Field::DECIMAL:
128
return DRIZZLE_TYPE_DECIMAL;
340
field_type= DRIZZLE_TYPE_DECIMAL;
130
342
case message::Table::Field::ENUM:
131
return DRIZZLE_TYPE_ENUM;
343
field_type= DRIZZLE_TYPE_ENUM;
133
345
case message::Table::Field::BLOB:
134
return DRIZZLE_TYPE_BLOB;
136
case message::Table::Field::UUID:
137
return DRIZZLE_TYPE_UUID;
139
case message::Table::Field::BOOLEAN:
140
return DRIZZLE_TYPE_BOOLEAN;
142
case message::Table::Field::TIME:
143
return DRIZZLE_TYPE_TIME;
346
field_type= DRIZZLE_TYPE_BLOB;
349
field_type= DRIZZLE_TYPE_LONG; /* Set value to kill GCC warning */
149
356
static Item *default_value_item(enum_field_types field_type,
352
blob_ptr_size(portable_sizeof_char_ptr),
569
column_bitmap_size(0),
353
571
db_low_byte_first(false),
573
replace_with_name_lock(false),
574
waiting_on_cond(false),
577
event_observers(NULL),
357
580
assert(identifier.getKey() == key);
583
memset(&path, 0, sizeof(LEX_STRING));
584
memset(&normalized_path, 0, sizeof(LEX_STRING));
359
586
private_key_for_cache= key;
588
memory::init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
361
589
table_category= TABLE_CATEGORY_TEMPORARY;
362
590
tmp_table= message::Table::INTERNAL;
364
db.str= const_cast<char *>(private_key_for_cache.vector());
365
db.length= strlen(private_key_for_cache.vector());
592
db.str= &private_key_for_cache[0];
593
db.length= strlen(&private_key_for_cache[0]);
367
table_name.str= const_cast<char *>(private_key_for_cache.vector()) + strlen(private_key_for_cache.vector()) + 1;
595
table_name.str= &private_key_for_cache[0] + strlen(&private_key_for_cache[0]) + 1;
368
596
table_name.length= strlen(table_name.str);
369
597
path.str= (char *)"";
370
598
normalized_path.str= path.str;
371
599
path.length= normalized_path.length= 0;
373
std::string tb_name(identifier.getTableName());
374
std::transform(tb_name.begin(), tb_name.end(), tb_name.begin(), ::tolower);
375
assert(strcmp(tb_name.c_str(), table_name.str) == 0);
600
assert(strcmp(identifier.getTableName().c_str(), table_name.str) == 0);
377
601
assert(strcmp(identifier.getSchemaName().c_str(), db.str) == 0);
381
TableShare::TableShare(const identifier::Table &identifier) : // Just used during createTable()
605
TableShare::TableShare(const TableIdentifier &identifier) : // Just used during createTable()
382
606
table_category(TABLE_UNKNOWN_CATEGORY),
383
608
found_next_number_field(NULL),
384
609
timestamp_field(NULL),
386
mem_root(TABLE_ALLOC_BLOCK_SIZE),
390
table_name(NULL_LEX_STRING),
391
path(NULL_LEX_STRING),
392
normalized_path(NULL_LEX_STRING),
395
614
timestamp_offset(0),
397
616
stored_rec_length(0),
617
row_type(ROW_TYPE_DEFAULT),
399
_table_message(NULL),
400
620
storage_engine(NULL),
401
621
tmp_table(identifier.getType()),
404
624
last_null_bit_pos(0),
406
626
rec_buff_length(0),
427
blob_ptr_size(portable_sizeof_char_ptr),
648
column_bitmap_size(0),
428
650
db_low_byte_first(false),
652
replace_with_name_lock(false),
653
waiting_on_cond(false),
656
event_observers(NULL),
660
memset(&db, 0, sizeof(LEX_STRING));
661
memset(&table_name, 0, sizeof(LEX_STRING));
662
memset(&path, 0, sizeof(LEX_STRING));
663
memset(&normalized_path, 0, sizeof(LEX_STRING));
432
665
private_key_for_cache= identifier.getKey();
433
666
assert(identifier.getPath().size()); // Since we are doing a create table, this should be a positive value
434
667
private_normalized_path.resize(identifier.getPath().size() + 1);
435
668
memcpy(&private_normalized_path[0], identifier.getPath().c_str(), identifier.getPath().size());
671
memory::init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
438
672
table_category= TABLE_CATEGORY_TEMPORARY;
439
673
tmp_table= message::Table::INTERNAL;
440
db.str= const_cast<char *>(private_key_for_cache.vector());
441
db.length= strlen(private_key_for_cache.vector());
674
db.str= &private_key_for_cache[0];
675
db.length= strlen(&private_key_for_cache[0]);
442
676
table_name.str= db.str + 1;
443
677
table_name.length= strlen(table_name.str);
444
678
path.str= &private_normalized_path[0];
527
identifier::Table::build_table_filename(_path, db.str, table_name.str, false);
771
TableIdentifier::build_table_filename(_path, db.str, table_name.str, false);
530
if ((path_buff= (char *)mem_root.alloc_root(_path.length() + 1)))
774
if (mem_root.multi_alloc_root(0,
775
&path_buff, _path.length() + 1,
532
778
setPath(path_buff, _path.length());
533
779
strcpy(path_buff, _path.c_str());
534
780
setNormalizedPath(path_buff, _path.length());
536
782
version= refresh_version;
784
pthread_mutex_init(&mutex, MY_MUTEX_INIT_FAST);
785
pthread_cond_init(&cond, NULL);
540
789
assert(0); // We should throw here.
545
795
void TableShare::init(const char *new_table_name,
546
796
const char *new_path)
799
memory::init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
549
800
table_category= TABLE_CATEGORY_TEMPORARY;
550
801
tmp_table= message::Table::INTERNAL;
551
802
db.str= (char *)"";
560
811
TableShare::~TableShare()
813
assert(ref_count == 0);
816
If someone is waiting for this to be deleted, inform it about this.
817
Don't do a delete until we know that no one is refering to this anymore.
819
if (tmp_table == message::Table::STANDARD)
821
/* share->mutex is locked in release_table_share() */
822
while (waiting_on_cond)
824
pthread_cond_broadcast(&cond);
825
pthread_cond_wait(&cond, &mutex);
827
/* No thread refers to this anymore */
828
pthread_mutex_unlock(&mutex);
829
pthread_mutex_destroy(&mutex);
830
pthread_cond_destroy(&cond);
562
833
storage_engine= NULL;
564
838
mem_root.free_root(MYF(0)); // Free's share
567
void TableShare::setIdentifier(const identifier::Table &identifier_arg)
841
void TableShare::setIdentifier(TableIdentifier &identifier_arg)
843
private_key_for_cache.clear();
569
844
private_key_for_cache= identifier_arg.getKey();
572
847
Let us use the fact that the key is "db/0/table_name/0" + optional
573
848
part for temporary tables.
575
db.str= const_cast<char *>(private_key_for_cache.vector());
850
db.str= &private_key_for_cache[0];
576
851
db.length= strlen(db.str);
577
852
table_name.str= db.str + db.length + 1;
578
853
table_name.length= strlen(table_name.str);
580
getTableMessage()->set_name(identifier_arg.getTableName());
581
getTableMessage()->set_schema(identifier_arg.getSchemaName());
855
table_proto->set_name(identifier_arg.getTableName());
856
table_proto->set_schema(identifier_arg.getSchemaName());
584
bool TableShare::parse_table_proto(Session& session, message::Table &table)
859
int TableShare::inner_parse_table_proto(Session& session, message::Table &table)
586
drizzled::error_t local_error= EE_OK;
588
863
if (! table.IsInitialized())
590
my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0),
591
table.name().empty() ? " " : table.name().c_str(),
592
table.InitializationErrorString().c_str());
865
my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0), table.InitializationErrorString().c_str());
594
866
return ER_CORRUPT_TABLE_DEFINITION;
597
setTableMessage(table);
869
setTableProto(new(nothrow) message::Table(table));
599
871
storage_engine= plugin::StorageEngine::findByName(session, table.engine().name());
600
872
assert(storage_engine); // We use an assert() here because we should never get this far and still have no suitable engine.
780
1044
keys_for_keyread.reset();
781
1045
set_prefix(keys_in_use, keys);
783
_field_size= table.field_size();
1047
fields= table.field_size();
785
setFields(_field_size + 1);
786
_fields[_field_size]= NULL;
1049
setFields(fields + 1);
1050
field[fields]= NULL;
788
1052
uint32_t local_null_fields= 0;
791
std::vector<uint32_t> field_offsets;
792
std::vector<uint32_t> field_pack_length;
1055
vector<uint32_t> field_offsets;
1056
vector<uint32_t> field_pack_length;
794
field_offsets.resize(_field_size);
795
field_pack_length.resize(_field_size);
1058
field_offsets.resize(fields);
1059
field_pack_length.resize(fields);
797
1061
uint32_t interval_count= 0;
798
1062
uint32_t interval_parts= 0;
800
1064
uint32_t stored_columns_reclength= 0;
802
for (unsigned int fieldnr= 0; fieldnr < _field_size; fieldnr++)
1066
for (unsigned int fieldnr= 0; fieldnr < fields; fieldnr++)
804
1068
message::Table::Field pfield= table.field(fieldnr);
805
if (pfield.constraints().is_nullable()) // Historical reference
809
else if (not pfield.constraints().is_notnull())
1069
if (pfield.constraints().is_nullable())
1070
local_null_fields++;
814
enum_field_types drizzle_field_type= proto_field_type_to_drizzle_type(pfield);
1072
enum_field_types drizzle_field_type=
1073
proto_field_type_to_drizzle_type(pfield.type());
816
1075
field_offsets[fieldnr]= stored_columns_reclength;
1165
1436
case DRIZZLE_TYPE_LONGLONG:
1167
uint32_t sign_len= pfield.constraints().is_unsigned() ? 0 : 1;
1168
field_length= MAX_BIGINT_WIDTH+sign_len;
1171
case DRIZZLE_TYPE_UUID:
1172
field_length= field::Uuid::max_string_length();
1174
case DRIZZLE_TYPE_BOOLEAN:
1175
field_length= field::Boolean::max_string_length();
1177
case DRIZZLE_TYPE_MICROTIME:
1178
field_length= field::Microtime::max_string_length();
1180
case DRIZZLE_TYPE_TIMESTAMP:
1181
field_length= field::Epoch::max_string_length();
1183
case DRIZZLE_TYPE_TIME:
1184
field_length= field::Time::max_string_length();
1437
field_length= MAX_BIGINT_WIDTH;
1186
1439
case DRIZZLE_TYPE_NULL:
1187
1440
abort(); // Programming error
1190
bool is_not_null= false;
1192
if (not pfield.constraints().is_nullable())
1196
else if (pfield.constraints().is_notnull())
1201
Field* f= make_field(pfield,
1202
record + field_offsets[fieldnr] + data_offset,
1210
MTYP_TYPENR(unireg_type),
1211
((field_type == DRIZZLE_TYPE_ENUM) ? &intervals[interval_nr++] : (TYPELIB*) 0),
1212
getTableMessage()->field(fieldnr).name().c_str());
1214
_fields[fieldnr]= f;
1216
// Insert post make_field code here.
1219
case DRIZZLE_TYPE_BLOB:
1220
case DRIZZLE_TYPE_VARCHAR:
1221
case DRIZZLE_TYPE_DOUBLE:
1222
case DRIZZLE_TYPE_DECIMAL:
1223
case DRIZZLE_TYPE_TIMESTAMP:
1224
case DRIZZLE_TYPE_TIME:
1225
case DRIZZLE_TYPE_DATETIME:
1226
case DRIZZLE_TYPE_MICROTIME:
1227
case DRIZZLE_TYPE_DATE:
1228
case DRIZZLE_TYPE_ENUM:
1229
case DRIZZLE_TYPE_LONG:
1230
case DRIZZLE_TYPE_LONGLONG:
1231
case DRIZZLE_TYPE_NULL:
1232
case DRIZZLE_TYPE_UUID:
1233
case DRIZZLE_TYPE_BOOLEAN:
1237
// This needs to go, we should be setting the "use" on the field so that
1238
// it does not reference the share/table.
1239
table::Shell temp_table(*this); /* Use this so that BLOB DEFAULT '' works */
1240
temp_table.in_use= &session;
1443
Field* f= make_field(record + field_offsets[fieldnr] + data_offset,
1445
pfield.constraints().is_nullable(),
1451
(Field::utype) MTYP_TYPENR(unireg_type),
1452
((field_type == DRIZZLE_TYPE_ENUM) ?
1453
&intervals[interval_nr++]
1455
getTableProto()->field(fieldnr).name().c_str());
1242
1459
f->init(&temp_table); /* blob default values need table obj */
1526
1770
6 Unknown .frm version
1529
int TableShare::open_table_def(Session& session, const identifier::Table &identifier)
1773
int TableShare::open_table_def(Session& session, TableIdentifier &identifier)
1531
drizzled::error_t local_error= EE_OK;
1533
message::table::shared_ptr table= plugin::StorageEngine::getTableMessage(session, identifier, local_error);
1535
if (table and table->IsInitialized())
1781
message::Table table;
1783
local_error= plugin::StorageEngine::getTableDefinition(session, identifier, table);
1785
if (local_error != EEXIST)
1537
if (parse_table_proto(session, *table))
1787
if (local_error > 0)
1539
local_error= ER_CORRUPT_TABLE_DEFINITION_UNKNOWN;
1540
my_error(ER_CORRUPT_TABLE_DEFINITION_UNKNOWN, identifier);
1544
setTableCategory(TABLE_CATEGORY_USER);
1794
if (not table.IsInitialized())
1548
else if (table and not table->IsInitialized())
1550
local_error= ER_CORRUPT_TABLE_DEFINITION_UNKNOWN;
1551
my_error(ER_CORRUPT_TABLE_DEFINITION_UNKNOWN, identifier);
1555
local_error= ER_TABLE_UNKNOWN;
1556
my_error(ER_TABLE_UNKNOWN, identifier);
1559
return static_cast<int>(local_error);
1802
local_error= parse_table_proto(session, table);
1804
setTableCategory(TABLE_CATEGORY_USER);
1807
if (local_error && !error_given)
1810
open_table_error(error, (open_errno= errno), 0);
1583
1837
5 Error (see open_table_error: charset unavailable)
1584
1838
7 Table definition has changed in engine
1586
1841
int TableShare::open_table_from_share(Session *session,
1587
const identifier::Table &identifier,
1842
const TableIdentifier &identifier,
1588
1843
const char *alias,
1589
1844
uint32_t db_stat, uint32_t ha_open_flags,
1590
1845
Table &outparam)
1848
uint32_t records, bitmap_size;
1592
1849
bool error_reported= false;
1593
int ret= open_table_from_share_inner(session, alias, db_stat, outparam);
1596
ret= open_table_cursor_inner(identifier, db_stat, ha_open_flags, outparam, error_reported);
1601
if (not error_reported)
1602
open_table_error(ret, errno, 0);
1604
boost::checked_delete(outparam.cursor);
1605
outparam.cursor= 0; // For easier error checking
1606
outparam.db_stat= 0;
1607
outparam.getMemRoot()->free_root(MYF(0)); // Safe to call on zeroed root
1608
outparam.clearAlias();
1613
int TableShare::open_table_from_share_inner(Session *session,
1620
unsigned char *record= NULL;
1850
unsigned char *record, *bitmaps;
1621
1851
Field **field_ptr;
1853
/* Parsing of partitioning information from .frm needs session->lex set up. */
1854
assert(session->lex->is_lex_started);
1623
1856
local_error= 1;
1624
1857
outparam.resetTable(session, this, db_stat);
1626
outparam.setAlias(alias);
1860
if (not (outparam.alias= strdup(alias)))
1628
1863
/* Allocate Cursor */
1629
if (not (outparam.cursor= db_type()->getCursor(outparam)))
1864
if (not (outparam.cursor= db_type()->getCursor(*this, outparam.getMemRoot())))
1632
1867
local_error= 4;
1650
1885
if (records > 1)
1651
1886
outparam.record[1]= record+ rec_buff_length;
1653
outparam.record[1]= outparam.getInsertRecord(); // Safety
1888
outparam.record[1]= outparam.record[0]; // Safety
1656
#ifdef HAVE_VALGRIND
1658
1893
We need this because when we read var-length rows, we are not updating
1659
1894
bytes after end of varchar
1661
1896
if (records > 1)
1663
memcpy(outparam.getInsertRecord(), getDefaultValues(), rec_buff_length);
1664
memcpy(outparam.getUpdateRecord(), getDefaultValues(), null_bytes);
1898
memcpy(outparam.record[0], getDefaultValues(), rec_buff_length);
1899
memcpy(outparam.record[1], getDefaultValues(), null_bytes);
1665
1900
if (records > 2)
1666
memcpy(outparam.getUpdateRecord(), getDefaultValues(), rec_buff_length);
1901
memcpy(outparam.record[1], getDefaultValues(), rec_buff_length);
1669
1904
if (records > 1)
1671
memcpy(outparam.getUpdateRecord(), getDefaultValues(), null_bytes);
1906
memcpy(outparam.record[1], getDefaultValues(), null_bytes);
1674
if (!(field_ptr = (Field **) outparam.alloc_root( (uint32_t) ((_field_size+1)* sizeof(Field*)))))
1909
if (!(field_ptr = (Field **) outparam.alloc_root( (uint32_t) ((fields+1)* sizeof(Field*)))))
1679
1914
outparam.setFields(field_ptr);
1681
record= (unsigned char*) outparam.getInsertRecord()-1; /* Fieldstart = 1 */
1916
record= (unsigned char*) outparam.record[0]-1; /* Fieldstart = 1 */
1683
1918
outparam.null_flags= (unsigned char*) record+1;
1685
1920
/* Setup copy of fields from share, but use the right alias and record */
1686
for (uint32_t i= 0 ; i < _field_size; i++, field_ptr++)
1921
for (uint32_t i= 0 ; i < fields; i++, field_ptr++)
1688
if (!((*field_ptr)= _fields[i]->clone(outparam.getMemRoot(), &outparam)))
1923
if (!((*field_ptr)= field[i]->clone(outparam.getMemRoot(), &outparam)))
1691
1926
(*field_ptr)= 0; // End marker
1744
1980
/* Allocate bitmaps */
1746
outparam.def_read_set.resize(_field_size);
1747
outparam.def_write_set.resize(_field_size);
1748
outparam.tmp_set.resize(_field_size);
1982
bitmap_size= column_bitmap_size;
1983
if (!(bitmaps= (unsigned char*) outparam.alloc_root(bitmap_size*3)))
1987
outparam.def_read_set.init((my_bitmap_map*) bitmaps, fields);
1988
outparam.def_write_set.init((my_bitmap_map*) (bitmaps+bitmap_size), fields);
1989
outparam.tmp_set.init((my_bitmap_map*) (bitmaps+bitmap_size*2), fields);
1749
1990
outparam.default_column_bitmaps();
1754
int TableShare::open_table_cursor_inner(const identifier::Table &identifier,
1755
uint32_t db_stat, uint32_t ha_open_flags,
1757
bool &error_reported)
1759
1992
/* The table struct is now initialized; Open the table */
1763
1996
assert(!(db_stat & HA_WAIT_IF_LOCKED));
1766
if ((ha_err= (outparam.cursor->ha_open(identifier,
1767
(db_stat & HA_READ_ONLY ? O_RDONLY : O_RDWR),
1768
(db_stat & HA_OPEN_TEMPORARY ? HA_OPEN_TMP_TABLE : HA_OPEN_IGNORE_IF_LOCKED) | ha_open_flags))))
1999
if ((ha_err= (outparam.cursor->ha_open(identifier, &outparam, getNormalizedPath(),
2000
(db_stat & HA_READ_ONLY ? O_RDONLY : O_RDWR),
2001
(db_stat & HA_OPEN_TEMPORARY ? HA_OPEN_TMP_TABLE : HA_OPEN_IGNORE_IF_LOCKED) | ha_open_flags))))
1770
2003
switch (ha_err)
1958
2186
false /* is_unsigned */);
1959
case DRIZZLE_TYPE_UUID:
1960
return new (&mem_root) field::Uuid(ptr,
1965
case DRIZZLE_TYPE_BOOLEAN:
1966
return new (&mem_root) field::Boolean(ptr,
1972
2187
case DRIZZLE_TYPE_LONG:
1973
return new (&mem_root) field::Int32(ptr,
2188
return new (&mem_root) Field_long(ptr,
2195
false /* is_unsigned */);
1979
2196
case DRIZZLE_TYPE_LONGLONG:
1983
return new (&mem_root) field::Size(ptr,
1991
return new (&mem_root) field::Int64(ptr,
1998
case DRIZZLE_TYPE_MICROTIME:
1999
return new (&mem_root) field::Microtime(ptr,
2197
return new (&mem_root) Field_int64_t(ptr,
2204
false /* is_unsigned */);
2005
2205
case DRIZZLE_TYPE_TIMESTAMP:
2006
return new (&mem_root) field::Epoch(ptr,
2012
case DRIZZLE_TYPE_TIME:
2013
return new (&mem_root) field::Time(ptr,
2206
return new (&mem_root) Field_timestamp(ptr,
2018
2214
case DRIZZLE_TYPE_DATE:
2019
2215
return new (&mem_root) Field_date(ptr,
2023
2220
case DRIZZLE_TYPE_DATETIME:
2024
2221
return new (&mem_root) Field_datetime(ptr,
2028
2226
case DRIZZLE_TYPE_NULL:
2029
2227
return new (&mem_root) Field_null(ptr,
2231
default: // Impossible (Wrong version)
2037
void TableShare::refreshVersion()
2039
version= refresh_version;