• Eager Eagle@lemmy.world
    link
    fedilink
    English
    arrow-up
    18
    ·
    edit-2
    18 hours ago

    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.

      • Eager Eagle@lemmy.world
        link
        fedilink
        English
        arrow-up
        7
        ·
        edit-2
        17 hours ago

        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.

        • Tja@programming.dev
          link
          fedilink
          arrow-up
          2
          ·
          15 hours ago

          UUID could be slower for SQLite. If you have a SEQUENCE and millions of concurrent writes you have other problems.

  • TehPers@beehaw.org
    link
    fedilink
    English
    arrow-up
    7
    ·
    17 hours 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.

  • ☭ghodawalaaman☭@programming.dev
    link
    fedilink
    arrow-up
    3
    arrow-down
    7
    ·
    19 hours ago

    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.

    • x00z@lemmy.world
      link
      fedilink
      English
      arrow-up
      16
      ·
      edit-2
      3 hours ago

      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)

        • exussum@lemmy.world
          link
          fedilink
          arrow-up
          2
          ·
          16 hours 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.

      • ☭ghodawalaaman☭@programming.dev
        link
        fedilink
        arrow-up
        1
        ·
        16 hours ago

        wow, I didn’t know we can have multiple databases for a single app/website. I assumed it wasn’t possible when I learned about k8s and the teacher said there will always be one database while you can replicate your frontend/backend pods

    • bitfucker@programming.dev
      link
      fedilink
      arrow-up
      9
      ·
      18 hours ago

      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.

      • ☭ghodawalaaman☭@programming.dev
        link
        fedilink
        arrow-up
        1
        ·
        17 hours ago

        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?

        • vrek@programming.dev
          link
          fedilink
          English
          arrow-up
          2
          ·
          15 hours ago

          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

    • lankydryness@lemmy.world
      link
      fedilink
      arrow-up
      3
      ·
      16 hours 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!

    • Eager Eagle@lemmy.world
      link
      fedilink
      English
      arrow-up
      5
      ·
      19 hours ago

      In most cases it’s more useful they’re not predictable, and I’m definitely not remembering private keys myself, so what’s the point. You can have preservation of creation order with UUID v6 and v7.

    • fizzbang@lemmy.world
      link
      fedilink
      arrow-up
      4
      ·
      18 hours 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