600
601
XTThreadPtr self;
601
602
static int ha_thread_count = 0, ha_id;
604
604
if (!(self = (XTThreadPtr) *thd->getEngineData(pbxt_hton))) {
606
if (!(self = (XTThreadPtr) *thd_ha_data(thd, pbxt_hton))) {
608
605
// const Security_context *sctx;
610
607
char ha_id_str[50];
649
642
XTThreadPtr self;
652
644
if (!(self = (XTThreadPtr) *thd->getEngineData(pbxt_hton))) {
653
645
*thd->getEngineData(pbxt_hton) = NULL;
655
if ((self = (XTThreadPtr) *thd_ha_data(thd, pbxt_hton))) {
656
*thd_ha_data(thd, pbxt_hton) = NULL;
658
646
xt_free_thread(self);
662
650
xtPublic XTThreadPtr xt_ha_thd_to_self(THD *thd)
665
652
return (XTThreadPtr) *thd->getEngineData(pbxt_hton);
667
return (XTThreadPtr) *thd_ha_data(thd, pbxt_hton);
672
/* The first bit is 1. */
673
static u_int ha_get_max_bit(MX_BITMAP *map)
676
uint32_t cnt = map->numOfBitsInMap();
677
uint32_t max_bit = 0;
679
for (uint32_t i = 0; i < cnt; i++)
680
if (map->isBitSet(i))
685
my_bitmap_map *data_ptr = map->bitmap;
686
my_bitmap_map *end_ptr = map->last_word_ptr;
687
u_int cnt = map->n_bits;
690
for (; end_ptr >= data_ptr; end_ptr--) {
691
if ((b = *end_ptr)) {
694
if (end_ptr == map->getLastWordPtr() && map->getLastWordMask())
695
mask = map->getLastWordMask() >> 1;
698
while (!(b & mask)) {
700
/* Should not happen, but if it does, we hang! */
702
return map->numOfBitsInMap();
707
if (end_ptr == map->getLastWordPtr())
708
cnt = ((cnt-1) / 32) * 32;
718
656
* -----------------------------------------------------------------------
1338
1276
pbxt_end(NULL);
1342
static int pbxt_panic(handlerton *hton, enum ha_panic_function flag)
1344
return pbxt_end(hton);
1349
1280
* Kill the PBXT thread associated with the MySQL thread.
1352
1282
int PBXTStorageEngine::close_connection(Session *thd)
1354
1284
PBXTStorageEngine * const hton = this;
1356
static int pbxt_close_connection(handlerton *hton, THD* thd)
1359
1285
XTThreadPtr self;
1361
1287
XT_TRACE_CALL();
1363
1288
if ((self = (XTThreadPtr) *thd->getEngineData(hton))) {
1364
1289
*thd->getEngineData(pbxt_hton) = NULL;
1366
if ((self = (XTThreadPtr) *thd_ha_data(thd, hton))) {
1367
*thd_ha_data(thd, hton) = NULL;
1369
1290
/* Required because freeing the thread could cause
1370
1291
* free of database which could call xt_close_file_ns()!
1448
1365
* pbxt_thr is a pointer the the PBXT thread structure.
1452
1368
int PBXTStorageEngine::commit(Session *thd, bool all)
1454
1370
PBXTStorageEngine * const hton = this;
1456
static int pbxt_commit(handlerton *hton, THD *thd, bool all)
1460
1372
XTThreadPtr self;
1463
1374
if ((self = (XTThreadPtr) *thd->getEngineData(hton))) {
1465
if ((self = (XTThreadPtr) *thd_ha_data(thd, hton))) {
1467
1375
XT_PRINT2(self, "%s pbxt_commit all=%d\n", all ? "END CONN XACT" : "END STAT", all);
1469
1377
if (self->st_xact_data) {
1488
1395
int PBXTStorageEngine::rollback(Session *thd, bool all)
1490
1397
PBXTStorageEngine * const hton = this;
1492
static int pbxt_rollback(handlerton *hton, THD *thd, bool all)
1496
1399
XTThreadPtr self;
1499
if ((self = (XTThreadPtr) *thd->getEngineData(hton))) {
1501
if ((self = (XTThreadPtr) *thd_ha_data(thd, hton))) {
1401
if ((self = (XTThreadPtr) *thd->getEngineData(hton))) {
1503
1402
XT_PRINT2(self, "%s pbxt_rollback all=%d\n", all ? "CONN END XACT" : "STAT END", all);
1505
1404
if (self->st_xact_data) {
1572
static XTThreadPtr ha_temp_open_global_database(handlerton *hton, THD **ret_thd, int *temp_thread, char *thread_name, int *err)
1471
static XTThreadPtr ha_temp_open_global_database(handlerton *hton, THD **ret_thd, int *temp_thread, const char *thread_name, int *err)
1575
1474
XTThreadPtr self = NULL;
1911
1810
* selectity of the indices, as soon as the number of rows
1912
1811
* exceeds 200 (see [**])
1813
#ifdef XT_ROW_COUNT_CORRECTED
1814
/* {CORRECTED-ROW-COUNT} */
1815
pb_share->sh_recalc_selectivity = (pb_share->sh_table->tab_row_eof_id - 1 - pb_share->sh_table->tab_row_fnum) < 150;
1914
1817
/* {FREE-ROWS-BAD} */
1915
1818
pb_share->sh_recalc_selectivity = (pb_share->sh_table->tab_row_eof_id - 1 /* - pb_share->sh_table->tab_row_fnum */) < 150;
1918
1822
/* I am not doing this anymore because it was only required
2268
2170
if (!thd || thd_sql_command(thd) == SQLCOM_FLUSH) // FLUSH TABLES
2269
2171
xt_sync_flush_table(self, ot, thd ? 0 : 4);
2173
/* This change is a result of a problem mentioned by Arjen.
2174
* REPAIR and ALTER lead to the following sequence:
2175
* 1. tab -- copy --> tmp1
2176
* 2. tab -- rename --> tmp2
2177
* 3. tmp1 -- rename --> tab
2180
* PBXT flushes a table before rename.
2181
* In the sequence above results in a table flush in step 3 which can
2182
* take a very long time.
2184
* The problem is, during this time frame we have only temp tables.
2185
* A crash in this state leaves the database in a bad state.
2187
* To reduce the time in this state, the flush needs to be done
2188
* elsewhere. The code below causes the flish to occur after
2191
switch (thd_sql_command(thd)) {
2192
case SQLCOM_RENAME_TABLE:
2193
case SQLCOM_ANALYZE:
2194
case SQLCOM_ALTER_TABLE:
2195
case SQLCOM_CREATE_INDEX:
2196
xt_sync_flush_table(self, ot, thd ? 0 : 4);
2271
2201
freer_(); // xt_db_return_table_to_pool(ot);
2328
2258
xt_tab_load_row_pointers(self, pb_open_tab);
2330
2261
xt_ind_set_index_selectivity(pb_open_tab, self);
2262
#ifdef XT_ROW_COUNT_CORRECTED
2263
/* {CORRECTED-ROW-COUNT} */
2264
pb_share->sh_recalc_selectivity = (pb_share->sh_table->tab_row_eof_id - 1 - pb_share->sh_table->tab_row_fnum) < 150;
2331
2266
/* {FREE-ROWS-BAD} */
2332
2267
pb_share->sh_recalc_selectivity = (pb_share->sh_table->tab_row_eof_id - 1 /* - pb_share->sh_table->tab_row_fnum */) < 150;
2335
2271
init_auto_increment(0);
2765
2700
XT_PRINT1(self, "update_row (%s)\n", pb_share->sh_table_path->ps_path);
2766
2701
XT_DISABLED_TRACE(("UPDATE tx=%d val=%d\n", (int) self->st_xact_data->xd_start_xn_id, (int) XT_GET_DISK_4(&new_data[1])));
2767
2702
//statistic_increment(ha_update_count,&LOCK_status);
2768
2704
/* {START-STAT-HACK} previously position of start statement hack. */
2769
2706
xt_xlog_check_long_writer(self);
2771
2708
/* {UPDATE-STACK} */
3914
3853
if ((ot = pb_open_tab)) {
3915
3854
if (flag & HA_STATUS_VARIABLE) {
3855
register XTTableHPtr tab = ot->ot_table;
3916
3857
/* {FREE-ROWS-BAD}
3917
3858
* Free row count is not reliable, so ignore it.
3918
3859
* The problem is if tab_row_fnum > tab_row_eof_id - 1 then
3939
3880
* the actual number of vectors. But it must assume that it has at
3940
3881
* least EXTRA_RECORDS vectors.
3942
stats.deleted = /* ot->ot_table->tab_row_fnum */ 0;
3943
stats.records = (ha_rows) (ot->ot_table->tab_row_eof_id - 1 /* - stats.deleted */);
3944
stats.data_file_length = xt_rec_id_to_rec_offset(ot->ot_table, ot->ot_table->tab_rec_eof_id);
3945
stats.index_file_length = xt_ind_node_to_offset(ot->ot_table, ot->ot_table->tab_ind_eof);
3946
stats.delete_length = ot->ot_table->tab_rec_fnum * ot->ot_rec_size;
3883
#ifdef XT_ROW_COUNT_CORRECTED
3884
if (tab->tab_row_eof_id <= tab->tab_row_fnum ||
3885
(!tab->tab_row_free_id && tab->tab_row_fnum))
3886
xt_tab_check_free_lists(NULL, ot, false, true);
3887
stats.records = (ha_rows) tab->tab_row_eof_id - 1;
3888
if (stats.records >= tab->tab_row_fnum) {
3889
stats.deleted = tab->tab_row_fnum;
3890
stats.records -= stats.deleted;
3897
stats.deleted = /* tab->tab_row_fnum */ 0;
3898
stats.records = (ha_rows) (tab->tab_row_eof_id - 1 /* - stats.deleted */);
3900
stats.data_file_length = xt_rec_id_to_rec_offset(tab, tab->tab_rec_eof_id);
3901
stats.index_file_length = xt_ind_node_to_offset(tab, tab->tab_ind_eof);
3902
stats.delete_length = tab->tab_rec_fnum * ot->ot_rec_size;
3947
3903
//check_time = info.check_time;
3948
3904
stats.mean_rec_length = (ulong) ot->ot_rec_size;
3961
3917
//share->db_options_in_use = info.options;
3962
3918
stats.block_size = XT_INDEX_PAGE_SIZE;
3965
3920
if (share->getType() == message::Table::STANDARD)
3967
if (share->tmp_table == NO_TMP_TABLE)
3969
3921
#ifdef DRIZZLED
3970
3922
#define WHICH_MUTEX mutex
3971
3923
#elif MYSQL_VERSION_ID >= 50404
4230
4182
* each row because it may be part of a transaction,
4231
4183
* and there may be foreign key actions.
4234
4185
XT_RETURN (errno = HA_ERR_WRONG_COMMAND);
4236
XT_RETURN (my_errno = HA_ERR_WRONG_COMMAND);
4240
4188
if (!(self = ha_set_current_thread(thd, &err)))
4407
4351
XT_RETURN(err);
4411
int ha_pbxt::repair(THD *XT_UNUSED(thd), HA_CHECK_OPT *XT_UNUSED(check_opt))
4413
return(HA_ADMIN_TRY_ALTER);
4417
* This is mapped to "ALTER TABLE tablename TYPE=PBXT", which rebuilds
4418
* the table in MySQL.
4420
int ha_pbxt::optimize(THD *XT_UNUSED(thd), HA_CHECK_OPT *XT_UNUSED(check_opt))
4422
return(HA_ADMIN_TRY_ALTER);
4427
4355
extern int pbxt_mysql_trace_on;
4431
4358
int ha_pbxt::check(THD* thd)
4433
int ha_pbxt::check(THD* thd, HA_CHECK_OPT* XT_UNUSED(check_opt))
4437
4361
XTThreadPtr self;
4596
4520
if (pb_share->sh_recalc_selectivity) {
4521
#ifdef XT_ROW_COUNT_CORRECTED
4522
/* {CORRECTED-ROW-COUNT} */
4523
if ((pb_share->sh_table->tab_row_eof_id - 1 - pb_share->sh_table->tab_row_fnum) >= 200)
4597
4525
/* {FREE-ROWS-BAD} */
4598
if ((pb_share->sh_table->tab_row_eof_id - 1 /* - pb_share->sh_table->tab_row_fnum */) >= 200) {
4526
if ((pb_share->sh_table->tab_row_eof_id - 1 /* - pb_share->sh_table->tab_row_fnum */) >= 200)
4600
4530
pb_share->sh_recalc_selectivity = FALSE;
4601
4531
xt_ind_set_index_selectivity(pb_open_tab, self);
4532
#ifdef XT_ROW_COUNT_CORRECTED
4533
/* {CORRECTED-ROW-COUNT} */
4534
pb_share->sh_recalc_selectivity = (pb_share->sh_table->tab_row_eof_id - 1 - pb_share->sh_table->tab_row_fnum) < 150;
4602
4536
/* {FREE-ROWS-BAD} */
4603
4537
pb_share->sh_recalc_selectivity = (pb_share->sh_table->tab_row_eof_id - 1 /* - pb_share->sh_table->tab_row_fnum */) < 150;
5253
5199
* during create if the table_flag HA_DROP_BEFORE_CREATE was specified for
5254
5200
* the storage engine.
5257
5202
int PBXTStorageEngine::doDropTable(Session &, const TableIdentifier& ident)
5259
5204
const std::string& path = ident.getPath();
5260
5205
const char *table_path = path.c_str();
5262
int ha_pbxt::delete_table(const char *table_path)
5265
5206
THD *thd = current_thd;
5267
5208
XTThreadPtr self = NULL;
5357
std::string path2(ident.getPath());
5358
path2.append(DEFAULT_FILE_EXTENSION);
5359
(void)internal::my_delete(path2.c_str(), MYF(0));
5297
std::string path2(ident.getPath());
5298
path2.append(DEFAULT_FILE_EXTENSION);
5299
(void)internal::my_delete(path2.c_str(), MYF(0));
5404
5343
* This function can be used to move a table from one database to
5408
5346
int PBXTStorageEngine::doRenameTable(Session&,
5409
5347
const TableIdentifier& from_ident,
5410
5348
const TableIdentifier& to_ident)
5983
5915
fk_info->referenced_table = thd_make_lex_string(thd, 0,
5984
5916
ref_tbl_name, (uint) strlen(ref_tbl_name), 1);
5986
5918
fk_info->referenced_key_name = NULL;
5988
5920
XTIndex *ix = fk->getReferenceIndexPtr();