~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/cursor.h

Merge in Stewart's FK work

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
20
20
#ifndef DRIZZLED_CURSOR_H
21
21
#define DRIZZLED_CURSOR_H
22
22
 
23
 
#include <drizzled/atomics.h>
24
 
#include <drizzled/definitions.h>
 
23
#include <drizzled/xid.h>
25
24
#include <drizzled/discrete_interval.h>
26
 
#include <drizzled/error_t.h>
27
 
#include <drizzled/ha_statistics.h>
28
 
#include <drizzled/handler_structs.h>
29
25
#include <drizzled/identifier.h>
30
 
#include <drizzled/key_map.h>
31
 
#include <drizzled/message/table.h>
 
26
 
 
27
/* Definitions for parameters to do with Cursor-routines */
 
28
 
 
29
#include <drizzled/thr_lock.h>
 
30
#include <drizzled/sql_string.h>
32
31
#include <drizzled/sql_list.h>
33
 
#include <drizzled/thr_lock.h>
34
 
#include <drizzled/xid.h>
 
32
#include <drizzled/plugin/storage_engine.h>
 
33
#include <drizzled/handler_structs.h>
 
34
#include <drizzled/ha_statistics.h>
 
35
#include <drizzled/atomics.h>
 
36
 
 
37
#include <drizzled/message/table.pb.h>
 
38
 
 
39
/* Bits to show what an alter table will do */
 
40
#include <drizzled/sql_bitmap.h>
35
41
 
36
42
#include <bitset>
37
43
#include <algorithm>
38
44
 
39
 
#include <drizzled/visibility.h>
40
 
 
41
45
namespace drizzled
42
46
{
43
47
 
45
49
 
46
50
typedef std::bitset<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
47
51
 
48
 
class AlterInfo;
49
 
class CreateField;
 
52
extern uint64_t refresh_version;  /* Increments on each reload */
 
53
 
 
54
class Table;
 
55
class TableList;
 
56
class TableShare;
 
57
class Select_Lex_Unit;
50
58
class ForeignKeyInfo;
 
59
struct order_st;
 
60
 
51
61
class Item;
52
 
class Item_ident;
 
62
 
53
63
class LEX;
54
64
class Select_Lex;
55
 
class Select_Lex_Unit;
56
 
class String;
57
 
class Table;
58
 
class TableList;
59
 
class TableShare;
 
65
class AlterInfo;
60
66
class select_result;
 
67
class CreateField;
61
68
class sys_var_str;
62
 
struct Order;
 
69
class Item_ident;
 
70
typedef struct st_sort_field SORT_FIELD;
63
71
 
64
72
typedef List<Item> List_item;
65
73
extern KEY_CREATE_INFO default_key_create_info;
69
77
 
70
78
typedef struct system_status_var system_status_var;
71
79
 
72
 
namespace optimizer { class CostVector; }
73
 
namespace plugin { class StorageEngine; }
 
80
namespace optimizer
 
81
{
 
82
  class CostVector;
 
83
}
74
84
 
75
85
/*
76
86
  bitmap with first N+1 bits set
135
145
  If a blob column has NULL value, then its length and blob data pointer
136
146
  must be set to 0.
137
147
*/
138
 
class DRIZZLED_API Cursor
 
148
class Cursor
139
149
{
140
 
  friend class SEAPITesterCursor;
141
 
  Table &table;               /* The current open table */
142
 
  plugin::StorageEngine &engine;      /* storage engine of this Cursor */
 
150
protected:
 
151
  TableShare *table_share;   /* The table definition */
 
152
  Table *table;               /* The current open table */
143
153
 
144
 
protected:
145
154
  ha_rows estimation_rows_to_insert;
146
 
 
 
155
  plugin::StorageEngine *engine;      /* storage engine of this Cursor */
147
156
public:
148
157
  inline plugin::StorageEngine *getEngine() const       /* table_type for handler */
149
158
  {
150
 
    return &engine;
 
159
    return engine;
151
160
  }
152
161
  unsigned char *ref;                           /* Pointer to current row */
153
162
  unsigned char *dup_ref;                       /* Pointer to duplicate row */
154
163
 
155
 
  TableShare *getShare();
156
 
 
157
 
  Table *getTable() const
 
164
  TableShare *getShare() const
158
165
  {
159
 
    return &table;
 
166
    return table_share;
160
167
  }
161
168
 
162
169
  ha_statistics stats;
205
212
  }
206
213
 
207
214
  /**
208
 
    Used by SHOW TABLE STATUS to get the current auto_inc from the engine
209
 
  */
210
 
  uint64_t getAutoIncrement()
211
 
  {
212
 
    return stats.auto_increment_value;
213
 
  }
214
 
 
215
 
  /**
216
215
    insert id for the current row (*autogenerated*; if not
217
216
    autogenerated, it's 0).
218
217
    At first successful insertion, this variable is stored into
225
224
  */
226
225
  Discrete_interval auto_inc_interval_for_cur_row;
227
226
 
228
 
  Cursor(plugin::StorageEngine &engine_arg, Table &share_arg);
 
227
  Cursor(plugin::StorageEngine &engine_arg, TableShare &share_arg);
229
228
  virtual ~Cursor(void);
230
229
  virtual Cursor *clone(memory::Root *mem_root);
231
230
 
232
231
  /* ha_ methods: pubilc wrappers for private virtual API */
233
232
 
234
 
  int ha_open(const identifier::Table &identifier, int mode, int test_if_locked);
235
 
  int startIndexScan(uint32_t idx, bool sorted) __attribute__ ((warn_unused_result));
 
233
  int ha_open(const TableIdentifier &identifier, Table *table, const char *name, int mode, int test_if_locked);
 
234
  int startIndexScan(uint32_t idx, bool sorted);
236
235
  int endIndexScan();
237
 
  int startTableScan(bool scan) __attribute__ ((warn_unused_result));
 
236
  int startTableScan(bool scan);
238
237
  int endTableScan();
239
238
  int ha_reset();
240
239
 
248
247
    and doDeleteRecord() below.
249
248
  */
250
249
  int ha_external_lock(Session *session, int lock_type);
251
 
  int insertRecord(unsigned char * buf) __attribute__ ((warn_unused_result));
252
 
  int updateRecord(const unsigned char * old_data, unsigned char * new_data) __attribute__ ((warn_unused_result));
253
 
  int deleteRecord(const unsigned char * buf) __attribute__ ((warn_unused_result));
 
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);
254
253
  void ha_release_auto_increment();
255
254
 
256
255
  /** to be actually called to get 'check()' functionality*/
269
268
 
270
269
  void adjust_next_insert_id_after_explicit_value(uint64_t nr);
271
270
  int update_auto_increment();
 
271
  virtual void change_table_ptr(Table *table_arg, TableShare *share);
272
272
 
273
273
  /* Estimates calculation */
274
274
  virtual double scan_time(void)
275
 
  { return static_cast<double>(stats.data_file_length) / IO_SIZE + 2; }
 
275
  { return uint64_t2double(stats.data_file_length) / IO_SIZE + 2; }
276
276
  virtual double read_time(uint32_t, uint32_t ranges, ha_rows rows)
277
 
  { return ranges + rows; }
 
277
  { return rows2double(ranges+rows); }
278
278
 
279
279
  virtual double index_only_read_time(uint32_t keynr, double records);
280
280
 
350
350
                                 const unsigned char * key,
351
351
                                 key_part_map keypart_map,
352
352
                                 enum ha_rkey_function find_flag);
353
 
  virtual int index_next(unsigned char *) __attribute__ ((warn_unused_result))
 
353
  virtual int index_next(unsigned char *)
354
354
   { return  HA_ERR_WRONG_COMMAND; }
355
355
  virtual int index_prev(unsigned char *)
356
356
   { return  HA_ERR_WRONG_COMMAND; }
476
476
    or partitioned.
477
477
 
478
478
    @note that one can NOT rely on table->in_use in store_lock().  It may
479
 
    refer to a different thread if called from abortLockForThread().
 
479
    refer to a different thread if called from mysql_lock_abort_for_thread().
480
480
 
481
481
    @note If the table is MERGE, store_lock() can return less locks
482
482
    than lock_count() claimed. This can happen when the MERGE children
523
523
    the corresponding 'ha_*' method above.
524
524
  */
525
525
 
526
 
  virtual int open(const char *, int , uint32_t ) { assert(0); return -1; }
527
 
  virtual int doOpen(const identifier::Table &identifier, int mode, uint32_t test_if_locked);
 
526
  virtual int open(const char *, int , uint32_t ) { assert(0); return -1; };
 
527
  virtual int doOpen(const TableIdentifier &identifier, int mode, uint32_t test_if_locked);
528
528
  virtual int doStartIndexScan(uint32_t idx, bool)
529
529
  { active_index= idx; return 0; }
530
530
  virtual int doEndIndexScan() { active_index= MAX_KEY; return 0; }
535
535
    if rnd_init allocates the cursor, second call should position it
536
536
    to the start of the table, no need to deallocate and allocate it again
537
537
  */
538
 
  virtual int doStartTableScan(bool scan) __attribute__ ((warn_unused_result)) = 0;
 
538
  virtual int doStartTableScan(bool scan)= 0;
539
539
  virtual int doEndTableScan() { return 0; }
540
540
  virtual int doInsertRecord(unsigned char *)
541
541
  {
584
584
  {
585
585
    return 0;
586
586
  }
587
 
  virtual void release_auto_increment(void) { return; }
 
587
  virtual void release_auto_increment(void) { return; };
588
588
  /** admin commands - called from mysql_admin_table */
589
589
  virtual int check(Session *)
590
590
  { return HA_ADMIN_NOT_IMPLEMENTED; }
640
640
/* basic stuff */
641
641
void ha_init_errors(void);
642
642
 
643
 
class SortField;
644
 
SortField *make_unireg_sortorder(Order *order, uint32_t *length,
645
 
                                 SortField *sortorder);
 
643
SORT_FIELD * make_unireg_sortorder(order_st *order, uint32_t *length,
 
644
                                   SORT_FIELD *sortorder);
646
645
int setup_order(Session *session, Item **ref_pointer_array, TableList *tables,
647
 
                List<Item> &fields, List <Item> &all_fields, Order *order);
 
646
                List<Item> &fields, List <Item> &all_fields, order_st *order);
648
647
int setup_group(Session *session, Item **ref_pointer_array, TableList *tables,
649
 
                List<Item> &fields, List<Item> &all_fields, Order *order,
 
648
                List<Item> &fields, List<Item> &all_fields, order_st *order,
650
649
                bool *hidden_group_fields);
651
650
bool fix_inner_refs(Session *session, List<Item> &all_fields, Select_Lex *select,
652
651
                    Item **ref_pointer_array);
655
654
                   uint64_t setup_tables_done_option);
656
655
void free_underlaid_joins(Session *session, Select_Lex *select);
657
656
 
658
 
bool handle_derived(LEX *lex, bool (*processor)(Session *session,
 
657
bool mysql_handle_derived(LEX *lex, bool (*processor)(Session *session,
659
658
                                                      LEX *lex,
660
659
                                                      TableList *table));
661
 
bool derived_prepare(Session *session, LEX *lex, TableList *t);
662
 
bool derived_filling(Session *session, LEX *lex, TableList *t);
 
660
bool mysql_derived_prepare(Session *session, LEX *lex, TableList *t);
 
661
bool mysql_derived_filling(Session *session, LEX *lex, TableList *t);
663
662
int prepare_create_field(CreateField *sql_field,
664
663
                         uint32_t *blob_columns,
665
664
                         int *timestamps, int *timestamps_with_niladic);
666
665
 
667
 
bool create_table(Session *session,
668
 
                  const identifier::Table &identifier,
669
 
                  HA_CREATE_INFO *create_info,
670
 
                  message::Table &table_proto,
671
 
                  AlterInfo *alter_info,
672
 
                  bool tmp_table, uint32_t select_field_count,
673
 
                  bool is_if_not_exists);
674
 
 
675
 
bool create_table_no_lock(Session *session,
676
 
                          const identifier::Table &identifier,
677
 
                          HA_CREATE_INFO *create_info,
678
 
                          message::Table &table_proto,
679
 
                          AlterInfo *alter_info,
680
 
                          bool tmp_table, uint32_t select_field_count,
681
 
                          bool is_if_not_exists);
682
 
 
683
 
bool create_like_table(Session* session,
684
 
                       identifier::Table::const_reference destination_identifier,
685
 
                       identifier::Table::const_reference source_identifier,
686
 
                       message::Table &create_table_proto,
687
 
                       bool is_if_not_exists,
688
 
                       bool is_engine_set);
689
 
 
690
 
bool rename_table(Session &session,
 
666
bool mysql_create_table(Session *session,
 
667
                        TableIdentifier &identifier,
 
668
                        HA_CREATE_INFO *create_info,
 
669
                        message::Table &table_proto,
 
670
                        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
                                TableIdentifier &identifier,
 
676
                                HA_CREATE_INFO *create_info,
 
677
                                message::Table &table_proto,
 
678
                                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
                             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,
691
690
                        plugin::StorageEngine *base,
692
 
                        const identifier::Table &old_identifier,
693
 
                        const identifier::Table &new_identifier);
 
691
                        TableIdentifier &old_identifier,
 
692
                        TableIdentifier &new_identifier);
694
693
 
695
 
bool prepare_update(Session *session, TableList *table_list,
696
 
                          Item **conds, uint32_t order_num, Order *order);
697
 
int update_query(Session *session,TableList *tables,List<Item> &fields,
 
694
bool mysql_prepare_update(Session *session, TableList *table_list,
 
695
                          Item **conds, uint32_t order_num, order_st *order);
 
696
int mysql_update(Session *session,TableList *tables,List<Item> &fields,
698
697
                 List<Item> &values,COND *conds,
699
 
                 uint32_t order_num, Order *order, ha_rows limit,
 
698
                 uint32_t order_num, order_st *order, ha_rows limit,
700
699
                 enum enum_duplicates handle_duplicates, bool ignore);
701
 
bool prepare_insert(Session *session, TableList *table_list, Table *table,
 
700
bool mysql_prepare_insert(Session *session, TableList *table_list, Table *table,
702
701
                          List<Item> &fields, List_item *values,
703
702
                          List<Item> &update_fields,
704
703
                          List<Item> &update_values, enum_duplicates duplic,
705
704
                          COND **where, bool select_insert,
706
705
                          bool check_fields, bool abort_on_warning);
707
 
bool insert_query(Session *session,TableList *table,List<Item> &fields,
 
706
bool mysql_insert(Session *session,TableList *table,List<Item> &fields,
708
707
                  List<List_item> &values, List<Item> &update_fields,
709
708
                  List<Item> &update_values, enum_duplicates flag,
710
709
                  bool ignore);
711
710
int check_that_all_fields_are_given_values(Session *session, Table *entry,
712
711
                                           TableList *table_list);
713
 
int prepare_delete(Session *session, TableList *table_list, Item **conds);
714
 
bool delete_query(Session *session, TableList *table_list, COND *conds,
 
712
int mysql_prepare_delete(Session *session, TableList *table_list, Item **conds);
 
713
bool mysql_delete(Session *session, TableList *table_list, COND *conds,
715
714
                  SQL_LIST *order, ha_rows rows, uint64_t options,
716
715
                  bool reset_auto_increment);
717
 
bool truncate(Session& session, TableList *table_list);
 
716
bool mysql_truncate(Session& session, TableList *table_list);
718
717
TableShare *get_table_share(Session *session, TableList *table_list, char *key,
719
718
                             uint32_t key_length, uint32_t db_flags, int *error);
720
719
TableShare *get_cached_table_share(const char *db, const char *table_name);
723
722
void close_handle_and_leave_table_as_lock(Table *table);
724
723
bool wait_for_tables(Session *session);
725
724
bool table_is_used(Table *table, bool wait_for_name_lock);
726
 
Table *drop_locked_tables(Session *session, const drizzled::identifier::Table &identifier);
727
 
void abort_locked_tables(Session *session, const drizzled::identifier::Table &identifier);
 
725
Table *drop_locked_tables(Session *session, const drizzled::TableIdentifier &identifier);
 
726
void abort_locked_tables(Session *session, const drizzled::TableIdentifier &identifier);
728
727
extern Field *not_found_field;
729
728
extern Field *view_ref_found;
730
729