MySQL 8.0.39
Source Code Documentation
ha_example.cc File Reference

The ha_example engine is a stubbed storage engine for example purposes only; it does nothing at this point. More...

#include "storage/example/ha_example.h"
#include "my_dbug.h"
#include "mysql/plugin.h"
#include "sql/sql_class.h"
#include "sql/sql_plugin.h"
#include "typelib.h"

Classes

struct  example_vars_t
 

Functions

static handlerexample_create_handler (handlerton *hton, TABLE_SHARE *table, bool partitioned, MEM_ROOT *mem_root)
 
static bool example_is_supported_system_table (const char *db, const char *table_name, bool is_sql_layer_system_table)
 Check if the given db.tablename is a system table for this SE. More...
 
static int example_init_func (void *p)
 
static int example_deinit_func (void *p)
 
static MYSQL_THDVAR_STR (last_create_thdvar, PLUGIN_VAR_MEMALLOC, nullptr, nullptr, nullptr, nullptr)
 
static MYSQL_THDVAR_UINT (create_count_thdvar, 0, nullptr, nullptr, nullptr, 0, 0, 1000, 0)
 
static MYSQL_SYSVAR_ENUM (enum_var, srv_enum_var, PLUGIN_VAR_RQCMDARG, "Sample ENUM system variable.", nullptr, nullptr, 0, &enum_var_typelib)
 
static MYSQL_SYSVAR_ULONG (ulong_var, srv_ulong_var, PLUGIN_VAR_RQCMDARG, "0..1000", nullptr, nullptr, 8, 0, 1000, 0)
 
static MYSQL_SYSVAR_DOUBLE (double_var, srv_double_var, PLUGIN_VAR_RQCMDARG, "0.500000..1000.500000", nullptr, nullptr, 8.5, 0.5, 1000.5, 0)
 
static MYSQL_THDVAR_DOUBLE (double_thdvar, PLUGIN_VAR_RQCMDARG, "0.500000..1000.500000", nullptr, nullptr, 8.5, 0.5, 1000.5, 0)
 
static MYSQL_SYSVAR_INT (signed_int_var, srv_signed_int_var, PLUGIN_VAR_RQCMDARG, "INT_MIN..INT_MAX", nullptr, nullptr, -10, INT_MIN, INT_MAX, 0)
 
static MYSQL_THDVAR_INT (signed_int_thdvar, PLUGIN_VAR_RQCMDARG, "INT_MIN..INT_MAX", nullptr, nullptr, -10, INT_MIN, INT_MAX, 0)
 
static MYSQL_SYSVAR_LONG (signed_long_var, srv_signed_long_var, PLUGIN_VAR_RQCMDARG, "LONG_MIN..LONG_MAX", nullptr, nullptr, -10, LONG_MIN, LONG_MAX, 0)
 
static MYSQL_THDVAR_LONG (signed_long_thdvar, PLUGIN_VAR_RQCMDARG, "LONG_MIN..LONG_MAX", nullptr, nullptr, -10, LONG_MIN, LONG_MAX, 0)
 
static MYSQL_SYSVAR_LONGLONG (signed_longlong_var, srv_signed_longlong_var, PLUGIN_VAR_RQCMDARG, "LLONG_MIN..LLONG_MAX", nullptr, nullptr, -10, LLONG_MIN, LLONG_MAX, 0)
 
static MYSQL_THDVAR_LONGLONG (signed_longlong_thdvar, PLUGIN_VAR_RQCMDARG, "LLONG_MIN..LLONG_MAX", nullptr, nullptr, -10, LLONG_MIN, LLONG_MAX, 0)
 
static int show_func_example (MYSQL_THD, SHOW_VAR *var, char *buf)
 
 mysql_declare_plugin (example)
 

Variables

handlertonexample_hton
 
static st_handler_tablename ha_example_system_tables []
 
struct st_mysql_storage_engine example_storage_engine
 
static ulong srv_enum_var = 0
 
static ulong srv_ulong_var = 0
 
static double srv_double_var = 0
 
static int srv_signed_int_var = 0
 
static long srv_signed_long_var = 0
 
static longlong srv_signed_longlong_var = 0
 
const char * enum_var_names [] = {"e1", "e2", NullS}
 
TYPELIB enum_var_typelib
 
static SYS_VARexample_system_variables []
 
example_vars_t example_vars = {100, 20.01, "three hundred", true, false, 8250}
 
static SHOW_VAR show_status_example []
 
static SHOW_VAR show_array_example []
 
static SHOW_VAR func_status []
 
 mysql_declare_plugin_end
 

Detailed Description

The ha_example engine is a stubbed storage engine for example purposes only; it does nothing at this point.

Its purpose is to provide a source code illustration of how to begin writing new storage engines; see also /storage/example/ha_example.h.

ha_example will let you create/open/delete tables, but nothing further (for example, indexes are not supported nor can data be stored in the table). Use this example as a template for implementing the same functionality in your own storage engine. You can enable the example storage engine in your build by doing the following during your build process:
./configure –with-example-storage-engine

Once this is done, MySQL will let you create tables with:
CREATE TABLE <table name> (...) ENGINE=EXAMPLE;

The example storage engine is set up to use table locks. It implements an example "SHARE" that is inserted into a hash by table name. You can use this to store information of state that any example handler object will be able to see when it is using that table.

Please read the object definition in ha_example.h before reading the rest of this file.

Note
When you create an EXAMPLE table, the MySQL Server creates a table .frm (format) file in the database directory, using the table name as the file name as is customary with MySQL. No other files are created. To get an idea of what occurs, here is an example select that would do a scan of an entire table:
ENUM HA_EXTRA_RESET Reset database to after open
int rnd_init(bool scan) override
Unlike index_init(), rnd_init() can be called two consecutive times without rnd_end() in between (it ...
Definition: ha_example.cc:437
int external_lock(THD *thd, int lock_type) override
required
Definition: ha_example.cc:612
THR_LOCK_DATA ** store_lock(THD *thd, THR_LOCK_DATA **to, enum thr_lock_type lock_type) override
required
Definition: ha_example.cc:654
int extra(enum ha_extra_function operation) override
extra() is called whenever the server wishes to send a hint to the storage engine.
Definition: ha_example.cc:565
int rnd_next(uchar *buf) override
required
Definition: ha_example.cc:462
int info(uint) override
required
Definition: ha_example.cc:551
stdx::expected< int, std::error_code > open(const char *fname, int flags, mode_t mode) noexcept
Definition: file_handle.cc:79

Here you see that the example storage engine has 9 rows called before rnd_next signals that it has reached the end of its data. Also note that the table in question was already opened; had it not been open, a call to ha_example::open() would also have been necessary. Calls to ha_example::extra() are hints as to what will be occurring to the request.

A Longer Example can be found called the "Skeleton Engine" which can be found on TangentOrg. It has both an engine and a full build environment for building a pluggable storage engine.

Happy coding!
-Brian

Function Documentation

◆ example_create_handler()

static handler * example_create_handler ( handlerton hton,
TABLE_SHARE table,
bool  partitioned,
MEM_ROOT mem_root 
)
static

◆ example_deinit_func()

static int example_deinit_func ( void *  p)
static

◆ example_init_func()

static int example_init_func ( void *  p)
static

◆ example_is_supported_system_table()

static bool example_is_supported_system_table ( const char *  db,
const char *  table_name,
bool  is_sql_layer_system_table 
)
static

Check if the given db.tablename is a system table for this SE.

Parameters
dbDatabase name to check.
table_nametable name to check.
is_sql_layer_system_tableif the supplied db.table_name is a SQL layer system table.
Return values
trueGiven db.table_name is supported system table.
falseGiven db.table_name is not a supported system table.

◆ mysql_declare_plugin()

mysql_declare_plugin ( example  )

◆ MYSQL_SYSVAR_DOUBLE()

static MYSQL_SYSVAR_DOUBLE ( double_var  ,
srv_double_var  ,
PLUGIN_VAR_RQCMDARG  ,
"0.500000..1000.500000"  ,
nullptr  ,
nullptr  ,
8.  5,
0.  5,
1000.  5,
 
)
static

◆ MYSQL_SYSVAR_ENUM()

static MYSQL_SYSVAR_ENUM ( enum_var  ,
srv_enum_var  ,
PLUGIN_VAR_RQCMDARG  ,
"Sample ENUM system variable."  ,
nullptr  ,
nullptr  ,
,
enum_var_typelib 
)
static

◆ MYSQL_SYSVAR_INT()

static MYSQL_SYSVAR_INT ( signed_int_var  ,
srv_signed_int_var  ,
PLUGIN_VAR_RQCMDARG  ,
"INT_MIN..INT_MAX"  ,
nullptr  ,
nullptr  ,
10,
INT_MIN  ,
INT_MAX  ,
 
)
static

◆ MYSQL_SYSVAR_LONG()

static MYSQL_SYSVAR_LONG ( signed_long_var  ,
srv_signed_long_var  ,
PLUGIN_VAR_RQCMDARG  ,
"LONG_MIN..LONG_MAX"  ,
nullptr  ,
nullptr  ,
10,
LONG_MIN  ,
LONG_MAX  ,
 
)
static

◆ MYSQL_SYSVAR_LONGLONG()

static MYSQL_SYSVAR_LONGLONG ( signed_longlong_var  ,
srv_signed_longlong_var  ,
PLUGIN_VAR_RQCMDARG  ,
"LLONG_MIN..LLONG_MAX"  ,
nullptr  ,
nullptr  ,
10,
LLONG_MIN  ,
LLONG_MAX  ,
 
)
static

◆ MYSQL_SYSVAR_ULONG()

static MYSQL_SYSVAR_ULONG ( ulong_var  ,
srv_ulong_var  ,
PLUGIN_VAR_RQCMDARG  ,
"0..1000"  ,
nullptr  ,
nullptr  ,
,
,
1000  ,
 
)
static

◆ MYSQL_THDVAR_DOUBLE()

static MYSQL_THDVAR_DOUBLE ( double_thdvar  ,
PLUGIN_VAR_RQCMDARG  ,
"0.500000..1000.500000"  ,
nullptr  ,
nullptr  ,
8.  5,
0.  5,
1000.  5,
 
)
static

◆ MYSQL_THDVAR_INT()

static MYSQL_THDVAR_INT ( signed_int_thdvar  ,
PLUGIN_VAR_RQCMDARG  ,
"INT_MIN..INT_MAX"  ,
nullptr  ,
nullptr  ,
10,
INT_MIN  ,
INT_MAX  ,
 
)
static

◆ MYSQL_THDVAR_LONG()

static MYSQL_THDVAR_LONG ( signed_long_thdvar  ,
PLUGIN_VAR_RQCMDARG  ,
"LONG_MIN..LONG_MAX"  ,
nullptr  ,
nullptr  ,
10,
LONG_MIN  ,
LONG_MAX  ,
 
)
static

◆ MYSQL_THDVAR_LONGLONG()

static MYSQL_THDVAR_LONGLONG ( signed_longlong_thdvar  ,
PLUGIN_VAR_RQCMDARG  ,
"LLONG_MIN..LLONG_MAX"  ,
nullptr  ,
nullptr  ,
10,
LLONG_MIN  ,
LLONG_MAX  ,
 
)
static

◆ MYSQL_THDVAR_STR()

static MYSQL_THDVAR_STR ( last_create_thdvar  ,
PLUGIN_VAR_MEMALLOC  ,
nullptr  ,
nullptr  ,
nullptr  ,
nullptr   
)
static

◆ MYSQL_THDVAR_UINT()

static MYSQL_THDVAR_UINT ( create_count_thdvar  ,
,
nullptr  ,
nullptr  ,
nullptr  ,
,
,
1000  ,
 
)
static

◆ show_func_example()

static int show_func_example ( MYSQL_THD  ,
SHOW_VAR var,
char *  buf 
)
static

Variable Documentation

◆ enum_var_names

const char* enum_var_names[] = {"e1", "e2", NullS}

◆ enum_var_typelib

TYPELIB enum_var_typelib
Initial value:
"enum_var_typelib", enum_var_names, nullptr}
const char * enum_var_names[]
Definition: ha_example.cc:783
#define array_elements(A)
Definition: validate_password_imp.cc:48

◆ example_hton

handlerton* example_hton

◆ example_storage_engine

struct st_mysql_storage_engine example_storage_engine
Initial value:
= {
#define MYSQL_HANDLERTON_INTERFACE_VERSION
Definition: plugin.h:701

◆ example_system_variables

SYS_VAR* example_system_variables[]
static
Initial value:
= {
MYSQL_SYSVAR(enum_var),
MYSQL_SYSVAR(ulong_var),
MYSQL_SYSVAR(double_var),
MYSQL_SYSVAR(double_thdvar),
MYSQL_SYSVAR(last_create_thdvar),
MYSQL_SYSVAR(create_count_thdvar),
MYSQL_SYSVAR(signed_int_var),
MYSQL_SYSVAR(signed_int_thdvar),
MYSQL_SYSVAR(signed_long_var),
MYSQL_SYSVAR(signed_long_thdvar),
MYSQL_SYSVAR(signed_longlong_var),
MYSQL_SYSVAR(signed_longlong_thdvar),
nullptr}
#define MYSQL_SYSVAR(name)
Definition: plugin.h:252

◆ example_vars

example_vars_t example_vars = {100, 20.01, "three hundred", true, false, 8250}

◆ func_status

SHOW_VAR func_status[]
static
Initial value:
= {
{"example_func_example", (char *)show_func_example, SHOW_FUNC,
{"example_status_var5", (char *)&example_vars.var5, SHOW_BOOL,
{"example_status_var6", (char *)&example_vars.var6, SHOW_LONG,
{"example_status", (char *)show_array_example, SHOW_ARRAY,
{nullptr, nullptr, SHOW_UNDEF, SHOW_SCOPE_UNDEF}}
static int show_func_example(MYSQL_THD, SHOW_VAR *var, char *buf)
Definition: ha_example.cc:849
static SHOW_VAR show_array_example[]
Definition: ha_example.cc:879
example_vars_t example_vars
Definition: ha_example.cc:870
@ SHOW_LONG
shown as unsigned long
Definition: status_var.h:34
@ SHOW_ARRAY
Definition: status_var.h:38
@ SHOW_FUNC
Definition: status_var.h:39
@ SHOW_BOOL
Definition: status_var.h:32
@ SHOW_UNDEF
Definition: status_var.h:31
@ SHOW_SCOPE_GLOBAL
Definition: status_var.h:70
@ SHOW_SCOPE_UNDEF
Definition: status_var.h:69
ulong var6
Definition: ha_example.cc:867
bool var5
Definition: ha_example.cc:866

◆ ha_example_system_tables

st_handler_tablename ha_example_system_tables[]
static
Initial value:
= {
{(const char *)nullptr, (const char *)nullptr}}

◆ mysql_declare_plugin_end

mysql_declare_plugin_end

◆ show_array_example

SHOW_VAR show_array_example[]
static
Initial value:
= {
{nullptr, nullptr, SHOW_UNDEF, SHOW_SCOPE_UNDEF}}
static SHOW_VAR show_status_example[]
Definition: ha_example.cc:872
@ SHOW_CHAR
Definition: status_var.h:36
char var3[64]
Definition: ha_example.cc:864
bool var4
Definition: ha_example.cc:865

◆ show_status_example

SHOW_VAR show_status_example[]
static
Initial value:
= {
{nullptr, nullptr, SHOW_UNDEF,
}
@ SHOW_DOUBLE
Definition: status_var.h:40
ulong var1
Definition: ha_example.cc:862
double var2
Definition: ha_example.cc:863

◆ srv_double_var

double srv_double_var = 0
static

◆ srv_enum_var

ulong srv_enum_var = 0
static

◆ srv_signed_int_var

int srv_signed_int_var = 0
static

◆ srv_signed_long_var

long srv_signed_long_var = 0
static

◆ srv_signed_longlong_var

longlong srv_signed_longlong_var = 0
static

◆ srv_ulong_var

ulong srv_ulong_var = 0
static