MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ha_example Class Reference

Class definition for the storage engine. More...

#include <ha_example.h>

Inheritance diagram for ha_example:
Collaboration diagram for ha_example:

Public Member Functions

 ha_example (handlerton *hton, TABLE_SHARE *table_arg)
const char * table_type () const
 The name that will be used for display purposes.
const char * index_type (uint inx)
 The name of the index type that will be used for display. Don't implement this method unless you really have indexes.
const char ** bas_ext () const
 The file extensions.
ulonglong table_flags () const
 This is a list of flags that indicate what functionality the storage engine implements. The current table flags are documented in handler.h.
ulong index_flags (uint inx, uint part, bool all_parts) const
 This is a bitmap of flags that indicates how the storage engine implements indexes. The current index flags are documented in handler.h. If you do not implement indexes, just return zero here.
uint max_supported_record_length () const
 unireg.cc will call max_supported_record_length(), max_supported_keys(), max_supported_key_parts(), uint max_supported_key_length() to make sure that the storage engine can handle the data it is about to send. Return real limits of your storage engine here; MySQL will do min(your_limits, MySQL_limits) automatically.
uint max_supported_keys () const
 unireg.cc will call this to make sure that the storage engine can handle the data it is about to send. Return real limits of your storage engine here; MySQL will do min(your_limits, MySQL_limits) automatically.
uint max_supported_key_parts () const
 unireg.cc will call this to make sure that the storage engine can handle the data it is about to send. Return real limits of your storage engine here; MySQL will do min(your_limits, MySQL_limits) automatically.
uint max_supported_key_length () const
 unireg.cc will call this to make sure that the storage engine can handle the data it is about to send. Return real limits of your storage engine here; MySQL will do min(your_limits, MySQL_limits) automatically.
virtual double scan_time ()
 Called in test_quick_select to determine if indexes should be used.
virtual double read_time (uint, uint, ha_rows rows)
 This method will never be called if you do not implement indexes.
int open (const char *name, int mode, uint test_if_locked)
 We implement this in ha_example.cc; it's a required method.
int close (void)
 We implement this in ha_example.cc; it's a required method.
int write_row (uchar *buf)
 We implement this in ha_example.cc. It's not an obligatory method; skip it and and MySQL will treat it as not implemented.
int update_row (const uchar *old_data, uchar *new_data)
 We implement this in ha_example.cc. It's not an obligatory method; skip it and and MySQL will treat it as not implemented.
int delete_row (const uchar *buf)
 We implement this in ha_example.cc. It's not an obligatory method; skip it and and MySQL will treat it as not implemented.
int index_read_map (uchar *buf, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag)
 We implement this in ha_example.cc. It's not an obligatory method; skip it and and MySQL will treat it as not implemented.
int index_next (uchar *buf)
 We implement this in ha_example.cc. It's not an obligatory method; skip it and and MySQL will treat it as not implemented.
int index_prev (uchar *buf)
 We implement this in ha_example.cc. It's not an obligatory method; skip it and and MySQL will treat it as not implemented.
int index_first (uchar *buf)
 We implement this in ha_example.cc. It's not an obligatory method; skip it and and MySQL will treat it as not implemented.
int index_last (uchar *buf)
 We implement this in ha_example.cc. It's not an obligatory method; skip it and and MySQL will treat it as not implemented.
int rnd_init (bool scan)
 Unlike index_init(), rnd_init() can be called two consecutive times without rnd_end() in between (it only makes sense if scan=1). In this case, the second call should prepare for the new table scan (e.g if rnd_init() allocates the cursor, the second call should position the cursor to the start of the table; no need to deallocate and allocate it again. This is a required method.
int rnd_end ()
int rnd_next (uchar *buf)
 required
int rnd_pos (uchar *buf, uchar *pos)
 required
void position (const uchar *record)
 required
int info (uint)
 required
int extra (enum ha_extra_function operation)
 extra() is called whenever the server wishes to send a hint to the storage engine. The myisam engine implements the most hints. ha_innodb.cc has the most exhaustive list of these hints.
int external_lock (THD *thd, int lock_type)
 required
int delete_all_rows (void)
 Used to delete all rows in a table, including cases of truncate and cases where the optimizer realizes that all rows will be removed as a result of an SQL statement.
int truncate ()
 Used for handler specific truncate table. The table is locked in exclusive mode and handler is responsible for reseting the auto- increment counter.
ha_rows records_in_range (uint inx, key_range *min_key, key_range *max_key)
 Given a starting key and an ending key, estimate the number of rows that will exist between the two keys.
int delete_table (const char *from)
 Used to delete a table. By the time delete_table() has been called all opened references to this table will have been closed (and your globally shared references released). The variable name will just be the name of the table. You will need to remove any files you have created at this point.
int rename_table (const char *from, const char *to)
 Renames a table from one name to another via an alter table call.
int create (const char *name, TABLE *form, HA_CREATE_INFO *create_info)
 required
THR_LOCK_DATA ** store_lock (THD *thd, THR_LOCK_DATA **to, enum thr_lock_type lock_type)
 required
- Public Member Functions inherited from handler
virtual void unbind_psi ()
virtual void rebind_psi ()
 handler (handlerton *ht_arg, TABLE_SHARE *share_arg)
virtual handlerclone (const char *name, MEM_ROOT *mem_root)
void init ()
int ha_open (TABLE *table, const char *name, int mode, int test_if_locked)
 Open database-handler.
int ha_close (void)
int ha_index_init (uint idx, bool sorted)
int ha_index_end ()
int ha_rnd_init (bool scan)
int ha_rnd_end ()
int ha_rnd_next (uchar *buf)
int ha_rnd_pos (uchar *buf, uchar *pos)
int ha_index_read_map (uchar *buf, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag)
int ha_index_read_last_map (uchar *buf, const uchar *key, key_part_map keypart_map)
int ha_index_read_idx_map (uchar *buf, uint index, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag)
int ha_index_next (uchar *buf)
int ha_index_prev (uchar *buf)
int ha_index_first (uchar *buf)
int ha_index_last (uchar *buf)
int ha_index_next_same (uchar *buf, const uchar *key, uint keylen)
int ha_index_read (uchar *buf, const uchar *key, uint key_len, enum ha_rkey_function find_flag)
int ha_index_read_last (uchar *buf, const uchar *key, uint key_len)
int ha_reset ()
 Check handler usage and reset state of file to after 'open'.
int ha_index_or_rnd_end ()
Table_flags ha_table_flags () const
int ha_external_lock (THD *thd, int lock_type)
int ha_write_row (uchar *buf)
int ha_update_row (const uchar *old_data, uchar *new_data)
int ha_delete_row (const uchar *buf)
void ha_release_auto_increment ()
int check_collation_compatibility ()
int ha_check_for_upgrade (HA_CHECK_OPT *check_opt)
int ha_check (THD *thd, HA_CHECK_OPT *check_opt)
int ha_repair (THD *thd, HA_CHECK_OPT *check_opt)
void ha_start_bulk_insert (ha_rows rows)
int ha_end_bulk_insert ()
int ha_bulk_update_row (const uchar *old_data, uchar *new_data, uint *dup_key_found)
int ha_delete_all_rows ()
int ha_truncate ()
int ha_reset_auto_increment (ulonglong value)
int ha_optimize (THD *thd, HA_CHECK_OPT *check_opt)
int ha_analyze (THD *thd, HA_CHECK_OPT *check_opt)
bool ha_check_and_repair (THD *thd)
int ha_disable_indexes (uint mode)
int ha_enable_indexes (uint mode)
int ha_discard_or_import_tablespace (my_bool discard)
int ha_rename_table (const char *from, const char *to)
int ha_delete_table (const char *name)
void ha_drop_table (const char *name)
int ha_create (const char *name, TABLE *form, HA_CREATE_INFO *info)
int ha_create_handler_files (const char *name, const char *old_name, int action_flag, HA_CREATE_INFO *info)
int ha_change_partitions (HA_CREATE_INFO *create_info, const char *path, ulonglong *const copied, ulonglong *const deleted, const uchar *pack_frm_data, size_t pack_frm_len)
int ha_drop_partitions (const char *path)
int ha_rename_partitions (const char *path)
void adjust_next_insert_id_after_explicit_value (ulonglong nr)
int update_auto_increment ()
virtual void print_error (int error, myf errflag)
virtual bool get_error_message (int error, String *buf)
uint get_dup_key (int error)
virtual bool get_foreign_dup_key (char *child_table_name, uint child_table_name_len, char *child_key_name, uint child_key_name_len)
virtual void change_table_ptr (TABLE *table_arg, TABLE_SHARE *share)
virtual double index_only_read_time (uint keynr, double records)
virtual longlong get_memory_buffer_size () const
virtual ha_rows multi_range_read_info_const (uint keyno, RANGE_SEQ_IF *seq, void *seq_init_param, uint n_ranges, uint *bufsz, uint *flags, Cost_estimate *cost)
virtual ha_rows multi_range_read_info (uint keyno, uint n_ranges, uint keys, uint *bufsz, uint *flags, Cost_estimate *cost)
virtual int multi_range_read_init (RANGE_SEQ_IF *seq, void *seq_init_param, uint n_ranges, uint mode, HANDLER_BUFFER *buf)
virtual int multi_range_read_next (char **range_info)
virtual const key_mapkeys_to_use_for_scanning ()
bool has_transactions ()
virtual uint extra_rec_buf_length () const
virtual bool is_fatal_error (int error, uint flags)
virtual ha_rows records ()
virtual ha_rows estimate_rows_upper_bound ()
virtual enum row_type get_row_type () const
virtual void column_bitmaps_signal ()
 MySQL signal that it changed the column bitmap.
uint get_index (void) const
virtual bool start_bulk_update ()
virtual bool start_bulk_delete ()
virtual int exec_bulk_update (uint *dup_key_found)
virtual void end_bulk_update ()
virtual int end_bulk_delete ()
virtual int read_range_first (const key_range *start_key, const key_range *end_key, bool eq_range, bool sorted)
 Read first row between two ranges. Store ranges for future calls to read_range_next.
virtual int read_range_next ()
 Read next row between two endpoints.
void set_end_range (const key_range *range, enum_range_scan_direction direction)
int compare_key (key_range *range)
int compare_key_icp (const key_range *range) const
virtual int ft_init ()
void ft_end ()
virtual FT_INFOft_init_ext (uint flags, uint inx, String *key)
virtual int ft_read (uchar *buf)
virtual int rnd_pos_by_record (uchar *record)
virtual int read_first_row (uchar *buf, uint primary_key)
virtual int restart_rnd_next (uchar *buf, uchar *pos)
virtual int rnd_same (uchar *buf, uint inx)
virtual void get_dynamic_partition_info (PARTITION_STATS *stat_info, uint part_id)
virtual uint32 calculate_key_hash_value (Field **field_array)
virtual int extra_opt (enum ha_extra_function operation, ulong cache_size)
virtual bool start_read_removal (void)
virtual ha_rows end_read_removal (void)
virtual bool was_semi_consistent_read ()
virtual void try_semi_consistent_read (bool)
virtual void unlock_row ()
virtual int start_stmt (THD *thd, thr_lock_type lock_type)
virtual void get_auto_increment (ulonglong offset, ulonglong increment, ulonglong nb_desired_values, ulonglong *first_value, ulonglong *nb_reserved_values)
void set_next_insert_id (ulonglong id)
void restore_auto_increment (ulonglong prev_insert_id)
virtual void update_create_info (HA_CREATE_INFO *create_info)
int check_old_types ()
virtual int assign_to_keycache (THD *thd, HA_CHECK_OPT *check_opt)
virtual int preload_keys (THD *thd, HA_CHECK_OPT *check_opt)
virtual int indexes_are_disabled (void)
virtual char * update_table_comment (const char *comment)
virtual void append_create_info (String *packet)
virtual bool is_fk_defined_on_table_or_index (uint index)
virtual char * get_foreign_key_create_info ()
virtual bool can_switch_engines ()
virtual int get_foreign_key_list (THD *thd, List< FOREIGN_KEY_INFO > *f_key_list)
virtual int get_parent_foreign_key_list (THD *thd, List< FOREIGN_KEY_INFO > *f_key_list)
virtual uint referenced_by_foreign_key ()
virtual void init_table_handle_for_HANDLER ()
virtual void free_foreign_key_create_info (char *str)
virtual int get_default_no_partitions (HA_CREATE_INFO *info)
virtual void set_auto_partitions (partition_info *part_info)
virtual bool get_no_parts (const char *name, uint *no_parts)
virtual void set_part_info (partition_info *part_info, bool early)
uint max_record_length () const
uint max_keys () const
uint max_key_parts () const
uint max_key_length () const
uint max_key_part_length () const
virtual uint max_supported_key_part_length () const
virtual uint min_record_length (uint options) const
virtual bool low_byte_first () const
virtual uint checksum () const
virtual bool is_crashed () const
virtual bool auto_repair () const
virtual uint lock_count (void) const
virtual uint8 table_cache_type ()
virtual my_bool register_query_cache_table (THD *thd, char *table_key, uint key_length, qc_engine_callback *engine_callback, ulonglong *engine_data)
 Register a named table with a call back function to the query cache.
virtual bool primary_key_is_clustered ()
virtual int cmp_ref (const uchar *ref1, const uchar *ref2)
virtual const Itemcond_push (const Item *cond)
virtual void cond_pop ()
virtual Itemidx_cond_push (uint keyno, Item *idx_cond)
virtual void cancel_pushed_idx_cond ()
virtual uint number_of_pushed_joins () const
virtual const TABLEroot_of_pushed_join () const
virtual const TABLEparent_of_pushed_join () const
virtual int index_read_pushed (uchar *buf, const uchar *key, key_part_map keypart_map)
virtual int index_next_pushed (uchar *buf)
virtual bool check_if_incompatible_data (HA_CREATE_INFO *create_info, uint table_changes)
virtual enum_alter_inplace_result check_if_supported_inplace_alter (TABLE *altered_table, Alter_inplace_info *ha_alter_info)
bool ha_prepare_inplace_alter_table (TABLE *altered_table, Alter_inplace_info *ha_alter_info)
bool ha_inplace_alter_table (TABLE *altered_table, Alter_inplace_info *ha_alter_info)
bool ha_commit_inplace_alter_table (TABLE *altered_table, Alter_inplace_info *ha_alter_info, bool commit)
void ha_notify_table_changed ()
virtual void use_hidden_primary_key ()
virtual uint alter_table_flags (uint flags)
virtual int bulk_update_row (const uchar *old_data, uchar *new_data, uint *dup_key_found)
virtual int reset_auto_increment (ulonglong value)
virtual int optimize (THD *thd, HA_CHECK_OPT *check_opt)
virtual int analyze (THD *thd, HA_CHECK_OPT *check_opt)
virtual bool check_and_repair (THD *thd)
virtual int disable_indexes (uint mode)
virtual int enable_indexes (uint mode)
virtual int discard_or_import_tablespace (my_bool discard)
virtual void drop_table (const char *name)
virtual int create_handler_files (const char *name, const char *old_name, int action_flag, HA_CREATE_INFO *info)
virtual int change_partitions (HA_CREATE_INFO *create_info, const char *path, ulonglong *const copied, ulonglong *const deleted, const uchar *pack_frm_data, size_t pack_frm_len)
virtual int drop_partitions (const char *path)
virtual int rename_partitions (const char *path)
virtual bool set_ha_share_ref (Handler_share **arg_ha_share)
int get_lock_type () const

Additional Inherited Members

- Public Types inherited from handler
enum  enum_range_scan_direction { RANGE_SCAN_ASC, RANGE_SCAN_DESC }
enum  { NONE = 0, INDEX, RND }
typedef ulonglong Table_flags
- Static Public Member Functions inherited from Sql_alloc
static void * operator new (size_t size) throw ()
static void * operator new[] (size_t size) throw ()
static void * operator new[] (size_t size, MEM_ROOT *mem_root) throw ()
static void * operator new (size_t size, MEM_ROOT *mem_root) throw ()
static void operator delete (void *ptr, size_t size)
static void operator delete (void *ptr, MEM_ROOT *mem_root)
static void operator delete[] (void *ptr, MEM_ROOT *mem_root)
static void operator delete[] (void *ptr, size_t size)
- Public Attributes inherited from handler
handlertonht
uchar * ref
uchar * dup_ref
ha_statistics stats
range_seq_t mrr_iter
RANGE_SEQ_IF mrr_funcs
HANDLER_BUFFERmulti_range_buffer
uint ranges_in_seq
bool mrr_is_output_sorted
bool mrr_have_range
KEY_MULTI_RANGE mrr_cur_range
key_rangeend_range
uint errkey
uint key_used_on_scan
uint active_index
uint ref_length
FT_INFOft_handler
enum handler:: { ... }  inited
bool implicit_emptied
const Itempushed_cond
Itempushed_idx_cond
uint pushed_idx_cond_keyno
ulonglong next_insert_id
ulonglong insert_id_for_cur_row
Discrete_interval auto_inc_interval_for_cur_row
uint auto_inc_intervals_count
PSI_table * m_psi
- Protected Member Functions inherited from handler
virtual int index_read_idx_map (uchar *buf, uint index, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag)
 Positions an index cursor to the index specified in argument. Fetches the row if available. If the key value is null, begin at the first key of the index.
virtual int index_next_same (uchar *buf, const uchar *key, uint keylen)
virtual int index_read_last_map (uchar *buf, const uchar *key, key_part_map keypart_map)
 The following functions works like index_read, but it find the last row with the current key value or prefix.
virtual bool prepare_inplace_alter_table (TABLE *altered_table, Alter_inplace_info *ha_alter_info)
virtual bool inplace_alter_table (TABLE *altered_table, Alter_inplace_info *ha_alter_info)
virtual bool commit_inplace_alter_table (TABLE *altered_table, Alter_inplace_info *ha_alter_info, bool commit)
virtual void notify_table_changed ()
void ha_statistic_increment (ulonglong SSV::*offset) const
void ** ha_data (THD *) const
THD * ha_thd (void) const
PSI_table_share * ha_table_share_psi (const TABLE_SHARE *share) const
virtual int index_read (uchar *buf, const uchar *key, uint key_len, enum ha_rkey_function find_flag)
virtual int index_read_last (uchar *buf, const uchar *key, uint key_len)
Handler_shareget_ha_share_ptr ()
void set_ha_share_ptr (Handler_share *arg_ha_share)
void lock_shared_ha_data ()
void unlock_shared_ha_data ()
- Protected Attributes inherited from handler
TABLE_SHAREtable_share
TABLEtable
Table_flags cached_table_flags
ha_rows estimation_rows_to_insert
KEY_PART_INFOrange_key_part
bool eq_range
bool in_range_check_pushed_down

Detailed Description

Class definition for the storage engine.

Definition at line 58 of file ha_example.h.

Member Function Documentation

int ha_example::close ( void  )
virtual

We implement this in ha_example.cc; it's a required method.

Closes a table.

Called from sql_base.cc, sql_select.cc, and table.cc. In sql_select.cc it is only used to close up temporary tables or during the process where a temporary table is converted over to being a myisam table.

For sql_base.cc look at close_data_tables().

See Also
sql_base.cc, sql_select.cc and table.cc

Implements handler.

Definition at line 323 of file ha_example.cc.

int ha_example::create ( const char *  name,
TABLE table_arg,
HA_CREATE_INFO create_info 
)
virtual

required

create() is called to create a database. The variable name will have the name of the table.

When create() is called you do not need to worry about opening the table. Also, the .frm file will have already been created so adjusting create_info is not necessary. You can overwrite the .frm file at this point if you wish to change the table definition, but there are no methods currently provided for doing so.

Called from handle.cc by ha_create_table().

See Also
ha_create_table() in handle.cc

Implements handler.

Definition at line 901 of file ha_example.cc.

int ha_example::delete_all_rows ( void  )
virtual

Used to delete all rows in a table, including cases of truncate and cases where the optimizer realizes that all rows will be removed as a result of an SQL statement.

Called from item_sum.cc by Item_func_group_concat::clear(), Item_sum_count_distinct::clear(), and Item_func_group_concat::clear(). Called from sql_delete.cc by mysql_delete(). Called from sql_select.cc by JOIN::reinit(). Called from sql_union.cc by st_select_lex_unit::exec().

See Also
Item_func_group_concat::clear(), Item_sum_count_distinct::clear() and Item_func_group_concat::clear() in item_sum.cc; mysql_delete() in sql_delete.cc; JOIN::reinit() in sql_select.cc and st_select_lex_unit::exec() in sql_union.cc.

Reimplemented from handler.

Definition at line 711 of file ha_example.cc.

int ha_example::delete_row ( const uchar *  buf)

We implement this in ha_example.cc. It's not an obligatory method; skip it and and MySQL will treat it as not implemented.

This will delete a row. buf will contain a copy of the row to be deleted. The server will call this right after the current row has been called (from either a previous rnd_nexT() or index call).

If you keep a pointer to the last row or can access a primary key it will make doing the deletion quite a bit easier. Keep in mind that the server does not guarantee consecutive deletions. ORDER BY clauses can be used.

Called in sql_acl.cc and sql_udf.cc to manage internal table information. Called in sql_delete.cc, sql_insert.cc, and sql_select.cc. In sql_select it is used for removing duplicates while in insert it is used for REPLACE calls.

See Also
sql_acl.cc, sql_udf.cc, sql_delete.cc, sql_insert.cc and sql_select.cc

Definition at line 424 of file ha_example.cc.

int ha_example::delete_table ( const char *  name)
virtual

Used to delete a table. By the time delete_table() has been called all opened references to this table will have been closed (and your globally shared references released). The variable name will just be the name of the table. You will need to remove any files you have created at this point.

If you do not implement this, the default delete_table() is called from handler.cc and it will delete all files with the file extensions returned by bas_ext().

Called from handler.cc by delete_table and ha_create_table(). Only used during create if the table_flag HA_DROP_BEFORE_CREATE was specified for the storage engine.

See Also
delete_table and ha_create_table() in handler.cc

Reimplemented from handler.

Definition at line 832 of file ha_example.cc.

int ha_example::external_lock ( THD *  thd,
int  lock_type 
)

required

This create a lock on the table. If you are implementing a storage engine that can handle transacations look at ha_berkely.cc to see how you will want to go about doing this. Otherwise you should consider calling flock() here. Hint: Read the section "locking functions for mysql" in lock.cc to understand this.

Called from lock.cc by lock_external() and unlock_external(). Also called from sql_table.cc by copy_data_between_tables().

See Also
lock.cc by lock_external() and unlock_external() in lock.cc; the section "locking functions for mysql" in lock.cc; copy_data_between_tables() in sql_table.cc.

Definition at line 758 of file ha_example.cc.

int ha_example::extra ( enum ha_extra_function  operation)
virtual

extra() is called whenever the server wishes to send a hint to the storage engine. The myisam engine implements the most hints. ha_innodb.cc has the most exhaustive list of these hints.

See Also
ha_innodb.cc

Reimplemented from handler.

Definition at line 685 of file ha_example.cc.

int ha_example::index_first ( uchar *  buf)
virtual

We implement this in ha_example.cc. It's not an obligatory method; skip it and and MySQL will treat it as not implemented.

index_first() asks for the first key in the index.

Called from opt_range.cc, opt_sum.cc, sql_handler.cc, and sql_select.cc.

See Also
opt_range.cc, opt_sum.cc, sql_handler.cc and sql_select.cc

Reimplemented from handler.

Definition at line 494 of file ha_example.cc.

ulong ha_example::index_flags ( uint  inx,
uint  part,
bool  all_parts 
) const
inlinevirtual

This is a bitmap of flags that indicates how the storage engine implements indexes. The current index flags are documented in handler.h. If you do not implement indexes, just return zero here.

part is the key part to check. First key part is 0. If all_parts is set, MySQL wants to know the flags for the combined index, up to and including 'part'.

Implements handler.

Definition at line 110 of file ha_example.h.

int ha_example::index_last ( uchar *  buf)
virtual

We implement this in ha_example.cc. It's not an obligatory method; skip it and and MySQL will treat it as not implemented.

index_last() asks for the last key in the index.

Called from opt_range.cc, opt_sum.cc, sql_handler.cc, and sql_select.cc.

See Also
opt_range.cc, opt_sum.cc, sql_handler.cc and sql_select.cc

Reimplemented from handler.

Definition at line 515 of file ha_example.cc.

int ha_example::index_next ( uchar *  buf)
virtual

We implement this in ha_example.cc. It's not an obligatory method; skip it and and MySQL will treat it as not implemented.

Used to read forward through the index.

Reimplemented from handler.

Definition at line 457 of file ha_example.cc.

int ha_example::index_prev ( uchar *  buf)
virtual

We implement this in ha_example.cc. It's not an obligatory method; skip it and and MySQL will treat it as not implemented.

Used to read backwards through the index.

Reimplemented from handler.

Definition at line 473 of file ha_example.cc.

int ha_example::index_read_map ( uchar *  buf,
const uchar *  key,
key_part_map  keypart_map,
enum ha_rkey_function  find_flag 
)
virtual

We implement this in ha_example.cc. It's not an obligatory method; skip it and and MySQL will treat it as not implemented.

Positions an index cursor to the index specified in the handle. Fetches the row if available. If the key value is null, begin at the first key of the index.

Reimplemented from handler.

Definition at line 438 of file ha_example.cc.

int ha_example::info ( uint  flag)
virtual

required

info() is used to return information to the optimizer. See my_base.h for the complete description.

Currently this table handler doesn't implement most of the fields really needed. SHOW also makes use of this data.

You will probably want to have the following in your code:

if (records < 2)
records = 2;

The reason is that the server will optimize for cases of only a single record. If, in a table scan, you don't know the number of records, it will probably be better to set records to two so you can return as many records as you need. Along with records, a few more variables you may wish to set are: records deleted data_file_length index_file_length delete_length check_time Take a look at the public variables in handler.h for more information.

Called in filesort.cc, ha_heap.cc, item_sum.cc, opt_sum.cc, sql_delete.cc, sql_delete.cc, sql_derived.cc, sql_select.cc, sql_select.cc, sql_select.cc, sql_select.cc, sql_select.cc, sql_show.cc, sql_show.cc, sql_show.cc, sql_show.cc, sql_table.cc, sql_union.cc, and sql_update.cc.

See Also
filesort.cc, ha_heap.cc, item_sum.cc, opt_sum.cc, sql_delete.cc, sql_delete.cc, sql_derived.cc, sql_select.cc, sql_select.cc, sql_select.cc, sql_select.cc, sql_select.cc, sql_show.cc, sql_show.cc, sql_show.cc, sql_show.cc, sql_table.cc, sql_union.cc and sql_update.cc

Implements handler.

Definition at line 669 of file ha_example.cc.

uint ha_example::max_supported_key_length ( void  ) const
inlinevirtual

unireg.cc will call this to make sure that the storage engine can handle the data it is about to send. Return real limits of your storage engine here; MySQL will do min(your_limits, MySQL_limits) automatically.

There is no need to implement ..._key_... methods if your engine doesn't support indexes.

Reimplemented from handler.

Definition at line 155 of file ha_example.h.

uint ha_example::max_supported_key_parts ( void  ) const
inlinevirtual

unireg.cc will call this to make sure that the storage engine can handle the data it is about to send. Return real limits of your storage engine here; MySQL will do min(your_limits, MySQL_limits) automatically.

There is no need to implement ..._key_... methods if your engine doesn't support indexes.

Reimplemented from handler.

Definition at line 144 of file ha_example.h.

uint ha_example::max_supported_keys ( void  ) const
inlinevirtual

unireg.cc will call this to make sure that the storage engine can handle the data it is about to send. Return real limits of your storage engine here; MySQL will do min(your_limits, MySQL_limits) automatically.

There is no need to implement ..._key_... methods if your engine doesn't support indexes.

Reimplemented from handler.

Definition at line 133 of file ha_example.h.

int ha_example::open ( const char *  name,
int  mode,
uint  test_if_locked 
)
virtual

We implement this in ha_example.cc; it's a required method.

Used for opening tables. The name will be the name of the file.

A table is opened when it needs to be opened; e.g. when a request comes in for a SELECT on the table (tables are not open and closed for each request, they are cached).

Called from handler.cc by handler::ha_open(). The server opens all tables by calling ha_open() which then calls the handler specific open().

See Also
handler::ha_open() in handler.cc

Implements handler.

Definition at line 296 of file ha_example.cc.

void ha_example::position ( const uchar *  record)
virtual

required

position() is called after each call to rnd_next() if the data needs to be ordered. You can do something like the following to store the position:

my_store_ptr(ref, ref_length, current_position);

The server uses ref to store data. ref_length in the above case is the size needed to store current_position. ref is just a byte array that the server will maintain. If you are using offsets to mark rows, then current_position should be the offset. If it is a primary key like in BDB, then it needs to be a primary key.

Called from filesort.cc, sql_select.cc, sql_delete.cc, and sql_update.cc.

See Also
filesort.cc, sql_select.cc, sql_delete.cc and sql_update.cc

Implements handler.

Definition at line 599 of file ha_example.cc.

ha_rows ha_example::records_in_range ( uint  inx,
key_range min_key,
key_range max_key 
)
virtual

Given a starting key and an ending key, estimate the number of rows that will exist between the two keys.

end_key may be empty, in which case determine if start_key matches any rows.

Called from opt_range.cc by check_quick_keys().

See Also
check_quick_keys() in opt_range.cc

Reimplemented from handler.

Definition at line 874 of file ha_example.cc.

int ha_example::rename_table ( const char *  from,
const char *  to 
)
virtual

Renames a table from one name to another via an alter table call.

If you do not implement this, the default rename_table() is called from handler.cc and it will delete all files with the file extensions returned by bas_ext().

Called from sql_table.cc by mysql_rename_table().

See Also
mysql_rename_table() in sql_table.cc

Reimplemented from handler.

Definition at line 854 of file ha_example.cc.

int ha_example::rnd_init ( bool  scan)
virtual

Unlike index_init(), rnd_init() can be called two consecutive times without rnd_end() in between (it only makes sense if scan=1). In this case, the second call should prepare for the new table scan (e.g if rnd_init() allocates the cursor, the second call should position the cursor to the start of the table; no need to deallocate and allocate it again. This is a required method.

rnd_init() is called when the system wants the storage engine to do a table scan. See the example in the introduction at the top of this file to see when rnd_init() is called.

Called from filesort.cc, records.cc, sql_handler.cc, sql_select.cc, sql_table.cc, and sql_update.cc.

See Also
filesort.cc, records.cc, sql_handler.cc, sql_select.cc, sql_table.cc and sql_update.cc

Implements handler.

Definition at line 539 of file ha_example.cc.

int ha_example::rnd_next ( uchar *  buf)
virtual

required

This is called for each row of the table scan. When you run out of records you should return HA_ERR_END_OF_FILE. Fill buff up with the row information. The Field structure for the table is the key to getting data into buf in a manner that will allow the server to understand it.

Called from filesort.cc, records.cc, sql_handler.cc, sql_select.cc, sql_table.cc, and sql_update.cc.

See Also
filesort.cc, records.cc, sql_handler.cc, sql_select.cc, sql_table.cc and sql_update.cc

Implements handler.

Definition at line 566 of file ha_example.cc.

int ha_example::rnd_pos ( uchar *  buf,
uchar *  pos 
)
virtual

required

This is like rnd_next, but you are given a position to use to determine the row. The position will be of the type that you stored in ref. You can use ha_get_ptr(pos,ref_length) to retrieve whatever key or position you saved when position() was called.

Called from filesort.cc, records.cc, sql_insert.cc, sql_select.cc, and sql_update.cc.

See Also
filesort.cc, records.cc, sql_insert.cc, sql_select.cc and sql_update.cc

Implements handler.

Definition at line 619 of file ha_example.cc.

THR_LOCK_DATA ** ha_example::store_lock ( THD *  thd,
THR_LOCK_DATA **  to,
enum thr_lock_type  lock_type 
)
virtual

required

The idea with handler::store_lock() is: The statement decides which locks should be needed for the table. For updates/deletes/inserts we get WRITE locks, for SELECT... we get read locks.

Before adding the lock into the table lock handler (see thr_lock.c), mysqld calls store lock with the requested locks. Store lock can now modify a write lock to a read lock (or some other lock), ignore the lock (if we don't want to use MySQL table locks at all), or add locks for many tables (like we do when we are using a MERGE handler).

Berkeley DB, for example, changes all WRITE locks to TL_WRITE_ALLOW_WRITE (which signals that we are doing WRITES, but are still allowing other readers and writers).

When releasing locks, store_lock() is also called. In this case one usually doesn't have to do anything.

In some exceptional cases MySQL may send a request for a TL_IGNORE; This means that we are requesting the same lock as last time and this should also be ignored. (This may happen when someone does a flush table when we have opened a part of the tables, in which case mysqld closes and reopens the tables and tries to get the same locks at last time). In the future we will probably try to remove this.

Called from lock.cc by get_lock_data().

Note
In this method one should NEVER rely on table->in_use, it may, in fact, refer to a different thread! (this happens if get_lock_data() is called from mysql_lock_abort_for_thread() function)
See Also
get_lock_data() in lock.cc

Implements handler.

Definition at line 802 of file ha_example.cc.

int ha_example::truncate ( )
virtual

Used for handler specific truncate table. The table is locked in exclusive mode and handler is responsible for reseting the auto- increment counter.

Called from Truncate_statement::handler_truncate. Not used if the handlerton supports HTON_CAN_RECREATE, unless this engine can be used as a partition. In this case, it is invoked when a particular partition is to be truncated.

See Also
Truncate_statement in sql_truncate.cc Remarks in handler::truncate.

Reimplemented from handler.

Definition at line 734 of file ha_example.cc.

int ha_example::update_row ( const uchar *  old_data,
uchar *  new_data 
)

We implement this in ha_example.cc. It's not an obligatory method; skip it and and MySQL will treat it as not implemented.

Yes, update_row() does what you expect, it updates a row. old_data will have the previous row record in it, while new_data will have the newest data in it. Keep in mind that the server can do updates based on ordering if an ORDER BY clause was used. Consecutive ordering is not guaranteed.

Currently new_data will not have an updated auto_increament record. You can do this for example by doing:

if (table->next_number_field && record == table->record[0])
update_auto_increment();

Called from sql_select.cc, sql_acl.cc, sql_update.cc, and sql_insert.cc.

See Also
sql_select.cc, sql_acl.cc, sql_update.cc and sql_insert.cc

Definition at line 396 of file ha_example.cc.

int ha_example::write_row ( uchar *  buf)

We implement this in ha_example.cc. It's not an obligatory method; skip it and and MySQL will treat it as not implemented.

write_row() inserts a row. No extra() hint is given currently if a bulk load is happening. buf() is a byte array of data. You can use the field information to extract the data from the native byte array type.

Example of this would be:

for (Field **field=table->field ; *field ; field++)
{
...
}

See ha_tina.cc for an example of extracting all of the data as strings. ha_berekly.cc has an example of how to store it intact by "packing" it for ha_berkeley's own native storage type.

See the note for update_row() on auto_increments. This case also applies to write_row().

Called from item_sum.cc, item_sum.cc, sql_acl.cc, sql_insert.cc, sql_insert.cc, sql_select.cc, sql_table.cc, sql_udf.cc, and sql_update.cc.

See Also
item_sum.cc, item_sum.cc, sql_acl.cc, sql_insert.cc, sql_insert.cc, sql_select.cc, sql_table.cc, sql_udf.cc and sql_update.cc

Definition at line 360 of file ha_example.cc.


The documentation for this class was generated from the following files: