2. Roland Bouman
http://rpbouman.blogspot.com/
2
Hi! Welcome to the MySQL UC,
Thanks for coming!!!
● Roland Bouman
● Ex MySQL AB/Sun
● BI guy, App.
Developer
● Leiden, Netherlands
● Sergei Golubchik
● Sun (MySQL)
● Architect, Senior
Software Developer
● Hamburg, Germany
5. Roland Bouman
http://rpbouman.blogspot.com/
5
MySQL 5.1 Plugin API – Overview
● New in MySQL 5.1
– Successor to User-defined Functions (UDFs)
● Plugin is a dynamically loadable binary library
– '.so' (linux)
– '.dylib' (Mac OS/X)
– '.dll' (Windows)
● Dynamically add or remove functionality
– No need to recompile
– No need to restart
6. Roland Bouman
http://rpbouman.blogspot.com/
6
Why to Extend ?
• You know why
• Adding functionality to the server that we have
no time to add
• Adding functions that we prefer not to have in
the server to avoid code bloat
• Adding features that you need!
7. Roland Bouman
http://rpbouman.blogspot.com/
7
How to Extend: Traditional
options
• Compiled-in function
• allows to use statically-compiled mysqld binary
• requires constant maintainance
• UDF
• user-defined function, loaded dynamically
• easier to maintain, but still not bullet-proof
• Procedure
• A filter that it is put after the select, but before the
data are sent (like in “ls -l|wc”)
• Only statically compiled, poorly documented
8. Roland Bouman
http://rpbouman.blogspot.com/
8
Plugin API
• New in MySQL 5.1
• Generic ― allows to load any functionality in the
running mysqld
• Built-in versioning
• Easy to maintain and distribute
• User friendly ― no cryptic arguments to install
• INSTALL PLUGIN foo SONAME 'bar.so'
• CREATE AGGREGATE FUNCTION median
RETURNS REAL SONAME 'aggr.so';
9. Roland Bouman
http://rpbouman.blogspot.com/
9
Compiling and Linking
• Built separately ? Loaded dynamically ?
• Yes! No!
• Plugin can be built separately
• Plugin can be built from the MySQL source tree
• No patching of MySQL code, simply unpack the
plugin tarball – it will be picked up automatically
• Plugin can be loaded dynamically
• Plugin can be linked in statically
• Without modifying plugin source code
10. Roland Bouman
http://rpbouman.blogspot.com/
10
Plugin Can
• provide the code for mysqld to execute
• add new status variables
• SHOW STATUS
• add new command-line options
• --plugin-option=value
• add new server variables
• SHOW VARIABLES, SET @@var
• add new SQL keywords (todo)
• CREATE TABLE ... METHOD='deflate'
12. Roland Bouman
http://rpbouman.blogspot.com/
12
MySQL 5.1 Plugins – Deployment
● Place plugin library in the plugin directory:
mysql> SHOW VARIABLES LIKE 'plugin_dir';
+----------------------------------------------------------+
| Variable_name | Value |
+---------------+------------------------------------------+
| plugin_dir | /usr/local/mysql/lib/plugin |
+---------------+------------------------------------------+
1 row in set (0.00 sec)
● Use DDL to install:
INSTALL PLUGIN <plugin_name> SONAME '<plugin_library>'
● ...and to uninstall:
UNINSTALL PLUGIN <plugin_name>
● NOTE: limited support for MS Windows
13. Roland Bouman
http://rpbouman.blogspot.com/
13
MySQL 5.1 Plugins – Managing
● Show all plugins with the SHOW syntax
mysql> SHOW PLUGINS LIKE 'PBXT';
● ...or query the information schema:
mysql> SELECT PLUGIN_NAME
-> , PLUGIN_VERSION
-> , PLUGIN_STATUS
-> , PLUGIN_TYPE
-> , PLUGIN_TYPE_VERSION
-> , PLUGIN_LIBRARY
-> , PLUGIN_LIBRARY_VERSION
-> , PLUGIN_AUTHOR
-> , PLUGIN_DESCRIPTION
-> , PLUGIN_LICENSE
-> FROM information_schema.PLUGINS
17. Roland Bouman
http://rpbouman.blogspot.com/
17
FULLTEXT parser Plugins
● For FULLTEXT indexes
● Filter text for built-in parser (Extraction)
– Example: parse PDF and pass on the text
● Instead of built-in parser (Splitting)
– Parse words out of text
● Postprocessing
● Usage:
CREATE TABLE t(
doc CHAR(255),
FULLTEXT INDEX (doc) WITH PARSER <parser-name>
);
18. Roland Bouman
http://rpbouman.blogspot.com/
18
FULLTEXT parser Plugins
Fulltext Parser Plugin
Lorem ipsum
dolor sit amet,
consectetuer
adipiscing elit.
Nunc quis felis
sed pede tristi-
que dignissim.
Fusce luctus,
nibh quis pel-
FOO
Extracting Splitting Postprocessing
Object Text Words Index
19. Roland Bouman
http://rpbouman.blogspot.com/
19
Information Schema Plugins
● Implements an information_schema table
– Can provide an arbitrary set of data
– Can report internal server data
● Usage: new information_schema table
becomes available after installation
21. Roland Bouman
http://rpbouman.blogspot.com/
21
Daemon Plugins
● Generic plugin
– no particular type specific interface
– basically, this is a hack
● Yes, more so than the other plugin types
● Examples:
– Heartbeat plugin
– UDP client protocol implementation
22. Roland Bouman
http://rpbouman.blogspot.com/
22
Learn more
● http://dev.mysql.com/doc/refman/5.1/en/plugin-api.html
● http://rpbouman.blogspot.com/2008/02/mysql-information-schema-plugins-best.html
● http://rpbouman.blogspot.com/2008/02/reporting-mysql-internals-with.html
● http://forge.mysql.com/wiki/MySQL_Internals_Custom_Engine
● http://tangent.org/543/Skeleton_Engine_for_MySQL.html