605
605
* stmt.modified_non_trans_table is used to keep track of
606
606
modified non-transactional tables of top-level statements. At
607
607
the end of the previous statement and at the beginning of the session,
608
it is reset to FALSE. If such functions
608
it is reset to false. If such functions
609
609
as mysql_insert, mysql_update, mysql_delete etc modify a
610
non-transactional table, they set this flag to TRUE. At the
610
non-transactional table, they set this flag to true. At the
611
611
end of the statement, the value of stmt.modified_non_trans_table
612
612
is merged with all.modified_non_trans_table and gets reset.
613
613
* all.modified_non_trans_table is reset at the end of transaction
618
618
At entrance into a sub-statement, a copy of the value of
619
619
stmt.modified_non_trans_table (containing the changes of the
620
620
outer statement) is saved on stack. Then
621
stmt.modified_non_trans_table is reset to FALSE and the
621
stmt.modified_non_trans_table is reset to false and the
622
622
substatement is executed. Then the new value is merged with the
625
625
bool modified_non_trans_table;
627
void reset() { no_2pc= FALSE; modified_non_trans_table= FALSE; }
627
void reset() { no_2pc= false; modified_non_trans_table= false; }
651
651
/** Register this storage engine in the given transaction context. */
652
652
void register_ha(THD_TRANS *trans, handlerton *ht_arg)
654
DBUG_ASSERT(m_flags == 0);
655
DBUG_ASSERT(m_ht == NULL);
656
DBUG_ASSERT(m_next == NULL);
654
assert(m_flags == 0);
655
assert(m_ht == NULL);
656
assert(m_next == NULL);
659
659
m_flags= (int) TRX_READ_ONLY; /* Assume read-only at start. */
675
675
void set_trx_read_write()
677
DBUG_ASSERT(is_started());
677
assert(is_started());
678
678
m_flags|= (int) TRX_READ_WRITE;
680
680
bool is_trx_read_write() const
682
DBUG_ASSERT(is_started());
682
assert(is_started());
683
683
return m_flags & (int) TRX_READ_WRITE;
685
685
bool is_started() const { return m_ht != NULL; }
691
691
Can be called many times, e.g. when we have many
692
692
read-write statements in a transaction.
694
DBUG_ASSERT(is_started());
694
assert(is_started());
695
695
if (stmt_trx->is_trx_read_write())
696
696
set_trx_read_write();
698
698
Ha_trx_info *next() const
700
DBUG_ASSERT(is_started());
700
assert(is_started());
703
703
handlerton *ht() const
705
DBUG_ASSERT(is_started());
705
assert(is_started());
1141
1141
RANGE_SEQ_IF mrr_funcs; /* Range sequence traversal functions */
1142
1142
HANDLER_BUFFER *multi_range_buffer; /* MRR buffer info */
1143
1143
uint ranges_in_seq; /* Total number of ranges in the traversed sequence */
1144
/* TRUE <=> source MRR ranges and the output are ordered */
1144
/* true <=> source MRR ranges and the output are ordered */
1145
1145
bool mrr_is_output_sorted;
1147
/** TRUE <=> we're currently traversing a range in mrr_cur_range. */
1147
/** true <=> we're currently traversing a range in mrr_cur_range. */
1148
1148
bool mrr_have_range;
1149
1149
/** Current range (the one we're now returning rows from) */
1150
1150
KEY_MULTI_RANGE mrr_cur_range;
1155
1155
int key_compare_result_on_equal;
1158
TRUE <=> the engine guarantees that returned records are within the range
1158
true <=> the engine guarantees that returned records are within the range
1161
1161
bool in_range_check_pushed_down;
1200
1200
handler(handlerton *ht_arg, TABLE_SHARE *share_arg)
1201
1201
:table_share(share_arg), table(0),
1202
1202
estimation_rows_to_insert(0), ht(ht_arg),
1203
ref(0), in_range_check_pushed_down(FALSE),
1203
ref(0), in_range_check_pushed_down(false),
1204
1204
key_used_on_scan(MAX_KEY), active_index(MAX_KEY),
1205
1205
ref_length(sizeof(my_off_t)),
1206
1206
ft_handler(0), inited(NONE),
1207
locked(FALSE), implicit_emptied(0),
1207
locked(false), implicit_emptied(0),
1208
1208
pushed_cond(0), pushed_idx_cond(NULL), pushed_idx_cond_keyno(MAX_KEY),
1209
1209
next_insert_id(0), insert_id_for_cur_row(0)
1211
1211
virtual ~handler(void)
1213
DBUG_ASSERT(locked == FALSE);
1214
/* TODO: DBUG_ASSERT(inited == NONE); */
1213
assert(locked == false);
1214
/* TODO: assert(inited == NONE); */
1216
1216
virtual handler *clone(MEM_ROOT *mem_root);
1217
1217
/** This is called after create to allow us to set up cached variables */
1225
1225
int ha_index_init(uint idx, bool sorted)
1228
DBUG_ENTER("ha_index_init");
1229
DBUG_ASSERT(inited==NONE);
1228
assert(inited==NONE);
1230
1229
if (!(result= index_init(idx, sorted)))
1232
1231
end_range= NULL;
1233
DBUG_RETURN(result);
1235
1234
int ha_index_end()
1237
DBUG_ENTER("ha_index_end");
1238
DBUG_ASSERT(inited==INDEX);
1236
assert(inited==INDEX);
1240
1238
end_range= NULL;
1241
DBUG_RETURN(index_end());
1239
return(index_end());
1243
1241
int ha_rnd_init(bool scan)
1246
DBUG_ENTER("ha_rnd_init");
1247
DBUG_ASSERT(inited==NONE || (inited==RND && scan));
1244
assert(inited==NONE || (inited==RND && scan));
1248
1245
inited= (result= rnd_init(scan)) ? NONE: RND;
1249
DBUG_RETURN(result);
1251
1248
int ha_rnd_end()
1253
DBUG_ENTER("ha_rnd_end");
1254
DBUG_ASSERT(inited==RND);
1250
assert(inited==RND);
1256
DBUG_RETURN(rnd_end());
1258
1254
int ha_reset();
1259
1255
/* this is necessary in many places, e.g. in HANDLER command */
1527
1523
virtual void position(const uchar *record)=0;
1528
1524
virtual int info(uint)=0; // see my_base.h for full description
1529
1525
virtual uint32 calculate_key_hash_value(Field **field_array __attribute__((__unused__)))
1530
{ DBUG_ASSERT(0); return 0; }
1526
{ assert(0); return 0; }
1531
1527
virtual int extra(enum ha_extra_function operation __attribute__((__unused__)))
1533
1529
virtual int extra_opt(enum ha_extra_function operation,
1564
1560
uint64_t *nb_reserved_values);
1565
1561
void set_next_insert_id(uint64_t id)
1567
DBUG_PRINT("info",("auto_increment: next value %lu", (uint32_t)id));
1568
1563
next_insert_id= id;
1570
1565
void restore_auto_increment(uint64_t prev_insert_id)
1603
1598
@param index Index to check if foreign key uses it
1605
@retval TRUE Foreign key defined on table or index
1606
@retval FALSE No foreign key defined
1600
@retval true Foreign key defined on table or index
1601
@retval false No foreign key defined
1608
1603
virtual bool is_fk_defined_on_table_or_index(uint index __attribute__((__unused__)))
1610
1605
virtual char* get_foreign_key_create_info(void)
1611
1606
{ return(NULL);} /* gets foreign key create string from InnoDB */
1612
1607
/** used in ALTER TABLE; 1 if changing storage engine is allowed */
1732
1727
@note If engine_data supplied with this function is different from
1733
1728
engine_data supplied with the callback function, and the callback returns
1734
FALSE, a table invalidation on the current table will occur.
1729
false, a table invalidation on the current table will occur.
1736
1731
@return Upon success the engine_callback will point to the storage engine
1737
1732
call back function, if any, and engine_data will point to any storage
1738
1733
engine data used in the specific implementation.
1739
@retval TRUE Success
1740
@retval FALSE The specified table or current statement should not be
1734
@retval true Success
1735
@retval false The specified table or current statement should not be
1749
1744
uint64_t *engine_data __attribute__((__unused__)))
1751
1746
*engine_callback= 0;
1757
@retval TRUE Primary key (if there is one) is clustered
1752
@retval true Primary key (if there is one) is clustered
1758
1753
key covering all fields
1759
@retval FALSE otherwise
1754
@retval false otherwise
1761
virtual bool primary_key_is_clustered() { return FALSE; }
1756
virtual bool primary_key_is_clustered() { return false; }
1762
1757
virtual int cmp_ref(const uchar *ref1, const uchar *ref2)
1764
1759
return memcmp(ref1, ref2, ref_length);
1843
1838
HA_ALTER_FLAGS *alter_flags __attribute__((__unused__)),
1844
1839
uint table_changes)
1846
DBUG_ENTER("check_if_supported_alter");
1847
1841
if (this->check_if_incompatible_data(create_info, table_changes)
1848
1842
== COMPATIBLE_DATA_NO)
1849
DBUG_RETURN(HA_ALTER_NOT_SUPPORTED);
1843
return(HA_ALTER_NOT_SUPPORTED);
1851
DBUG_RETURN(HA_ALTER_SUPPORTED_WAIT_LOCK);
1845
return(HA_ALTER_SUPPORTED_WAIT_LOCK);
1854
1848
Tell storage engine to prepare for the on-line alter table (pre-alter)
2113
2107
HA_CHECK_OPT* check_opt __attribute__((__unused__)))
2114
2108
{ return HA_ADMIN_NOT_IMPLEMENTED; }
2115
2109
virtual bool check_and_repair(THD *thd __attribute__((__unused__)))
2117
2111
virtual int disable_indexes(uint mode __attribute__((__unused__)))
2118
2112
{ return HA_ERR_WRONG_COMMAND; }
2119
2113
virtual int enable_indexes(uint mode __attribute__((__unused__)))
2168
2162
uchar *rowids_buf_last; /* When reading: end of used buffer space */
2169
2163
uchar *rowids_buf_end; /* End of the buffer */
2171
bool dsmrr_eof; /* TRUE <=> We have reached EOF when reading index tuples */
2165
bool dsmrr_eof; /* true <=> We have reached EOF when reading index tuples */
2173
/* TRUE <=> need range association, buffer holds {rowid, range_id} pairs */
2167
/* true <=> need range association, buffer holds {rowid, range_id} pairs */
2174
2168
bool is_mrr_assoc;
2176
bool use_default_impl; /* TRUE <=> shortcut all calls to default MRR impl */
2170
bool use_default_impl; /* true <=> shortcut all calls to default MRR impl */
2178
2172
void init(handler *h_arg, TABLE *table_arg)
2209
2203
extern uint32_t total_ha, total_ha_2pc;
2211
2205
/* Wrapper functions */
2212
#define ha_commit(thd) (ha_commit_trans((thd), TRUE))
2213
#define ha_rollback(thd) (ha_rollback_trans((thd), TRUE))
2206
#define ha_commit(thd) (ha_commit_trans((thd), true))
2207
#define ha_rollback(thd) (ha_rollback_trans((thd), true))
2216
2210
handlerton *ha_default_handlerton(THD *thd);
2236
2230
static inline bool ha_check_storage_engine_flag(const handlerton *db_type, uint32 flag)
2238
return db_type == NULL ? FALSE : test(db_type->flags & flag);
2232
return db_type == NULL ? false : test(db_type->flags & flag);
2241
2235
static inline bool ha_storage_engine_is_enabled(const handlerton *db_type)
2243
2237
return (db_type && db_type->create) ?
2244
(db_type->state == SHOW_OPTION_YES) : FALSE;
2238
(db_type->state == SHOW_OPTION_YES) : false;
2247
2241
/* basic stuff */