[
https://issues.apache.org/jira/browse/CASSANDRA-9200?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14520469#comment-14520469
]
Robert Stupp commented on CASSANDRA-9200:
-----------------------------------------
We could do it a bit better than ”just” integer/numeric sequences.
By involving UDFs to generate the "next block", people could do very fancy
things - somewhat similar to user-defined-aggregates.
{code}
CREATE FUNCTION wordListIncrementer(previous text)
RETURNS text
LANGUAGE java
AS ' return previous + 'x';'
CREATE FUNCTION wordListNextBlock(previous text)
RETURNS text
LANGUAGE java
AS $$
switch (previous) {
case "alpha": return "beta";
case "beta": return "gamma";
...
CREATE SEQUENCE wordListSequence
START WITH 'alpha'
INCREMENT USING wordListIncrementer
SKIP_BLOCK USING wordListNextBlock;
CREATE TABLE foo ( pk text PRIMARY KEY, ...);
INSERT INTO foo (pk, ...) VALUES (wordListSequence.nextval, ...);
{code}
By writing the pseudo code I realized that we either need something like
{{SELECT xyz() FROM DUAL}} or the ability to return a result set from an
{{INSERT}}/{{UPDATE}} statement to actually return the generated values to the
client.
I'm just brain-dumping:
We could also distinguish between per-node and global sequences, where the
per-node sequences could optionally include the host-id or IP (if and how the
user wants it).
Maybe the user only wants some sequence per node just to generate some part of
a primary key.
Per-node sequences would also not need to use cluster-wide synchronization.
”Global” sequences could possibly fail, if one DC is not available.
Probably start with local and global integer sequences and add UDFs on top?
> Sequences
> ---------
>
> Key: CASSANDRA-9200
> URL: https://issues.apache.org/jira/browse/CASSANDRA-9200
> Project: Cassandra
> Issue Type: New Feature
> Reporter: Jonathan Ellis
> Fix For: 3.x
>
>
> UUIDs are usually the right choice for surrogate keys, but sometimes
> application constraints dictate an increasing numeric value.
> We could do this by using LWT to reserve "blocks" of the sequence for each
> member of the cluster, which would eliminate paxos contention at the cost of
> not being strictly increasing.
> PostgreSQL syntax:
> http://www.postgresql.org/docs/9.4/static/sql-createsequence.html
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)