ha_tokudb.h 17.6 KB
Newer Older
1
#ifdef USE_PRAGMA_INTERFACE
2
#pragma interface               /* gcc class implementation */
3 4
#endif

5 6 7
#define TOKU_INCLUDE_CHECKPOINT_LOCK 1


8 9 10 11 12
#if !defined(HA_CLUSTERING)
#define HA_CLUSTERING 0
#define HA_CLUSTERED_INDEX 0
#endif

13
#include <db.h>
Zardosht Kasheff's avatar
Zardosht Kasheff committed
14
#include "hatoku_cmp.h"
15

16 17 18 19 20 21 22
class ha_tokudb;

typedef struct loader_context {
    THD* thd;
    char write_status_msg[200];
    ha_tokudb* ha;
} *LOADER_CONTEXT;
Zardosht Kasheff's avatar
Zardosht Kasheff committed
23

24 25 26 27 28 29 30
//
// This object stores table information that is to be shared
// among all ha_tokudb objects.
// There is one instance per table, shared among threads.
// Some of the variables here are the DB* pointers to indexes,
// and auto increment information.
//
31
typedef struct st_tokudb_share {
32 33 34 35 36 37
    char *table_name;
    uint table_name_length, use_count;
    pthread_mutex_t mutex;
    THR_LOCK lock;

    ulonglong auto_ident;
Zardosht Kasheff's avatar
Zardosht Kasheff committed
38
    ulonglong last_auto_increment, auto_inc_create_value;
Zardosht Kasheff's avatar
Zardosht Kasheff committed
39 40 41
    //
    // estimate on number of rows in table
    //
Zardosht Kasheff's avatar
Zardosht Kasheff committed
42
    ha_rows rows;
Zardosht Kasheff's avatar
Zardosht Kasheff committed
43 44 45 46 47
    //
    // estimate on number of rows added in the process of a locked tables
    // this is so we can better estimate row count during a lock table
    //
    ha_rows rows_from_locked_table;
Zardosht Kasheff's avatar
Zardosht Kasheff committed
48 49 50 51 52 53 54
    DB *status_block;
    //
    // DB that is indexed on the primary key
    //
    DB *file;
    //
    // array of all DB's that make up table, includes DB that
Zardosht Kasheff's avatar
Zardosht Kasheff committed
55 56
    // is indexed on the primary key, add 1 in case primary
    // key is hidden
Zardosht Kasheff's avatar
Zardosht Kasheff committed
57
    //
Zardosht Kasheff's avatar
Zardosht Kasheff committed
58
    DB *key_file[MAX_KEY +1];
Zardosht Kasheff's avatar
Zardosht Kasheff committed
59
    uint status, version, capabilities;
60
    uint ref_length;
Zardosht Kasheff's avatar
Zardosht Kasheff committed
61 62 63 64 65 66 67 68
    //
    // whether table has an auto increment column
    //
    bool has_auto_inc;
    //
    // index of auto increment column in table->field, if auto_inc exists
    //
    uint ai_field_index;
Zardosht Kasheff's avatar
Zardosht Kasheff committed
69

70 71
    KEY_AND_COL_INFO kc_info;
    
72 73 74 75 76 77 78
    // 
    // we want the following optimization for bulk loads, if the table is empty, 
    // attempt to grab a table lock. emptiness check can be expensive, 
    // so we try it once for a table. After that, we keep this variable around 
    // to tell us to not try it again. 
    // 
    bool try_table_lock; 
79 80

    bool has_unique_keys;
81
    bool replace_into_fast;
82 83
    rw_lock_t num_DBs_lock;
    u_int32_t num_DBs;
84 85
} TOKUDB_SHARE;

86
#define HA_TOKU_VERSION 3
Zardosht Kasheff's avatar
Zardosht Kasheff committed
87 88 89
//
// no capabilities yet
//
Zardosht Kasheff's avatar
Zardosht Kasheff committed
90
#define HA_TOKU_CAP 0
Zardosht Kasheff's avatar
Zardosht Kasheff committed
91 92 93 94 95 96 97


//
// These are keys that will be used for retrieving metadata in status.tokudb
// To get the version, one looks up the value associated with key hatoku_version
// in status.tokudb
//
Zardosht Kasheff's avatar
Zardosht Kasheff committed
98

Zardosht Kasheff's avatar
Zardosht Kasheff committed
99 100 101 102 103
typedef ulonglong HA_METADATA_KEY;
#define hatoku_version 0
#define hatoku_capabilities 1
#define hatoku_max_ai 2 //maximum auto increment value found so far
#define hatoku_ai_create_value 3
104
#define hatoku_key_name 4
Zardosht Kasheff's avatar
Zardosht Kasheff committed
105

Zardosht Kasheff's avatar
Zardosht Kasheff committed
106
typedef struct st_filter_key_part_info {
Zardosht Kasheff's avatar
Zardosht Kasheff committed
107 108
    uint offset;
    uint part_index;
Zardosht Kasheff's avatar
Zardosht Kasheff committed
109
} FILTER_KEY_PART_INFO;
Zardosht Kasheff's avatar
Zardosht Kasheff committed
110

Zardosht Kasheff's avatar
Zardosht Kasheff committed
111 112 113 114 115
typedef enum {
    lock_read = 0,
    lock_write
} TABLE_LOCK_TYPE;

116
int create_tokudb_trx_data_instance(tokudb_trx_data** out_trx);
117 118 119 120 121
int generate_row_for_del(
    DB *dest_db, 
    DB *src_db,
    DBT *dest_key,
    const DBT *src_key, 
122
    const DBT *src_val
123
    );
Zardosht Kasheff's avatar
Zardosht Kasheff committed
124 125 126 127 128 129
int generate_row_for_put(
    DB *dest_db, 
    DB *src_db,
    DBT *dest_key, 
    DBT *dest_val,
    const DBT *src_key, 
130
    const DBT *src_val
Zardosht Kasheff's avatar
Zardosht Kasheff committed
131
    ); 
132 133


134
class ha_tokudb : public handler {
135
private:
136 137 138
    THR_LOCK_DATA lock;         ///< MySQL lock
    TOKUDB_SHARE *share;        ///< Shared lock info

Zardosht Kasheff's avatar
Zardosht Kasheff committed
139 140 141 142 143
    //
    // last key returned by ha_tokudb's cursor
    //
    DBT last_key;
    //
Zardosht Kasheff's avatar
Zardosht Kasheff committed
144 145
    // pointer used for multi_alloc of key_buff, key_buff2, primary_key_buff
    //
146
    void *alloc_ptr;
Zardosht Kasheff's avatar
Zardosht Kasheff committed
147 148 149 150 151
    //
    // buffer used to temporarily store a "packed row" 
    // data pointer of a DBT will end up pointing to this
    // see pack_row for usage
    //
152
    uchar *rec_buff;
Zardosht Kasheff's avatar
Zardosht Kasheff committed
153 154 155 156
    //
    // number of bytes allocated in rec_buff
    //
    ulong alloced_rec_buff_length;
157 158 159 160 161
    //
    // same as above two, but for updates
    //
    uchar *rec_update_buff;
    ulong alloced_update_rec_buff_length;
162
    u_int32_t max_key_length;
Zardosht Kasheff's avatar
Zardosht Kasheff committed
163 164 165 166 167 168 169 170 171 172 173 174
    //
    // buffer used to temporarily store a "packed key" 
    // data pointer of a DBT will end up pointing to this
    //
    uchar *key_buff; 
    //
    // buffer used to temporarily store a "packed key" 
    // data pointer of a DBT will end up pointing to this
    // This is used in functions that require the packing
    // of more than one key
    //
    uchar *key_buff2; 
Zardosht Kasheff's avatar
Zardosht Kasheff committed
175
    uchar *key_buff3; 
Zardosht Kasheff's avatar
Zardosht Kasheff committed
176 177 178 179 180 181 182 183
    //
    // buffer used to temporarily store a "packed key" 
    // data pointer of a DBT will end up pointing to this
    // currently this is only used for a primary key in
    // the function update_row, hence the name. It 
    // does not carry any state throughout the class.
    //
    uchar *primary_key_buff;
Zardosht Kasheff's avatar
Zardosht Kasheff committed
184

185 186 187
    //
    // individual key buffer for each index
    //
188
    uchar* mult_key_buff[2*(MAX_KEY + 1)];
189
    uchar* mult_rec_buff[MAX_KEY + 1];
190
    DBT mult_key_dbt[2*(MAX_KEY + 1)];
Zardosht Kasheff's avatar
Zardosht Kasheff committed
191
    DBT mult_rec_dbt[MAX_KEY + 1];
192
    u_int32_t mult_put_flags[MAX_KEY + 1];
193
    u_int32_t mult_del_flags[MAX_KEY + 1];
194
    u_int32_t mult_dbt_flags[MAX_KEY + 1];
Zardosht Kasheff's avatar
Zardosht Kasheff committed
195
    
196 197
    ulong alloced_mult_rec_buff_length;

Zardosht Kasheff's avatar
Zardosht Kasheff committed
198 199 200 201 202 203 204 205 206
    //
    // when unpacking blobs, we need to store it in a temporary
    // buffer that will persist because MySQL just gets a pointer to the 
    // blob data, a pointer we need to ensure is valid until the next
    // query
    //
    uchar* blob_buff;
    u_int32_t num_blob_bytes;

Zardosht Kasheff's avatar
Zardosht Kasheff committed
207 208 209 210 211 212 213 214 215 216 217 218 219
    bool unpack_entire_row;

    //
    // buffers (and their sizes) that will hold the indexes
    // of fields that need to be read for a query
    //
    u_int32_t* fixed_cols_for_query;
    u_int32_t num_fixed_cols_for_query;
    u_int32_t* var_cols_for_query;
    u_int32_t num_var_cols_for_query;
    bool read_blobs;
    bool read_key;

Zardosht Kasheff's avatar
Zardosht Kasheff committed
220 221 222
    //
    // transaction used by ha_tokudb's cursor
    //
223
    DB_TXN *transaction;
Zardosht Kasheff's avatar
Zardosht Kasheff committed
224

Zardosht Kasheff's avatar
Zardosht Kasheff committed
225 226 227
    //
    // instance of cursor being used for init_xxx and rnd_xxx functions
    //
228
    DBC *cursor;
229
    u_int32_t cursor_flags; // flags for cursor
Zardosht Kasheff's avatar
Zardosht Kasheff committed
230 231 232
    //
    // flags that are returned in table_flags()
    //
Zardosht Kasheff's avatar
Zardosht Kasheff committed
233
    ulonglong int_table_flags;
Zardosht Kasheff's avatar
Zardosht Kasheff committed
234
    // 
Zardosht Kasheff's avatar
Zardosht Kasheff committed
235 236
    // count on the number of rows that gets changed, such as when write_row occurs
    // this is meant to help keep estimate on number of elements in DB
Zardosht Kasheff's avatar
Zardosht Kasheff committed
237 238 239
    // 
    ulonglong added_rows;
    ulonglong deleted_rows;
Zardosht Kasheff's avatar
Zardosht Kasheff committed
240 241


Zardosht Kasheff's avatar
Zardosht Kasheff committed
242 243 244 245 246 247
    uint last_dup_key;
    //
    // if set to 0, then the primary key is not hidden
    // if non-zero (not necessarily 1), primary key is hidden
    //
    uint hidden_primary_key;
248
    bool key_read, using_ignore;
Zardosht Kasheff's avatar
Zardosht Kasheff committed
249

Zardosht Kasheff's avatar
Zardosht Kasheff committed
250 251 252 253 254 255 256
    //
    // After a cursor encounters an error, the cursor will be unusable
    // In case MySQL attempts to do a cursor operation (such as rnd_next
    // or index_prev), we will gracefully return this error instead of crashing
    //
    int last_cursor_error;

Zardosht Kasheff's avatar
Zardosht Kasheff committed
257 258 259 260 261
    //
    // For instances where we successfully prelock a range or a table,
    // we set this to TRUE so that successive cursor calls can know
    // know to limit the locking overhead in a call to the fractal tree
    //
Zardosht Kasheff's avatar
Zardosht Kasheff committed
262
    bool range_lock_grabbed;
Zardosht Kasheff's avatar
Zardosht Kasheff committed
263

Zardosht Kasheff's avatar
Zardosht Kasheff committed
264 265 266 267
    //
    // For bulk inserts, we want option of not updating auto inc
    // until all inserts are done. By default, is false
    //
268 269
    bool delay_updating_ai_metadata; // if true, don't update auto-increment metadata until bulk load completes
    bool ai_metadata_update_required; // if true, autoincrement metadata must be updated 
Zardosht Kasheff's avatar
Zardosht Kasheff committed
270

Zardosht Kasheff's avatar
Zardosht Kasheff committed
271 272 273 274 275 276 277
    //
    // buffer for updating the status of long insert, delete, and update
    // statements. Right now, the the messages are 
    // "[inserted|updated|deleted] about %llu rows",
    // so a buffer of 200 is good enough.
    //
    char write_status_msg[200]; //buffer of 200 should be a good upper bound.
278
    struct loader_context lc;
Zardosht Kasheff's avatar
Zardosht Kasheff committed
279

280
    ulonglong read_lock_wait_time;
281 282 283 284
    DB_LOADER* loader;
    bool abort_loader;
    int loader_error;
    
285
    bool fix_rec_buff_for_blob(ulong length);
286
    bool fix_rec_update_buff_for_blob(ulong length);
287
    void fix_mult_rec_buff();
288 289 290
    uchar current_ident[TOKUDB_HIDDEN_PRIMARY_KEY_LENGTH];

    ulong max_row_length(const uchar * buf);
291 292 293 294 295 296
    int pack_row_in_buff(
        DBT * row, 
        const uchar* record,
        uint index,
        uchar* row_buff
        );
Zardosht Kasheff's avatar
Zardosht Kasheff committed
297 298 299 300 301
    int pack_row(
        DBT * row, 
        const uchar* record,
        uint index
        );
302 303 304 305 306
    int pack_old_row_for_update(
        DBT * row, 
        const uchar* record,
        uint index
        );
Zardosht Kasheff's avatar
Zardosht Kasheff committed
307
    u_int32_t place_key_into_mysql_buff(KEY* key_info, uchar * record, uchar* data);
Zardosht Kasheff's avatar
Zardosht Kasheff committed
308
    void unpack_key(uchar * record, DBT const *key, uint index);
Zardosht Kasheff's avatar
Zardosht Kasheff committed
309
    u_int32_t place_key_into_dbt_buff(KEY* key_info, uchar * buff, const uchar * record, bool* has_null, int key_length);
310
    DBT* create_dbt_key_from_key(DBT * key, KEY* key_info, uchar * buff, const uchar * record, bool* has_null, bool dont_pack_pk, int key_length = MAX_KEY_LENGTH);
Zardosht Kasheff's avatar
Zardosht Kasheff committed
311
    DBT *create_dbt_key_from_table(DBT * key, uint keynr, uchar * buff, const uchar * record, bool* has_null, int key_length = MAX_KEY_LENGTH);
Zardosht Kasheff's avatar
Zardosht Kasheff committed
312
    DBT* create_dbt_key_for_lookup(DBT * key, KEY* key_info, uchar * buff, const uchar * record, bool* has_null, int key_length = MAX_KEY_LENGTH);
313
    DBT *pack_key(DBT * key, uint keynr, uchar * buff, const uchar * key_ptr, uint key_length, int8_t inf_byte);
314
    int key_cmp(uint keynr, const uchar * old_row, const uchar * new_row);
Zardosht Kasheff's avatar
Zardosht Kasheff committed
315
    int handle_cursor_error(int error, int err_to_return, uint keynr);
316
    DBT *get_pos(DBT * to, uchar * pos);
Zardosht Kasheff's avatar
Zardosht Kasheff committed
317
 
Zardosht Kasheff's avatar
Zardosht Kasheff committed
318 319
    int open_main_dictionary(const char* name, bool is_read_only, DB_TXN* txn);
    int open_secondary_dictionary(DB** ptr, KEY* key_info, const char* name, bool is_read_only, DB_TXN* txn);
320
    int open_status_dictionary(DB** ptr, const char* name, DB_TXN* txn);
Zardosht Kasheff's avatar
Zardosht Kasheff committed
321
    int acquire_table_lock (DB_TXN* trans, TABLE_LOCK_TYPE lt);
322
    int estimate_num_rows(DB* db, u_int64_t* num_rows, DB_TXN* txn);
Zardosht Kasheff's avatar
Zardosht Kasheff committed
323
    bool has_auto_increment_flag(uint* index);
324 325 326
    int write_to_status(DB* db, HA_METADATA_KEY curr_key_data, void* data, uint size, DB_TXN* txn );
    int write_metadata(DB* db, void* key, uint key_size, void* data, uint data_size, DB_TXN* txn );
    int remove_metadata(DB* db, void* key_data, uint key_size, DB_TXN* transaction);
Zardosht Kasheff's avatar
Zardosht Kasheff committed
327
    int update_max_auto_inc(DB* db, ulonglong val);
328 329 330
    int remove_key_name_from_status(DB* status_block, char* key_name, DB_TXN* txn);
    int write_key_name_to_status(DB* status_block, char* key_name, DB_TXN* txn);
    int write_auto_inc_create(DB* db, ulonglong val, DB_TXN* txn);
Zardosht Kasheff's avatar
Zardosht Kasheff committed
331
    void init_auto_increment();
332
    bool can_replace_into_be_fast(TABLE_SHARE* table_share, KEY_AND_COL_INFO* kc_info, uint pk);
Zardosht Kasheff's avatar
Zardosht Kasheff committed
333 334 335 336 337 338
    int initialize_share(
        const char* name,
        int mode
        );

    void set_query_columns(uint keynr);
Zardosht Kasheff's avatar
Zardosht Kasheff committed
339
    int prelock_range ( const key_range *start_key, const key_range *end_key);
340
    int create_txn(THD* thd, tokudb_trx_data* trx);
341
    bool may_table_be_empty();
342
    int delete_or_rename_table (const char* from_name, const char* to_name, bool is_delete);
343
    int delete_or_rename_dictionary( const char* from_name, const char* to_name, const char* index_name, bool is_key, DB_TXN* txn, bool is_delete);
344
    int truncate_dictionary( uint keynr, DB_TXN* txn );
345 346
    int create_secondary_dictionary(const char* name, TABLE* form, KEY* key_info, DB_TXN* txn, KEY_AND_COL_INFO* kc_info, u_int32_t keynr);
    int create_main_dictionary(const char* name, TABLE* form, DB_TXN* txn, KEY_AND_COL_INFO* kc_info);
347
    void trace_create_table_info(const char *name, TABLE * form);
348
    int is_index_unique(bool* is_unique, DB_TXN* txn, DB* db, KEY* key_info);
Zardosht Kasheff's avatar
Zardosht Kasheff committed
349
    int is_val_unique(bool* is_unique, uchar* record, KEY* key_info, uint dict_index, DB_TXN* txn);
350
    int do_uniqueness_checks(uchar* record, DB_TXN* txn, THD* thd);
351
    void set_main_dict_put_flags(THD* thd, u_int32_t* put_flags);
352
    int insert_row_to_main_dictionary(uchar* record, DBT* pk_key, DBT* pk_val, DB_TXN* txn);
Zardosht Kasheff's avatar
Zardosht Kasheff committed
353
    int insert_rows_to_dictionaries_mult(DBT* pk_key, DBT* pk_val, DB_TXN* txn, THD* thd);
354
    void test_row_packing(uchar* record, DBT* pk_key, DBT* pk_val);
355

Zardosht Kasheff's avatar
Zardosht Kasheff committed
356
 
357 358 359 360 361
public:
    ha_tokudb(handlerton * hton, TABLE_SHARE * table_arg);
    ~ha_tokudb() {
    } 
    const char *table_type() const {
362
        return "TOKUDB";
363 364
    } 
    const char *index_type(uint inx) {
365 366 367
        return "BTREE";
    }
    const char **bas_ext() const;
Zardosht Kasheff's avatar
Zardosht Kasheff committed
368 369 370 371 372

    //
    // Returns a bit mask of capabilities of storage engine. Capabilities 
    // defined in sql/handler.h
    //
373 374
    ulonglong table_flags(void) const;
    
375
    ulong index_flags(uint inx, uint part, bool all_parts) const;
376

Zardosht Kasheff's avatar
Zardosht Kasheff committed
377 378 379
    //
    // Returns limit on the number of keys imposed by tokudb.
    //
380
    uint max_supported_keys() const {
Zardosht Kasheff's avatar
Zardosht Kasheff committed
381
        return MAX_KEY;
382
    } 
Zardosht Kasheff's avatar
Zardosht Kasheff committed
383

384
    uint extra_rec_buf_length() const {
385
        return TOKUDB_HIDDEN_PRIMARY_KEY_LENGTH;
386 387
    } 
    ha_rows estimate_rows_upper_bound();
Zardosht Kasheff's avatar
Zardosht Kasheff committed
388 389 390 391

    //
    // Returns the limit on the key length imposed by tokudb.
    //
392 393
    uint max_supported_key_length() const {
        return UINT_MAX32;
394
    } 
Zardosht Kasheff's avatar
Zardosht Kasheff committed
395 396 397 398

    //
    // Returns limit on key part length imposed by tokudb.
    //
399
    uint max_supported_key_part_length() const {
400
        return UINT_MAX32;
401 402
    } 
    const key_map *keys_to_use_for_scanning() {
403 404 405 406
        return &key_map_full;
    }

    double scan_time();
Zardosht Kasheff's avatar
Zardosht Kasheff committed
407
    double read_time(uint index, uint ranges, ha_rows rows);
408 409 410

    int open(const char *name, int mode, uint test_if_locked);
    int close(void);
Zardosht Kasheff's avatar
Zardosht Kasheff committed
411
    void update_create_info(HA_CREATE_INFO* create_info);
412 413 414
    int create(const char *name, TABLE * form, HA_CREATE_INFO * create_info);
    int delete_table(const char *name);
    int rename_table(const char *from, const char *to);
Zardosht Kasheff's avatar
Zardosht Kasheff committed
415
    int optimize(THD * thd, HA_CHECK_OPT * check_opt);
Zardosht Kasheff's avatar
Zardosht Kasheff committed
416
#if 0
417
    int analyze(THD * thd, HA_CHECK_OPT * check_opt);
Zardosht Kasheff's avatar
Zardosht Kasheff committed
418
#endif
419 420 421 422
    int write_row(uchar * buf);
    int update_row(const uchar * old_data, uchar * new_data);
    int delete_row(const uchar * buf);

Zardosht Kasheff's avatar
Zardosht Kasheff committed
423 424
    void start_bulk_insert(ha_rows rows);
    int end_bulk_insert();
425
    int end_bulk_insert(bool abort);
Zardosht Kasheff's avatar
Zardosht Kasheff committed
426

Zardosht Kasheff's avatar
Zardosht Kasheff committed
427
    int prepare_index_scan();
Zardosht Kasheff's avatar
Zardosht Kasheff committed
428
    int prepare_index_key_scan( const uchar * key, uint key_len );
Zardosht Kasheff's avatar
Zardosht Kasheff committed
429
    int prepare_range_scan( const key_range *start_key, const key_range *end_key);
Zardosht Kasheff's avatar
Zardosht Kasheff committed
430
    void column_bitmaps_signal();
431 432
    int index_init(uint index, bool sorted);
    int index_end();
Zardosht Kasheff's avatar
Zardosht Kasheff committed
433
    int index_next_same(uchar * buf, const uchar * key, uint keylen); 
434 435 436 437 438 439 440 441 442 443 444 445
    int index_read(uchar * buf, const uchar * key, uint key_len, enum ha_rkey_function find_flag);
    int index_read_last(uchar * buf, const uchar * key, uint key_len);
    int index_next(uchar * buf);
    int index_prev(uchar * buf);
    int index_first(uchar * buf);
    int index_last(uchar * buf);

    int rnd_init(bool scan);
    int rnd_end();
    int rnd_next(uchar * buf);
    int rnd_pos(uchar * buf, uchar * pos);

Zardosht Kasheff's avatar
Zardosht Kasheff committed
446 447 448 449 450 451
    int read_range_first(const key_range *start_key,
                                 const key_range *end_key,
                                 bool eq_range, bool sorted);
    int read_range_next();


452 453 454 455 456 457 458 459 460
    void position(const uchar * record);
    int info(uint);
    int extra(enum ha_extra_function operation);
    int reset(void);
    int external_lock(THD * thd, int lock_type);
    int start_stmt(THD * thd, thr_lock_type lock_type);

    ha_rows records_in_range(uint inx, key_range * min_key, key_range * max_key);

461
    u_int32_t get_cursor_isolation_flags(enum thr_lock_type lock_type, THD* thd);
462 463
    THR_LOCK_DATA **store_lock(THD * thd, THR_LOCK_DATA ** to, enum thr_lock_type lock_type);

Zardosht Kasheff's avatar
Zardosht Kasheff committed
464
    int get_status();
Zardosht Kasheff's avatar
Zardosht Kasheff committed
465
    void init_hidden_prim_key_info();
466 467 468
    inline void get_auto_primary_key(uchar * to) {
        pthread_mutex_lock(&share->mutex);
        share->auto_ident++;
Zardosht Kasheff's avatar
Zardosht Kasheff committed
469
        hpk_num_to_char(to, share->auto_ident);
470 471 472
        pthread_mutex_unlock(&share->mutex);
    }
    virtual void get_auto_increment(ulonglong offset, ulonglong increment, ulonglong nb_desired_values, ulonglong * first_value, ulonglong * nb_reserved_values);
Zardosht Kasheff's avatar
Zardosht Kasheff committed
473
    bool is_auto_inc_singleton();
474 475 476 477 478 479 480
    void print_error(int error, myf errflag);
    uint8 table_cache_type() {
        return HA_CACHE_TBL_TRANSACT;
    }
    bool primary_key_is_clustered() {
        return true;
    }
Zardosht Kasheff's avatar
Zardosht Kasheff committed
481 482 483
    bool supports_clustered_keys() {
        return true;
    }
484 485 486
    int cmp_ref(const uchar * ref1, const uchar * ref2);
    bool check_if_incompatible_data(HA_CREATE_INFO * info, uint table_changes);

Zardosht Kasheff's avatar
Zardosht Kasheff committed
487 488 489 490
    int add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys);
    int prepare_drop_index(TABLE *table_arg, uint *key_num, uint num_of_keys);
    int final_drop_index(TABLE *table_arg);

491 492
    // delete all rows from the table
    // effect: all dictionaries, including the main and indexes, should be empty
493
    int discard_or_import_tablespace(my_bool discard);
494
    int delete_all_rows();
Zardosht Kasheff's avatar
Zardosht Kasheff committed
495 496
    void extract_hidden_primary_key(uint keynr, DBT const *found_key);
    void read_key_only(uchar * buf, uint keynr, DBT const *found_key);
497
    int read_row_callback (uchar * buf, uint keynr, DBT const *row, DBT const *found_key);
Zardosht Kasheff's avatar
Zardosht Kasheff committed
498 499
    int read_primary_key(uchar * buf, uint keynr, DBT const *row, DBT const *found_key);
    int unpack_blobs(
Zardosht Kasheff's avatar
Zardosht Kasheff committed
500 501
        uchar* record,
        const uchar* from_tokudb_blob,
502 503
        u_int32_t num_blob_bytes,
        bool check_bitmap
Zardosht Kasheff's avatar
Zardosht Kasheff committed
504
        );
Zardosht Kasheff's avatar
Zardosht Kasheff committed
505
    int unpack_row(
Zardosht Kasheff's avatar
Zardosht Kasheff committed
506 507 508 509 510
        uchar* record, 
        DBT const *row, 
        DBT const *key,
        uint index
        );
511

512 513 514 515
    int prefix_cmp_dbts( uint keynr, const DBT* first_key, const DBT* second_key) {
        return tokudb_prefix_cmp_dbt_key(share->key_file[keynr], first_key, second_key);
    }

516
    void track_progress(THD* thd);
517 518
    void set_loader_error(int err);
    void set_dup_value_for_pk(DBT* key);
519

Zardosht Kasheff's avatar
Zardosht Kasheff committed
520

Zardosht Kasheff's avatar
Zardosht Kasheff committed
521 522 523 524 525 526
    //
    // index into key_file that holds DB* that is indexed on
    // the primary_key. this->key_file[primary_index] == this->file
    //
    uint primary_key;

527
private:
Zardosht Kasheff's avatar
Zardosht Kasheff committed
528
    int read_full_row(uchar * buf);
529
    int __close(int mutex_is_locked);
530
    int read_last(uint keynr);
531
};
532

533 534 535 536 537 538 539 540 541 542 543 544
#if MYSQL_VERSION_ID >= 50506

static inline void my_free(void *p, int arg) {
    my_free(p);
}

static inline void *memcpy_fixed(void *a, const void *b, size_t n) {
    return memcpy(a, b, n);
}

#endif