~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/cursor.h

  • Committer: Brian Aker
  • Date: 2011-02-22 06:12:02 UTC
  • mfrom: (2190.1.6 drizzle-build)
  • Revision ID: brian@tangent.org-20110222061202-k03czxykqy4x9hjs
List update, header fixes, multiple symbols, and David deletes some code.

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