C.4. Sequences #

C.4.1. Are global sequences supported in Shardman? #

Yes, they are supported. However, there are specifics of their work that should be taken into account. Under the hood of global sequences, there are regular sequences on each shard, and they are allocated by sequential blocks (of 65536 numbers by default). When numbers are passed to the sequence, the local sequential block is given to the local sequential block on the shard. I.e., numbers from the global sequences are unique, but there is no strict monotony (unlike in PostgreSQL). Well, there may be "holes" in the values given by the sequencer.

C.4.2. How to create a global sequence? #

CREATE SEQUENCE ... WITH (GLOBAL);
    

The nextval function can be used to fetch the next value of a sequence:

SELECT nextval('acl_id_seq'::regclass);
    

Data types bigserial, smallserial, and serial (for automatic creation of sequences and output of default values from it) are implemented and work for both sharded and global tables. It is recommended to use bigserial unless there are special requirements.

pdf