Drizzled Public API Documentation

ha_innodb.h

00001 /*****************************************************************************
00002 
00003 Copyright (C) 2000, 2010, MySQL AB & Innobase Oy. All Rights Reserved.
00004 
00005 This program is free software; you can redistribute it and/or modify it under
00006 the terms of the GNU General Public License as published by the Free Software
00007 Foundation; version 2 of the License.
00008 
00009 This program is distributed in the hope that it will be useful, but WITHOUT
00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
00012 
00013 You should have received a copy of the GNU General Public License along with
00014 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
00015 St, Fifth Floor, Boston, MA 02110-1301 USA
00016 
00017 *****************************************************************************/
00018 
00019 /*
00020   This file is based on ha_berkeley.h of MySQL distribution
00021 
00022   This file defines the Innodb Cursor: the interface between MySQL and
00023   Innodb
00024 */
00025 
00026 #pragma once
00027 #ifndef INNODB_HANDLER_HA_INNODB_H
00028 #define INNODB_HANDLER_HA_INNODB_H
00029 
00030 #include <drizzled/cursor.h>
00031 #include <drizzled/thr_lock.h>
00032 #include <drizzled/plugin/transactional_storage_engine.h>
00033 
00034 using namespace drizzled;
00035 
00036 /* Structure defines translation table between mysql index and innodb
00037 index structures */
00038 typedef struct innodb_idx_translate_struct {
00039   ulint   index_count;  
00041   ulint   array_size; 
00042   dict_index_t**  index_mapping;  
00045 } innodb_idx_translate_t;
00046 
00048 typedef struct st_innobase_share {
00049   THR_LOCK  lock;   
00051   char  table_name[FN_REFLEN];  
00052   uint    use_count;  
00055   void*   table_name_hash;
00056   innodb_idx_translate_t  idx_trans_tbl;  
00060         st_innobase_share(const char *arg) :
00061           use_count(0)
00062         {
00063           strncpy(table_name, arg, FN_REFLEN);
00064         }
00065 
00066 } INNOBASE_SHARE;
00067 
00068 
00070 struct dict_index_struct;
00072 struct row_prebuilt_struct;
00073 
00075 typedef struct dict_index_struct dict_index_t;
00077 typedef struct row_prebuilt_struct row_prebuilt_t;
00078 
00080 class ha_innobase: public Cursor
00081 {
00082   row_prebuilt_t* prebuilt; 
00085   Session*  user_session; 
00088   THR_LOCK_DATA lock;
00089   INNOBASE_SHARE* share;    
00092         std::vector<unsigned char> upd_buff; 
00093         std::vector<unsigned char> key_val_buff; 
00096   ulong   upd_and_key_val_buff_len;
00097           /* the length of each of the previous
00098           two buffers */
00099   uint    primary_key;
00100   ulong   start_of_scan;  
00103   uint    last_match_mode;/* match mode of the latest search:
00104           ROW_SEL_EXACT, ROW_SEL_EXACT_PREFIX,
00105           or undefined */
00106   uint    num_write_row;  
00108   UNIV_INTERN uint store_key_val_for_row(uint keynr, char* buff, 
00109                                    uint buff_len, const unsigned char* record);
00110   UNIV_INTERN void update_session(Session* session);
00111   UNIV_INTERN int change_active_index(uint32_t keynr);
00112   UNIV_INTERN int general_fetch(unsigned char* buf, uint32_t direction, uint32_t match_mode);
00113   UNIV_INTERN ulint innobase_lock_autoinc();
00114   UNIV_INTERN uint64_t innobase_peek_autoinc();
00115   UNIV_INTERN ulint innobase_set_max_autoinc(uint64_t auto_inc);
00116   UNIV_INTERN ulint innobase_reset_autoinc(uint64_t auto_inc);
00117   UNIV_INTERN ulint innobase_get_autoinc(uint64_t* value);
00118   ulint innobase_update_autoinc(uint64_t  auto_inc);
00119   UNIV_INTERN void innobase_initialize_autoinc();
00120   UNIV_INTERN dict_index_t* innobase_get_index(uint keynr);
00121 
00122   /* Init values for the class: */
00123  public:
00124   UNIV_INTERN ha_innobase(plugin::StorageEngine &engine,
00125                                 Table &table_arg);
00126   UNIV_INTERN ~ha_innobase();
00135   UNIV_INTERN plugin::TransactionalStorageEngine *getTransactionalEngine()
00136   {
00137     return static_cast<plugin::TransactionalStorageEngine *>(getEngine());
00138   }
00139 
00140   UNIV_INTERN const char* index_type(uint key_number);
00141   UNIV_INTERN const key_map* keys_to_use_for_scanning();
00142 
00143   UNIV_INTERN int doOpen(const drizzled::identifier::Table &identifier, int mode, uint test_if_locked);
00144   UNIV_INTERN int close(void);
00145   UNIV_INTERN double scan_time();
00146   UNIV_INTERN double read_time(uint index, uint ranges, ha_rows rows);
00147 
00148   UNIV_INTERN int doInsertRecord(unsigned char * buf);
00149   UNIV_INTERN int doUpdateRecord(const unsigned char * old_data, unsigned char * new_data);
00150   UNIV_INTERN int doDeleteRecord(const unsigned char * buf);
00151   UNIV_INTERN bool was_semi_consistent_read();
00152   UNIV_INTERN void try_semi_consistent_read(bool yes);
00153   UNIV_INTERN void unlock_row();
00154 
00155   UNIV_INTERN int doStartIndexScan(uint index, bool sorted);
00156   UNIV_INTERN int doEndIndexScan();
00157   UNIV_INTERN int index_read(unsigned char * buf, const unsigned char * key,
00158     uint key_len, enum ha_rkey_function find_flag);
00159   UNIV_INTERN int index_read_idx(unsigned char * buf, uint index, const unsigned char * key,
00160          uint key_len, enum ha_rkey_function find_flag);
00161   UNIV_INTERN int index_read_last(unsigned char * buf, const unsigned char * key, uint key_len);
00162   UNIV_INTERN int index_next(unsigned char * buf);
00163   UNIV_INTERN int index_next_same(unsigned char * buf, const unsigned char *key, uint keylen);
00164   UNIV_INTERN int index_prev(unsigned char * buf);
00165   UNIV_INTERN int index_first(unsigned char * buf);
00166   UNIV_INTERN int index_last(unsigned char * buf);
00167 
00168   UNIV_INTERN int doStartTableScan(bool scan);
00169   UNIV_INTERN int doEndTableScan();
00170   UNIV_INTERN int rnd_next(unsigned char *buf);
00171   UNIV_INTERN int rnd_pos(unsigned char * buf, unsigned char *pos);
00172 
00173   UNIV_INTERN void position(const unsigned char *record);
00174   UNIV_INTERN int info(uint);
00175   UNIV_INTERN int analyze(Session* session);
00176   UNIV_INTERN int discard_or_import_tablespace(bool discard);
00177   UNIV_INTERN int extra(enum ha_extra_function operation);
00178         UNIV_INTERN int reset();
00179   UNIV_INTERN int external_lock(Session *session, int lock_type);
00180   void position(unsigned char *record);
00181   UNIV_INTERN ha_rows records_in_range(uint inx, key_range *min_key, key_range
00182                 *max_key);
00183   UNIV_INTERN ha_rows estimate_rows_upper_bound();
00184 
00185   UNIV_INTERN int delete_all_rows();
00186   UNIV_INTERN int check(Session* session);
00187   UNIV_INTERN char* update_table_comment(const char* comment);
00188   UNIV_INTERN char* get_foreign_key_create_info();
00189   UNIV_INTERN int get_foreign_key_list(Session *session, List<ForeignKeyInfo> *f_key_list);
00190   UNIV_INTERN bool can_switch_engines();
00191   UNIV_INTERN uint referenced_by_foreign_key();
00192   UNIV_INTERN void free_foreign_key_create_info(char* str);
00193   UNIV_INTERN THR_LOCK_DATA **store_lock(Session *session, THR_LOCK_DATA **to,
00194           enum thr_lock_type lock_type);
00195         UNIV_INTERN virtual void get_auto_increment(uint64_t offset, 
00196                                                     uint64_t increment,
00197                                                     uint64_t nb_desired_values,
00198                                                     uint64_t *first_value,
00199                                                     uint64_t *nb_reserved_values);
00200         UNIV_INTERN int reset_auto_increment(uint64_t value);
00201 
00202   UNIV_INTERN bool primary_key_is_clustered();
00203   UNIV_INTERN int cmp_ref(const unsigned char *ref1, const unsigned char *ref2);
00205         // Don't use these, I have just left them in here as reference for
00206         // the future. -Brian 
00207 #if 0
00208   UNIV_INTERN int add_index(Session *session, TABLE *table_arg, KeyInfo *key_info, uint num_of_keys);
00209   UNIV_INTERN int prepare_drop_index(Session *session,
00210                                            TABLE *table_arg,
00211                                            uint *key_num,
00212                                            uint num_of_keys);
00213         UNIV_INTERN int final_drop_index(Session *session, TABLE *table_arg);
00214 #endif
00215 
00216 public:
00217   int read_range_first(const key_range *start_key, const key_range *end_key,
00218            bool eq_range_arg, bool sorted);
00219   int read_range_next();
00220 };
00221 
00222 
00226 const char* drizzle_bin_log_file_name(void);
00227 
00231 uint64_t drizzle_bin_log_file_pos(void);
00232 
00239 int session_slave_thread(const Session *session);
00240 
00241 typedef struct trx_struct trx_t;
00242 /********************************************************************/
00248 UNIV_INTERN
00249 int
00250 convert_error_code_to_mysql(
00251 /*========================*/
00252   int   error,    
00253   ulint   flags,    
00254   Session   *session);  
00256 /*********************************************************************/
00259 UNIV_INTERN
00260 trx_t*
00261 innobase_trx_allocate(
00262 /*==================*/
00263   Session   *session);  
00265 /***********************************************************************
00266 This function checks each index name for a table against reserved
00267 system default primary index name 'GEN_CLUST_INDEX'. If a name matches,
00268 this function pushes an error message to the client, and returns true. */
00269 bool
00270 innobase_index_name_is_reserved(
00271 /*============================*/
00272           /* out: true if index name matches a
00273           reserved name */
00274   const trx_t*  trx,    /* in: InnoDB transaction handle */
00275   const drizzled::KeyInfo*  key_info,/* in: Indexes to be created */
00276   ulint   num_of_keys); /* in: Number of indexes to
00277           be created. */
00278 
00279 #endif /* INNODB_HANDLER_HA_INNODB_H */