Skip to content

Support for SERIAL type #511

Closed
Closed

Description

@KES777

When table is created on the master node of citus claster

# CREATE TABLE "offers" (
(#   "id" serial NOT NULL,
(#   "ctime" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
(# );

We may distribute it:

# select master_create_distributed_table( 'offers', 'id', 'range' );
 master_create_distributed_table 
---------------------------------

(1 row)

But when we try to create empty shard we get error:

# select master_create_empty_shard( 'offers' );
WARNING:  could not receive query results from citus-work1:9701
DETAIL:  Client error: relation "offers_id_seq" does not exist
WARNING:  could not create shard on "citus-work1:9701"
WARNING:  could not receive query results from citus-work2:9701
DETAIL:  Client error: relation "offers_id_seq" does not exist
WARNING:  could not create shard on "citus-work2:9701"
ERROR:  could only create 0 of 2 of required shard replicas

That is because of the id column:

id               | integer                     | not null default nextval('offers_id_seq'::regclass)

Do not allow to distribute tables with serial type.

Activity

  1. KES777 commented on May 10, 2016

    @KES777
    Author

    Ambiguous because it is not clear: the tables with serial type not supported or master_create_empty_shard does not distribute required info.

  2. changed the title [-]ambigious behaviour not covered in the doc[/-] [+]Ambiguous behaviour not covered in the doc[/+] on May 10, 2016
  3. mtuncer commented on May 10, 2016

    @mtuncer
    Member

    Hey Eugen Konkov (@KES777)

    This issue is related to serial type not being supported. We have 2 issues related to this one
    #211 is about the issue you are describing, #213 is about a feature that offers a fix for this one too.

  4. changed the title [-]Ambiguous behaviour not covered in the doc[/-] [+]Support for SERIAL type[/+] on May 24, 2016
  5. lithp commented on May 24, 2016

    @lithp
    Contributor

    Unfortunately the fix for #213 won't cover this. Even though nextval() will be supported, when we try to create shards the worker fails on not null default nextval('offers_id_seq'::regclass).

    Fixes:

    1. Also push down sequence creation so the workers get their own (unused) sequences
    2. Notice SERIAL and emit modified DML commands to the workers, they only see an not null type
  6. marcocitus commented on Jul 15, 2016

    @marcocitus
    Contributor

    With #488 merged, serial can now be used in distributed tables, provided that the user also creates the sequence on all the workers and that it is not the partition column.

    If the sequences do not exist on the worker, master_create_worker_shards errors out because it does not recognize the sequence reference in the create table command (e.g. "id int not null default nextval('events_id_seq')"), but the sequences on the workers are never actually used, since nextval is evaluated by the master. If the partition column is serial, INSERT will error out, though COPY will work.

    A way of addressing the master_create_worker_shards error would be to strip the default value from create table statement used to create shard placements. When we do an INSERT or COPY, we send all columns with the default filled in even if the user only provided a subset, so there is no need for the workers to know about default values.

    We should also add a check to master_create_distributed_table to error out if there is a non-constant expression in the partition column.

  7. ozgune commented on Jan 3, 2017

    @ozgune
    Contributor

    Marco Slot (@marcocitus) -- I'm sifting through our old issues and had a question on this one.

    I think we can now create a distributed table that has a SERIAL column, without asking the user to create sequences on workers. Does that align with your understanding as well? If so, I'm planning to close this issue.

    (We have a separate issue related to using a SERIAL column for distribution in #687. We'll keep that one open.)

  8. marcocitus commented on Jan 4, 2017

    @marcocitus
    Contributor

    Yep, fixed by #673

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions