Hartmut was asking me some time ago how table discovery in the storage engine interface works. After reading through the code from ndb, archive and memcache I was a bit disappointed: all of them are just copying the definition in binary form around.

For the wormhole SE the lua-file has to create table structure on the fly. You only drop in the .lua into the db-folder and a SELECT will pick it up automaticly.

We use a small function which returns the table definition:

function discover()
        return {
                { name = "fld1", type = 1 },
                { name = "fld2", type = 2 },
                { name = "fld3", type = 15, length = 64 }
        }
end

A SHOW CREATE TABLE against the table shows us:

root@127.0.0.1:test> show create table foobar\G
*************************** 1. row ***************************
       Table: foobar
Create Table: CREATE TABLE `foobar` (
  `fld1` tinyint(4) unsigned,
  `fld2` smallint(6) unsigned,
  `fld3` varbinary(64)
) ENGINE=WORMHOLE DEFAULT CHARSET=latin1
1 row in set (0.01 sec)

The types are numbers for now, I'll export all the field defs in a next push.

Summary

The table definition is in control of the lua-script. No need for a extra CREATE TABLE statement to declare the existence of the table.

With this basic framework we can now rewrite our previous examples and generate tables on the fly.


Comments

Enable javascript to load comments.