25 #define IS_NDB_BLOB_PREFIX(A) is_prefix(A, "NDB$BLOB")
27 #include <ndbapi/NdbApi.hpp>
28 #include <ndbapi/ndbapi_limits.h>
29 #include <kernel/ndb_limits.h>
31 #define NDB_IGNORE_VALUE(x) (void)x
33 #define NDB_HIDDEN_PRIMARY_KEY_LENGTH 8
48 class NdbQueryOperationTypeWrapper;
52 typedef enum ndb_index_type {
54 PRIMARY_KEY_INDEX = 1,
55 PRIMARY_KEY_ORDERED_INDEX = 2,
57 UNIQUE_ORDERED_INDEX = 4,
61 typedef enum ndb_index_status {
69 NDB_INDEX_STATUS status;
72 unsigned char *unique_index_attrid_map;
73 bool null_in_unique_index;
85 typedef enum ndb_write_op {
103 {
delete new_table; }
108 Uint32 old_table_version;
114 uchar*& buffer, uint& buffer_size,
115 my_ptrdiff_t ptrdiff);
117 #include "ndb_share.h"
122 range(share->tuple_id_range) {
123 pthread_mutex_lock(&share->mutex);
126 pthread_mutex_unlock(&share->mutex);
133 #define NSF_HIDDEN_PK 1u
134 #define NSF_BLOB_FLAG 2u
135 #define NSF_NO_BINLOG 4u
136 #define NSF_BINLOG_FULL 8u
137 #define NSF_BINLOG_USE_UPDATE 16u
139 inline void set_binlog_logging(
NDB_SHARE *share)
141 DBUG_PRINT(
"info", (
"set_binlog_logging"));
142 share->flags&= ~NSF_NO_BINLOG;
144 inline void set_binlog_nologging(
NDB_SHARE *share)
146 DBUG_PRINT(
"info", (
"set_binlog_nologging"));
147 share->flags|= NSF_NO_BINLOG;
149 inline my_bool get_binlog_nologging(
NDB_SHARE *share)
150 {
return (share->flags & NSF_NO_BINLOG) != 0; }
151 inline void set_binlog_updated_only(
NDB_SHARE *share)
153 DBUG_PRINT(
"info", (
"set_binlog_updated_only"));
154 share->flags&= ~NSF_BINLOG_FULL;
156 inline void set_binlog_full(
NDB_SHARE *share)
158 DBUG_PRINT(
"info", (
"set_binlog_full"));
159 share->flags|= NSF_BINLOG_FULL;
161 inline my_bool get_binlog_full(
NDB_SHARE *share)
162 {
return (share->flags & NSF_BINLOG_FULL) != 0; }
163 inline void set_binlog_use_write(
NDB_SHARE *share)
165 DBUG_PRINT(
"info", (
"set_binlog_use_write"));
166 share->flags&= ~NSF_BINLOG_USE_UPDATE;
168 inline void set_binlog_use_update(
NDB_SHARE *share)
170 DBUG_PRINT(
"info", (
"set_binlog_use_update"));
171 share->flags|= NSF_BINLOG_USE_UPDATE;
173 inline my_bool get_binlog_use_update(
NDB_SHARE *share)
174 {
return (share->flags & NSF_BINLOG_USE_UPDATE) != 0; }
183 Uint32 current_conflict_defined_op_count;
184 Uint32 current_violation_count[CFT_NUMBER_OF_CFTS];
185 Uint64 current_master_server_epoch;
186 Uint64 current_max_rep_epoch;
189 Uint64 total_violation_count[CFT_NUMBER_OF_CFTS];
190 Uint64 max_rep_epoch;
194 void atTransactionCommit();
195 void atTransactionAbort();
198 void atApplyStatusWrite(Uint32 master_server_id,
199 Uint32 row_server_id,
201 bool is_row_server_id_local);
207 int no_uncommitted_rows_count;
212 #include "ndb_thd_ndb.h"
216 long cluster_node_id;
217 const char * connected_host;
219 long number_of_replicas;
220 long number_of_data_nodes;
221 long number_of_ready_data_nodes;
225 long pruned_scan_count;
226 long schema_locks_count;
227 long sorted_scan_count;
228 long pushed_queries_defined;
229 long pushed_queries_dropped;
230 long pushed_queries_executed;
232 long transaction_no_hint_count[MAX_NDB_NODES];
233 long transaction_hint_count[MAX_NDB_NODES];
234 long long api_client_stats[Ndb::NumClientStatistics];
237 int ndbcluster_commit(
handlerton *hton, THD *thd,
bool all);
246 int open(
const char *
name,
int mode, uint test_if_locked);
248 void local_close(THD *thd,
bool release_metadata);
252 int analyze_index(THD* thd);
254 int write_row(uchar *
buf);
255 int update_row(
const uchar *old_data, uchar *new_data);
256 int delete_row(
const uchar *buf);
257 int index_init(uint
index,
bool sorted);
260 key_part_map keypart_map,
261 enum ha_rkey_function find_flag);
262 int index_read(uchar *buf,
const uchar *key, uint key_len,
263 enum ha_rkey_function find_flag);
268 int index_read_last(uchar * buf,
const uchar * key, uint key_len);
272 int rnd_pos(uchar *buf, uchar *pos);
273 void position(
const uchar *
record);
275 virtual int cmp_ref(
const uchar * ref1,
const uchar * ref2);
278 bool eq_range,
bool sorted);
279 int read_range_first_to_buf(
const key_range *start_key,
281 bool eq_range,
bool sorted,
285 #ifndef NDB_WITH_NEW_MRR_INTERFACE
301 {
return HA_POS_ERROR; }
303 #if MYSQL_VERSION_ID < 50501
306 void get_dynamic_partition_info(
PARTITION_STATS *stat_info, uint part_id);
307 uint32 calculate_key_hash_value(
Field **field_array);
310 int extra(
enum ha_extra_function operation);
311 int extra_opt(
enum ha_extra_function operation, ulong cache_size);
313 int external_lock(THD *thd,
int lock_type);
315 int start_stmt(THD *thd, thr_lock_type lock_type);
320 ulonglong table_flags(
void)
const;
322 ulong index_flags(uint idx, uint part,
bool all_parts)
const;
323 virtual const key_map *keys_to_use_for_scanning() {
return &btree_keys; }
324 bool primary_key_is_clustered();
325 uint max_supported_record_length()
const;
326 uint max_supported_keys()
const;
327 uint max_supported_key_parts()
const;
328 uint max_supported_key_length()
const;
329 uint max_supported_key_part_length()
const;
340 error == HA_ERR_NO_PARTITION_FOUND)
347 enum thr_lock_type lock_type);
349 bool low_byte_first()
const;
351 const char* index_type(uint key_number);
355 void start_bulk_insert(ha_rows rows);
356 int end_bulk_insert();
360 uint *dup_key_found);
363 int ndb_update_row(
const uchar *old_data, uchar *new_data,
366 static void set_dbname(
const char *pathname,
char *dbname);
367 static void set_tabname(
const char *pathname,
char *tabname);
414 bool maybe_pushable_join(
const char*& reason)
const;
421 int index_read_pushed(uchar *buf,
const uchar *key,
422 key_part_map keypart_map);
424 int index_next_pushed(uchar * buf);
435 qc_engine_callback *engine_callback,
436 ulonglong *engine_data);
438 #ifndef NDB_WITHOUT_ONLINE_ALTER
439 int check_if_supported_alter(
TABLE *altered_table,
442 HA_ALTER_FLAGS *alter_flags,
445 int alter_table_phase1(THD *thd,
446 TABLE *altered_table,
448 HA_ALTER_INFO *alter_info,
449 HA_ALTER_FLAGS *alter_flags);
451 int alter_table_phase2(THD *thd,
452 TABLE *altered_table,
454 HA_ALTER_INFO *alter_info,
455 HA_ALTER_FLAGS *alter_flags);
457 int alter_table_phase3(THD *thd,
TABLE *table,
459 HA_ALTER_INFO *alter_info,
460 HA_ALTER_FLAGS *alter_flags);
464 #ifdef HAVE_NDB_BINLOG
465 int prepare_conflict_detection(enum_conflicting_op_type op_type,
467 const uchar* old_data,
468 const uchar* new_data,
472 void setup_key_ref_for_ndb_record(
const NdbRecord **key_rec,
473 const uchar **key_row,
475 bool use_active_index);
476 friend int ndbcluster_drop_database_impl(THD *thd,
const char *path);
477 friend int ndb_handle_schema_change(THD *thd,
481 void check_read_before_write_removal();
487 int add_index_impl(THD *thd,
TABLE *table_arg,
488 KEY *key_info, uint num_of_keys);
489 int create_ndb_index(THD *thd,
const char *name,
KEY *key_info,
bool unique);
490 int create_ordered_index(THD *thd,
const char *name,
KEY *key_info);
491 int create_unique_index(THD *thd,
const char *name,
KEY *key_info);
492 int create_index(THD *thd,
const char *name,
KEY *key_info,
493 NDB_INDEX_TYPE idx_type, uint idx_no);
495 int create_indexes(THD *thd,
Ndb *ndb,
TABLE *tab);
496 int open_indexes(THD *thd,
Ndb *ndb,
TABLE *tab,
bool ignore_error);
497 void renumber_indexes(
Ndb *ndb,
TABLE *tab);
498 int drop_indexes(
Ndb *ndb,
TABLE *tab);
500 KEY *key_info,
const char *key_name, uint index_no);
504 KEY *key_info, uint index_no);
506 int get_metadata(THD *thd,
const char* path);
507 void release_metadata(THD *thd,
Ndb *ndb);
508 NDB_INDEX_TYPE get_index_type(uint idx_no)
const;
509 NDB_INDEX_TYPE get_index_type_from_table(uint index_no)
const;
510 NDB_INDEX_TYPE get_index_type_from_key(uint index_no,
KEY *key_info,
512 bool has_null_in_unique_index(uint idx_no)
const;
513 bool check_index_fields_not_null(
KEY *key_info);
515 bool check_if_pushable(
int type,
517 bool rootSorted=
false)
const;
518 bool check_is_pushed()
const;
528 int ndb_pk_update_row(THD *thd,
529 const uchar *old_data, uchar *new_data,
531 int pk_read(
const uchar *key, uint key_len, uchar *buf, uint32 *part_id);
532 int ordered_index_scan(
const key_range *start_key,
534 bool sorted,
bool descending, uchar* buf,
536 int unique_index_read(
const uchar *key, uint key_len,
538 int full_table_scan(
const KEY* key_info,
542 int flush_bulk_insert(
bool allow_batch= FALSE);
543 int ndb_write_row(uchar *record,
bool primary_key_update,
544 bool batched_update);
546 bool start_bulk_delete();
547 int end_bulk_delete();
548 int ndb_delete_row(
const uchar *record,
bool primary_key_update);
550 int ndb_optimize_table(THD* thd, uint delay);
552 #ifndef NDB_WITHOUT_ONLINE_ALTER
560 int peek_indexed_rows(
const uchar *record, NDB_WRITE_OP write_op);
563 int fetch_next_pushed();
564 int set_auto_inc(THD *thd,
Field *field);
565 int set_auto_inc_val(THD *thd, Uint64 value);
566 int next_result(uchar *buf);
568 void unpack_record(uchar *dst_row,
const uchar *src_row);
570 void set_dbname(
const char *pathname);
571 void set_tabname(
const char *pathname);
574 return m_table->
getColumn(table_share->fields);
577 Uint32 index= table_share->fields + (table_share->primary_key == MAX_KEY);
581 bool add_row_check_if_batch_full_size(
Thd_ndb *thd_ndb, uint
size);
582 bool add_row_check_if_batch_full(
Thd_ndb *thd_ndb) {
583 return add_row_check_if_batch_full_size(thd_ndb, m_bytes_per_write);
586 uchar *copy_row_to_buffer(
Thd_ndb *thd_ndb,
const uchar *record);
588 int get_blob_values(
const NdbOperation *ndb_op, uchar *dst_record,
590 int set_blob_values(
const NdbOperation *ndb_op, my_ptrdiff_t row_offset,
591 const MY_BITMAP *bitmap, uint *set_count,
bool batch);
592 friend int g_get_ndb_blobs_value(
NdbBlob *ndb_blob,
void *arg);
593 void release_blobs_buffer();
599 void eventSetAnyValue(THD *thd,
601 bool check_index_fields_in_write_set(uint keyno);
604 const uchar *key, uchar *buf,
606 Uint32 *ppartition_id);
607 int pk_unique_index_read_key_pushed(uint idx,
609 Uint32 *ppartition_id);
611 int read_multi_range_fetch_next();
613 int primary_key_cmp(
const uchar * old_row,
const uchar * new_row);
614 void print_results();
616 virtual void get_auto_increment(ulonglong
offset, ulonglong increment,
617 ulonglong nb_desired_values,
618 ulonglong *first_value,
619 ulonglong *nb_reserved_values);
620 bool uses_blob_value(
const MY_BITMAP *bitmap)
const;
622 static inline bool isManualBinlogExec(THD *thd);
624 char *update_table_comment(
const char * comment);
626 int write_ndb_file(
const char *name);
628 int check_ndb_connection(THD* thd);
630 void set_rec_per_key();
631 int records_update();
632 void no_uncommitted_rows_execute_failure();
633 void no_uncommitted_rows_update(
int);
634 void no_uncommitted_rows_reset(THD *);
637 int ndb_index_stat_query(uint inx,
642 int ndb_index_stat_get_rir(uint inx,
646 int ndb_index_stat_set_rpk(uint inx);
647 int ndb_index_stat_analyze(
Ndb *ndb,
651 NdbTransaction *start_transaction_part_id(uint32 part_id,
int &error);
652 inline NdbTransaction *get_transaction_part_id(uint32 part_id,
int &error)
654 if (m_thd_ndb->trans)
655 return m_thd_ndb->trans;
656 return start_transaction_part_id(part_id, error);
662 if (m_thd_ndb->trans)
663 return m_thd_ndb->trans;
664 return start_transaction(error);
671 const uchar *key_data,
674 friend int check_completed_operations_pre_commit(
Thd_ndb*,
678 friend int ndbcluster_commit(
handlerton *hton, THD *thd,
bool all);
679 int start_statement(THD *thd,
Thd_ndb *thd_ndb, uint table_count);
680 int init_handler_for_statement(THD *thd);
695 my_bitmap_map m_bitmap_buf[(NDB_MAX_ATTRIBUTES_IN_TABLE +
696 8*
sizeof(my_bitmap_map) - 1) /
697 (8*
sizeof(my_bitmap_map))];
700 my_bitmap_map m_pk_bitmap_buf[(NDB_MAX_ATTRIBUTES_IN_TABLE +
701 8*
sizeof(my_bitmap_map) - 1) /
702 (8*
sizeof(my_bitmap_map))];
705 char m_dbname[FN_HEADLEN];
707 char m_tabname[FN_HEADLEN];
719 const char *_m_next_row;
720 const uchar *m_next_row;
723 int m_current_range_no;
727 NdbValue m_value[NDB_MAX_ATTRIBUTES_IN_TABLE];
731 bool m_user_defined_partitioning;
732 bool m_use_partition_pruning;
735 bool m_ignore_dup_key;
736 bool m_has_unique_index;
737 bool m_ignore_no_key;
738 bool m_read_before_write_removal_possible;
739 bool m_read_before_write_removal_used;
740 ha_rows m_rows_updated;
741 ha_rows m_rows_deleted;
742 ha_rows m_rows_to_insert;
743 ha_rows m_rows_inserted;
744 ha_rows m_rows_changed;
745 bool m_delete_cannot_batch;
746 bool m_update_cannot_batch;
747 uint m_bytes_per_write;
748 bool m_skip_auto_increment;
749 bool m_blobs_pending;
751 bool m_is_bulk_delete;
755 uint m_blob_expected_count_per_row;
756 uchar *m_blob_destination_record;
757 Uint64 m_blobs_row_total_size;
760 uchar *m_blobs_buffer;
761 Uint64 m_blobs_buffer_size;
764 ha_rows m_autoincrement_prefetch;
768 *m_pushed_join_member;
769 int m_pushed_join_operation;
770 static const int PUSHED_ROOT= 0;
772 bool m_disable_pushed_join;
777 bool m_disable_multi_read;
778 const uchar *m_multi_range_result_ptr;
787 Ndb *get_ndb(THD *thd);
789 int update_stats(THD *thd,
bool do_read_stat,
bool have_lock= FALSE,
790 uint part_id= ~(uint)0);
794 int ndbcluster_discover(THD* thd,
const char* dbname,
const char* name,
795 const void** frmblob, uint* frmlen);
796 int ndbcluster_table_exists_in_engine(THD* thd,
797 const char *db,
const char *name);
798 void ndbcluster_print_error(
int error,
const NdbOperation *error_op);
800 static const char ndbcluster_hton_name[]=
"ndbcluster";
801 static const int ndbcluster_hton_name_length=
sizeof(ndbcluster_hton_name)-1;
802 extern int ndbcluster_terminating;
803 extern int ndb_util_thread_running;
804 extern pthread_cond_t COND_ndb_util_ready;
805 extern int ndb_index_stat_thread_running;
806 extern pthread_cond_t COND_ndb_index_stat_ready;