News for hackers. Stuff that matters.
Re:Nanosecond timestamp collisions are common by madsbuch on Friday July 21, 2023 @04:51AM (#36811570)
You need it to make database indices perform better.

If you don't need that, but just need a random UUID, UUIDv4 is better.

Re:Nanosecond timestamp collisions are common by mcv on Friday July 21, 2023 @05:20AM (#36811747)
But shouldn't that be a separate field then?
Re:Nanosecond timestamp collisions are common by mattashii on Friday July 21, 2023 @05:32AM (#36811822)
The logistics of combining fields in indexes and identifiers is relatively complex, while the logistics of indexing a single field is comparatively trivial. This is also why you don't ship timestamps using separate fields for second/minute/hour/day/month/year, but a single ISO-string or UNIX timestamp as representation: it makes querying and interpreting the value more consistent.
Re:Nanosecond timestamp collisions are common by frankreyes on Friday July 21, 2023 @06:37AM (#36812208)
Create a new column with an MD5 hash of the other columns. Easy.

/s

Re:Nanosecond timestamp collisions are common by rvnx on Friday July 21, 2023 @05:29PM (#36820062)
This is how it works, except it's not MD5 but a less-costly hash function
Re:Nanosecond timestamp collisions are common by eru on Saturday July 22, 2023 @10:53PM (#36832160)
MD5 is a useless hash function these days.

It's not cryptographically secure (anymore). And there are cheaper non-cryptographically secure hash functions.

Re:Nanosecond timestamp collisions are common by btilly on Friday July 21, 2023 @04:50PM (#36819533)
Disagree on "relatively complex".

    create index on $table ($field1, $field2);
Seems pretty simple to me.
Re:Nanosecond timestamp collisions are common by mattashii on Saturday July 22, 2023 @06:06AM (#36824934)
It is noy just the DDL of the primary table that needs to care about it, but also all foreign keys, DML, queries, APIs accessing the data, etc. Storing that UUIDv7 is likely going to be cheaper than pushing the cost of keeping a composite identity onto other components and systems that work with that data.
Re:Nanosecond timestamp collisions are common by btilly on Saturday July 22, 2023 @12:10PM (#36827424)
Well, that depends on how you manage it. An ORM will find it trivial. Custom SQL, not always so much.

That said, PostgreSQL offers https://www.postgresql.org/docs/current/rowtypes.html which gives you the best of both worlds. A single field which contains 2 fields that can later be extracted. So everywhere you can write a single field for joins, etc. But then when you need it broken out...

Re:Nanosecond timestamp collisions are common by madsbuch on Friday July 21, 2023 @05:34AM (#36811832)
I am curios about this, and might be misunderstanding what you mean.

Can you layout a demo architecture where you use multiple keys like you propose?

Re:Nanosecond timestamp collisions are common by junon on Friday July 21, 2023 @05:37AM (#36811847)
There are many DBMSes that combine columns into a singular primary key. Performance tradeoffs vary, especially when it comes to indexing.
Re:Nanosecond timestamp collisions are common by e12e on Friday July 21, 2023 @07:41AM (#36812664)
Any pure relational database design will eschew surrogate keys - most real-world systems will (should) add them back - because a surprising number of good natural keys end up changing (names change, phone numbers change, emails change, twitter handles become irrelevant/disappear, location of birth may change subject to geographic regions changing size...).

And on top of all that, there are efficiency concerns.

That said, at least for join tables AFAIK - there aren't often a need for row IDs beyond the involved foreign keys - unless you need to add meta data from other relations/tables...

Re:Nanosecond timestamp collisions are common by TRiG_Ireland on Friday July 21, 2023 @08:24AM (#36812990)
> location of birth may change

My British passport says I was born in Birr; my Irish passport says I was born in Galway. These are both correct, because they are answering different questions. (I was born in the town of Ballinasloe in County Galway, but my mother's place of residence at the time of my birth was the town of Birr in County Offaly.)

Re:Nanosecond timestamp collisions are common by pc86 on Friday July 21, 2023 @04:01PM (#36818897)
So British place of birth means "mother's residence" and not place of birth?
Re:Nanosecond timestamp collisions are common by rvnx on Friday July 21, 2023 @05:43PM (#36820266)
Official guidances here: https://assets.publishing.service.gov.uk/government/uploads/...

Could maybe be just a mistake when doing the UK registration ? It's an easy fix if wanted.

Re:Nanosecond timestamp collisions are common by e12e on Friday July 21, 2023 @07:40PM (#36821520)
> Could maybe be just a mistake when doing the UK registration ? It's an easy fix if wanted.

Changes! lol

Re:Nanosecond timestamp collisions are common by TRiG_Ireland on Monday July 24, 2023 @05:21AM (#36845018)
That's my memory of it. My British passport is expired, and is probably somewhere in my parents' house. I don't actually know what it says on it. I do clearly remember that at least one British form of ID I had at one time recorded my mother's place of residence rather than my actual birth place. I thought it was the passport. Maybe I was wrong.
Re:Nanosecond timestamp collisions are common by dtech on Friday July 21, 2023 @05:54AM (#36811966)
But then you have 2 identifiers which complicates everything.
Re:Nanosecond timestamp collisions are common by dtech on Friday July 21, 2023 @05:53AM (#36811960)
I feel like v7 is almost a strictly better v4. Assuming you can generate a v7 (you have a time source), what are the disadvantages?
Re:Nanosecond timestamp collisions are common by wolf550e on Friday July 21, 2023 @06:36AM (#36812202)
You can hand out uuidv4 to clients without revealing anything.
Re:Nanosecond timestamp collisions are common by madsbuch on Friday July 21, 2023 @06:27AM (#36812151)
Entropy. You loose bits to a known source, which reduce entropy of the UUID.
Re:Nanosecond timestamp collisions are common by dralley on Friday July 21, 2023 @12:42PM (#36816080)
128 bits is a lot of entropy to go around, though.
Re:Nanosecond timestamp collisions are common by dtech on Friday July 21, 2023 @03:37PM (#36818534)
I do feel 74 bits per second is enough though. That would require 2^(74/2) = 137 billion UUIDs generated in a single second for a 50% chance of a single collision.
Re:Nanosecond timestamp collisions are common by andersa on Friday July 21, 2023 @02:24PM (#36817505)
Anyone who can see the uuidv7 can determine at what time it was generated. You might not want that for things exposed to users.
Re:Nanosecond timestamp collisions are common by EGreg on Friday July 21, 2023 @07:09AM (#36812400)
I dont know why people use relational databases other than they were first and “that’s the way it’s always been done”.

Why not use a graph database? O(1) lookups instead of O(N). Why need indices if you can just point to the data. Why use JOINs when map-reduce querying is far more flexible?

Re:Nanosecond timestamp collisions are common by tharkun__ on Friday July 21, 2023 @08:47AM (#36813150)
They were not first.

ISAM and VSAM come to mind. Yes it says "files" in there a lot but it got used like a database with programming interfaces like finding records in a database. If you will this method is more like NoSQL databases than a relational DB. The I in ISAM was a step towards not having to know the key (true "NoSQL"). Kind of like today's NoSQL databases all also give the ability to add indexes now.

https://en.m.wikipedia.org/wiki/ISAM

Re:Nanosecond timestamp collisions are common by dlisboa on Friday July 21, 2023 @10:14AM (#36814023)
I've been interested in learning more about them and how to best utilize them in my company. What graph database and query language would you recommend (regardless of stack)?
Re:Nanosecond timestamp collisions are common by EGreg on Friday July 21, 2023 @10:15AM (#36814033)
1. Memgraph 2. Neo4j

As for query language: definitely Cypher!

Re:Nanosecond timestamp collisions are common by madsbuch on Friday July 21, 2023 @11:23AM (#36814870)
How do you do constant time lookup an graph databases?

My intuition let's me know that you can not get below O(n log n) (Lower limit for comparison based ordering)

Re:Nanosecond timestamp collisions are common by eru on Sunday July 23, 2023 @04:46AM (#36833619)
> My intuition let's me know that you can not get below O(n log n) (Lower limit for comparison based ordering)

That intuition should point at O(log n), shouldn't it?

In any case, it totally depends how your data is stored and how/what you want to look up.

If you already have some kind of id of your node in the graph you want to look up, you can get O(1) lookup and still call it a graph database. If you have to traverse the graph, then it depends on the structure of the graph and where your entry point is, etc.

I'm rather skeptical of graph databases. Whatever they can do, you can do with a relation database and datalog. (Think of datalog as SQL plus recursion, perhaps.) See https://en.wikipedia.org/wiki/Datalog

Re:Nanosecond timestamp collisions are common by insanitybit on Friday July 21, 2023 @12:43PM (#36816093)
You aren't describing a property of a graph database. You're describing a property of some set of key value based systems.

The reason why you want indices is because some query patterns don't have a key to perform a look up on.

Re:Nanosecond timestamp collisions are common by eru on Saturday July 22, 2023 @10:54PM (#36832166)
You might want to read Codd's paper: https://www.seas.upenn.edu/~zives/03f/cis550/codd.pdf