From: Stewart Smith Date: May 10 2012 2:51am Subject: Re: pointers on implementing foreign keys for a storage engine List-Archive: http://lists.mysql.com/internals/38511 Message-Id: <87d36ceojb.fsf@flamingspork.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Tue, 8 May 2012 11:23:34 -0400, Zardosht Kasheff wrote: > Are there any pointers for how one would go about implementing foreign > keys in the storage engine? I cannot seem to figure it out from the > handler API. As Tomas said, there isn't really an API. Ther was an aborted attempt to have server side Foreign keys (see http://bugs.mysql.com/bug.php?id=43521 for public evidence of this existing in some form) so that Falcon and other engines could have foreign keys. I wouldn't hold my breath for this though, since Oracle has both MySQL and InnoDB, the motivation to work on a rather complex task to benefit other engines (of which there are not many, and users are a very small number compared to InnoDB users) is rather small. It is, and will be for the forseeable future, pretty much entirely the responsibility of the storage engine. There's three interactions with the MySQL core: 1) parsing the foreign key statements - look at InnoDB CREATE TABLE code for how this is done. Yes, you're going to have to have your own parser. At some point, MySQL began parsing these too... but that may have been in earlier 6.0 trees around the time we forked Drizzle than in 5.1 or 5.5 or 5.6 which you'd be working against. 2) SHOW CREATE TABLE - again, look at InnoDB for how this is done, you supply snippets of the SQL back to the server SHOW CREATE TABLE code. 3) propagating errors back to the user (again, look at innodb) Other engines that have supported foreign keys through this interface include PBXT... I'm not sure if anyone else got close or ont, I honestly don't think so.... *maybe* some of the 6.0-falcon trees, but I doubt it. -- Stewart Smith