MySQL has a quite unique feature: the pluggable storage engine interface. Thanks to it MySQL supports different Storage Engines for different needs: MyISAM is perfect for heavy read, InnoDB for transational data and blackhole .... for sending data to /dev/null.
Thanks to some advance science we now have a wormhole Storage Engine. While the blackhole can only be written to but nothing ever comes back, the wormhole is the inverse of it. You get data from another galaxy, but all writes might have no effect on your side. Sounds useful ?
What's the deal ? The wormhole
SE is a lua
-based storage engine. The data is "stored" in a script-language. ... Ok, this explaination doesn't help very much. Let's take a look at an example:
The CREATE TABLE
for a wormhole table is pretty simple. No magic:
1 2 3 4 | root@127.0.0.1:test> show create table t1\G
CREATE TABLE `t1` (
`id` int(11) DEFAULT NULL
) ENGINE=WORMHOLE DEFAULT CHARSET=latin1
|
You can select from it as usual:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | root@127.0.0.1:test> select * from t1;
+------+
| id |
+------+
| 5 |
| 7 |
| 3 |
| 92 |
+------+
4 rows in set (0.13 sec)
root@127.0.0.1:test> select * from t1;
+------+
| id |
+------+
| 5 |
| 7 |
| 3 |
| 20 |
+------+
4 rows in set (0.11 sec)
|
But hey, we never wrote to it, but the data is changing. Let's take a look at the storage:
1 2 3 | $ cd test/
$ cat t1.lua
return { { 5 }, { 7 }, { 3 }, { math.random(1, 100)} }
|
A lua-script, the last field is generated at run-time. Now that this works, what is it good for ?
Coming up
For me this is more an experiment on how to write a storage engine. So, we will see some more stuff getting implemented other than just table-scans. Next is table-discovery to generate the .frm
at runtime from the lua-script.
Comments