Generating unique ID's in triple-store, ala MySQL AUTO_INCREMENT

I'm under increasing pressure to start using RDF as a back-end for websites, rather than MySQL.

I've been considering the basic "patterns" of use, generally they boil down to create item, delete item, update item, get-from-id, get-items-matching-x.

In MySQL, when creating an item, we use an AUTO_INCREMENT field to be sure we get a unique ID. Is there a reliable way to do this with a triple-store as a backend?

I don't want to generate UUID's (although thanks for the suggestion), we often need to expose primary keys in URLs. eg: http://foobar.com/news/134.html I don't want to have to use: http://foobar.com/news/12Ef0023-F238EbA673CAA38-F34.html It's not user-friendly.

Is this necessary? I would assume that each triple's dereferencable URL would be a unique (though not necessarily incremented) id :)

This approach allows you to abstract away from the storage.

When using virtuoso you can use the fact that it is also a rdbms to use its internal atomic sequences. With something like this.

SPARQL INSERT INTO GRAPH <http://mygraph.com> {  
        <:a>
        <:p>
        sql:sequence_next("GRAPH_IDENTIFIER") };

See http://docs.openlinksw.com/virtuoso/sequenceobjects.html and http://docs.openlinksw.com/virtuoso/rdfsparql.html#rdfsqlfromsparql

To be honest I have not tested it yet. I will try this tonight. In practice you might need to do a separate select for key and then insert later as you might need the key directly in your front-end application.

Just an idea: how about GUIDs? I hear they are increasingly common in the RDBMS land as well. Maybe they are more expensive to produce and locate than integers, but you don’t have to care about concurrency.

By 'a reliable way' do you mean 'a way that makes the data store enforce it natively'? If so, then I believe that the answer is No.

Would it be hard to just store the value in a triple and handle an auto-increment mechanism that update it ? or a select max ? (also handling concurrence)

Sorry if that is stupid...but a few years back, we did the same with a DB that didn't handle auto-increment, it was just fine...

It's not quite triple-store only, but you could use a redis instance to look after your sequence in a non-racy kinda way. That way, whenever you need to create a new identifier you can perform an INCR command to get the unique integer you want to stick in your URIs.

Here are some links that might give you some ideas: