~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/cursor.h

  • Committer: Jay Pipes
  • Date: 2009-11-16 22:00:02 UTC
  • mto: (1234.1.1 push) (1237.2.10 push)
  • mto: This revision was merged to the branch mainline in revision 1229.
  • Revision ID: jpipes@serialcoder-20091116220002-rdsha64utt41i8w8
Adds INFORMATION_SCHEMA views for the transaction log:

TRANSACTION_LOG
TRANSACTION_LOG_ENTRIES
TRANSACTION_LOG_TRANSACTIONS

Adds a new user-defined function:

PRINT_TRANSACTION_MESSAGE(filename, offset)

Adds tests for all of the above

Implementation notes:

An indexer now runs when transaction messages are applied
to the transaction log.  It creates a simple index of the
transaction log entries.  This index is used when the
information schema views' fillTable() method is called.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
#include <drizzled/xid.h>
24
24
#include <drizzled/discrete_interval.h>
25
 
#include <drizzled/identifier.h>
26
 
#include <drizzled/definitions.h>
27
 
#include <drizzled/key_map.h>
28
25
 
29
26
/* Definitions for parameters to do with Cursor-routines */
30
27
 
31
 
#include <drizzled/thr_lock.h>
 
28
#include <mysys/thr_lock.h>
 
29
#include <mysys/hash.h>
32
30
#include <drizzled/sql_string.h>
33
31
#include <drizzled/sql_list.h>
34
32
#include <drizzled/plugin/storage_engine.h>
38
36
 
39
37
#include <drizzled/message/table.pb.h>
40
38
 
 
39
/* Bits to show what an alter table will do */
 
40
#include <drizzled/sql_bitmap.h>
 
41
 
 
42
#include <drizzled/cursor.h>
 
43
 
41
44
#include <bitset>
42
45
#include <algorithm>
43
46
 
44
 
namespace drizzled
45
 
{
46
 
 
47
47
#define HA_MAX_ALTER_FLAGS 40
48
48
 
 
49
 
49
50
typedef std::bitset<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
50
51
 
51
 
extern uint64_t refresh_version;  /* Increments on each reload */
 
52
extern drizzled::atomic<uint32_t> refresh_version;  /* Increments on each reload */
 
53
 
 
54
 
 
55
typedef bool (*qc_engine_callback)(Session *session, char *table_key,
 
56
                                      uint32_t key_length,
 
57
                                      uint64_t *engine_data);
 
58
 
 
59
 
 
60
/* The Cursor for a table type.  Will be included in the Table structure */
52
61
 
53
62
class Table;
54
63
class TableList;
55
64
class TableShare;
56
65
class Select_Lex_Unit;
57
 
class ForeignKeyInfo;
58
 
struct Order;
 
66
struct st_foreign_key_info;
 
67
typedef struct st_foreign_key_info FOREIGN_KEY_INFO;
 
68
struct order_st;
59
69
 
60
70
class Item;
 
71
struct st_table_log_memory_entry;
61
72
 
62
73
class LEX;
63
74
class Select_Lex;
66
77
class CreateField;
67
78
class sys_var_str;
68
79
class Item_ident;
 
80
typedef struct st_sort_field SORT_FIELD;
69
81
 
70
82
typedef List<Item> List_item;
 
83
 
 
84
typedef struct st_savepoint SAVEPOINT;
 
85
extern uint32_t savepoint_alloc_size;
71
86
extern KEY_CREATE_INFO default_key_create_info;
72
87
 
73
88
/* Forward declaration for condition pushdown to storage engine */
74
89
typedef class Item COND;
75
90
 
76
 
typedef struct system_status_var system_status_var;
77
 
 
78
 
namespace optimizer
79
 
{
80
 
  class CostVector;
81
 
}
82
 
 
 
91
typedef struct system_status_var SSV;
 
92
 
 
93
class COST_VECT;
 
94
 
 
95
uint32_t calculate_key_len(Table *, uint, const unsigned char *, key_part_map);
83
96
/*
84
97
  bitmap with first N+1 bits set
85
98
  (keypart_map for a key prefix of [0..N] keyparts)
111
124
     storage engine
112
125
 
113
126
  2. KeyTupleFormat - used to pass index search tuples (aka "keys") to
114
 
     storage engine. See optimizer/range.cc for description of this format.
 
127
     storage engine. See opt_range.cc for description of this format.
115
128
 
116
129
  TableRecordFormat
117
130
  =================
136
149
  present, its length is one byte <not-sure> which must be set to 0xFF
137
150
  at all times. </not-sure>
138
151
 
 
152
  If the table has columns of type BIT, then certain bits from those columns
 
153
  may be stored in null_bytes as well. Grep around for Field_bit for
 
154
  details.
 
155
 
139
156
  For blob columns (see Field_blob), the record buffer stores length of the
140
157
  data, following by memory pointer to the blob data. The pointer is owned
141
158
  by the storage engine and is valid until the next operation.
143
160
  If a blob column has NULL value, then its length and blob data pointer
144
161
  must be set to 0.
145
162
*/
146
 
class Cursor
 
163
 
 
164
class Cursor :public Sql_alloc
147
165
{
148
 
  Table &table;               /* The current open table */
149
 
  plugin::StorageEngine &engine;      /* storage engine of this Cursor */
 
166
public:
 
167
  typedef uint64_t Table_flags;
150
168
 
151
169
protected:
 
170
  TableShare *table_share;   /* The table definition */
 
171
  Table *table;               /* The current open table */
 
172
  Table_flags cached_table_flags;       /* Set on init() and open() */
 
173
 
152
174
  ha_rows estimation_rows_to_insert;
153
 
 
154
175
public:
155
 
  inline plugin::StorageEngine *getEngine() const       /* table_type for handler */
156
 
  {
157
 
    return &engine;
158
 
  }
159
 
  unsigned char *ref;                           /* Pointer to current row */
 
176
  drizzled::plugin::StorageEngine *engine;      /* storage engine of this Cursor */
 
177
  unsigned char *ref;                           /* Pointer to current row */
160
178
  unsigned char *dup_ref;                       /* Pointer to duplicate row */
161
179
 
162
 
  TableShare *getShare();
163
 
 
164
 
  Table *getTable() const
165
 
  {
166
 
    return &table;
167
 
  }
168
 
 
169
180
  ha_statistics stats;
170
181
  /** MultiRangeRead-related members: */
171
182
  range_seq_t mrr_iter;    /* Interator to traverse the range sequence */
172
183
  RANGE_SEQ_IF mrr_funcs;  /* Range sequence traversal functions */
173
 
 
 
184
  HANDLER_BUFFER *multi_range_buffer; /* MRR buffer info */
174
185
  uint32_t ranges_in_seq; /* Total number of ranges in the traversed sequence */
175
186
  /* true <=> source MRR ranges and the output are ordered */
176
187
  bool mrr_is_output_sorted;
179
190
  bool mrr_have_range;
180
191
 
181
192
  bool eq_range;
 
193
  /*
 
194
    true <=> the engine guarantees that returned records are within the range
 
195
    being scanned.
 
196
  */
 
197
  bool in_range_check_pushed_down;
182
198
 
183
199
  /** Current range (the one we're now returning rows from) */
184
200
  KEY_MULTI_RANGE mrr_cur_range;
185
201
 
186
202
  /** The following are for read_range() */
187
203
  key_range save_end_range, *end_range;
188
 
  KeyPartInfo *range_key_part;
 
204
  KEY_PART_INFO *range_key_part;
189
205
  int key_compare_result_on_equal;
190
206
 
191
207
  uint32_t errkey;                              /* Last dup key */
195
211
  uint32_t ref_length;
196
212
  enum {NONE=0, INDEX, RND} inited;
197
213
  bool locked;
 
214
  bool implicit_emptied;                /* Can be !=0 only if HEAP */
198
215
 
199
216
  /**
200
217
    next_insert_id is the next value which should be inserted into the
206
223
    get_auto_increment().
207
224
  */
208
225
  uint64_t next_insert_id;
209
 
  uint64_t getNextInsertId()
210
 
  {
211
 
    return next_insert_id;
212
 
  }
213
 
 
214
226
  /**
215
227
    insert id for the current row (*autogenerated*; if not
216
228
    autogenerated, it's 0).
224
236
  */
225
237
  Discrete_interval auto_inc_interval_for_cur_row;
226
238
 
227
 
  Cursor(plugin::StorageEngine &engine_arg, Table &share_arg);
 
239
  Cursor(drizzled::plugin::StorageEngine *engine_arg, TableShare *share_arg)
 
240
    :table_share(share_arg), table(0),
 
241
    estimation_rows_to_insert(0), engine(engine_arg),
 
242
    ref(0), in_range_check_pushed_down(false),
 
243
    key_used_on_scan(MAX_KEY), active_index(MAX_KEY),
 
244
    ref_length(sizeof(my_off_t)),
 
245
    inited(NONE),
 
246
    locked(false), implicit_emptied(0),
 
247
    next_insert_id(0), insert_id_for_cur_row(0)
 
248
    {}
228
249
  virtual ~Cursor(void);
229
 
  virtual Cursor *clone(memory::Root *mem_root);
 
250
  virtual Cursor *clone(MEM_ROOT *mem_root);
 
251
  /** This is called after create to allow us to set up cached variables */
 
252
  void init()
 
253
  {
 
254
    cached_table_flags= table_flags();
 
255
  }
230
256
 
231
257
  /* ha_ methods: pubilc wrappers for private virtual API */
232
258
 
233
 
  int ha_open(const TableIdentifier &identifier, int mode, int test_if_locked);
234
 
  int startIndexScan(uint32_t idx, bool sorted);
235
 
  int endIndexScan();
236
 
  int startTableScan(bool scan);
237
 
  int endTableScan();
 
259
  int ha_open(Table *table, const char *name, int mode, int test_if_locked);
 
260
  int ha_index_init(uint32_t idx, bool sorted);
 
261
  int ha_index_end();
 
262
  int ha_rnd_init(bool scan);
 
263
  int ha_rnd_end();
238
264
  int ha_reset();
239
265
 
240
266
  /* this is necessary in many places, e.g. in HANDLER command */
241
267
  int ha_index_or_rnd_end();
 
268
  Table_flags ha_table_flags() const;
242
269
 
243
270
  /**
244
271
    These functions represent the public interface to *users* of the
245
272
    Cursor class, hence they are *not* virtual. For the inheritance
246
 
    interface, see the (private) functions doInsertRecord(), doUpdateRecord(),
247
 
    and doDeleteRecord() below.
 
273
    interface, see the (private) functions write_row(), update_row(),
 
274
    and delete_row() below.
248
275
  */
249
276
  int ha_external_lock(Session *session, int lock_type);
250
 
  int insertRecord(unsigned char * buf);
251
 
  int updateRecord(const unsigned char * old_data, unsigned char * new_data);
252
 
  int deleteRecord(const unsigned char * buf);
 
277
  int ha_write_row(unsigned char * buf);
 
278
  int ha_update_row(const unsigned char * old_data, unsigned char * new_data);
 
279
  int ha_delete_row(const unsigned char * buf);
253
280
  void ha_release_auto_increment();
254
281
 
255
282
  /** to be actually called to get 'check()' functionality*/
257
284
 
258
285
  void ha_start_bulk_insert(ha_rows rows);
259
286
  int ha_end_bulk_insert();
 
287
  int ha_bulk_update_row(const unsigned char *old_data, unsigned char *new_data,
 
288
                         uint32_t *dup_key_found);
260
289
  int ha_delete_all_rows();
261
290
  int ha_reset_auto_increment(uint64_t value);
 
291
  int ha_optimize(Session* session, HA_CHECK_OPT* check_opt);
262
292
  int ha_analyze(Session* session, HA_CHECK_OPT* check_opt);
263
293
 
264
294
  int ha_disable_indexes(uint32_t mode);
268
298
 
269
299
  void adjust_next_insert_id_after_explicit_value(uint64_t nr);
270
300
  int update_auto_increment();
 
301
  void print_keydup_error(uint32_t key_nr, const char *msg);
 
302
  virtual void print_error(int error, myf errflag);
 
303
  virtual bool get_error_message(int error, String *buf);
 
304
  uint32_t get_dup_key(int error);
 
305
  virtual void change_table_ptr(Table *table_arg, TableShare *share);
271
306
 
272
307
  /* Estimates calculation */
273
308
  virtual double scan_time(void)
280
315
  virtual ha_rows multi_range_read_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
281
316
                                              void *seq_init_param,
282
317
                                              uint32_t n_ranges, uint32_t *bufsz,
283
 
                                              uint32_t *flags, optimizer::CostVector *cost);
 
318
                                              uint32_t *flags, COST_VECT *cost);
284
319
  virtual int multi_range_read_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys,
285
 
                                    uint32_t *bufsz, uint32_t *flags, optimizer::CostVector *cost);
 
320
                                    uint32_t *bufsz, uint32_t *flags, COST_VECT *cost);
286
321
  virtual int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
287
 
                                    uint32_t n_ranges, uint32_t mode);
 
322
                                    uint32_t n_ranges, uint32_t mode,
 
323
                                    HANDLER_BUFFER *buf);
288
324
  virtual int multi_range_read_next(char **range_info);
289
325
 
290
326
 
308
344
    (table_flags() & (HA_HAS_RECORDS | HA_STATS_RECORDS_IS_EXACT)) != 0
309
345
  */
310
346
  virtual ha_rows records();
311
 
  virtual uint64_t tableSize();
312
 
  virtual uint64_t rowSize();
313
347
  /**
314
348
    Return upper bound of current number of records in the table
315
349
    (max. of how many records one will retrieve when doing a full table scan)
319
353
  virtual ha_rows estimate_rows_upper_bound()
320
354
  { return stats.records+EXTRA_RECORDS; }
321
355
 
 
356
  /**
 
357
    Get the row type from the storage engine.  If this method returns
 
358
    ROW_TYPE_NOT_USED, the information in HA_CREATE_INFO should be used.
 
359
  */
 
360
  virtual enum row_type get_row_type() const { return ROW_TYPE_NOT_USED; }
 
361
 
322
362
  virtual const char *index_type(uint32_t)
323
363
  { assert(0); return "";}
324
364
 
327
367
  virtual int close(void)=0;
328
368
 
329
369
  /**
 
370
    @retval  0   Bulk update used by Cursor
 
371
    @retval  1   Bulk update not used, normal operation used
 
372
  */
 
373
  virtual bool start_bulk_update() { return 1; }
 
374
  /**
 
375
    @retval  0   Bulk delete used by Cursor
 
376
    @retval  1   Bulk delete not used, normal operation used
 
377
  */
 
378
  virtual bool start_bulk_delete() { return 1; }
 
379
  /**
 
380
    After this call all outstanding updates must be performed. The number
 
381
    of duplicate key errors are reported in the duplicate key parameter.
 
382
    It is allowed to continue to the batched update after this call, the
 
383
    Cursor has to wait until end_bulk_update with changing state.
 
384
 
 
385
    @param    dup_key_found       Number of duplicate keys found
 
386
 
 
387
    @retval  0           Success
 
388
    @retval  >0          Error code
 
389
  */
 
390
  virtual int exec_bulk_update(uint32_t *)
 
391
  {
 
392
    assert(false);
 
393
    return HA_ERR_WRONG_COMMAND;
 
394
  }
 
395
  /**
 
396
    Perform any needed clean-up, no outstanding updates are there at the
 
397
    moment.
 
398
  */
 
399
  virtual void end_bulk_update() { return; }
 
400
  /**
 
401
    Execute all outstanding deletes and close down the bulk delete.
 
402
 
 
403
    @retval 0             Success
 
404
    @retval >0            Error code
 
405
  */
 
406
  virtual int end_bulk_delete()
 
407
  {
 
408
    assert(false);
 
409
    return HA_ERR_WRONG_COMMAND;
 
410
  }
 
411
  /**
330
412
     @brief
331
413
     Positions an index cursor to the index specified in the handle. Fetches the
332
414
     row if available. If the key value is null, begin at the first key of the
333
415
     index.
334
416
  */
335
 
  virtual int index_read_map(unsigned char * buf, const unsigned char *key,
 
417
  virtual int index_read_map(unsigned char * buf, const unsigned char * key,
336
418
                             key_part_map keypart_map,
337
419
                             enum ha_rkey_function find_flag)
338
420
  {
339
 
    uint32_t key_len= calculate_key_len(active_index, keypart_map);
 
421
    uint32_t key_len= calculate_key_len(table, active_index, key, keypart_map);
340
422
    return  index_read(buf, key, key_len, find_flag);
341
423
  }
342
424
  /**
358
440
  virtual int index_last(unsigned char *)
359
441
   { return  HA_ERR_WRONG_COMMAND; }
360
442
  virtual int index_next_same(unsigned char *, const unsigned char *, uint32_t);
361
 
 
362
 
private:
363
 
  uint32_t calculate_key_len(uint32_t key_position, key_part_map keypart_map_arg);
364
 
public:
365
 
 
366
443
  /**
367
444
     @brief
368
445
     The following functions works like index_read, but it find the last
371
448
  virtual int index_read_last_map(unsigned char * buf, const unsigned char * key,
372
449
                                  key_part_map keypart_map)
373
450
  {
374
 
    uint32_t key_len= calculate_key_len(active_index, keypart_map);
 
451
    uint32_t key_len= calculate_key_len(table, active_index, key, keypart_map);
375
452
    return index_read_last(buf, key, key_len);
376
453
  }
377
454
  virtual int read_range_first(const key_range *start_key,
379
456
                               bool eq_range, bool sorted);
380
457
  virtual int read_range_next();
381
458
  int compare_key(key_range *range);
 
459
  int compare_key2(key_range *range);
382
460
  virtual int rnd_next(unsigned char *)=0;
383
461
  virtual int rnd_pos(unsigned char *, unsigned char *)=0;
 
462
  /**
 
463
    One has to use this method when to find
 
464
    random position by record as the plain
 
465
    position() call doesn't work for some
 
466
    handlers for random position.
 
467
  */
 
468
  virtual int rnd_pos_by_record(unsigned char *record);
384
469
  virtual int read_first_row(unsigned char *buf, uint32_t primary_key);
 
470
  /**
 
471
    The following function is only needed for tables that may be temporary
 
472
    tables during joins.
 
473
  */
 
474
  virtual int restart_rnd_next(unsigned char *, unsigned char *)
 
475
    { return HA_ERR_WRONG_COMMAND; }
385
476
  virtual int rnd_same(unsigned char *, uint32_t)
386
477
    { return HA_ERR_WRONG_COMMAND; }
387
478
  virtual ha_rows records_in_range(uint32_t, key_range *, key_range *)
416
507
  */
417
508
  virtual void try_semi_consistent_read(bool) {}
418
509
  virtual void unlock_row(void) {}
 
510
  virtual int start_stmt(Session *, thr_lock_type)
 
511
  {return 0;}
419
512
  virtual void get_auto_increment(uint64_t offset, uint64_t increment,
420
513
                                  uint64_t nb_desired_values,
421
514
                                  uint64_t *first_value,
422
 
                                  uint64_t *nb_reserved_values)= 0;
423
 
 
 
515
                                  uint64_t *nb_reserved_values);
424
516
  void set_next_insert_id(uint64_t id)
425
517
  {
426
518
    next_insert_id= id;
441
533
      insert_id_for_cur_row;
442
534
  }
443
535
 
 
536
  virtual void update_create_info(HA_CREATE_INFO *) {}
 
537
  int check_old_types(void);
444
538
  /* end of the list of admin commands */
445
539
 
446
540
  virtual int indexes_are_disabled(void) {return 0;}
463
557
   */
464
558
  virtual bool can_switch_engines(void) { return true; }
465
559
  /** used in REPLACE; is > 0 if table is referred by a FOREIGN KEY */
466
 
  virtual int get_foreign_key_list(Session *, List<ForeignKeyInfo> *)
 
560
  virtual int get_foreign_key_list(Session *, List<FOREIGN_KEY_INFO> *)
467
561
  { return 0; }
468
562
  virtual uint32_t referenced_by_foreign_key() { return 0;}
469
563
  virtual void free_foreign_key_create_info(char *) {}
 
564
  /** The following can be called without an open Cursor */
 
565
 
 
566
  virtual uint32_t index_flags(uint32_t idx, uint32_t part, bool all_parts) const =0;
 
567
 
 
568
  virtual int add_index(Table *, KEY *, uint32_t)
 
569
  { return (HA_ERR_WRONG_COMMAND); }
 
570
  virtual int prepare_drop_index(Table *, uint32_t *, uint32_t)
 
571
  { return (HA_ERR_WRONG_COMMAND); }
 
572
  virtual int final_drop_index(Table *)
 
573
  { return (HA_ERR_WRONG_COMMAND); }
 
574
 
 
575
  uint32_t max_record_length() const
 
576
  { return std::min((unsigned int)HA_MAX_REC_LENGTH, max_supported_record_length()); }
 
577
  uint32_t max_keys() const
 
578
  { return std::min((unsigned int)MAX_KEY, max_supported_keys()); }
 
579
  uint32_t max_key_parts() const
 
580
  { return std::min((unsigned int)MAX_REF_PARTS, max_supported_key_parts()); }
 
581
  uint32_t max_key_length() const
 
582
  { return std::min((unsigned int)MAX_KEY_LENGTH, max_supported_key_length()); }
 
583
  uint32_t max_key_part_length(void) const
 
584
  { return std::min((unsigned int)MAX_KEY_LENGTH, max_supported_key_part_length()); }
 
585
 
 
586
  virtual uint32_t max_supported_record_length(void) const
 
587
  { return HA_MAX_REC_LENGTH; }
 
588
  virtual uint32_t max_supported_keys(void) const { return 0; }
 
589
  virtual uint32_t max_supported_key_parts(void) const { return MAX_REF_PARTS; }
 
590
  virtual uint32_t max_supported_key_length(void) const { return MAX_KEY_LENGTH; }
 
591
  virtual uint32_t max_supported_key_part_length(void) const { return 255; }
 
592
 
 
593
  virtual bool low_byte_first(void) const { return 1; }
 
594
  virtual uint32_t checksum(void) const { return 0; }
 
595
  virtual bool is_crashed(void) const  { return 0; }
 
596
  virtual bool auto_repair(void) const { return 0; }
470
597
 
471
598
  /**
472
599
    Is not invoked for non-transactional temporary tables.
475
602
    or partitioned.
476
603
 
477
604
    @note that one can NOT rely on table->in_use in store_lock().  It may
478
 
    refer to a different thread if called from abortLockForThread().
 
605
    refer to a different thread if called from mysql_lock_abort_for_thread().
479
606
 
480
607
    @note If the table is MERGE, store_lock() can return less locks
481
608
    than lock_count() claimed. This can happen when the MERGE children
482
609
    are not attached when this is called from another thread.
483
610
  */
484
 
  virtual THR_LOCK_DATA **store_lock(Session *,
 
611
  virtual THR_LOCK_DATA **store_lock(Session *session,
485
612
                                     THR_LOCK_DATA **to,
486
 
                                     enum thr_lock_type)
487
 
  {
488
 
    assert(0); // Impossible programming situation
489
 
 
490
 
    return(to);
491
 
  }
 
613
                                     enum thr_lock_type lock_type)=0;
492
614
 
493
615
 /*
494
616
   @retval true   Primary key (if there is one) is clustered
501
623
   return memcmp(ref1, ref2, ref_length);
502
624
 }
503
625
 
504
 
  virtual bool isOrdered(void)
 
626
  /**
 
627
    Lock table.
 
628
 
 
629
    @param    session                     Thread handle
 
630
    @param    lock_type               HA_LOCK_IN_SHARE_MODE     (F_RDLCK)
 
631
                                      HA_LOCK_IN_EXCLUSIVE_MODE (F_WRLCK)
 
632
    @param    lock_timeout            -1 default timeout
 
633
                                      0  no wait
 
634
                                      >0 wait timeout in milliseconds.
 
635
 
 
636
   @note
 
637
      lock_timeout >0 is not used by MySQL currently. If the storage
 
638
      engine does not support NOWAIT (lock_timeout == 0) it should
 
639
      return an error. But if it does not support WAIT X (lock_timeout
 
640
      >0) it should treat it as lock_timeout == -1 and wait a default
 
641
      (or even hard-coded) timeout.
 
642
 
 
643
    @retval HA_ERR_WRONG_COMMAND      Storage engine does not support
 
644
                                      lock_table()
 
645
    @retval HA_ERR_UNSUPPORTED        Storage engine does not support NOWAIT
 
646
    @retval HA_ERR_LOCK_WAIT_TIMEOUT  Lock request timed out or
 
647
                                      lock conflict with NOWAIT option
 
648
    @retval HA_ERR_LOCK_DEADLOCK      Deadlock detected
 
649
  */
 
650
  virtual int lock_table(Session *, int, int)
505
651
  {
506
 
    return false;
 
652
    return HA_ERR_WRONG_COMMAND;
507
653
  }
508
654
 
509
 
 
510
655
protected:
511
656
  /* Service methods for use by storage engines. */
512
 
  void ha_statistic_increment(uint64_t system_status_var::*offset) const;
 
657
  void ha_statistic_increment(ulong SSV::*offset) const;
513
658
  void **ha_data(Session *) const;
 
659
  Session *ha_session(void) const;
514
660
 
515
661
private:
516
662
  /* Private helpers */
517
 
  inline void setTransactionReadWrite();
 
663
  inline void mark_trx_read_write();
518
664
private:
519
665
  /*
520
666
    Low-level primitives for storage engines.  These should be
522
668
    the corresponding 'ha_*' method above.
523
669
  */
524
670
 
525
 
  virtual int open(const char *, int , uint32_t ) { assert(0); return -1; }
526
 
  virtual int doOpen(const TableIdentifier &identifier, int mode, uint32_t test_if_locked);
527
 
  virtual int doStartIndexScan(uint32_t idx, bool)
 
671
  virtual int open(const char *name, int mode, uint32_t test_if_locked)=0;
 
672
  virtual int index_init(uint32_t idx, bool)
528
673
  { active_index= idx; return 0; }
529
 
  virtual int doEndIndexScan() { active_index= MAX_KEY; return 0; }
 
674
  virtual int index_end() { active_index= MAX_KEY; return 0; }
530
675
  /**
531
 
    doStartTableScan() can be called two times without doEndTableScan() in between
 
676
    rnd_init() can be called two times without rnd_end() in between
532
677
    (it only makes sense if scan=1).
533
678
    then the second call should prepare for the new table scan (e.g
534
679
    if rnd_init allocates the cursor, second call should position it
535
680
    to the start of the table, no need to deallocate and allocate it again
536
681
  */
537
 
  virtual int doStartTableScan(bool scan)= 0;
538
 
  virtual int doEndTableScan() { return 0; }
539
 
  virtual int doInsertRecord(unsigned char *)
540
 
  {
541
 
    return HA_ERR_WRONG_COMMAND;
542
 
  }
543
 
 
544
 
  virtual int doUpdateRecord(const unsigned char *, unsigned char *)
545
 
  {
546
 
    return HA_ERR_WRONG_COMMAND;
547
 
  }
548
 
 
549
 
  virtual int doDeleteRecord(const unsigned char *)
 
682
  virtual int rnd_init(bool scan)= 0;
 
683
  virtual int rnd_end() { return 0; }
 
684
  virtual int write_row(unsigned char *)
 
685
  {
 
686
    return HA_ERR_WRONG_COMMAND;
 
687
  }
 
688
 
 
689
  virtual int update_row(const unsigned char *, unsigned char *)
 
690
  {
 
691
    return HA_ERR_WRONG_COMMAND;
 
692
  }
 
693
 
 
694
  virtual int delete_row(const unsigned char *)
550
695
  {
551
696
    return HA_ERR_WRONG_COMMAND;
552
697
  }
556
701
    by that statement.
557
702
  */
558
703
  virtual int reset() { return 0; }
 
704
  virtual Table_flags table_flags(void) const= 0;
559
705
 
560
706
  /**
561
707
    Is not invoked for non-transactional temporary tables.
583
729
  {
584
730
    return 0;
585
731
  }
586
 
  virtual void release_auto_increment(void) { return; }
 
732
  virtual void release_auto_increment(void) { return; };
587
733
  /** admin commands - called from mysql_admin_table */
588
 
  virtual int check(Session *)
 
734
  virtual int check(Session *, HA_CHECK_OPT *)
589
735
  { return HA_ADMIN_NOT_IMPLEMENTED; }
590
736
 
591
737
  virtual void start_bulk_insert(ha_rows)
595
741
                         uint32_t, enum ha_rkey_function)
596
742
   { return  HA_ERR_WRONG_COMMAND; }
597
743
  virtual int index_read_last(unsigned char *, const unsigned char *, uint32_t)
598
 
   { return (errno= HA_ERR_WRONG_COMMAND); }
 
744
   { return (my_errno= HA_ERR_WRONG_COMMAND); }
 
745
  /**
 
746
    This method is similar to update_row, however the Cursor doesn't need
 
747
    to execute the updates at this point in time. The Cursor can be certain
 
748
    that another call to bulk_update_row will occur OR a call to
 
749
    exec_bulk_update before the set of updates in this query is concluded.
 
750
 
 
751
    @param    old_data       Old record
 
752
    @param    new_data       New record
 
753
    @param    dup_key_found  Number of duplicate keys found
 
754
 
 
755
    @retval  0   Bulk delete used by Cursor
 
756
    @retval  1   Bulk delete not used, normal operation used
 
757
  */
 
758
  virtual int bulk_update_row(const unsigned char *, unsigned char *, uint32_t *)
 
759
  {
 
760
    assert(false);
 
761
    return HA_ERR_WRONG_COMMAND;
 
762
  }
599
763
  /**
600
764
    This is called to delete all rows in a table
601
765
    If the Cursor don't support this, then this function will
603
767
    by one.
604
768
  */
605
769
  virtual int delete_all_rows(void)
606
 
  { return (errno=HA_ERR_WRONG_COMMAND); }
 
770
  { return (my_errno=HA_ERR_WRONG_COMMAND); }
607
771
  /**
608
772
    Reset the auto-increment counter to the given value, i.e. the next row
609
773
    inserted will get the given value. This is called e.g. after TRUNCATE
612
776
  */
613
777
  virtual int reset_auto_increment(uint64_t)
614
778
  { return HA_ERR_WRONG_COMMAND; }
615
 
 
616
 
  virtual int analyze(Session *)
 
779
  virtual int optimize(Session *, HA_CHECK_OPT *)
 
780
  { return HA_ADMIN_NOT_IMPLEMENTED; }
 
781
  virtual int analyze(Session *, HA_CHECK_OPT *)
617
782
  { return HA_ADMIN_NOT_IMPLEMENTED; }
618
783
 
619
784
  virtual int disable_indexes(uint32_t)
620
785
  { return HA_ERR_WRONG_COMMAND; }
621
 
 
622
786
  virtual int enable_indexes(uint32_t)
623
787
  { return HA_ERR_WRONG_COMMAND; }
624
 
 
625
788
  virtual int discard_or_import_tablespace(bool)
626
 
  { return (errno=HA_ERR_WRONG_COMMAND); }
627
 
 
628
 
  /* 
629
 
    @todo this is just for the HEAP engine, it should
630
 
    be removed at some point in the future (and
631
 
    no new engine should ever use it). Right
632
 
    now HEAP does rely on it, so we cannot remove it.
633
 
  */
 
789
  { return (my_errno=HA_ERR_WRONG_COMMAND); }
634
790
  virtual void drop_table(const char *name);
635
791
};
636
792
 
637
793
extern const char *ha_row_type[];
 
794
extern const char *tx_isolation_names[];
 
795
extern const char *binlog_format_names[];
 
796
extern TYPELIB tx_isolation_typelib;
 
797
extern uint32_t total_ha, total_ha_2pc;
 
798
 
 
799
       /* Wrapper functions */
 
800
#define ha_commit(session) (ha_commit_trans((session), true))
 
801
#define ha_rollback(session) (ha_rollback_trans((session), true))
638
802
 
639
803
/* basic stuff */
640
 
void ha_init_errors(void);
641
 
 
642
 
class SortField;
643
 
SortField *make_unireg_sortorder(Order *order, uint32_t *length,
644
 
                                 SortField *sortorder);
 
804
int ha_init_errors(void);
 
805
int ha_init(void);
 
806
int ha_end(void);
 
807
 
 
808
/* transactions: interface to plugin::StorageEngine functions */
 
809
int ha_commit_one_phase(Session *session, bool all);
 
810
int ha_rollback_trans(Session *session, bool all);
 
811
 
 
812
/* transactions: these functions never call plugin::StorageEngine functions directly */
 
813
int ha_commit_trans(Session *session, bool all);
 
814
int ha_autocommit_or_rollback(Session *session, int error);
 
815
int ha_enable_transaction(Session *session, bool on);
 
816
 
 
817
/* savepoints */
 
818
int ha_rollback_to_savepoint(Session *session, SAVEPOINT *sv);
 
819
int ha_savepoint(Session *session, SAVEPOINT *sv);
 
820
int ha_release_savepoint(Session *session, SAVEPOINT *sv);
 
821
 
 
822
/* these are called by storage engines */
 
823
void trans_register_ha(Session *session, bool all, drizzled::plugin::StorageEngine *engine);
 
824
 
 
825
uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length);
 
826
bool tablename_to_filename(const char *from, char *to, size_t to_length);
 
827
 
 
828
 
 
829
/*
 
830
  Storage engine has to assume the transaction will end up with 2pc if
 
831
   - there is more than one 2pc-capable storage engine available
 
832
   - in the current transaction 2pc was not disabled yet
 
833
*/
 
834
#define trans_need_2pc(session, all)                   ((total_ha_2pc > 1) && \
 
835
        !((all ? &session->transaction.all : &session->transaction.stmt)->no_2pc))
 
836
 
 
837
 
 
838
bool mysql_xa_recover(Session *session);
 
839
 
 
840
SORT_FIELD * make_unireg_sortorder(order_st *order, uint32_t *length,
 
841
                                   SORT_FIELD *sortorder);
645
842
int setup_order(Session *session, Item **ref_pointer_array, TableList *tables,
646
 
                List<Item> &fields, List <Item> &all_fields, Order *order);
 
843
                List<Item> &fields, List <Item> &all_fields, order_st *order);
647
844
int setup_group(Session *session, Item **ref_pointer_array, TableList *tables,
648
 
                List<Item> &fields, List<Item> &all_fields, Order *order,
 
845
                List<Item> &fields, List<Item> &all_fields, order_st *order,
649
846
                bool *hidden_group_fields);
650
847
bool fix_inner_refs(Session *session, List<Item> &all_fields, Select_Lex *select,
651
848
                    Item **ref_pointer_array);
652
849
 
653
850
bool handle_select(Session *session, LEX *lex, select_result *result,
654
851
                   uint64_t setup_tables_done_option);
 
852
bool mysql_select(Session *session, Item ***rref_pointer_array,
 
853
                  TableList *tables, uint32_t wild_num,  List<Item> &list,
 
854
                  COND *conds, uint32_t og_num, order_st *order, order_st *group,
 
855
                  Item *having, uint64_t select_type,
 
856
                  select_result *result, Select_Lex_Unit *unit,
 
857
                  Select_Lex *select_lex);
655
858
void free_underlaid_joins(Session *session, Select_Lex *select);
 
859
bool mysql_explain_union(Session *session, Select_Lex_Unit *unit,
 
860
                         select_result *result);
 
861
int mysql_explain_select(Session *session, Select_Lex *sl, char const *type,
 
862
                         select_result *result);
656
863
 
657
864
bool mysql_handle_derived(LEX *lex, bool (*processor)(Session *session,
658
865
                                                      LEX *lex,
661
868
bool mysql_derived_filling(Session *session, LEX *lex, TableList *t);
662
869
int prepare_create_field(CreateField *sql_field,
663
870
                         uint32_t *blob_columns,
664
 
                         int *timestamps, int *timestamps_with_niladic);
665
 
 
666
 
bool mysql_create_table(Session *session,
667
 
                        const TableIdentifier &identifier,
 
871
                         int *timestamps, int *timestamps_with_niladic,
 
872
                         int64_t table_flags);
 
873
bool mysql_create_table(Session *session,const char *db, const char *table_name,
668
874
                        HA_CREATE_INFO *create_info,
669
 
                        message::Table &table_proto,
 
875
                        drizzled::message::Table *table_proto,
670
876
                        AlterInfo *alter_info,
671
 
                        bool tmp_table, uint32_t select_field_count,
672
 
                        bool is_if_not_exists);
673
 
 
674
 
bool mysql_create_table_no_lock(Session *session,
675
 
                                const TableIdentifier &identifier,
 
877
                        bool tmp_table, uint32_t select_field_count);
 
878
bool mysql_create_table_no_lock(Session *session, const char *db,
 
879
                                const char *table_name,
676
880
                                HA_CREATE_INFO *create_info,
677
 
                                message::Table &table_proto,
 
881
                                drizzled::message::Table *table_proto,
678
882
                                AlterInfo *alter_info,
679
 
                                bool tmp_table, uint32_t select_field_count,
680
 
                                bool is_if_not_exists);
681
 
 
682
 
bool mysql_create_like_table(Session* session,
683
 
                             const TableIdentifier &destination_identifier,
684
 
                             TableList* table, TableList* src_table,
685
 
                             message::Table &create_table_proto,
686
 
                             bool is_if_not_exists,
687
 
                             bool is_engine_set);
688
 
 
689
 
bool mysql_rename_table(Session &session,
690
 
                        plugin::StorageEngine *base,
691
 
                        const TableIdentifier &old_identifier,
692
 
                        const TableIdentifier &new_identifier);
693
 
 
 
883
                                bool tmp_table, uint32_t select_field_count);
 
884
 
 
885
bool mysql_recreate_table(Session *session, TableList *table_list);
 
886
bool mysql_create_like_table(Session* session, TableList* table, TableList* src_table,
 
887
                             drizzled::message::Table& create_table_proto,
 
888
                             HA_CREATE_INFO *create_info);
 
889
bool mysql_rename_table(drizzled::plugin::StorageEngine *base, const char *old_db,
 
890
                        const char * old_name, const char *new_db,
 
891
                        const char * new_name, uint32_t flags);
694
892
bool mysql_prepare_update(Session *session, TableList *table_list,
695
 
                          Item **conds, uint32_t order_num, Order *order);
 
893
                          Item **conds, uint32_t order_num, order_st *order);
696
894
int mysql_update(Session *session,TableList *tables,List<Item> &fields,
697
895
                 List<Item> &values,COND *conds,
698
 
                 uint32_t order_num, Order *order, ha_rows limit,
 
896
                 uint32_t order_num, order_st *order, ha_rows limit,
699
897
                 enum enum_duplicates handle_duplicates, bool ignore);
700
898
bool mysql_prepare_insert(Session *session, TableList *table_list, Table *table,
701
899
                          List<Item> &fields, List_item *values,
713
911
bool mysql_delete(Session *session, TableList *table_list, COND *conds,
714
912
                  SQL_LIST *order, ha_rows rows, uint64_t options,
715
913
                  bool reset_auto_increment);
716
 
bool mysql_truncate(Session& session, TableList *table_list);
 
914
bool mysql_truncate(Session& session, TableList *table_list, bool dont_send_ok);
717
915
TableShare *get_table_share(Session *session, TableList *table_list, char *key,
718
916
                             uint32_t key_length, uint32_t db_flags, int *error);
719
917
TableShare *get_cached_table_share(const char *db, const char *table_name);
720
918
bool reopen_name_locked_table(Session* session, TableList* table_list, bool link_in);
 
919
Table *table_cache_insert_placeholder(Session *session, const char *key,
 
920
                                      uint32_t key_length);
 
921
bool lock_table_name_if_not_cached(Session *session, const char *db,
 
922
                                   const char *table_name, Table **table);
 
923
bool reopen_table(Table *table);
721
924
bool reopen_tables(Session *session,bool get_locks,bool in_refresh);
 
925
void close_data_files_and_morph_locks(Session *session, const char *db,
 
926
                                      const char *table_name);
722
927
void close_handle_and_leave_table_as_lock(Table *table);
723
928
bool wait_for_tables(Session *session);
724
929
bool table_is_used(Table *table, bool wait_for_name_lock);
725
 
Table *drop_locked_tables(Session *session, const drizzled::TableIdentifier &identifier);
726
 
void abort_locked_tables(Session *session, const drizzled::TableIdentifier &identifier);
 
930
Table *drop_locked_tables(Session *session,const char *db, const char *table_name);
 
931
void abort_locked_tables(Session *session,const char *db, const char *table_name);
727
932
extern Field *not_found_field;
728
933
extern Field *view_ref_found;
729
934
 
743
948
Field *
744
949
find_field_in_table(Session *session, Table *table, const char *name, uint32_t length,
745
950
                    bool allow_rowid, uint32_t *cached_field_index_ptr);
 
951
Field *
 
952
find_field_in_table_sef(Table *table, const char *name);
746
953
 
747
 
} /* namespace drizzled */
748
954
 
749
955
#endif /* DRIZZLED_CURSOR_H */