{"id":154,"date":"2010-02-02T14:35:16","date_gmt":"2010-02-02T14:35:16","guid":{"rendered":"http:\/\/blog.soton.ac.uk\/webteam\/?p=154"},"modified":"2010-02-02T14:35:16","modified_gmt":"2010-02-02T14:35:16","slug":"replacing-mysql-with-a-triple-store","status":"publish","type":"post","link":"https:\/\/blog.soton.ac.uk\/webteam\/2010\/02\/02\/replacing-mysql-with-a-triple-store\/","title":{"rendered":"Replacing MySQL with a triple-store"},"content":{"rendered":"<p>Some academics have urged me to consider using an triple-store as a back-end for some of our websites, as oppose to our normal MySQL approach. I&#8217;m not convinced, but it&#8217;s an interesting challenge. I started by looking into what common &#8220;patterns&#8221; we use SQL which we would need to replicate in RDF. Or change how we approach problems in the first place.<\/p>\n<h3>Our usual MySQL &#8220;patterns&#8221;<\/h3>\n<ol>\n<li>Create a record from &lt;object&gt;<br \/>\nWe create record, which is in effect a serialisation of an object. Most often it represents a human, an account, an event, an organisation or an article (text + metadata). We use the database to generate a unique key for the item, in the current context. Generally an integer. In MySQL we use AUTO_INCREMENT for this, but every SQL DB has a varient.<\/li>\n<li>Delete record with &lt;ID&gt;<\/li>\n<li>Update record with &lt;ID&gt; to match &lt;object&gt;<\/li>\n<li>Retrieve record with &lt;ID&gt;<\/li>\n<li>Find\/retrieve records matching &lt;criteria&gt;<\/li>\n<\/ol>\n<p>Update can reasonably be abstracted to &#8220;delete then create&#8221; so lets ignore it.<\/p>\n<p>&#8220;Find&#8221; and &#8220;retrieve&#8221; require some new techniques, but are not a big concern.<\/p>\n<p>My current understanding is that when adding a set of triples you can say that they are all part of a &#8220;graph&#8221; with URI &lt;x&gt;, and later you can remove or replace all URIs from graph &lt;x&gt;.<\/p>\n<p>The one thing entirely missing is the ability to generate new integers in a sequence.<\/p>\n<p>I&#8217;ve been given two suggested solutions by the experts&#8230;<\/p>\n<h3>UUID<\/h3>\n<p>Suggestion one, to use UUID (universal unique IDs) or hashes. But the problem is, I want to use these in URLs and URIs and I want to use http:\/\/webscience.org\/person\/6.html not http:\/\/webscience.org\/person\/e530d212-0ff1-11df-8660-003048bd79d6.html<\/p>\n<h3>Flock a file<\/h3>\n<p>A second suggestion, was to flock a local file containing the next value. (lock file, read file, update file, unlock file). This would work, but I want the current position in each sequence to be stored with my other data, and accessed\/modified using the same rights as can read\/write the triple store. That&#8217;s what I&#8217;m used to with MySQL.<\/p>\n<h3>My Idea 1: Sequence Service<\/h3>\n<p>My first idea, was to create a stand alone service which could run on the same server as the triple store, and you could query it, via HTTP or command line, for a new integer in an sequence. Sequences could be identified via a URI.<\/p>\n<pre>http:\/\/dbserver:12345\/next_in_sequence?seq=http:\/\/webscience.org\/people_sequence<\/pre>\n<p>Which would return &#8220;23&#8221; then &#8220;24&#8221; etc. The locking code could be handled in the sequence server, and the assumption would be that only trusted parties could connect (like SPARQL). This service could work by:<\/p>\n<ul>\n<li>Locking (all requests processed sequentially)<\/li>\n<li>Querying the triple store for &lt;http:\/\/webscience.org\/people_sequence&gt; &lt;currentValue&gt; ?value<\/li>\n<li>Replacing the triple with ?value+1<\/li>\n<li>Unlocking<\/li>\n<li>Returning ?value+1<\/li>\n<\/ul>\n<p>While this is a bit icky, it does mean that my data remains stored in one place, including the state of each sequence.<\/p>\n<p>What this doesn&#8217;t do is provide one access point. All SQL implementations provide a solution for this, and I suspect that, long term, so will triple stores. But I can&#8217;t see the purists liking it going through the same access interface as it&#8217;s clearly a hack.<\/p>\n<h3>Non technical concerns with RDF back-ends<\/h3>\n<p>On a non-technical note, I&#8217;m also concerned that an RDF+PHP solution is not very maintainable. You can&#8217;t easily hire someone with these skills yet.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Some academics have urged me to consider using an triple-store as a back-end for some of our websites, as oppose to our normal MySQL approach. I&#8217;m not convinced, but it&#8217;s an interesting challenge. I started by looking into what common &#8220;patterns&#8221; we use SQL which we would need to replicate in RDF. Or change how [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[198,86,136,227],"tags":[],"class_list":["post-154","post","type-post","status-publish","format-standard","hentry","category-best-practice","category-database","category-rdf","category-sql"],"_links":{"self":[{"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/posts\/154","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/comments?post=154"}],"version-history":[{"count":2,"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/posts\/154\/revisions"}],"predecessor-version":[{"id":156,"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/posts\/154\/revisions\/156"}],"wp:attachment":[{"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/media?parent=154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/categories?post=154"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/tags?post=154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}