Clifford Meece Personal Blog
Thoughts, stories and ideas.
What is a quine?
q=chr(34)*3
s='q=chr(34)*3\ns={2!r}\na="""{0}"""\nb="""{1}"""\nprint(s.format(a,b,s))'
a="""
A quine is...
I just woke up from a nightmare. The events are still hazy, as they always
are, but if I jot them down quickly, maybe they will stay.
I used to have lots of nightmares when I was a little boy. The wake up and
piss yourself kind of nightmares. I struggled with them for years before they
finally went away, of their own accord. The most troubling part about them was
that I could never figure out what exactly they were about. I don't mean like
metaphorically, I mean I didn't know what they were. And I don't mean I forgot
them per se, because I remembered enough about them the next day to still send
a shiver down my spine. Over theFractional Nested Sets: Solving a 30-Year-Old Tree Problem with Floats
The Problem with Nested Sets
If you've ever stored a tree in a relational database, you've probably encountered the Modified Preorder Tree Traversal (MPTT) pattern — also known as nested sets. It's Joe Celko's classic: every node gets a lft and rgt integer, and a subtree query becomes a simple range scan:
SELECT * FROM categories WHERE lft > 2 AND rgt < 11;
Beautiful for reads. Brutal for writes.
Insert "Tablets" under "Electronics" in a 1,000-node tree? MPTT needs to shift the lft and rgt values of every node to the right of the insertion point. That's potentially 500+ UPDATE statements for a single insert. Move a subtree? Same story. The write cost is O(n), and in production, with triggers, indexes, and replication — it hurts.
This is a problem the industry has lived with since Celko published it in the early 1990s. The usual advice is "use adjacency lists