2. Roland Bouman
http://rpbouman.blogspot.com/
2
Tasks Before Implementing
Information Schema Plugins
● Standard headers
– <stdlib.h>, <ctype.h>
● Non-specific MySQL headers:
– <mysql_version.h>, <mysql/plugin.h>
● Extra headers for Information Schema plug-ins
– <mysql_priv.h>
– <my_global.h>
– <my_dir.h>
3. Roland Bouman
http://rpbouman.blogspot.com/
3
Implementing Information
Schema Plug-ins
● Setup the column layout
– Defines the column names and data types
● Implement a fill function
– Is called to fill the (in-memory) table
● Hook up table object with colum layout and fill
function
– Plug-in initialization function
4. Roland Bouman
http://rpbouman.blogspot.com/
4
Information Schema Plug-ins:
Column Layout
● Array of ST_FIELD_INFO
– typedef struct st_field_info
– Defined in sql/table.h
typedef struct st_field_info
{
const char* field_name;
uint field_length;
enum enum_field_types field_type;
int value;
uint field_flags;
const char* old_name;
uint open_method;
} ST_FIELD_INFO;
5. Roland Bouman
http://rpbouman.blogspot.com/
5
ST_FIELD_INFO members (1/2)
● field_name: Column name
● field_length:
– String type columns: #characters
– Non-string types: 'display length'
● field_type: type constant
– enum_field_types (mysql_com.h)
● field_flags:
– MY_I_S_MAYBE_NULL
– MY_I_S_UNSIGNED
8. Roland Bouman
http://rpbouman.blogspot.com/
8
Information Schema Plug-ins:
Fill Function (1/4)
● fill_table(
THD *thd,
TABLE_LIST *tables,
COND *cond
)
● THD: thread descriptor (sql/sql_class.h)
● TABLE_LIST: (sql/sql_table.h)
– List of struct st_table (a.k.a. TABLE)
● COND: Condition.
9. Roland Bouman
http://rpbouman.blogspot.com/
9
Information Schema Plug-ins:
Fill Function (2/4)
● Grab first table from the list:
TABLE *table= (TABLE *)tables->table;
● Store data in fields:
table->field[i]->store(...);
● Store row in table
schema_table_store_record(thd, table);