Skip to content

Support sequences #211

Closed
Closed

Description

@citus-github-bot

Issue by jberkus
Thursday Dec 04, 2014 at 22:58 GMT
Originally opened as citusdata/pg_shard#4


pg_shard needs to support sequences and SERIAL/BIGSERIAL. The simplest way to do these for now is to have the sequence live on the master. Later we'll need to do something more complicated, but 9.5 will have machinery for that, I think.

Activity

  1. citus-github-bot commented on Feb 4, 2016

    @citus-github-bot
    Author

    Comment by jasonmp85
    Thursday Dec 04, 2014 at 23:57 GMT


    Having the sequence live on the master is essentially a must right now, as INSERT statements are commutable: conditions could arise wherein two racing INSERT commands result in different sequence values across replicas. Perhaps that's an argument for looking into logical replication, but the feature wasn't mature enough for us to investigate earlier in pg_shard's lifecycle.

    Right now we eagerly evaluate any "constant expressions" during planning, e.g. we transform char_length('Jason') into the integer 5. Certain other functions could reasonably be supported by eagerly evaluating them on the master during planning, even things like rand or in your case, nextval. Since sequence values are never rolled back, our loose transactional semantics don't even get in the way here.

    For the immediate future, we could expand the types of expressions we eagerly evaluate, or even offer a special eager function to allow users to force eager evaluation of functions on the master.

  2. added
    feature
    on Feb 4, 2016
  3. citus-github-bot commented on Feb 4, 2016

    @citus-github-bot
    Author

    Comment by jasonmp85
    Friday Dec 05, 2014 at 00:00 GMT


    Nothing stands out in my mind about special support for this kind of thing in 9.5… do you have a quick link to a pgsql-hackers thread on the topic? I'm a pretty heavy lurker in that list but don't remember anything about this.

  4. citus-github-bot commented on Feb 4, 2016

    @citus-github-bot
    Author

    Comment by jberkus
    Friday Dec 05, 2014 at 00:11 GMT


    Jason: there's some stuff buried in the Bi-directional replication code which allows replicas to pull "chunks" of sequences, in effect allowing for distributed sequences. However, this doesn't at all solve the consistency issue between shards.

    Maybe we'd be better off implementing a UUID which is compatible with pg_shard instead, something which will be consistent yet unique across shards. Not quite sure how that would work, though.

  5. citus-github-bot commented on Feb 4, 2016

    @citus-github-bot
    Author

    Comment by jberkus
    Friday Dec 05, 2014 at 18:31 GMT


    Maybe we should borrow code from here? https://github.com/OptionsHouse/shard_manager

    Shaun has a fairly advanced distributed ID-generation widget. We may need to work out licensing issues though.

  6. citus-github-bot commented on Feb 4, 2016

    @citus-github-bot
    Author

    Comment by digi604
    Thursday Jul 23, 2015 at 12:29 GMT


    implementing this would be highly appriciated.

  7. citus-github-bot commented on Feb 4, 2016

    @citus-github-bot
    Author

    Comment by rodo
    Sunday Aug 09, 2015 at 16:06 GMT


    Support sequences is definitely a nice to have.
    Thanks for pg_shard it's a huge improvement for postgresql.

  8. ozgune commented on Feb 25, 2016

    @ozgune
    Contributor

    We frequently hear this feature request. Most application libraries that work with PostgreSQL use sequences (Active Record) by default.

  9. travisjeffery commented on Apr 21, 2016

    @travisjeffery

    What's the best workaround for this right now?

  10. lithp commented on Apr 28, 2016

    @lithp
    Contributor

    Travis Jeffery (@travisjeffery) I think the easiest workaround is do create an "IMMUTABLE" function which actually calls nextval() internally. The master will automatically call the function while planning the query.

  11. KES777 commented on May 10, 2016

    @KES777

    As workaround I want to create trigger BEFORE INSERT but saw there is another way to complete that. Brian Cloutier (@lithp) : may you supply a link to how to create such function which will be called by master while planning the query?

  12. KES777 commented on May 10, 2016

    @KES777

    Answer my question: http://www.postgresql.org/docs/9.5/static/xfunc-volatility.html

    Even a function with no side-effects needs to be labeled VOLATILE if its value can change within a single query; some examples are random(), currval(), timeofday().

    But doing so (mark function as immutable) the next query may be optimized and this function will not be called instead it will be replaced by value from previous call. But this is not the result we are trying to achieve.

  13. sumedhpathak commented on Jun 3, 2016

    @sumedhpathak

    Murat Tuncer (@mtuncer) Before starting on this task, could you sync up with Andres Freund (@anarazel) ?

  14. mtuncer commented on Jun 10, 2016

    @mtuncer
    Member

    There are 2 legs for this work:

    • make sure shards could be created at workers
    • row insertion honors serial type and evaluates sequence

    Our original thinking on the first part was to replicate sequence on workers so that shard creation does not fail due to non-exiting sequence at worker. Having a sequence at worker would not have any other function other than being there doing shard table creation.

    Can we instead drop sequence reference from shard table ? I think that would make our intention more explicit. If go this way, table definition at master will have the serial type and sequence definition, however shard table in worker would only have type but not default value coming from sequence.

  15. sumedhpathak commented on Jun 17, 2016

    @sumedhpathak

    Currently blocked on #213

  16. marcocitus commented on Jul 15, 2016

    @marcocitus
    Contributor

    You should now be able to use sequences in INSERT statements. They are forbidden in DELETE and UPDATE statements and a little wonky in SELECT statements (nextval calls used in SELECT get pushed down to the workers), but using nextval in a SELECT is a little wonky in and of itself.

    There are some separate issues around using serial:
    #511 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

feature

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions