MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ha_ndbcluster.h
1 /*
2  Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 /*
19  This file defines the NDB Cluster handler: the interface between MySQL and
20  NDB Cluster
21 */
22 
23 
24 /* Blob tables and events are internal to NDB and must never be accessed */
25 #define IS_NDB_BLOB_PREFIX(A) is_prefix(A, "NDB$BLOB")
26 
27 #include <ndbapi/NdbApi.hpp>
28 #include <ndbapi/ndbapi_limits.h>
29 #include <kernel/ndb_limits.h>
30 
31 #define NDB_IGNORE_VALUE(x) (void)x
32 
33 #define NDB_HIDDEN_PRIMARY_KEY_LENGTH 8
34 
35 class Ndb; // Forward declaration
36 class NdbOperation; // Forward declaration
37 class NdbTransaction; // Forward declaration
38 class NdbRecAttr; // Forward declaration
39 class NdbScanOperation;
41 class NdbBlob;
42 class NdbIndexStat;
43 class NdbEventOperation;
44 class ha_ndbcluster_cond;
45 class Ndb_event_data;
46 class NdbQuery;
47 class NdbQueryOperation;
48 class NdbQueryOperationTypeWrapper;
49 class NdbQueryParamValue;
50 class ndb_pushed_join;
51 
52 typedef enum ndb_index_type {
53  UNDEFINED_INDEX = 0,
54  PRIMARY_KEY_INDEX = 1,
55  PRIMARY_KEY_ORDERED_INDEX = 2,
56  UNIQUE_INDEX = 3,
57  UNIQUE_ORDERED_INDEX = 4,
58  ORDERED_INDEX = 5
59 } NDB_INDEX_TYPE;
60 
61 typedef enum ndb_index_status {
62  UNDEFINED = 0,
63  ACTIVE = 1,
64  TO_BE_DROPPED = 2
65 } NDB_INDEX_STATUS;
66 
67 typedef struct ndb_index_data {
68  NDB_INDEX_TYPE type;
69  NDB_INDEX_STATUS status;
70  const NdbDictionary::Index *index;
71  const NdbDictionary::Index *unique_index;
72  unsigned char *unique_index_attrid_map;
73  bool null_in_unique_index;
74  /*
75  In mysqld, keys and rows are stored differently (using KEY_PART_INFO for
76  keys and Field for rows).
77  So we need to use different NdbRecord for an index for passing values
78  from a key and from a row.
79  */
80  NdbRecord *ndb_record_key;
81  NdbRecord *ndb_unique_record_key;
82  NdbRecord *ndb_unique_record_row;
84 
85 typedef enum ndb_write_op {
86  NDB_INSERT = 0,
87  NDB_UPDATE = 1,
88  NDB_PK_UPDATE = 2
89 } NDB_WRITE_OP;
90 
91 class NDB_ALTER_DATA : public Sql_alloc
92 {
93 public:
95  const NdbDictionary::Table *table) :
96  dictionary(dict),
97  old_table(table),
98  new_table(new NdbDictionary::Table(*table)),
99  table_id(table->getObjectId()),
100  old_table_version(table->getObjectVersion())
101  {}
102  ~NDB_ALTER_DATA()
103  { delete new_table; }
104  NdbDictionary::Dictionary *dictionary;
105  const NdbDictionary::Table *old_table;
106  NdbDictionary::Table *new_table;
107  Uint32 table_id;
108  Uint32 old_table_version;
109 };
110 
111 typedef union { const NdbRecAttr *rec; NdbBlob *blob; void *ptr; } NdbValue;
112 
113 int get_ndb_blobs_value(TABLE* table, NdbValue* value_array,
114  uchar*& buffer, uint& buffer_size,
115  my_ptrdiff_t ptrdiff);
116 
117 #include "ndb_share.h"
118 
121  share(_share),
122  range(share->tuple_id_range) {
123  pthread_mutex_lock(&share->mutex);
124  }
126  pthread_mutex_unlock(&share->mutex);
127  }
128  NDB_SHARE* share;
129  Ndb::TupleIdRange& range;
130 };
131 
132 /* NDB_SHARE.flags */
133 #define NSF_HIDDEN_PK 1u /* table has hidden primary key */
134 #define NSF_BLOB_FLAG 2u /* table has blob attributes */
135 #define NSF_NO_BINLOG 4u /* table should not be binlogged */
136 #define NSF_BINLOG_FULL 8u /* table should be binlogged with full rows */
137 #define NSF_BINLOG_USE_UPDATE 16u /* table update should be binlogged using
138  update log event */
139 inline void set_binlog_logging(NDB_SHARE *share)
140 {
141  DBUG_PRINT("info", ("set_binlog_logging"));
142  share->flags&= ~NSF_NO_BINLOG;
143 }
144 inline void set_binlog_nologging(NDB_SHARE *share)
145 {
146  DBUG_PRINT("info", ("set_binlog_nologging"));
147  share->flags|= NSF_NO_BINLOG;
148 }
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)
152 {
153  DBUG_PRINT("info", ("set_binlog_updated_only"));
154  share->flags&= ~NSF_BINLOG_FULL;
155 }
156 inline void set_binlog_full(NDB_SHARE *share)
157 {
158  DBUG_PRINT("info", ("set_binlog_full"));
159  share->flags|= NSF_BINLOG_FULL;
160 }
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)
164 {
165  DBUG_PRINT("info", ("set_binlog_use_write"));
166  share->flags&= ~NSF_BINLOG_USE_UPDATE;
167 }
168 inline void set_binlog_use_update(NDB_SHARE *share)
169 {
170  DBUG_PRINT("info", ("set_binlog_use_update"));
171  share->flags|= NSF_BINLOG_USE_UPDATE;
172 }
173 inline my_bool get_binlog_use_update(NDB_SHARE *share)
174 { return (share->flags & NSF_BINLOG_USE_UPDATE) != 0; }
175 
176 /*
177  State associated with the Slave thread
178  (From the Ndb handler's point of view)
179 */
180 struct st_ndb_slave_state
181 {
182  /* Counter values for current slave transaction */
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;
187 
188  /* Cumulative counter values */
189  Uint64 total_violation_count[CFT_NUMBER_OF_CFTS];
190  Uint64 max_rep_epoch;
191  Uint32 sql_run_id;
192 
193  /* Methods */
194  void atTransactionCommit();
195  void atTransactionAbort();
196  void atResetSlave();
197 
198  void atApplyStatusWrite(Uint32 master_server_id,
199  Uint32 row_server_id,
200  Uint64 row_epoch,
201  bool is_row_server_id_local);
202 
204 };
207  int no_uncommitted_rows_count;
208  ulong last_count;
209  ha_rows records;
210 };
211 
212 #include "ndb_thd_ndb.h"
213 
215  st_ndb_status() { memset(this, 0, sizeof(struct st_ndb_status)); }
216  long cluster_node_id;
217  const char * connected_host;
218  long connected_port;
219  long number_of_replicas;
220  long number_of_data_nodes;
221  long number_of_ready_data_nodes;
222  long connect_count;
223  long execute_count;
224  long scan_count;
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;
231  long pushed_reads;
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];
235 };
236 
237 int ndbcluster_commit(handlerton *hton, THD *thd, bool all);
238 class ha_ndbcluster: public handler
239 {
240  friend class ndb_pushed_builder_ctx;
241 
242  public:
244  ~ha_ndbcluster();
245 
246  int open(const char *name, int mode, uint test_if_locked);
247  int close(void);
248  void local_close(THD *thd, bool release_metadata);
249 
250  int optimize(THD* thd, HA_CHECK_OPT* check_opt);
251  int analyze(THD* thd, HA_CHECK_OPT* check_opt);
252  int analyze_index(THD* thd);
253 
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);
258  int index_end();
259  int index_read_idx_map(uchar *buf, uint index, const uchar *key,
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);
264  int index_next(uchar *buf);
265  int index_prev(uchar *buf);
266  int index_first(uchar *buf);
267  int index_last(uchar *buf);
268  int index_read_last(uchar * buf, const uchar * key, uint key_len);
269  int rnd_init(bool scan);
270  int rnd_end();
271  int rnd_next(uchar *buf);
272  int rnd_pos(uchar *buf, uchar *pos);
273  void position(const uchar *record);
274  int read_first_row(uchar *buf, uint primary_key);
275  virtual int cmp_ref(const uchar * ref1, const uchar * ref2);
276  int read_range_first(const key_range *start_key,
277  const key_range *end_key,
278  bool eq_range, bool sorted);
279  int read_range_first_to_buf(const key_range *start_key,
280  const key_range *end_key,
281  bool eq_range, bool sorted,
282  uchar* buf);
283  int read_range_next();
284 
285 #ifndef NDB_WITH_NEW_MRR_INTERFACE
286 
289  int read_multi_range_first(KEY_MULTI_RANGE **found_range_p,
290  KEY_MULTI_RANGE*ranges, uint range_count,
291  bool sorted, HANDLER_BUFFER *buffer);
292  int read_multi_range_next(KEY_MULTI_RANGE **found_range_p);
293  bool null_value_index_search(KEY_MULTI_RANGE *ranges,
294  KEY_MULTI_RANGE *end_range,
295  HANDLER_BUFFER *buffer);
296 #endif
297 
298  bool get_error_message(int error, String *buf);
299  ha_rows records();
301  { return HA_POS_ERROR; }
302  int info(uint);
303 #if MYSQL_VERSION_ID < 50501
304  typedef PARTITION_INFO PARTITION_STATS;
305 #endif
306  void get_dynamic_partition_info(PARTITION_STATS *stat_info, uint part_id);
307  uint32 calculate_key_hash_value(Field **field_array);
308  bool start_read_removal(void);
309  ha_rows end_read_removal(void);
310  int extra(enum ha_extra_function operation);
311  int extra_opt(enum ha_extra_function operation, ulong cache_size);
312  int reset();
313  int external_lock(THD *thd, int lock_type);
314  void unlock_row();
315  int start_stmt(THD *thd, thr_lock_type lock_type);
316  void update_create_info(HA_CREATE_INFO *create_info);
317  void print_error(int error, myf errflag);
318  const char * table_type() const;
319  const char ** bas_ext() const;
320  ulonglong table_flags(void) const;
321  void set_part_info(partition_info *part_info, bool early);
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;
330 
331  int rename_table(const char *from, const char *to);
332  int delete_table(const char *name);
333  int create(const char *name, TABLE *form, HA_CREATE_INFO *info);
334  int get_default_no_partitions(HA_CREATE_INFO *info);
335  bool get_no_parts(const char *name, uint *no_parts);
336  void set_auto_partitions(partition_info *part_info);
337  virtual bool is_fatal_error(int error, uint flags)
338  {
339  if (!handler::is_fatal_error(error, flags) ||
340  error == HA_ERR_NO_PARTITION_FOUND)
341  return FALSE;
342  return TRUE;
343  }
344 
345  THR_LOCK_DATA **store_lock(THD *thd,
346  THR_LOCK_DATA **to,
347  enum thr_lock_type lock_type);
348 
349  bool low_byte_first() const;
350 
351  const char* index_type(uint key_number);
352 
353  double scan_time();
354  ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key);
355  void start_bulk_insert(ha_rows rows);
356  int end_bulk_insert();
357 
358  bool start_bulk_update();
359  int bulk_update_row(const uchar *old_data, uchar *new_data,
360  uint *dup_key_found);
361  int exec_bulk_update(uint *dup_key_found);
362  void end_bulk_update();
363  int ndb_update_row(const uchar *old_data, uchar *new_data,
364  int is_bulk_update);
365 
366 static void set_dbname(const char *pathname, char *dbname);
367 static void set_tabname(const char *pathname, char *tabname);
368 
369  /*
370  static member function as it needs to access private
371  NdbTransaction methods
372  */
373  static void release_completed_operations(NdbTransaction*);
374 
375  /*
376  Condition pushdown
377  */
378 
379  /*
380  Push condition down to the table handler.
381  SYNOPSIS
382  cond_push()
383  cond Condition to be pushed. The condition tree must not be
384  modified by the by the caller.
385  RETURN
386  The 'remainder' condition that caller must use to filter out records.
387  NULL means the handler will not return rows that do not match the
388  passed condition.
389  NOTES
390  The pushed conditions form a stack (from which one can remove the
391  last pushed condition using cond_pop).
392  The table handler filters out rows using (pushed_cond1 AND pushed_cond2
393  AND ... AND pushed_condN)
394  or less restrictive condition, depending on handler's capabilities.
395 
396  handler->reset() call empties the condition stack.
397  Calls to rnd_init/rnd_end, index_init/index_end etc do not affect the
398  condition stack.
399  The current implementation supports arbitrary AND/OR nested conditions
400  with comparisons between columns and constants (including constant
401  expressions and function calls) and the following comparison operators:
402  =, !=, >, >=, <, <=, like, "not like", "is null", and "is not null".
403  Negated conditions are supported by NOT which generate NAND/NOR groups.
404  */
405  const Item *cond_push(const Item *cond);
406  /*
407  Pop the top condition from the condition stack of the handler instance.
408  SYNOPSIS
409  cond_pop()
410  Pops the top if condition stack, if stack is not empty
411  */
412  void cond_pop();
413 
414  bool maybe_pushable_join(const char*& reason) const;
415  int assign_pushed_join(const ndb_pushed_join* pushed_join);
416 
417  uint number_of_pushed_joins() const;
418  const TABLE* root_of_pushed_join() const;
419  const TABLE* parent_of_pushed_join() const;
420 
421  int index_read_pushed(uchar *buf, const uchar *key,
422  key_part_map keypart_map);
423 
424  int index_next_pushed(uchar * buf);
425 
426  uint8 table_cache_type();
427 
428  /*
429  * Internal to ha_ndbcluster, used by C functions
430  */
431  int ndb_err(NdbTransaction*, bool have_lock= FALSE);
432 
433  my_bool register_query_cache_table(THD *thd, char *table_key,
434  uint key_length,
435  qc_engine_callback *engine_callback,
436  ulonglong *engine_data);
437 
438 #ifndef NDB_WITHOUT_ONLINE_ALTER
439  int check_if_supported_alter(TABLE *altered_table,
440  HA_CREATE_INFO *create_info,
441  Alter_info *alter_info,
442  HA_ALTER_FLAGS *alter_flags,
443  uint table_changes);
444 
445  int alter_table_phase1(THD *thd,
446  TABLE *altered_table,
447  HA_CREATE_INFO *create_info,
448  HA_ALTER_INFO *alter_info,
449  HA_ALTER_FLAGS *alter_flags);
450 
451  int alter_table_phase2(THD *thd,
452  TABLE *altered_table,
453  HA_CREATE_INFO *create_info,
454  HA_ALTER_INFO *alter_info,
455  HA_ALTER_FLAGS *alter_flags);
456 
457  int alter_table_phase3(THD *thd, TABLE *table,
458  HA_CREATE_INFO *create_info,
459  HA_ALTER_INFO *alter_info,
460  HA_ALTER_FLAGS *alter_flags);
461 #endif
462 
463 private:
464 #ifdef HAVE_NDB_BINLOG
465  int prepare_conflict_detection(enum_conflicting_op_type op_type,
466  const NdbRecord* key_rec,
467  const uchar* old_data,
468  const uchar* new_data,
471 #endif
472  void setup_key_ref_for_ndb_record(const NdbRecord **key_rec,
473  const uchar **key_row,
474  const uchar *record,
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,
478  Ndb *ndb, NdbEventOperation *pOp,
479  NDB_SHARE *share);
480 
481  void check_read_before_write_removal();
482  static int drop_table_impl(THD *thd, ha_ndbcluster *h, Ndb *ndb,
483  const char *path,
484  const char *db,
485  const char *table_name);
486 
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);
494 // Index list management
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);
499  int add_index_handle(THD *thd, NdbDictionary::Dictionary *dict,
500  KEY *key_info, const char *key_name, uint index_no);
501  int add_table_ndb_record(NdbDictionary::Dictionary *dict);
502  int add_hidden_pk_ndb_record(NdbDictionary::Dictionary *dict);
503  int add_index_ndb_record(NdbDictionary::Dictionary *dict,
504  KEY *key_info, uint index_no);
505  int check_default_values(const NdbDictionary::Table* ndbtab);
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,
511  bool primary) const;
512  bool has_null_in_unique_index(uint idx_no) const;
513  bool check_index_fields_not_null(KEY *key_info);
514 
515  bool check_if_pushable(int type, //NdbQueryOperationDef::Type,
516  uint idx= MAX_KEY,
517  bool rootSorted= false) const;
518  bool check_is_pushed() const;
519  int create_pushed_join(const NdbQueryParamValue* keyFieldParams=NULL,
520  uint paramCnt= 0);
521 
522  int set_up_partition_info(partition_info *part_info,
523  NdbDictionary::Table&) const;
524  int set_range_data(const partition_info* part_info,
525  NdbDictionary::Table&) const;
526  int set_list_data(const partition_info* part_info,
527  NdbDictionary::Table&) const;
528  int ndb_pk_update_row(THD *thd,
529  const uchar *old_data, uchar *new_data,
530  uint32 old_part_id);
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,
533  const key_range *end_key,
534  bool sorted, bool descending, uchar* buf,
535  part_id_range *part_spec);
536  int unique_index_read(const uchar *key, uint key_len,
537  uchar *buf);
538  int full_table_scan(const KEY* key_info,
539  const key_range *start_key,
540  const key_range *end_key,
541  uchar *buf);
542  int flush_bulk_insert(bool allow_batch= FALSE);
543  int ndb_write_row(uchar *record, bool primary_key_update,
544  bool batched_update);
545 
546  bool start_bulk_delete();
547  int end_bulk_delete();
548  int ndb_delete_row(const uchar *record, bool primary_key_update);
549 
550  int ndb_optimize_table(THD* thd, uint delay);
551 
552 #ifndef NDB_WITHOUT_ONLINE_ALTER
553  int alter_frm(THD *thd, const char *file, NDB_ALTER_DATA *alter_data);
554 #endif
555 
556  bool check_all_operations_for_error(NdbTransaction *trans,
557  const NdbOperation *first,
558  const NdbOperation *last,
559  uint errcode);
560  int peek_indexed_rows(const uchar *record, NDB_WRITE_OP write_op);
561  int scan_handle_lock_tuple(NdbScanOperation *scanOp, NdbTransaction *trans);
562  int fetch_next(NdbScanOperation* 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);
567  int close_scan();
568  void unpack_record(uchar *dst_row, const uchar *src_row);
569 
570  void set_dbname(const char *pathname);
571  void set_tabname(const char *pathname);
572 
573  const NdbDictionary::Column *get_hidden_key_column() {
574  return m_table->getColumn(table_share->fields);
575  }
576  const NdbDictionary::Column *get_partition_id_column() {
577  Uint32 index= table_share->fields + (table_share->primary_key == MAX_KEY);
578  return m_table->getColumn(index);
579  }
580 
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);
584  }
585  uchar *get_buffer(Thd_ndb *thd_ndb, uint size);
586  uchar *copy_row_to_buffer(Thd_ndb *thd_ndb, const uchar *record);
587 
588  int get_blob_values(const NdbOperation *ndb_op, uchar *dst_record,
589  const MY_BITMAP *bitmap);
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();
594  Uint32 setup_get_hidden_fields(NdbOperation::GetValueSpec gets[2]);
595  void get_hidden_fields_keyop(NdbOperation::OperationOptions *options,
597  void get_hidden_fields_scan(NdbScanOperation::ScanOptions *options,
599  void eventSetAnyValue(THD *thd,
600  NdbOperation::OperationOptions *options) const;
601  bool check_index_fields_in_write_set(uint keyno);
602 
603  const NdbOperation *pk_unique_index_read_key(uint idx,
604  const uchar *key, uchar *buf,
606  Uint32 *ppartition_id);
607  int pk_unique_index_read_key_pushed(uint idx,
608  const uchar *key,
609  Uint32 *ppartition_id);
610 
611  int read_multi_range_fetch_next();
612 
613  int primary_key_cmp(const uchar * old_row, const uchar * new_row);
614  void print_results();
615 
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;
621 
622  static inline bool isManualBinlogExec(THD *thd);
623 
624  char *update_table_comment(const char * comment);
625 
626  int write_ndb_file(const char *name);
627 
628  int check_ndb_connection(THD* thd);
629 
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 *);
635 
636  /* Ordered index statistics v4 */
637  int ndb_index_stat_query(uint inx,
638  const key_range *min_key,
639  const key_range *max_key,
640  NdbIndexStat::Stat& stat,
641  int from);
642  int ndb_index_stat_get_rir(uint inx,
643  key_range *min_key,
644  key_range *max_key,
645  ha_rows *rows_out);
646  int ndb_index_stat_set_rpk(uint inx);
647  int ndb_index_stat_analyze(Ndb *ndb,
648  uint *inx_list,
649  uint inx_count);
650 
651  NdbTransaction *start_transaction_part_id(uint32 part_id, int &error);
652  inline NdbTransaction *get_transaction_part_id(uint32 part_id, int &error)
653  {
654  if (m_thd_ndb->trans)
655  return m_thd_ndb->trans;
656  return start_transaction_part_id(part_id, error);
657  }
658 
659  NdbTransaction *start_transaction(int &error);
660  inline NdbTransaction *get_transaction(int &error)
661  {
662  if (m_thd_ndb->trans)
663  return m_thd_ndb->trans;
664  return start_transaction(error);
665  }
666 
667  NdbTransaction *start_transaction_row(const NdbRecord *ndb_record,
668  const uchar *record,
669  int &error);
670  NdbTransaction *start_transaction_key(uint index,
671  const uchar *key_data,
672  int &error);
673 
674  friend int check_completed_operations_pre_commit(Thd_ndb*,
676  const NdbOperation*,
677  uint *ignore_count);
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);
681 
682  Thd_ndb *m_thd_ndb;
683  NdbScanOperation *m_active_cursor;
684  const NdbDictionary::Table *m_table;
685  /*
686  Normal NdbRecord for accessing rows, with all fields including hidden
687  fields (hidden primary key, user-defined partitioning function value).
688  */
689  NdbRecord *m_ndb_record;
690  /* NdbRecord for accessing tuple by hidden Uint64 primary key. */
691  NdbRecord *m_ndb_hidden_key_record;
692 
693  /* Bitmap used for NdbRecord operation column mask. */
694  MY_BITMAP m_bitmap;
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))]; // Buffer for m_bitmap
698  /* Bitmap with bit set for all primary key columns. */
699  MY_BITMAP *m_pk_bitmap_p;
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))]; // Buffer for m_pk_bitmap
703  struct Ndb_local_table_statistics *m_table_info;
704  struct Ndb_local_table_statistics m_table_info_instance;
705  char m_dbname[FN_HEADLEN];
706  //char m_schemaname[FN_HEADLEN];
707  char m_tabname[FN_HEADLEN];
708  THR_LOCK_DATA m_lock;
709  bool m_lock_tuple;
710  NDB_SHARE *m_share;
711  NDB_INDEX_DATA m_index[MAX_KEY];
712  key_map btree_keys;
713 
714  /*
715  Pointer to row returned from scan nextResult().
716  */
717  union
718  {
719  const char *_m_next_row;
720  const uchar *m_next_row;
721  };
722  /* For read_multi_range scans, the get_range_no() of current row. */
723  int m_current_range_no;
724 
725  MY_BITMAP **m_key_fields;
726  // NdbRecAttr has no reference to blob
727  NdbValue m_value[NDB_MAX_ATTRIBUTES_IN_TABLE];
728  Uint64 m_ref;
729  partition_info *m_part_info;
730  uint32 m_part_id;
731  bool m_user_defined_partitioning;
732  bool m_use_partition_pruning;
733  bool m_sorted;
734  bool m_use_write;
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; // TODO: merge it with handler::estimation_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;
750  bool m_slow_path;
751  bool m_is_bulk_delete;
752 
753  /* State for setActiveHook() callback for reading blob data. */
754  uint m_blob_counter;
755  uint m_blob_expected_count_per_row;
756  uchar *m_blob_destination_record;
757  Uint64 m_blobs_row_total_size; /* Bytes needed for all blobs in current row */
758 
759  // memory for blobs in one tuple
760  uchar *m_blobs_buffer;
761  Uint64 m_blobs_buffer_size;
762  uint m_dupkey;
763  // set from thread variables at external lock
764  ha_rows m_autoincrement_prefetch;
765 
766  // Joins pushed to NDB.
767  const ndb_pushed_join
768  *m_pushed_join_member; // Pushed join def. I am member of
769  int m_pushed_join_operation; // Op. id. in above pushed join
770  static const int PUSHED_ROOT= 0; // Op. id. if I'm root
771 
772  bool m_disable_pushed_join; // Pushed execution allowed?
773  NdbQuery* m_active_query; // Pushed query instance executing
774  NdbQueryOperation* m_pushed_operation; // Pushed operation instance
775 
776  ha_ndbcluster_cond *m_cond;
777  bool m_disable_multi_read;
778  const uchar *m_multi_range_result_ptr;
779  KEY_MULTI_RANGE *m_multi_ranges;
780  /*
781  Points 1 past the end of last multi range operation currently being
782  executed, to support splitting large multi range reands into manageable
783  pieces.
784  */
785  KEY_MULTI_RANGE *m_multi_range_defined_end;
786  NdbIndexScanOperation *m_multi_cursor;
787  Ndb *get_ndb(THD *thd);
788 
789  int update_stats(THD *thd, bool do_read_stat, bool have_lock= FALSE,
790  uint part_id= ~(uint)0);
791  int add_handler_to_open_tables(THD*, Thd_ndb*, ha_ndbcluster* handler);
792 };
793 
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);
799 
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;