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

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. More...

#include "sql_priv.h"
#include "sql_class.h"
#include "ha_example.h"
#include "probes_mysql.h"
#include "sql_plugin.h"
Include dependency graph for ha_example.cc:

Go to the source code of this file.

Functions

 mysql_declare_plugin (example)

Variables

handlertonexample_hton
const char * ha_example_system_database = NULL
struct st_mysql_storage_engine example_storage_engine
const char * enum_var_names []
TYPELIB enum_var_typelib
 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

...) 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_CACHE Cache record in HA_rrnd()
ha_example::rnd_next
ha_example::rnd_next
ha_example::rnd_next
ha_example::rnd_next
ha_example::rnd_next
ha_example::rnd_next
ha_example::rnd_next
ha_example::rnd_next
ha_example::rnd_next
ENUM HA_EXTRA_NO_CACHE End caching of records (def)
ha_example::external_lock
ENUM HA_EXTRA_RESET Reset database to after open

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 occuring 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

Definition in file ha_example.cc.

Variable Documentation

const char* enum_var_names[]
Initial value:
{
"e1", "e2", NullS
}

Definition at line 920 of file ha_example.cc.

TYPELIB enum_var_typelib
Initial value:
{
array_elements(enum_var_names) - 1, "enum_var_typelib",
enum_var_names, NULL
}

Definition at line 925 of file ha_example.cc.

struct st_mysql_storage_engine example_storage_engine
Initial value:
{ MYSQL_HANDLERTON_INTERFACE_VERSION }

Definition at line 913 of file ha_example.cc.