all 21 comments

sorted by: hot top controversial new old
[–] 19 points 5 months ago* (last edited 5 months ago) (3 children)

It's weird their main reason is performance, but then proceed to benchmark SQLite. Who's inserting 10s of millions of records per minute on sqlite?

Even in production, client-server DBMSs, I'd wager that there are plenty of other things that dominate performance before you even get near your choice of a primary key, so it probably doesn't matter until you get a large enough throughput in your database.

  • source
  • hideshow 3 child comments
  • [–] 3 points 5 months ago (2 children)

    I would say their findings would be pretty consistent no matter which DBMS you use.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 9 points 5 months ago* (1 child)

    But that's the thing with benchmarks, you run them because making assumptions about performance based on guesswork often fails. SQLite is very much architecturally unique for being a daemon-less database that doesn't concern itself with concurrent writes.

    Is UUID as pk slower than int or bigints? Probably - you're storing 4x more data than a 32-bit integer. Does it matter? Probably not.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 9 points 5 months ago

    I'm glad this covers UUIDv7. Unless you need cryptographically-random, unpredictable row IDs, using UUIDv7 helps a lot with the performance by making the keys ordered at least.

  • source
  • [–] -5 points 5 months ago (15 children)

    awesome!

    but seriously who uses UUID as their primary keys? what's wrong with plain old INT. it's more predictable you can look at the integer primary key and tell which records created when relative to each other. also you can easily remember them. unlike UUID.

  • source
  • hideshow 15 child comments
  • [–] 23 points 5 months ago* (last edited 5 months ago) (5 children)

    Using integer primary keys often creates race conditions (that result in collisions) when you have multiple database shards, so UUIDs have become the standard. (2 different webservers can create a record in 2 different database that then sync with eachother in the background). Using UUIDs for SQLite is less common though as SQLite is mostly used for small or local applications, but developers are used to UUIDs now and even consider them the standard for primary keys now so you do see them in SQLite databases. (Oh and there's some SQLite compatible sharding servers too)

  • source
  • parent
  • hideshow 5 child comments
  • [–] 2 points 5 months ago (2 children)

    Can't you just reserve X bits of the primary key to store a shard ID?

  • source
  • parent
  • hideshow 2 child comments
  • [–] 3 points 5 months ago

    If you are owning every little part of the design in every nuance, sure. But how do you configure this in mysqll, postgres, etc etc. does your favorite framework support this easily.

  • source
  • parent
  • [–] 12 points 5 months ago (5 children)

    Lemmy sure loves swallowing my reply. To answer your question shortly is an offline first app where the user can add records and the relation during offline and then sync it later after connection is re-established.

  • source
  • parent
  • hideshow 5 child comments
  • [–] 1 point 5 months ago (3 children)

    um, I am not sure if I understood this.

    Let's say I want to create a record with my username and password. I will create it offline like saving it in a Json or plain text file. now when I get an internet connection back I will just send that username and password to the database. here the user isnt sending the Id so it shouldn't matter. but if the user is sending the Id then yeah I can see how it could become a problem. eg, two user can be sending the same Id 500 and will lead to race condition as someone else mentioned here.

    is it correct?

  • source
  • parent
  • hideshow 3 child comments
  • [–] 2 points 5 months ago (2 children)

    Yeah if your only storing username and passwords and hoping no one uses the same username. Now consider I'm running tests on a piece of hardware and storing results in the database. I run 45 tests per unit so I can't use serial number as id, I want a way to get all results for a single unit and I have 5 testers since I'm high volume but each test takes 30 seconds.

    Tester 1 and tester 4 might get same pk if offline, random IDs for each record won't work since I can't combine everything for 1 unit. This is more why you use uuids for each test

  • source
  • parent
  • hideshow 2 child comments
  • [–] 5 points 5 months ago

    Distributed systems where the identity isn’t provided by the DBMS need UUIDs. I don’t really get why you’d use uuids in sql, except in the case mentioned where the client is bringing its own ids

  • source
  • parent
  • [–] 2 points 5 months ago

    lots of people, I use them in certain applications. Not sure I’ve ever had a use case where I needed to memorize the PK of my data, but I suppose if you needed that, then a simply INT might be the choice.

    As for sorting/creation related to each other, you can use UUIDv7. The first group of bits is time since epoch. So they naturally sort based on time created. Handy!

  • source
  • parent
  • 1 comment in c/programming@lemmy.ml view that post
    [–] 3 points 5 months ago

    This goes to show that using uuid4 is not a good thing for db tables, but that is what uuid7 was designed for. Also using ROWID or autonumber or whatever built in system the database is using is the best bet. Only use uuid7 if you need distributed inserts and you want the clients to be able to generate their own keys.

  • source