Toru Maesaka: Extending CREATE TABLE Syntax in Drizzle
The flexibility to add table-specific options for things like compression, encryption and optimization can be useful to storage engine developers as this flexibility can open up new possibilities. Here’s what I’m talking about:
CREATE TABLE t1 ( ... ) ENGINE = my_engine, MY_OPTION = your_arg;
Supporting this is relatively easy in Drizzle and this API feature (and a bit more) is available in MariaDB as well. Unfortunately Drizzle’s method to do this isn’t documented in the Wiki yet but it should be added when our Storage Engine API becomes stable (as in, no interface changes).
Implement StorageEngine::doValidateTableOptions()
Here’s the actual interface.
bool StorageEngine::doValidateTableOptions(const std::string &key, const std::string &state);This function is called for each table options given at CREATE TABLE syntax execution. The first argument, key is a const reference to a string that represents the option name. The second argument, state represents the argument given for that option.
Therefore, given: COMPRESSION = YES_PLEASE, key would be “COMPRESSION” and state would be “YES_PLEASE”. The objective of this function is to check whether the key/state pair makes sense to your storage engine. If this function returns false, Drizzle will return an error for the CREATE TABLE query. Personally I think this interface can be improved to be a bit more Developer friendly, such as making life easier to validate numeric values without enforcing the developer to play around with the data. Saying that, given the pace that Drizzle is growing, this could be improved before we know it.
Access Options at StorageEngine::doCreateTable()
Here’s the actual interface for doCreateTable().
int doCreateTable(drizzled::Session &session, drizzled::Table &table_arg, const drizzled::TableIdentifier &identifier, drizzled::message::Table &table_proto);Given that the options were successfully validated, doCreateTable() is called next. In Drizzle, all information regarding a table (including options) is represented in a Google Protocol Buffer message. A reference to that message object is passed to doCreateTable() as the fourth argument so all you need to do is loop through the options list in the message object and extract what you need. Here’s a minimal example that only takes care of one option.
int n_options = table_proto.engine().options_size(); for (int i = 0; i < n_options; i++) { if (table_proto.engine().options(i).name() == "my_option_name") { // Do whatever you like with this stream. std::istringstream stream(table_proto.engine().options(i).state()); } }The above example should be simple to extend to handle multiple options. What’s really important in the above example is that the option name can be accessed with the name() accessor and the state (value) of that option with the state() accessor.
So, that’s all I have to cover for now. I hope this feature will help storage engine developers create and provide useful table specific features for their engine.
Happy Hacking.
URL: http://torum.net/2010/07/extending-create-table-syntax-in-drizzle/
_______________________________________________ Mailing list: https://launchpad.net/~drizzle-discuss Post to : [email protected] Unsubscribe : https://launchpad.net/~drizzle-discuss More help : https://help.launchpad.net/ListHelp

