~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbxt/src/ha_pbxt.cc

  • Committer: Brian Aker
  • Date: 2010-07-30 20:31:19 UTC
  • mto: This revision was merged to the branch mainline in revision 1679.
  • Revision ID: brian@gaz-20100730203119-89g2ye4zwnvcacxg
First pass in encapsulating row

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2005 PrimeBase Technologies GmbH
 
1
/* Copyright (c) 2005 PrimeBase Technologies GmbH
2
2
 *
3
3
 * Derived from ha_example.h
4
4
 * Copyright (C) 2003 MySQL AB
17
17
 *
18
18
 * You should have received a copy of the GNU General Public License
19
19
 * along with this program; if not, write to the Free Software
20
 
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA    02110-1301      USA
 
20
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA     02111-1307      USA
21
21
 *
22
22
 * 2005-11-10   Paul McCullagh
23
23
 *
47
47
#include <drizzled/data_home.h>
48
48
#include <drizzled/error.h>
49
49
#include <drizzled/table.h>
 
50
#include <drizzled/field/timestamp.h>
50
51
#include <drizzled/session.h>
51
52
 
52
 
#include <string>
53
 
 
54
53
#define my_strdup(a,b) strdup(a)
55
54
 
56
55
using namespace drizzled;
80
79
#include "systab_xt.h"
81
80
#include "xaction_xt.h"
82
81
#include "backup_xt.h"
83
 
#include "heap_xt.h"
84
82
 
85
83
#ifdef DEBUG
86
84
//#define XT_USE_SYS_PAR_DEBUG_SIZES
197
195
static char                             *pbxt_data_file_grow_size;
198
196
static char                             *pbxt_row_file_grow_size;
199
197
static char                             *pbxt_record_write_threshold;
 
198
static my_bool                  pbxt_support_xa;
200
199
 
201
200
#ifndef DRIZZLED
202
201
// drizzle complains it's not used
203
 
static my_bool                  pbxt_support_xa;
204
202
static XTXactEnumXARec  pbxt_xa_enum;
205
203
#endif
206
204
 
392
390
        }
393
391
 
394
392
        if (share->sh_ex_cond) {
395
 
                share->sh_lock.unlock();
 
393
                thr_lock_delete(&share->sh_lock);
396
394
                xt_delete_cond(self, (xt_cond_type *) share->sh_ex_cond);
397
395
                share->sh_ex_cond = NULL;
398
396
        }
602
600
        XTThreadPtr     self;
603
601
        static int      ha_thread_count = 0, ha_id;
604
602
 
 
603
#ifdef DRIZZLED
605
604
        if (!(self = (XTThreadPtr) *thd->getEngineData(pbxt_hton))) {
 
605
#else
 
606
        if (!(self = (XTThreadPtr) *thd_ha_data(thd, pbxt_hton))) {
 
607
#endif
606
608
//              const                   Security_context *sctx;
607
609
                char                    name[120];
608
610
                char                    ha_id_str[50];
633
635
                        return NULL;
634
636
 
635
637
                self->st_xact_mode = XT_XACT_REPEATABLE_READ;
 
638
#ifdef DRIZZLED
636
639
                *thd->getEngineData(pbxt_hton) = (void *) self;
 
640
#else
 
641
                *thd_ha_data(thd, pbxt_hton) = (void *) self;
 
642
#endif
637
643
        }
638
644
        return self;
639
645
}
642
648
{
643
649
        XTThreadPtr             self;
644
650
 
 
651
#ifdef DRIZZLED
645
652
        if (!(self = (XTThreadPtr) *thd->getEngineData(pbxt_hton))) {
646
653
        *thd->getEngineData(pbxt_hton) = NULL;
 
654
#else
 
655
        if ((self = (XTThreadPtr) *thd_ha_data(thd, pbxt_hton))) {
 
656
                *thd_ha_data(thd, pbxt_hton) = NULL;
 
657
#endif
647
658
                xt_free_thread(self);
648
659
        }
649
660
}
650
661
 
651
662
xtPublic XTThreadPtr xt_ha_thd_to_self(THD *thd)
652
663
{
 
664
#ifdef DRIZZLED
653
665
        return (XTThreadPtr) *thd->getEngineData(pbxt_hton);
654
 
}
 
666
#else
 
667
        return (XTThreadPtr) *thd_ha_data(thd, pbxt_hton);
 
668
#endif
 
669
}
 
670
 
 
671
#ifndef DRIZZLED
 
672
/* The first bit is 1. */
 
673
static u_int ha_get_max_bit(MX_BITMAP *map)
 
674
{
 
675
#ifdef DRIZZLED
 
676
        uint32_t        cnt = map->numOfBitsInMap();
 
677
        uint32_t        max_bit = 0;
 
678
 
 
679
        for (uint32_t i = 0; i < cnt; i++)
 
680
                if (map->isBitSet(i))
 
681
                        max_bit = i+1;
 
682
 
 
683
        return max_bit;
 
684
#else
 
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;
 
688
        my_bitmap_map   b;
 
689
        
 
690
        for (; end_ptr >= data_ptr; end_ptr--) {
 
691
                if ((b = *end_ptr)) {
 
692
                        my_bitmap_map mask;
 
693
                        
 
694
                        if (end_ptr == map->getLastWordPtr() && map->getLastWordMask())
 
695
                                mask = map->getLastWordMask() >> 1;
 
696
                        else
 
697
                                mask = 0x80000000;
 
698
                        while (!(b & mask)) {
 
699
                                b = b << 1;
 
700
                                /* Should not happen, but if it does, we hang! */
 
701
                                if (!b)
 
702
                                        return map->numOfBitsInMap();
 
703
                                cnt--;
 
704
                        }
 
705
                        return cnt;
 
706
                }
 
707
                if (end_ptr == map->getLastWordPtr())
 
708
                        cnt = ((cnt-1) / 32) * 32;
 
709
                else
 
710
                        cnt -= 32;
 
711
        }
 
712
        return 0;
 
713
#endif
 
714
}
 
715
#endif
655
716
 
656
717
/*
657
718
 * -----------------------------------------------------------------------
1250
1311
        XT_RETURN(1);
1251
1312
}
1252
1313
 
1253
 
void PBXTStorageEngine::shutdownPlugin()
 
1314
static int pbxt_end(void *)
1254
1315
{
1255
 
        XTThreadPtr self;
 
1316
        XTThreadPtr             self;
 
1317
        int                             err = 0;
1256
1318
 
1257
1319
        XT_TRACE_CALL();
1258
1320
 
1267
1329
                        ha_exit(self);
1268
1330
                }
1269
1331
        }
 
1332
 
 
1333
        XT_RETURN(err);
1270
1334
}
1271
1335
 
1272
1336
PBXTStorageEngine::~PBXTStorageEngine()
1273
1337
{
1274
 
        /* We do nothing here, because it is now all done in shutdownPlugin(). */
 
1338
  pbxt_end(NULL);
1275
1339
}
1276
1340
 
1277
 
/*
1278
 
 * The following query from the DBT1 test is VERY slow
1279
 
 * if we do not set HA_READ_ORDER.
1280
 
 * The reason is that it must scan all duplicates, then
1281
 
 * sort.
1282
 
 *
1283
 
 * SELECT o_id, o_carrier_id, o_entry_d, o_ol_cnt
1284
 
 * FROM orders FORCE INDEX (o_w_id)
1285
 
 * WHERE o_w_id = 2
1286
 
   * AND o_d_id = 1
1287
 
   * AND o_c_id = 500
1288
 
 * ORDER BY o_id DESC limit 1;
1289
 
 *
1290
 
 */
1291
 
//#define FLAGS_ARE_READ_DYNAMICALLY
1292
 
 
1293
 
uint32_t PBXTStorageEngine::index_flags(enum  ha_key_alg) const
 
1341
#ifndef DRIZZLED
 
1342
static int pbxt_panic(handlerton *hton, enum ha_panic_function flag)
1294
1343
{
1295
 
        /* It would be nice if the dynamic version of this function works,
1296
 
         * but it does not. MySQL loads this information when the table is openned,
1297
 
         * and then it is fixed.
1298
 
         *
1299
 
         * The problem is, I have had to remove the HA_READ_ORDER option although
1300
 
         * it applies to PBXT. PBXT returns entries in index order during an index
1301
 
         * scan in _almost_ all cases.
1302
 
         *
1303
 
         * A number of cases are demostrated here: [(11)]
1304
 
         *
1305
 
         * If involves the following conditions:
1306
 
         * - a SELECT FOR UPDATE, UPDATE or DELETE statement
1307
 
         * - an ORDER BY, or join that requires the sort order
1308
 
         * - another transaction which updates the index while it is being
1309
 
         *   scanned.
1310
 
         *
1311
 
         * In this "obscure" case, the index scan may return index
1312
 
         * entries in the wrong order.
1313
 
         */
1314
 
#ifdef FLAGS_ARE_READ_DYNAMICALLY
1315
 
        /* If were are in an update (SELECT FOR UPDATE, UPDATE or DELETE), then
1316
 
         * it may be that we return the rows from an index in the wrong
1317
 
         * order! This is due to the fact that update reads wait for transactions
1318
 
         * to commit and this means that index entries may change position during
1319
 
         * the scan!
1320
 
         */
1321
 
        if (pb_open_tab && pb_open_tab->ot_for_update)
1322
 
                return (HA_READ_NEXT | HA_READ_PREV | HA_READ_RANGE | HA_KEYREAD_ONLY);
1323
 
        /* If I understand HA_KEYREAD_ONLY then this means I do not
1324
 
         * need to fetch the record associated with an index
1325
 
         * key.
1326
 
         */
1327
 
        return (HA_READ_NEXT | HA_READ_PREV | HA_READ_ORDER | HA_READ_RANGE | HA_KEYREAD_ONLY);
1328
 
#else
1329
 
        return (HA_READ_NEXT | HA_READ_PREV | HA_READ_RANGE | HA_KEYREAD_ONLY);
 
1344
        return pbxt_end(hton);
 
1345
}
1330
1346
#endif
1331
 
}
1332
1347
 
1333
1348
/*
1334
1349
 * Kill the PBXT thread associated with the MySQL thread.
1335
1350
 */
 
1351
#ifdef DRIZZLED
1336
1352
int PBXTStorageEngine::close_connection(Session *thd)
1337
1353
{
1338
1354
        PBXTStorageEngine * const hton = this;
 
1355
#else
 
1356
static int pbxt_close_connection(handlerton *hton, THD* thd)
 
1357
{
 
1358
#endif
1339
1359
        XTThreadPtr             self;
1340
1360
 
1341
1361
        XT_TRACE_CALL();
 
1362
#ifdef DRIZZLED
1342
1363
        if ((self = (XTThreadPtr) *thd->getEngineData(hton))) {
1343
1364
                *thd->getEngineData(pbxt_hton) = NULL;
 
1365
#else
 
1366
        if ((self = (XTThreadPtr) *thd_ha_data(thd, hton))) {
 
1367
                *thd_ha_data(thd, hton) = NULL;
 
1368
#endif
1344
1369
                /* Required because freeing the thread could cause
1345
1370
                 * free of database which could call xt_close_file_ns()!
1346
1371
                 */
1355
1380
 * when the last PBXT table was removed from the 
1356
1381
 * database.
1357
1382
 */
 
1383
#ifdef DRIZZLED
1358
1384
void PBXTStorageEngine::drop_database(char *)
 
1385
#else
 
1386
static void pbxt_drop_database(handlerton *XT_UNUSED(hton), char *XT_UNUSED(path))
 
1387
#endif
1359
1388
{
1360
1389
        XT_TRACE_CALL();
1361
1390
}
1419
1448
 * pbxt_thr is a pointer the the PBXT thread structure.
1420
1449
 *
1421
1450
 */
 
1451
#ifdef DRIZZLED
1422
1452
int PBXTStorageEngine::commit(Session *thd, bool all)
1423
1453
{
1424
1454
        PBXTStorageEngine * const hton = this;
 
1455
#else
 
1456
static int pbxt_commit(handlerton *hton, THD *thd, bool all)
 
1457
{
 
1458
#endif
1425
1459
        int                     err = 0;
1426
1460
        XTThreadPtr     self;
1427
1461
 
 
1462
#ifdef DRIZZLED
1428
1463
        if ((self = (XTThreadPtr) *thd->getEngineData(hton))) {
 
1464
#else
 
1465
        if ((self = (XTThreadPtr) *thd_ha_data(thd, hton))) {
 
1466
#endif
1429
1467
                XT_PRINT2(self, "%s pbxt_commit all=%d\n", all ? "END CONN XACT" : "END STAT", all);
1430
1468
 
1431
1469
                if (self->st_xact_data) {
1446
1484
        return err;
1447
1485
}
1448
1486
 
 
1487
#ifdef DRIZZLED
1449
1488
int PBXTStorageEngine::rollback(Session *thd, bool all)
1450
1489
{
1451
1490
        PBXTStorageEngine * const hton = this;
 
1491
#else
 
1492
static int pbxt_rollback(handlerton *hton, THD *thd, bool all)
 
1493
{
 
1494
#endif
1452
1495
        int                     err = 0;
1453
1496
        XTThreadPtr     self;
1454
1497
 
1455
 
        if ((self = (XTThreadPtr) *thd->getEngineData(hton))) {
 
1498
#ifdef DRIZZLED
 
1499
        if ((self = (XTThreadPtr) *thd->getEngineData(hton))) {
 
1500
#else
 
1501
        if ((self = (XTThreadPtr) *thd_ha_data(thd, hton))) {
 
1502
#endif
1456
1503
                XT_PRINT2(self, "%s pbxt_rollback all=%d\n", all ? "CONN END XACT" : "STAT END", all);
1457
1504
 
1458
1505
                if (self->st_xact_data) {
1481
1528
        return 0;
1482
1529
}
1483
1530
 
1484
 
Cursor *PBXTStorageEngine::create(Table& table)
 
1531
Cursor *PBXTStorageEngine::create(TableShare& table, memory::Root *mem_root)
1485
1532
{
1486
 
        return new ha_pbxt(*this, table);
 
1533
        return new (mem_root) ha_pbxt(*this, table);
1487
1534
}
1488
1535
 
1489
1536
/*
1522
1569
        return err;
1523
1570
}
1524
1571
 
1525
 
static XTThreadPtr ha_temp_open_global_database(handlerton *hton, THD **ret_thd, int *temp_thread, const char *thread_name, int *err)
 
1572
static XTThreadPtr ha_temp_open_global_database(handlerton *hton, THD **ret_thd, int *temp_thread, char *thread_name, int *err)
1526
1573
{
1527
1574
        THD                     *thd;
1528
1575
        XTThreadPtr     self = NULL;
1864
1911
                         * selectity of the indices, as soon as the number of rows
1865
1912
                         * exceeds 200 (see [**])
1866
1913
                         */
1867
 
#ifdef XT_ROW_COUNT_CORRECTED
1868
 
                        /* {CORRECTED-ROW-COUNT} */
1869
 
                        pb_share->sh_recalc_selectivity = (pb_share->sh_table->tab_row_eof_id - 1 - pb_share->sh_table->tab_row_fnum) < 150;
1870
 
#else
1871
1914
                        /* {FREE-ROWS-BAD} */
1872
1915
                        pb_share->sh_recalc_selectivity = (pb_share->sh_table->tab_row_eof_id - 1 /* - pb_share->sh_table->tab_row_fnum */) < 150;
1873
 
#endif
1874
1916
                }
1875
1917
 
1876
1918
                /* I am not doing this anymore because it was only required
2019
2061
 *
2020
2062
 */
2021
2063
 
2022
 
ha_pbxt::ha_pbxt(plugin::StorageEngine &engine_arg, Table &table_arg) : Cursor(engine_arg, table_arg)
 
2064
ha_pbxt::ha_pbxt(plugin::StorageEngine &engine_arg, TableShare &table_arg) : Cursor(engine_arg, table_arg)
2023
2065
{
2024
2066
        pb_share = NULL;
2025
2067
        pb_open_tab = NULL;
2085
2127
                 * purposes!
2086
2128
                HA_NOT_EXACT_COUNT |
2087
2129
                 */
 
2130
#ifndef DRIZZLED
2088
2131
                /*
2089
2132
                 * This basically means we have a file with the name of
2090
2133
                 * database table (which we do).
2091
2134
                 */
2092
2135
                HA_FILE_BASED |
 
2136
#endif
2093
2137
                /*
2094
2138
                 * Not sure what this does (but MyISAM and InnoDB have it)?!
2095
2139
                 * Could it mean that we support the handler functions.
2118
2162
}
2119
2163
#endif
2120
2164
 
 
2165
/*
 
2166
 * The following query from the DBT1 test is VERY slow
 
2167
 * if we do not set HA_READ_ORDER.
 
2168
 * The reason is that it must scan all duplicates, then
 
2169
 * sort.
 
2170
 *
 
2171
 * SELECT o_id, o_carrier_id, o_entry_d, o_ol_cnt
 
2172
 * FROM orders FORCE INDEX (o_w_id)
 
2173
 * WHERE o_w_id = 2
 
2174
   * AND o_d_id = 1
 
2175
   * AND o_c_id = 500
 
2176
 * ORDER BY o_id DESC limit 1;
 
2177
 *
 
2178
 */
 
2179
#define FLAGS_ARE_READ_DYNAMICALLY
 
2180
 
 
2181
MX_ULONG_T ha_pbxt::index_flags(uint XT_UNUSED(inx), uint XT_UNUSED(part), bool XT_UNUSED(all_parts)) const
 
2182
{
 
2183
        /* It would be nice if the dynamic version of this function works,
 
2184
         * but it does not. MySQL loads this information when the table is openned,
 
2185
         * and then it is fixed.
 
2186
         *
 
2187
         * The problem is, I have had to remove the HA_READ_ORDER option although
 
2188
         * it applies to PBXT. PBXT returns entries in index order during an index
 
2189
         * scan in _almost_ all cases.
 
2190
         *
 
2191
         * A number of cases are demostrated here: [(11)]
 
2192
         *
 
2193
         * If involves the following conditions:
 
2194
         * - a SELECT FOR UPDATE, UPDATE or DELETE statement
 
2195
         * - an ORDER BY, or join that requires the sort order
 
2196
         * - another transaction which updates the index while it is being
 
2197
         *   scanned.
 
2198
         *
 
2199
         * In this "obscure" case, the index scan may return index
 
2200
         * entries in the wrong order.
 
2201
         */
 
2202
#ifdef FLAGS_ARE_READ_DYNAMICALLY
 
2203
        /* If were are in an update (SELECT FOR UPDATE, UPDATE or DELETE), then
 
2204
         * it may be that we return the rows from an index in the wrong
 
2205
         * order! This is due to the fact that update reads wait for transactions
 
2206
         * to commit and this means that index entries may change position during
 
2207
         * the scan!
 
2208
         */
 
2209
        if (pb_open_tab && pb_open_tab->ot_for_update)
 
2210
                return (HA_READ_NEXT | HA_READ_PREV | HA_READ_RANGE | HA_KEYREAD_ONLY);
 
2211
        /* If I understand HA_KEYREAD_ONLY then this means I do not
 
2212
         * need to fetch the record associated with an index
 
2213
         * key.
 
2214
         */
 
2215
        return (HA_READ_NEXT | HA_READ_PREV | HA_READ_ORDER | HA_READ_RANGE | HA_KEYREAD_ONLY);
 
2216
#else
 
2217
        return (HA_READ_NEXT | HA_READ_PREV | HA_READ_RANGE | HA_KEYREAD_ONLY);
 
2218
#endif
 
2219
}
 
2220
 
2121
2221
void ha_pbxt::internal_close(THD *thd, struct XTThread *self)
2122
2222
{
2123
2223
        if (pb_share) {
2167
2267
                                         */
2168
2268
                                        if (!thd || thd_sql_command(thd) == SQLCOM_FLUSH) // FLUSH TABLES
2169
2269
                                                xt_sync_flush_table(self, ot, thd ? 0 : 4);
2170
 
                                        else {
2171
 
                                                /* This change is a result of a problem mentioned by Arjen.
2172
 
                                                 * REPAIR and ALTER lead to the following sequence:
2173
 
                                                 * 1. tab  -- copy --> tmp1
2174
 
                                                 * 2. tab  -- rename --> tmp2
2175
 
                                                 * 3. tmp1 -- rename --> tab
2176
 
                                                 * 4. delete tmp2
2177
 
                                                 *
2178
 
                                                 * PBXT flushes a table before rename.
2179
 
                                                 * In the sequence above results in a table flush in step 3 which can
2180
 
                                                 * take a very long time.
2181
 
                                                 *
2182
 
                                                 * The problem is, during this time frame we have only temp tables.
2183
 
                                                 * A crash in this state leaves the database in a bad state.
2184
 
                                                 *
2185
 
                                                 * To reduce the time in this state, the flush needs to be done
2186
 
                                                 * elsewhere. The code below causes the flish to occur after
2187
 
                                                 * step 1:
2188
 
                                                 */ 
2189
 
                                                switch (thd_sql_command(thd)) {
2190
 
                                                        case SQLCOM_RENAME_TABLE:
2191
 
                                                        case SQLCOM_ANALYZE:
2192
 
                                                        case SQLCOM_ALTER_TABLE:
2193
 
                                                        case SQLCOM_CREATE_INDEX:
2194
 
                                                                xt_sync_flush_table(self, ot, thd ? 0 : 4);
2195
 
                                                                break;
2196
 
                                                }
2197
 
                                        }
2198
2270
                                }
2199
2271
                                freer_(); // xt_db_return_table_to_pool(ot);
2200
2272
                        }
2243
2315
 
2244
2316
                ha_open_share(self, pb_share);
2245
2317
 
2246
 
                pb_lock.init(&pb_share->sh_lock);
 
2318
                thr_lock_data_init(&pb_share->sh_lock, &pb_lock, NULL);
2247
2319
                if (!(pb_open_tab = xt_db_open_table_using_tab(pb_share->sh_table, self)))
2248
2320
                        xt_throw(self);
2249
2321
                pb_open_tab->ot_thread = self;
2255
2327
#else
2256
2328
                        xt_tab_load_row_pointers(self, pb_open_tab);
2257
2329
#endif
2258
 
 
2259
2330
                        xt_ind_set_index_selectivity(pb_open_tab, self);
2260
 
#ifdef XT_ROW_COUNT_CORRECTED
2261
 
                        /* {CORRECTED-ROW-COUNT} */
2262
 
                        pb_share->sh_recalc_selectivity = (pb_share->sh_table->tab_row_eof_id - 1 - pb_share->sh_table->tab_row_fnum) < 150;
2263
 
#else
2264
2331
                        /* {FREE-ROWS-BAD} */
2265
2332
                        pb_share->sh_recalc_selectivity = (pb_share->sh_table->tab_row_eof_id - 1 /* - pb_share->sh_table->tab_row_fnum */) < 150;
2266
 
#endif
2267
2333
                }
2268
2334
 
2269
2335
                init_auto_increment(0);
2350
2416
                return;
2351
2417
 
2352
2418
        xt_spinlock_lock(&tab->tab_ainc_lock);
2353
 
        if (getTable()->found_next_number_field && !tab->tab_auto_inc) {
2354
 
                Field           *tmp_fie = getTable()->next_number_field;
2355
 
                THD                     *tmp_thd = getTable()->in_use;
 
2419
        if (table->found_next_number_field && !tab->tab_auto_inc) {
 
2420
                Field           *tmp_fie = table->next_number_field;
 
2421
                THD                     *tmp_thd = table->in_use;
2356
2422
                xtBool          xn_started = FALSE;
2357
2423
                XTThreadPtr     self = pb_open_tab->ot_thread;
2358
2424
 
 
2425
//#ifndef DRIZZLED
2359
2426
                /*
2360
2427
                 * A table may be opened by a thread with a running
2361
2428
                 * transaction!
2378
2445
                        }
2379
2446
                        xn_started = TRUE;
2380
2447
                }
2381
 
 
 
2448
//#endif
2382
2449
                /* Setup the conditions for the next call! */
2383
 
                getTable()->in_use = current_thd;
2384
 
                getTable()->next_number_field = getTable()->found_next_number_field;
 
2450
                table->in_use = current_thd;
 
2451
                table->next_number_field = table->found_next_number_field;
2385
2452
 
2386
2453
                extra(HA_EXTRA_KEYREAD);
2387
 
                getTable()->mark_columns_used_by_index_no_reset(getTable()->getShare()->next_number_index, *getTable()->read_set);
 
2454
                table->mark_columns_used_by_index_no_reset(TS(table)->next_number_index, table->read_set);
2388
2455
                column_bitmaps_signal();
2389
 
                doStartIndexScan(getTable()->getShare()->next_number_index, 0);
2390
 
                if (!getTable()->getShare()->next_number_key_offset) {
 
2456
                doStartIndexScan(TS(table)->next_number_index, 0);
 
2457
                if (!TS(table)->next_number_key_offset) {
2391
2458
                        // Autoincrement at key-start
2392
 
                        err = index_last(getTable()->getUpdateRecord());
2393
 
                        if (!err && !getTable()->next_number_field->is_null(getTable()->getShare()->rec_buff_length)) {
 
2459
                        err = index_last(table->getUpdateRecord());
 
2460
                        if (!err && !table->next_number_field->is_null(TS(table)->rec_buff_length)) {
2394
2461
                                /* {PRE-INC} */
2395
 
                                nr = (xtWord8) getTable()->next_number_field->val_int_offset(getTable()->getShare()->rec_buff_length);
 
2462
                                nr = (xtWord8) table->next_number_field->val_int_offset(TS(table)->rec_buff_length);
2396
2463
                        }
2397
2464
                }
2398
2465
                else {
2402
2469
                         */
2403
2470
                        xtWord8 val;
2404
2471
 
2405
 
                        err = index_first(getTable()->getUpdateRecord());
 
2472
                        err = index_first(table->getUpdateRecord());
2406
2473
                        while (!err) {
2407
2474
                                /* {PRE-INC} */
2408
 
                                val = (xtWord8) getTable()->next_number_field->val_int_offset(getTable()->getShare()->rec_buff_length);
 
2475
                                val = (xtWord8) table->next_number_field->val_int_offset(TS(table)->rec_buff_length);
2409
2476
                                if (val > nr)
2410
2477
                                        nr = val;
2411
 
                                err = index_next(getTable()->getUpdateRecord());
 
2478
                                err = index_next(table->getUpdateRecord());
2412
2479
                        }
2413
2480
                }
2414
2481
 
2443
2510
                        tab->tab_auto_inc = min_auto_inc-1;
2444
2511
 
2445
2512
                /* Restore the changed values: */
2446
 
                getTable()->next_number_field = tmp_fie;
2447
 
                getTable()->in_use = tmp_thd;
 
2513
                table->next_number_field = tmp_fie;
 
2514
                table->in_use = tmp_thd;
2448
2515
 
2449
2516
                if (xn_started) {
2450
2517
                        XT_PRINT0(self, "xt_xn_commit in init_auto_increment\n");
2479
2546
                nr += increment - ((nr - offset) % increment);
2480
2547
        else
2481
2548
                nr += increment;
2482
 
        if (getTable()->next_number_field->cmp((const unsigned char *)&nr_less_inc, (const unsigned char *)&nr) < 0)
 
2549
        if (table->next_number_field->cmp((const unsigned char *)&nr_less_inc, (const unsigned char *)&nr) < 0)
2483
2550
                tab->tab_auto_inc = (xtWord8) (nr);
2484
2551
        else
2485
2552
                nr = ~0;        /* indicate error to the caller */
2504
2571
        nr_int_val = nr->val_int();
2505
2572
        tab = ot->ot_table;
2506
2573
 
2507
 
        if (nr->cmp_internal((const unsigned char *)&tab->tab_auto_inc) > 0) {
 
2574
        if (nr->cmp((const unsigned char *)&tab->tab_auto_inc) > 0) {
2508
2575
                xt_spinlock_lock(&tab->tab_ainc_lock);
2509
2576
 
2510
 
                if (nr->cmp_internal((const unsigned char *)&tab->tab_auto_inc) > 0) {
2511
 
                  /* {PRE-INC}
2512
 
                   * We increment later, so just set the value!
2513
 
                   MX_ULONGLONG_T nr_int_val_plus_one = nr_int_val + 1;
2514
 
                   if (nr->cmp((const unsigned char *)&nr_int_val_plus_one) < 0)
2515
 
                   tab->tab_auto_inc = nr_int_val_plus_one;
2516
 
                   else
2517
 
                 */
2518
 
                  tab->tab_auto_inc = nr_int_val;
2519
 
                }
 
2577
                if (nr->cmp((const unsigned char *)&tab->tab_auto_inc) > 0) {
 
2578
                        /* {PRE-INC}
 
2579
                         * We increment later, so just set the value!
 
2580
                        MX_ULONGLONG_T nr_int_val_plus_one = nr_int_val + 1;
 
2581
                        if (nr->cmp((const unsigned char *)&nr_int_val_plus_one) < 0)
 
2582
                                tab->tab_auto_inc = nr_int_val_plus_one;
 
2583
                        else
 
2584
                         */
 
2585
                        tab->tab_auto_inc = nr_int_val;
 
2586
                }
2520
2587
                xt_spinlock_unlock(&tab->tab_ainc_lock);
2521
2588
        }
2522
2589
 
2609
2676
                        pb_import_row_count++;
2610
2677
        }
2611
2678
 
2612
 
        if (getTable()->next_number_field && buf == getTable()->getInsertRecord()) {
 
2679
        if (table->next_number_field && buf == table->getInsertRecord()) {
2613
2680
                int update_err = update_auto_increment();
2614
2681
                if (update_err) {
2615
2682
                        ha_log_pbxt_thread_error_for_mysql(pb_ignore_dup_key);
2616
2683
                        err = update_err;
2617
2684
                        goto done;
2618
2685
                }
2619
 
                ha_set_auto_increment(pb_open_tab, getTable()->next_number_field);
 
2686
                ha_set_auto_increment(pb_open_tab, table->next_number_field);
2620
2687
        }
2621
2688
 
2622
2689
        if (!xt_tab_new_record(pb_open_tab, (xtWord1 *) buf)) {
2698
2765
        XT_PRINT1(self, "update_row (%s)\n", pb_share->sh_table_path->ps_path);
2699
2766
        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])));
2700
2767
        //statistic_increment(ha_update_count,&LOCK_status);
2701
 
 
2702
2768
        /* {START-STAT-HACK} previously position of start statement hack. */
2703
 
 
2704
2769
        xt_xlog_check_long_writer(self);
2705
2770
 
2706
2771
        /* {UPDATE-STACK} */
2734
2799
         * update t1 set a=2 where a=1;
2735
2800
         * insert into t1 (val) values (1);
2736
2801
         */
2737
 
        if (getTable()->found_next_number_field && new_data == getTable()->getInsertRecord()) {
 
2802
        if (table->found_next_number_field && new_data == table->getInsertRecord()) {
2738
2803
                MX_LONGLONG_T   nr;
2739
 
        const boost::dynamic_bitset<>& old_bitmap= getTable()->use_all_columns(*getTable()->read_set);
2740
 
                nr = getTable()->found_next_number_field->val_int();
2741
 
                ha_set_auto_increment(pb_open_tab, getTable()->found_next_number_field);
2742
 
        getTable()->restore_column_map(old_bitmap);
 
2804
                my_bitmap_map   *old_map;
 
2805
 
 
2806
                old_map = mx_tmp_use_all_columns(table, table->read_set);
 
2807
                nr = table->found_next_number_field->val_int();
 
2808
                ha_set_auto_increment(pb_open_tab, table->found_next_number_field);
 
2809
                mx_tmp_restore_column_map(table, old_map);
2743
2810
        }
2744
2811
 
2745
2812
        if (!xt_tab_update_record(pb_open_tab, (xtWord1 *) old_data, (xtWord1 *) new_data))
2783
2850
                return err;
2784
2851
        }
2785
2852
#endif
2786
 
 
2787
2853
        /* {START-STAT-HACK} previously position of start statement hack. */
2788
 
 
2789
2854
        xt_xlog_check_long_writer(pb_open_tab->ot_thread);
2790
2855
 
2791
2856
        if (!xt_tab_delete_record(pb_open_tab, (xtWord1 *) buf))
3089
3154
        return ha_log_pbxt_thread_error_for_mysql(FALSE);
3090
3155
}
3091
3156
 
3092
 
#ifdef DRIZZLED
3093
 
 
3094
 
static std::string convert_long_to_bit_string(uint64_t bitset, uint64_t bitset_size)
3095
 
{
3096
 
  std::string res; 
3097
 
  while (bitset)
3098
 
  {
3099
 
    res.push_back((bitset & 1) + '0');
3100
 
    bitset>>= 1;
3101
 
  }
3102
 
  if (! res.empty())
3103
 
  {
3104
 
    std::reverse(res.begin(), res.end());
3105
 
  }
3106
 
  else
3107
 
  {
3108
 
    res= "0";
3109
 
  }
3110
 
  std::string final(bitset_size - res.length(), '0');
3111
 
  final.append(res);
3112
 
  return final;
3113
 
}
3114
 
#endif
3115
 
 
3116
3157
int ha_pbxt::doStartIndexScan(uint idx, bool XT_UNUSED(sorted))
3117
3158
{
3118
3159
        XTIndexPtr      ind;
3133
3174
        /* The number of columns required: */
3134
3175
        if (pb_open_tab->ot_is_modify) {
3135
3176
 
3136
 
                pb_open_tab->ot_cols_req = getTable()->read_set->MX_BIT_SIZE();
 
3177
                pb_open_tab->ot_cols_req = table->read_set->MX_BIT_SIZE();
3137
3178
#ifdef XT_PRINT_INDEX_OPT
3138
3179
                ind = (XTIndexPtr) pb_share->sh_dic_keys[idx];
3139
3180
 
3148
3189
        }
3149
3190
        else {
3150
3191
                //pb_open_tab->ot_cols_req = ha_get_max_bit(table->read_set);
3151
 
                pb_open_tab->ot_cols_req = getTable()->read_set->MX_BIT_SIZE();
 
3192
                pb_open_tab->ot_cols_req = table->read_set->MX_BIT_SIZE();
3152
3193
 
3153
3194
                /* Check for index coverage!
3154
3195
                 *
3189
3230
                 * seem to have this problem!
3190
3231
                 */
3191
3232
                ind = (XTIndexPtr) pb_share->sh_dic_keys[idx];
3192
 
#ifdef DRIZZLED
3193
 
        /*
3194
 
         * Need to do this for drizzle because we use boost's dynamic_bitset
3195
 
         * to represent the bitsets and allocating memory for an object of that 
3196
 
         * type does not play well with the memory allocation routines in PBXT.
3197
 
         * For that reason, we just store a uint which represents the bitset
3198
 
         * in the XTIndexPtr structure for PBXT. 
3199
 
         */
3200
 
        std::string bitmap_str= convert_long_to_bit_string(ind->mi_col_map, ind->mi_col_map_size);
3201
 
        MX_BITMAP tmp(bitmap_str);
3202
 
                if (MX_BIT_IS_SUBSET(getTable()->read_set, tmp))
3203
 
#else
3204
 
                if (MX_BIT_IS_SUBSET(getTable()->read_set, ind->mi_col_map))
3205
 
#endif
 
3233
                if (MX_BIT_IS_SUBSET(table->read_set, &ind->mi_col_map))
3206
3234
                        pb_key_read = TRUE;
3207
3235
#ifdef XT_PRINT_INDEX_OPT
3208
3236
                printf("index_init %s index %d cols req=%d/%d read_bits=%X write_bits=%X index_bits=%X converage=%d\n", pb_open_tab->ot_table->tab_name->ps_path, (int) idx, pb_open_tab->ot_cols_req, table->read_set->MX_BIT_SIZE(), (int) *table->read_set->bitmap, (int) *table->write_set->bitmap, (int) *ind->mi_col_map.bitmap, (int) (MX_BIT_IS_SUBSET(table->read_set, &ind->mi_col_map) != 0));
3346
3374
        XT_DISABLED_TRACE(("search tx=%d val=%d err=%d\n", (int) pb_open_tab->ot_thread->st_xact_data->xd_start_xn_id, (int) XT_GET_DISK_4(key), err));
3347
3375
        done:
3348
3376
        if (err)
3349
 
                getTable()->status = STATUS_NOT_FOUND;
 
3377
                table->status = STATUS_NOT_FOUND;
3350
3378
        else {
3351
3379
                pb_open_tab->ot_thread->st_statistics.st_row_select++;
3352
 
                getTable()->status = 0;
 
3380
                table->status = 0;
3353
3381
        }
3354
3382
        return err;
3355
3383
}
3407
3435
#endif
3408
3436
        done:
3409
3437
        if (err)
3410
 
                getTable()->status = STATUS_NOT_FOUND;
 
3438
                table->status = STATUS_NOT_FOUND;
3411
3439
        else {
3412
3440
                pb_open_tab->ot_thread->st_statistics.st_row_select++;
3413
 
                getTable()->status = 0;
 
3441
                table->status = 0;
3414
3442
        }
3415
3443
        XT_RETURN(err);
3416
3444
}
3461
3489
#endif
3462
3490
        done:
3463
3491
        if (err)
3464
 
                getTable()->status = STATUS_NOT_FOUND;
 
3492
                table->status = STATUS_NOT_FOUND;
3465
3493
        else {
3466
3494
                pb_open_tab->ot_thread->st_statistics.st_row_select++;
3467
 
                getTable()->status = 0;
 
3495
                table->status = 0;
3468
3496
        }
3469
3497
        XT_RETURN(err);
3470
3498
}
3499
3527
#endif
3500
3528
        done:
3501
3529
        if (err)
3502
 
                getTable()->status = STATUS_NOT_FOUND;
 
3530
                table->status = STATUS_NOT_FOUND;
3503
3531
        else {
3504
3532
                pb_open_tab->ot_thread->st_statistics.st_row_select++;
3505
 
                getTable()->status = 0;
 
3533
                table->status = 0;
3506
3534
        }
3507
3535
        XT_RETURN(err);
3508
3536
}
3552
3580
#endif
3553
3581
        done:
3554
3582
        if (err)
3555
 
                getTable()->status = STATUS_NOT_FOUND;
 
3583
                table->status = STATUS_NOT_FOUND;
3556
3584
        else {
3557
3585
                pb_open_tab->ot_thread->st_statistics.st_row_select++;
3558
 
                getTable()->status = 0;
 
3586
                table->status = 0;
3559
3587
        }
3560
3588
        XT_RETURN(err);
3561
3589
}
3598
3626
#endif
3599
3627
        done:
3600
3628
        if (err)
3601
 
                getTable()->status = STATUS_NOT_FOUND;
 
3629
                table->status = STATUS_NOT_FOUND;
3602
3630
        else {
3603
3631
                pb_open_tab->ot_thread->st_statistics.st_row_select++;
3604
 
                getTable()->status = 0;
 
3632
                table->status = 0;
3605
3633
        }
3606
3634
        XT_RETURN(err);
3607
3635
}
3645
3673
 
3646
3674
        /* The number of columns required: */
3647
3675
        if (pb_open_tab->ot_is_modify) {
3648
 
                pb_open_tab->ot_cols_req = getTable()->read_set->MX_BIT_SIZE();
 
3676
                pb_open_tab->ot_cols_req = table->read_set->MX_BIT_SIZE();
3649
3677
                /* {START-STAT-HACK} previously position of start statement hack,
3650
3678
                 * previous comment to code below: */
3651
3679
                /* Start a statement based transaction as soon
3655
3683
        }
3656
3684
        else {
3657
3685
                //pb_open_tab->ot_cols_req = ha_get_max_bit(table->read_set);
3658
 
                pb_open_tab->ot_cols_req = getTable()->read_set->MX_BIT_SIZE();
 
3686
                pb_open_tab->ot_cols_req = table->read_set->MX_BIT_SIZE();
3659
3687
 
3660
3688
                /*
3661
3689
                 * in case of queries like SELECT COUNT(*) FROM t
3725
3753
                err = HA_ERR_END_OF_FILE;
3726
3754
 
3727
3755
        if (err)
3728
 
                getTable()->status = STATUS_NOT_FOUND;
 
3756
                table->status = STATUS_NOT_FOUND;
3729
3757
        else {
3730
3758
                pb_open_tab->ot_thread->st_statistics.st_row_select++;
3731
 
                getTable()->status = 0;
 
3759
                table->status = 0;
3732
3760
        }
3733
3761
        XT_RETURN(err);
3734
3762
}
3800
3828
        }               
3801
3829
 
3802
3830
        if (err)
3803
 
                getTable()->status = STATUS_NOT_FOUND;
 
3831
                table->status = STATUS_NOT_FOUND;
3804
3832
        else {
3805
3833
                pb_open_tab->ot_thread->st_statistics.st_row_select++;
3806
 
                getTable()->status = 0;
 
3834
                table->status = 0;
3807
3835
        }
3808
3836
        XT_RETURN(err);
3809
3837
}
3885
3913
 
3886
3914
        if ((ot = pb_open_tab)) {
3887
3915
                if (flag & HA_STATUS_VARIABLE) {
3888
 
                        register XTTableHPtr tab = ot->ot_table;
3889
 
 
3890
3916
                        /* {FREE-ROWS-BAD}
3891
3917
                         * Free row count is not reliable, so ignore it.
3892
3918
                         * The problem is if tab_row_fnum > tab_row_eof_id - 1 then
3901
3927
                         * #1   0x0022e1f1 in make_sortkey at filesort.cc:769
3902
3928
                         * #2   0x0022f1cf in find_all_keys at filesort.cc:619
3903
3929
                         * #3   0x00230eec in filesort at filesort.cc:243
3904
 
                         * #4   0x001b9d89 in update_query at sql_update.cc:415
 
3930
                         * #4   0x001b9d89 in mysql_update at sql_update.cc:415
3905
3931
                         * #5   0x0010db12 in mysql_execute_command at sql_parse.cc:2959
3906
3932
                         * #6   0x0011480d in mysql_parse at sql_parse.cc:5787
3907
3933
                         * #7   0x00115afb in dispatch_command at sql_parse.cc:1200
3913
3939
                         * the actual number of vectors. But it must assume that it has at
3914
3940
                         * least EXTRA_RECORDS vectors.
3915
3941
                         */
3916
 
#ifdef XT_ROW_COUNT_CORRECTED
3917
 
                        if (tab->tab_row_eof_id <= tab->tab_row_fnum ||
3918
 
                                (!tab->tab_row_free_id && tab->tab_row_fnum))
3919
 
                                xt_tab_check_free_lists(NULL, ot, false, true);
3920
 
                        stats.records = (ha_rows) tab->tab_row_eof_id - 1;
3921
 
                        if (stats.records >= tab->tab_row_fnum) {
3922
 
                                stats.deleted = tab->tab_row_fnum;
3923
 
                                stats.records -= stats.deleted;
3924
 
                        }
3925
 
                        else {
3926
 
                                stats.deleted = 0;
3927
 
                                stats.records = 2;
3928
 
                        }
3929
 
#else
3930
 
                        stats.deleted = /* tab->tab_row_fnum */ 0;
3931
 
                        stats.records = (ha_rows) (tab->tab_row_eof_id - 1 /* - stats.deleted */);
3932
 
#endif
3933
 
                        stats.data_file_length = xt_rec_id_to_rec_offset(tab, tab->tab_rec_eof_id);
3934
 
                        stats.index_file_length = xt_ind_node_to_offset(tab, tab->tab_ind_eof);
3935
 
                        stats.delete_length = tab->tab_rec_fnum * ot->ot_rec_size;
 
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;
3936
3947
                        //check_time = info.check_time;
3937
3948
                        stats.mean_rec_length = (ulong) ot->ot_rec_size;
3938
3949
                }
3939
3950
 
3940
 
#if 0 // Commented out, I am pretty sure this will blow up on someone since the global share should be treated as being non-mutable
3941
3951
                if (flag & HA_STATUS_CONST) {
3942
3952
                        ha_rows         rec_per_key;
3943
3953
                        XTIndexPtr      ind;
3950
3960
                        //share->db_options_in_use = info.options;
3951
3961
                        stats.block_size = XT_INDEX_PAGE_SIZE;
3952
3962
 
 
3963
#ifdef DRIZZLED
3953
3964
                        if (share->getType() == message::Table::STANDARD)
 
3965
#else
 
3966
                        if (share->tmp_table == NO_TMP_TABLE)
 
3967
#endif
3954
3968
#ifdef DRIZZLED
3955
3969
#define WHICH_MUTEX                     mutex
3956
3970
#elif MYSQL_VERSION_ID >= 50404
3977
3991
#ifdef MY_PTHREAD_FASTMUTEX
3978
3992
                                my_pthread_fastmutex_lock(&share->WHICH_MUTEX);
3979
3993
#else
3980
 
                                share->lock();
 
3994
                                pthread_mutex_lock(&share->WHICH_MUTEX);
3981
3995
#endif
3982
3996
 
3983
3997
#endif // SAFE_MUTEX
4013
4027
#ifdef MY_PTHREAD_FASTMUTEX
4014
4028
                                pthread_mutex_unlock(&share->WHICH_MUTEX.mutex);
4015
4029
#else
4016
 
                                share->unlock();
 
4030
                                pthread_mutex_unlock(&share->WHICH_MUTEX);
4017
4031
#endif
4018
4032
#endif
4019
4033
                        /*
4030
4044
                                index_file_name = info.index_file_name;
4031
4045
                        */
4032
4046
                }
4033
 
#endif  // if(0)
4034
4047
 
4035
4048
                if (flag & HA_STATUS_ERRKEY)
4036
4049
                        errkey = ot->ot_err_index_no;
4194
4207
 *
4195
4208
 * Called from item_sum.cc by Item_func_group_concat::clear(),
4196
4209
 * Item_sum_count_distinct::clear(), and Item_func_group_concat::clear().
4197
 
 * Called from sql_delete.cc by delete_query().
 
4210
 * Called from sql_delete.cc by mysql_delete().
4198
4211
 * Called from sql_select.cc by JOIN::reinit().
4199
4212
 * Called from sql_union.cc by st_select_lex_unit::exec().
4200
4213
 */
4215
4228
                 * each row because it may be part of a transaction,
4216
4229
                 * and there may be foreign key actions.
4217
4230
                 */
 
4231
#ifdef DRIZZLED
4218
4232
                XT_RETURN (errno = HA_ERR_WRONG_COMMAND);
 
4233
#else
 
4234
                XT_RETURN (my_errno = HA_ERR_WRONG_COMMAND);
 
4235
#endif
4219
4236
        }
4220
4237
 
4221
4238
        if (!(self = ha_set_current_thread(thd, &err)))
4302
4319
 * now agree with the MyISAM strategy.
4303
4320
 * 
4304
4321
 */
 
4322
#ifdef DRIZZLED
4305
4323
int ha_pbxt::analyze(THD *thd)
 
4324
#else
 
4325
int ha_pbxt::analyze(THD *thd, HA_CHECK_OPT *XT_UNUSED(check_opt))
 
4326
#endif
4306
4327
{
4307
4328
        int                             err = 0;
4308
4329
        XTDatabaseHPtr  db;
4347
4368
        else
4348
4369
                my_xn_id = db->db_xn_to_clean_id;
4349
4370
 
4350
 
        while ((!db->db_sw_idle || xt_xn_is_before(db->db_xn_to_clean_id, my_xn_id)) && not (thd->getKilled())) {
 
4371
        while ((!db->db_sw_idle || xt_xn_is_before(db->db_xn_to_clean_id, my_xn_id)) && !thd_killed(thd)) {
4351
4372
                xt_busy_wait();
4352
4373
 
4353
4374
                /*
4384
4405
        XT_RETURN(err);
4385
4406
}
4386
4407
 
 
4408
#ifndef DRIZZLED
 
4409
int ha_pbxt::repair(THD *XT_UNUSED(thd), HA_CHECK_OPT *XT_UNUSED(check_opt))
 
4410
{
 
4411
        return(HA_ADMIN_TRY_ALTER);
 
4412
}
 
4413
 
 
4414
/*
 
4415
 * This is mapped to "ALTER TABLE tablename TYPE=PBXT", which rebuilds
 
4416
 * the table in MySQL.
 
4417
 */
 
4418
int ha_pbxt::optimize(THD *XT_UNUSED(thd), HA_CHECK_OPT *XT_UNUSED(check_opt))
 
4419
{
 
4420
        return(HA_ADMIN_TRY_ALTER);
 
4421
}
 
4422
#endif
 
4423
 
4387
4424
#ifdef DEBUG
4388
4425
extern int pbxt_mysql_trace_on;
4389
4426
#endif
4390
4427
 
 
4428
#ifdef DRIZZLED
4391
4429
int ha_pbxt::check(THD* thd)
 
4430
#else
 
4431
int ha_pbxt::check(THD* thd, HA_CHECK_OPT* XT_UNUSED(check_opt))
 
4432
#endif
4392
4433
{
4393
4434
        int                             err = 0;
4394
4435
        XTThreadPtr             self;
4551
4592
                                }
4552
4593
 
4553
4594
                                if (pb_share->sh_recalc_selectivity) {
4554
 
#ifdef XT_ROW_COUNT_CORRECTED
4555
 
                                        /* {CORRECTED-ROW-COUNT} */
4556
 
                                        if ((pb_share->sh_table->tab_row_eof_id - 1 - pb_share->sh_table->tab_row_fnum) >= 200)
4557
 
#else
4558
4595
                                        /* {FREE-ROWS-BAD} */
4559
 
                                        if ((pb_share->sh_table->tab_row_eof_id - 1 /* - pb_share->sh_table->tab_row_fnum */) >= 200)
4560
 
#endif
4561
 
                                        {
 
4596
                                        if ((pb_share->sh_table->tab_row_eof_id - 1 /* - pb_share->sh_table->tab_row_fnum */) >= 200) {
4562
4597
                                                /* [**] */
4563
4598
                                                pb_share->sh_recalc_selectivity = FALSE;
4564
4599
                                                xt_ind_set_index_selectivity(pb_open_tab, self);
4565
 
#ifdef XT_ROW_COUNT_CORRECTED
4566
 
                                                /* {CORRECTED-ROW-COUNT} */
4567
 
                                                pb_share->sh_recalc_selectivity = (pb_share->sh_table->tab_row_eof_id - 1 - pb_share->sh_table->tab_row_fnum) < 150;
4568
 
#else
4569
4600
                                                /* {FREE-ROWS-BAD} */
4570
4601
                                                pb_share->sh_recalc_selectivity = (pb_share->sh_table->tab_row_eof_id - 1 /* - pb_share->sh_table->tab_row_fnum */) < 150;
4571
 
#endif
4572
4602
                                        }
4573
4603
                                }
4574
4604
                        }
4617
4647
                                goto complete;
4618
4648
                        }
4619
4649
                        cont_(a);
4620
 
 
4621
 
                        /* Occurs if you do:
4622
 
                         * truncate table t1;
4623
 
                         * truncate table t1;
4624
 
                         */
4625
 
                        if (!pb_open_tab) {
4626
 
                                if ((err = reopen())) {
4627
 
                                        pb_ex_in_use = 0;
4628
 
                                        goto complete;
4629
 
                                }
4630
 
                        }
4631
4650
                }
4632
4651
                else {
4633
4652
                        pb_ex_in_use = 1;
4958
4977
#ifndef DRIZZLED
4959
4978
                        case SQLCOM_REPAIR:
4960
4979
                        case SQLCOM_OPTIMIZE:
 
4980
                                self->st_stat_modify = TRUE;
4961
4981
#endif
4962
 
                                self->st_stat_modify = TRUE;
4963
4982
                                break;
4964
4983
                }
4965
4984
        }
5232
5251
 * during create if the table_flag HA_DROP_BEFORE_CREATE was specified for
5233
5252
 * the storage engine.
5234
5253
*/
 
5254
#ifdef DRIZZLED
5235
5255
int PBXTStorageEngine::doDropTable(Session &, const TableIdentifier& ident)
5236
5256
{
5237
5257
        const std::string& path = ident.getPath();
5238
5258
        const char *table_path = path.c_str();
 
5259
#else
 
5260
int ha_pbxt::delete_table(const char *table_path)
 
5261
{
 
5262
#endif
5239
5263
        THD                             *thd = current_thd;
5240
5264
        int                             err = 0;
5241
5265
        XTThreadPtr             self = NULL;
5327
5351
        }
5328
5352
#endif
5329
5353
 
5330
 
        std::string path2(ident.getPath());
5331
 
        path2.append(DEFAULT_FILE_EXTENSION);
5332
 
        (void)internal::my_delete(path2.c_str(), MYF(0));
 
5354
#ifdef DRIZZLED
 
5355
          std::string path2(ident.getPath());
 
5356
          path2.append(DEFAULT_FILE_EXTENSION);
 
5357
          (void)internal::my_delete(path2.c_str(), MYF(0));
 
5358
#endif
5333
5359
 
5334
5360
        return err;
5335
5361
}
5376
5402
 * This function can be used to move a table from one database to
5377
5403
 * another.
5378
5404
 */
 
5405
#ifdef DRIZZLED
5379
5406
int PBXTStorageEngine::doRenameTable(Session&,
5380
5407
                                     const TableIdentifier& from_ident,
5381
5408
                                     const TableIdentifier& to_ident)
5386
5413
        if (strcmp(from, to) == 0)
5387
5414
                return 0;
5388
5415
 
 
5416
#else
 
5417
int ha_pbxt::rename_table(const char *from, const char *to)
 
5418
{
 
5419
#endif
5389
5420
        THD                             *thd = current_thd;
5390
5421
        int                             err = 0;
5391
5422
        XTThreadPtr             self;
5462
5493
        pbms_completed(NULL, (err == 0));
5463
5494
#endif
5464
5495
 
 
5496
#ifdef DRIZZLED
5465
5497
        if (err == 0)
5466
5498
                plugin::StorageEngine::renameDefinitionFromPath(to_ident, from_ident);
 
5499
#endif
5467
5500
 
5468
5501
        XT_RETURN(err);
5469
5502
}
5611
5644
        try_(a) {
5612
5645
                xt_ha_open_database_of_table(self, (XTPathStrPtr) table_path);
5613
5646
 
5614
 
                for (uint i=0; i<table_arg.getShare()->keys; i++) {
 
5647
                for (uint i=0; i<table_arg.s->keys; i++) {
5615
5648
                        if (table_arg.key_info[i].key_length > XT_INDEX_MAX_KEY_SIZE)
5616
5649
                                xt_throw_sulxterr(XT_CONTEXT, XT_ERR_KEY_TOO_LARGE, table_arg.key_info[i].name, (u_long) XT_INDEX_MAX_KEY_SIZE);
5617
5650
                }
5628
5661
 
5629
5662
                StorageEngine::writeDefinitionFromPath(ident, proto);
5630
5663
 
5631
 
                Session::QueryString query_string(thd->getQueryString());
5632
 
                tab_def = xt_ri_create_table(self, true, (XTPathStrPtr) table_path, const_cast<char *>(query_string->c_str()), myxt_create_table_from_table(self, table_arg.getMutableShare()), &source_dic);
 
5664
                tab_def = xt_ri_create_table(self, true, (XTPathStrPtr) table_path, const_cast<char *>(thd->getQueryString().c_str()), myxt_create_table_from_table(self, table_arg.s), &source_dic);
5633
5665
                tab_def->checkForeignKeys(self, proto.type() == message::Table::TEMPORARY);
5634
5666
 
5635
5667
                dic.dic_table = tab_def;
5636
 
                dic.dic_my_table = table_arg.getMutableShare();
 
5668
                dic.dic_my_table = table_arg.s;
5637
5669
                dic.dic_tab_flags = source_dic.dic_tab_flags;
5638
5670
                //if (create_info.storage_media == HA_SM_MEMORY)
5639
5671
                //      dic.dic_tab_flags |= XT_TF_MEMORY_TABLE;
5700
5732
        if (!self->st_database)
5701
5733
                xt_ha_open_database_of_table(self, NULL);
5702
5734
 
5703
 
        assert(!self->st_xact_data); // Check we're not called twice
5704
 
        if (!xt_xn_begin(self)) {
5705
 
          err = xt_ha_pbxt_thread_error_for_mysql(thd, self, /*pb_ignore_dup_key*/false);
 
5735
        if (!xt_xn_begin(self)) {
 
5736
                        err = xt_ha_pbxt_thread_error_for_mysql(thd, self, /*pb_ignore_dup_key*/false);
 
5737
                        //pb_ex_in_use = 0;
5706
5738
        }
5707
5739
 
5708
5740
        return err;
5723
5755
        return xt_ha_pbxt_thread_error_for_mysql(thd, xt_ha_thd_to_self(thd), false);
5724
5756
}
5725
5757
 
5726
 
int PBXTStorageEngine::doCommit(drizzled::Session* thd, bool real_commit)
 
5758
int PBXTStorageEngine::doCommit(drizzled::Session* thd, bool)
5727
5759
{
5728
5760
        int err = 0;
5729
5761
        XTThreadPtr self = (XTThreadPtr) *thd->getEngineData(pbxt_hton);
5730
5762
 
 
5763
        bool real_commit = !session_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN);
 
5764
        
5731
5765
        XT_PRINT1(self, "PBXTStorageEngine::doCommit(real_commit = %s)\n", real_commit ? "true" : "false");
5732
5766
 
5733
5767
        if (real_commit && self) {
5738
5772
        return err;
5739
5773
}
5740
5774
 
5741
 
int PBXTStorageEngine::doRollback(drizzled::Session* thd, bool real_commit)
 
5775
int PBXTStorageEngine::doRollback(drizzled::Session* thd, bool)
5742
5776
{
5743
5777
        int err = 0;
5744
5778
        XTThreadPtr self = (XTThreadPtr) *thd->getEngineData(pbxt_hton);
5745
5779
 
 
5780
        bool real_commit = !session_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN);
 
5781
 
5746
5782
        XT_PRINT1(self, "PBXTStorageEngine::doRollback(real_commit = %s)\n", real_commit ? "true" : "false");
5747
5783
 
5748
5784
        if (real_commit && self) {
5944
5980
 
5945
5981
                        fk_info->referenced_table = thd_make_lex_string(thd, 0,
5946
5982
                                ref_tbl_name, (uint) strlen(ref_tbl_name), 1);
5947
 
 
 
5983
                        
5948
5984
                        fk_info->referenced_key_name = NULL;                    
5949
5985
 
5950
5986
                        XTIndex *ix = fk->getReferenceIndexPtr();
6016
6052
}
6017
6053
#endif // DRI_IS
6018
6054
 
6019
 
#ifndef DRIZZLED
6020
6055
struct st_mysql_sys_var
6021
6056
{
6022
6057
        MYSQL_PLUGIN_VAR_HEADER;
6031
6066
#define USE_CONST_SAVE
6032
6067
#endif
6033
6068
#endif
6034
 
#endif
6035
6069
 
6036
6070
#ifdef DRIZZLED
6037
6071
#define st_mysql_sys_var drizzled::drizzle_sys_var
6038
6072
#endif
6039
6073
 
6040
 
#ifndef DRIZZLED
6041
6074
#ifdef USE_CONST_SAVE
6042
6075
static void pbxt_record_cache_size_func(THD *XT_UNUSED(thd), struct st_mysql_sys_var *var, void *tgt, const void *save)
6043
6076
#else
6063
6096
#endif
6064
6097
}
6065
6098
 
 
6099
#ifndef DRIZZLED
6066
6100
struct st_mysql_storage_engine pbxt_storage_engine = {
6067
6101
        MYSQL_HANDLERTON_INTERFACE_VERSION
6068
6102
};
6069
6103
static st_mysql_information_schema pbxt_statitics = {
6070
6104
        MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION
6071
6105
};
 
6106
#endif
6072
6107
 
6073
6108
#if MYSQL_VERSION_ID >= 50118
6074
6109
static MYSQL_SYSVAR_STR(index_cache_size, pbxt_index_cache_size,
6201
6236
  NULL
6202
6237
};
6203
6238
#endif
6204
 
#endif
6205
6239
 
6206
6240
#ifdef DRIZZLED
6207
6241
DRIZZLE_DECLARE_PLUGIN
6213
6247
        "High performance, multi-versioning transactional engine",
6214
6248
        PLUGIN_LICENSE_GPL,
6215
6249
        pbxt_init, /* Plugin Init */
6216
 
        NULL,          /* depends */
 
6250
        pbxt_system_variables,          /* system variables                */
6217
6251
        NULL                                            /* config options                  */
6218
6252
}
6219
6253
DRIZZLE_DECLARE_PLUGIN_END;
6231
6265
        0x0001 /* 0.1 */,
6232
6266
        NULL,                       /* status variables                */
6233
6267
#if MYSQL_VERSION_ID >= 50118
6234
 
        pbxt_system_variables,          /* depends */
 
6268
        pbxt_system_variables,          /* system variables                */
6235
6269
#else
6236
6270
        NULL,
6237
6271
#endif
6247
6281
        pbxt_exit_statistics,                                           /* plugin deinit */
6248
6282
        0x0005,
6249
6283
        NULL,                                                                           /* status variables */
6250
 
        NULL,                                                                           /* depends */
 
6284
        NULL,                                                                           /* system variables */
6251
6285
        NULL                                                                            /* config options */
6252
6286
}
6253
6287
mysql_declare_plugin_end;