Skip to content

Support multiple pkey autogen schemes #117

Open

Description

@coffeemug

The uuid key autogen scheme we use isn't enough. We should allow picking an autogen scheme at table creation. Here are some alternative schemes we should support:

  1. Approximately chronological (e.g. non-colliding timestamps, roughly ordered)
  2. Approximately ordered (e.g. incrementing from zero, roughly ordered)

Activity

  1. pzol commented on May 30, 2013

    @pzol

    You probably are aware how mongodb creates its ids? This is similar to twitter snowflake. The hidden timestamp is a great bonus

    http://docs.mongodb.org/manual/reference/object-id/

  2. coffeemug commented on May 30, 2013

    @coffeemug
    ContributorAuthor

    Yes, the snowflake approach would probably be the first one we implement once we add another autogeneration scheme (I also suspect that coupled with the current scheme, it will be enough for most people).

  3. sandstrom commented on Jul 31, 2013

    @sandstrom

    I agree, Snowflake or something similar to MongoDB would be neat. Although not too different than UUIDs they are shorter [nicer in urls] and a bit easier to pass around.

  4. coffeemug commented on Aug 6, 2013

    @coffeemug
    ContributorAuthor

    For those watching this issue, this almost certainly won't happen until Rethink hits 2.0 -- sorry. Between UUID and upcoming date support, people should be able to find workarounds for almost every use case. While additional generation schemes are really nice, unfortunately there are much more important things we have to do first.

    If you run into a use case where this is a real showstopper, please let us know and we'll see if we can reprioritize.

  5. bryanhelmig commented on Nov 4, 2013

    @bryanhelmig

    👍 for this.

    The UUIDv1 scheme could work, although the MAC address encoding would probably be replaced with a random seed.

  6. sandstrom commented on Mar 11, 2014

    @sandstrom

    Two thoughts, regarding migrations from other databases to Rethink and string representation.

    When moving from MongoDB/MySQL to Rethink it's nice to use a uniform id format. It would be good if the Rethink ID function could both generate them randomly (normal method of operation) or based on a seed (which would be the old id from another structure).

    For example:

    rdbUuidFunction('mysql_table_name-1') => '1u7v7tzap6ua18f6lyr' // mysql to rethink
    rdbUuidFunction('5318cd64421aa9f2e800002d') => '40aubkd55r8yhoo2qr' // mongodb to rethink
    

    This use-case would be only for migrations, and it would always generate the same output for one input string.

    It would leave it to the developer to ensure that the input is unique (i.e. database_table_id for e.g. MySQL and another unique id for e.g. MongoDB.


    I know nothing about database design and choice of id algorithms, but having an id where the string representation is short (and url compatible) is neat, i.e. [a-z0-9] [alpha num] is better than [a-f0-9] [hex].

  7. coffeemug commented on Mar 11, 2014

    @coffeemug
    ContributorAuthor

    @sandstrom -- in case of a migration, why not just use the original ID as the new RethinkDB ID? (unless you want IDs for old data and new data to look consistent, which is the only consideration I can think of at the moment)

  8. sandstrom commented on Mar 12, 2014

    @sandstrom

    @coffeemug The thing I thought of was consistency. Maybe it's just my OCD :) (but I think others may find it useful too). And for some types of uuid generation it would not be difficult to include.

  9. modified the milestones: , backlog, subsequent on Mar 26, 2014
  10. mike-marcacci commented on Apr 10, 2014

    @mike-marcacci

    @sandstrom, not sure that's a good idea – you're going to completely break relationships between records that use the ID field. This is really something that would need to be scripted for your particular situation.

  11. sandstrom commented on Apr 10, 2014

    @sandstrom

    @mike-marcacci Yes, foreign keys must be updated too, naturally.

  12. coffeemug commented on Aug 14, 2014

    @coffeemug
    ContributorAuthor

    Note, this is related to #2063.

  13. 15 remaining items

  14. mbrevda commented on Sep 26, 2015

    @mbrevda

    Perhaps considering additional flexability would be usefull. For example, we don't like the hyphens in our UUID's. It would be nice if it was possible to remove these

  15. coffeemug commented on Sep 26, 2015

    @coffeemug
    ContributorAuthor

    👍

  16. DeividasJackus commented on Mar 9, 2016

    @DeividasJackus

    Hopefully this proves to be of some value... I find it to be a pretty elegant solution: Sharding & IDs at Instagram

  17. xfg commented on Jul 16, 2016

    @xfg

    +1 for human-readable ids

  18. RubenKelevra commented on Aug 2, 2017

    @RubenKelevra

    wondering why we don't have a simple increasing int, I know this might hurt performance to do a global lock on the database, but it would be useful for some application types.

    So we would need to run something like this atomically:

    r.db('nodes').table('basicdata').insert({'id': r.db('nodes').table('basicdata').max('id').getField('id')+1 })

  19. thelinuxlich commented on Aug 2, 2017

    @thelinuxlich

    The problem with autoincrementing ids is that RethinkDB uses range sharding, so you would need to run rebalance() on the table often.

  20. RubenKelevra commented on Aug 2, 2017

    @RubenKelevra

    @thelinuxlich are you sure this is really an issue? I've imported a table with an auto-incrementing id from a MySQL-Server and this is the data-distribution:

    bildschirmfoto von 2017-08-02 12-27-03

  21. thelinuxlich commented on Aug 2, 2017

    @thelinuxlich

    I'm sure it's a issue

  22. RubenKelevra commented on Aug 2, 2017

    @RubenKelevra

    @thelinuxlich forgive me the noobish question, but why is my table in this case perfectly balanced?

  23. thelinuxlich commented on Aug 2, 2017

    @thelinuxlich

    I don't have the technical knowledge to explain it, but I've tested inserting millions of records and the final result is unbalanced.

  24. mike-marcacci commented on Aug 2, 2017

    @mike-marcacci

    @RubenKelevra are you sure your primary keys are numbers and not in fact strings? Range sorting the string representations of auto incremented ints would balance, although not in the order you would expect of numbers.

    Also, how did you do the import? If you used a bulk utility, it’s possible it ran a rebalance for you; also, if you changed the sharding or replication strategies after your initial import or added/removed nodes, you likely triggered a rebalance.

  25. RubenKelevra commented on Aug 3, 2017

    @RubenKelevra

    @mike-marcacci yes - type is int.

    Imported by webui and simple r....insert({...}) a JSON dump of a MySQL Database-query.

    Because my export contains only strings, I‘ve bulk converted the export with sed to get an int as primary key and floats to be floats etc.

    I haven’t changed the geometry of the database table after import.

  26. added 3 commits that reference this issue on Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions