4 ms·
I'll save you some time: you probably just want to use a closure table. I did a bunch of research on this while working on a comments system. You pay a price i
by acjohnson55 10y ago
I'll save you some time: you probably just want to use a closure table.
I did a bunch of research on this while working on a comments system. You pay a price in table space if your hierarchies tend to get very deep. But for most applications I can think of, it's the way to go, which you'll see if you page through to Slide 69.
- TeMPOraL 10y agoWell, I haven't heard of closure tables before. I only used nested sets. From this presentation I learned not just the name, but how they look and how to make a basic version (I'm sure there are some practical optimizations - O(n^2) of the basic version feels like it could hurt).
- grzm 10y agoClosure tables are new to me as well. If you're interested in encoding hierarchies in relations, I took a look at static trees and binary fractions in particular here: http://seespotcode.net/2016/04/30/static-trees/ http://seespotcode.net/2016/04/30/static-trees/ It's got some pretty serious practical limitations, but I found it an interesting exploration.
- acjohnson55 10y agoHere's another great resource on the options: http://stackoverflow.com/questions/4048151/what-are-the-options-for-storing-hierarchical-data-in-a-relational-database http://stackoverflow.com/questions/4048151/what-are-the-opti... Yeah, O(n^2) could hurt. I guess you have to have some idea of what average and max depths are to figure out how many rows you're talking about. But the other advantages are pretty compelling.
- closuretome 10y agoor keep both adjency list and closure table: https://gist.github.com/desfrenes/733a83ef82b03ee701caa761951767c9 https://gist.github.com/desfrenes/733a83ef82b03ee701caa76195...