~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/cursor.h

  • Committer: Andrew Hutchings
  • Date: 2010-10-23 10:43:00 UTC
  • mto: (1874.2.1 merge)
  • mto: This revision was merged to the branch mainline in revision 1876.
  • Revision ID: andrew@linuxjedi.co.uk-20101023104300-90rgyfw2eokcvsp3
Make port 4427 the default for client apps

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