Skip to main content

Auto generated sequences, the silver bullet for concurrency ?

Ingres incorporated automatic generated sequences, a feature that was built into other dbms products, into version 9 onwards.

So are automatic generated sequences just for convenience or are they really useful?

They have many advantages which are speed, especially when caching is enabled, scalability, and elimination of concurrency issues associated with unique key generation.

But the drawback is that they can introduce gaps in the sequence in a variety of ways :
since auto generated sequences are an object that lives in the server, on server failure
it is lost. The same is true in case of caching since it can age out of the shared pool.

Gaps can also be introduced programmatically e.g. by means of a rollback:
user A is getting a number from the sequence let's say number 8 and commits
user A is getting the next number from the sequence, number 9
user B is getting the next number from the sequence, number 10
user A rolls back and user B commits thus a gap was effectively introduced between numbers 8 and 10

So really do you want to use auto generated sequences?
It depends on the system at hand. Does is it require gapless sequences with low
concurrency in return?(since the unique key must be generated and committed before generating a new one thus employing locking) or can it live with gaps and be highly concurrent and scalable ?

Although the sequences eliminate the concurrency issues associated with unique key generation, the key generated has to eventually be inserted into the database and as Mr. Roy Hann points out, depending on the storage structure and locking scheme employed there will be small or large concurrency issues and that Ingres prepares a solution to this problem with the introduction of unordered sequences which in essence will "randomize insertion into B-trees and ISAM tables, eliminating concurrency problems."

Comments

Artemus said…
Gapless sequences of numbers are rarely required in real business processes, and in those few where they are, one also usually needs very sophisticated protocols to ensure the numbers are kept in sync with other entities such a pre-printed cheques and certificates. There are other less obvious problems with gapless sequence numbers; for instance no new transaction can use the "next number" until the previous number has be used and committed. This has the effect of making the application strictly single-user--it doesn't scale at all. There are innumerable other problems too.

The general rule of thumb is that designs that depend on gapless sequences should be avoided at almost any cost. In fact, there are good reasons to prefer unique values generated in pseudo-random order. There are efficient algorithms for doing that and one was implemented in Ingres during the 2008 code sprint in London.

Popular posts from this blog

Serverless JavaScript

We recently joined in an interesting two-hour long conversation about Serverless JavaScript led by Steve Faulkner of Bustle who answered questions on Bustle, the Shep framework, the mindset behind the AWS Lambda infrastructure, and related topics.

The discussion took place on the Sideway conversation-sharing platform on January 6th. Here we present the best takeaways from the session which really should be taken notice of by anyone working on AWS.

Steve Faulkner:
At Bustle we serve over 50 million unique readers per month through a "serverless" architecture based on AWS Lambda and Node.js.  Of course there are still servers but we don't manage them. This shift has allowed us to develop products faster and decreased the cost of our infrastructure. I'll answer any questions about how we made this transition and how it has worked out. I'll also discuss some of the tools and best practises including our open source framework shep

Eran Hammer:
When would you…

First Hybrid Open-Source RDBMS Powered By Hadoop and Spark

Splice Machine is a novel attempt to merge the best parts of the traditional relational database management systems and their NoSQL counterparts with distributed and in-memory computing based on Hadoop and Spark.

Traditional RDBMS find it tough when faced with massive amounts of data, which they typically handle by scaling up, albeit expensively. Another side effect of the sheer volume of data accumulating from the likes of social media and mobile devices, is that OLTP and OLAP queries carry high performance hits that subsequently have detrimental effects on real time analysis and instant decision making.

full article on i-programmer

Google's Cloud Spanner To Settle the Relational vs NoSQL Debate?

Cloud Spanner is a new proposition for database as a service that emphatically offers "Relational with NoSQL scaling". Will Google come to dominate yet another market?

Once upon a time there was only one kind of database management system, the RDBMS, "R" for relational. Despite its resilience and trustworthiness, it had its shortcomings; it did not scale well, and the relational model it served proved inadequate in the dawn of the Big Data era for handling massive amounts of schema-less, unstructured data.
For this and a few other reasons, a new breed of DBMS's emerged, one that could handle the avalanche of big data, based on the notion of the key-value pair, and doing so by scaling horizontally. But, in order to become versatile, this new breed of management systems had to forgo the safety of the ACID and the cosiness of SQL, both long term partners of the relational model. full article on i-programmer