0
Roland Bouman
http://rpbouman.blogspot.com/
1
Writing MySQL 5.1 Information
Schema Plugins
Roland Bouman
http://rpbouman.blogspot.com/
2
Tasks Before Implementing
Information Schema Plugins
● Standard headers
– <s...
Roland Bouman
http://rpbouman.blogspot.com/
3
Implementing Information
Schema Plug-ins
● Setup the column layout
– Defines...
Roland Bouman
http://rpbouman.blogspot.com/
4
Information Schema Plug-ins:
Column Layout
● Array of ST_FIELD_INFO
– typede...
Roland Bouman
http://rpbouman.blogspot.com/
5
ST_FIELD_INFO members (1/2)
● field_name: Column name
● field_length:
– Stri...
Roland Bouman
http://rpbouman.blogspot.com/
6
ST_FIELD_INFO members (2/2)
● open_method: (sql/table.h)
– SKIP_OPEN_TABLE
–...
Roland Bouman
http://rpbouman.blogspot.com/
7
Information Schema Plug-ins:
Column Layout Example
● information_schema.SCHE...
Roland Bouman
http://rpbouman.blogspot.com/
8
Information Schema Plug-ins:
Fill Function (1/4)
● fill_table(
THD *thd,
TAB...
Roland Bouman
http://rpbouman.blogspot.com/
9
Information Schema Plug-ins:
Fill Function (2/4)
● Grab first table from the...
Roland Bouman
http://rpbouman.blogspot.com/
10
Information Schema Plug-ins:
Fill Function (3/4)
● schema_table_store_recor...
Roland Bouman
http://rpbouman.blogspot.com/
11
Information Schema Plug-ins:
Fill Function (4/4)
int myplugin_fill_table(
T...
Roland Bouman
http://rpbouman.blogspot.com/
12
Information Schema Plug-ins:
Hookup Column Layout and Filler
● plugin_init
...
Roland Bouman
http://rpbouman.blogspot.com/
13
Information Schema Plug-ins:
ST_SCHEMA_TABLE
● ST_SCHEMA_TABLE a.k.a st_sch...
Roland Bouman
http://rpbouman.blogspot.com/
14
Information Schema Plug-ins:
Hookup Column Layout and Filler
● plugin_init
...
Roland Bouman
http://rpbouman.blogspot.com/
15
Information Schema Plug-ins:
Hookup Column Layout and Filler
● plugin_init
...
Roland Bouman
http://rpbouman.blogspot.com/
16
Information Schema Plug-ins:
Hookup Column Layout and Filler
● plugin_init
...
Upcoming SlideShare
Loading in...5
×

3. writing MySql plugins for the information schema

234

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
234
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "3. writing MySql plugins for the information schema"

  1. 1. Roland Bouman http://rpbouman.blogspot.com/ 1 Writing MySQL 5.1 Information Schema Plugins
  2. 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. 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. 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. 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
  6. 6. Roland Bouman http://rpbouman.blogspot.com/ 6 ST_FIELD_INFO members (2/2) ● open_method: (sql/table.h) – SKIP_OPEN_TABLE – OPEN_FRM_ONLY – OPEN_FULL_TABLE ● old_name: Column name for SHOW command ● value: ??
  7. 7. Roland Bouman http://rpbouman.blogspot.com/ 7 Information Schema Plug-ins: Column Layout Example ● information_schema.SCHEMATA ST_FIELD_INFO schema_fields_info[]= { {"CATALOG_NAME", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE}, {"SCHEMA_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Database", SKIP_OPEN_TABLE}, {"DEFAULT_CHARACTER_SET_NAME", MY_CS_NAME_SIZE, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}, {"DEFAULT_COLLATION_NAME", MY_CS_NAME_SIZE, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}, {"SQL_PATH", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE}, {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE} }
  8. 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. 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);
  10. 10. Roland Bouman http://rpbouman.blogspot.com/ 10 Information Schema Plug-ins: Fill Function (3/4) ● schema_table_store_record( THD *thd , TABLE *table ) ● Forward declaration in mysql_priv.h ● Defined in sql/sql_show.cc
  11. 11. Roland Bouman http://rpbouman.blogspot.com/ 11 Information Schema Plug-ins: Fill Function (4/4) int myplugin_fill_table( THD *thd, TABLE_LIST *tables, COND *cond ){ int status; CHARSET_INFO *scs= system_charset_info; TABLE *table= (TABLE *)tables->table; for ( ... ) { // table->field[0]->store( ... ); ... table->field[X]->store( ... ); status= schema_table_store_record( thd, table ); } return status; }
  12. 12. Roland Bouman http://rpbouman.blogspot.com/ 12 Information Schema Plug-ins: Hookup Column Layout and Filler ● plugin_init static int myplugin_init(void *p) { ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE *)p; schema->fields_info= myplugin_field_info; schema->fill_table= myplugin_fill_table; return 0; }
  13. 13. Roland Bouman http://rpbouman.blogspot.com/ 13 Information Schema Plug-ins: ST_SCHEMA_TABLE ● ST_SCHEMA_TABLE a.k.a st_schema_table typedef struct st_schema_table { const char* table_name; ST_FIELD_INFO *fields_info; TABLE *(*create_table)(THD *thd, TABLE_LIST *table_list); int (*fill_table) ( THD *thd, TABLE_LIST *tables, COND *cond); int (*old_format) ( THD *thd, struct st_schema_table *schema_table); int (*process_table) ( THD *thd, TABLE_LIST *tables,TABLE *table, bool res, LEX_STRING *db_name, LEX_STRING *table_name); int idx_field1, idx_field2; bool hidden; uint i_s_requested_object; } ST_SCHEMA_TABLE;
  14. 14. Roland Bouman http://rpbouman.blogspot.com/ 14 Information Schema Plug-ins: Hookup Column Layout and Filler ● plugin_init static int myplugin_init(void *p) { ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE *)p; schema->fields_info= myplugin_field_info; schema->fill_table= myplugin_fill_table; return 0; }
  15. 15. Roland Bouman http://rpbouman.blogspot.com/ 15 Information Schema Plug-ins: Hookup Column Layout and Filler ● plugin_init static int myplugin_init(void *p) { ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE *)p; schema->fields_info= myplugin_field_info; schema->fill_table= myplugin_fill_table; return 0; }
  16. 16. Roland Bouman http://rpbouman.blogspot.com/ 16 Information Schema Plug-ins: Hookup Column Layout and Filler ● plugin_init static int myplugin_init(void *p) { ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE *)p; schema->fields_info= myplugin_field_info; schema->fill_table= myplugin_fill_table; return 0; }
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×