Implementing An N-Level Nested Tree In PHP And PostgreSQL

Discussion in 'OT Technology' started by Peyomp, Sep 3, 2008.

  1. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
  2. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    Aside from PostgreSQL sucking balls. Just a really horrible SQL engine...
     
  3. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    Who gives a shit what database system you like? You piece of shit, click the article it would work on anything! :squint: You think I like PHP? The language is not relevant.

    Don't shit on my thread.
     
  4. Frequency

    Frequency New Member

    Joined:
    Dec 30, 2004
    Messages:
    7,504
    Likes Received:
    0
    Location:
    PA
    Nice read, not sure how much i like the nLeft / nRight having to be updated manually if you insert into the tree but for an established tree its pretty pimp
     
  5. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    The idea being that you view the tree much more than you update it, so do the work as you update, then it is optimized for viewing.
     
  6. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    :ugh: Step away from the computer and get some fresh air. No one should be this upset over an indexing vs recursion method of retrieving data.
     
  7. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    I'm not pissed about that. I'm pissed that you reduced this cool link post to a brand war, just like every other piece of shit thread in this forum.

    But yes, I am going to surf hurricane swell now.
     
  8. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    Actually, I didn't reduce it to that. I read it the first time, and it was an interesting method. But PostgreSQL IS a horrible piece of shit. And that's why I said, "ASIDE from PostgreSQL sucking balls"
     
  9. Frequency

    Frequency New Member

    Joined:
    Dec 30, 2004
    Messages:
    7,504
    Likes Received:
    0
    Location:
    PA
    And here we go again
    Cool article linked, some people get sand in their pussies and now the thread is headed towards drivel
     
  10. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    I like Postgres, and it does the job he's doing just fine. I usually use MySQL but have no problem working with postgres. It is much more feature rich.

    Anyway, PHP is a piece of shit... but he's using OO PHP, so I can't even complain there.

    The whole article struck me as wrong at first, but it really does make sense to do most of your display computation when you edit, since you probably edit less than you display.
     
  11. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    The DBAdmin screams no, the web dev screams yay!

    Maybe it is my limited experience with it, but I really don't like it considering there are better and just as free alternatives (MySQL and SQL Express to name a couple). From an enterprise point of view, it just sucks - besides anything that has a Vacuum function in it, has to be for women and the :greddy:
     
  12. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    Yeah... you haven't actually criticized it in any real way, so I'm gonna go with 'I wasn't familiar with it so it frustrated me' for $500, bob.
     
  13. CodeX

    CodeX Guest

    welcome to CSC-220 data structures and algorithms...
     
  14. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    They cover implementing this in SQL?

    Didn't think so, plz drive through n00b
     
  15. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    I came here to say that. :mamoru:

    Wouldn't be all that hard to put it into the database once you know your data structure. The most annoying part would be keeping it up to date and re-generated if you have a lot of content continuously added to the list.

    I remember creating bi-directional circular linked lists in LISP. It was just as fun as writing frogger in ASM using ARROW ASM. :hsd:

    We've used a N-Level nested tree used for a sitemap, which works great if you only pull 2 or 3 tiers and slowly drill down, but try generating all the tiers for over 2 million unique pages of content... The job takes almost 2 hours to complete. I blame the DBA (and the developer), the DBA blames the developer. I just keep clear from that monstrosity.
     
  16. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    No, how about the database ballooned to twice the size because it couldn't manage deleted records properly and I had to "Vacuum" it. :greddy2: Or how bout it's not supported by real backup software? But I'm sure it's fine for little dev projects.
     
  17. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    I'll admit that I don't administer it, but my use of postgres is not a little dev project. Its a ginormous video site with 10s of thousands of users. They moved from MySQL.
     
  18. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    <50's PSA narrator voice>

    Ah, we see here that Billy has hurt Tommy's feelings with his harsh response. Surely there's a way for Billy to let Tommy know what he thinks without making him upset. Let's try that again.

    "Yeah, that's a good idea Tommy, but I think it would be even better if you tried it in MySQL instead of PostgreSQL."

    See, that's much better. All Billy had to do was think about how his words might sound to Tommy, and be careful to say what he thinks without making Tommy feel bad for thinking differently; he pointed out the good parts of Tommy's idea and suggested ways to fix the bad parts, instead of just pointing out the bad parts. We call this constructive criticism, and it's a great way to tell other people how they can do things better instead of making them feel bad for not being perfect the first time.

    Everyone disagrees with other people from time to time, and it's important to know how to handle disagreements productively. As you can see, it wasn't very hard for Billy to practice constructive criticism while talking to Tommy, he just had to stop and think for a moment. I'm sure you can take this example and apply it to your own life. With a little care and a friendly smile, you too can make friends and influence people!

    </>
     
    Last edited: Sep 4, 2008
  19. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    i took that. unfortunately my teacher was iranian and spoke poor english. unfortunately i have him again for advanced database theory, looks like i'll be reading the book a lot.

    :ugh:
     
  20. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    <Jolly>Go suck a dick</Jolly>
     
  21. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    I wouldn't have taken the time to type all that shit out if it didn't apply. I guess most people here actually manage to hold down jobs, but unless they intentionally try to be assholes online, probably half the population of C&P have all the social grace of sharp pointy rocks.
     
  22. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    I kinda like duex's post.
     
  23. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    Aside from it being from deus, and the post itself, so do I.

    :fawk:
     
  24. whup

    whup I wish you had children and.. so that I could step

    Joined:
    Feb 12, 2007
    Messages:
    1,603
    Likes Received:
    0
    I think this approach is fine but what I prefer is storing the parent / child data, and then just reading the hierarchy into memory. That way the database data is kept very simple, and any querying and manipulation can be done in memory with whatever optimized structure that suits. Persisting any changes to the database don't involve a rebuild of the data in the database.

    e.g. database data is like:

    NodeID, ParentNodeID, Name, SiblingOrder etc

    All of the table data is fetched with a single SELECT and could be loaded into an object implementing something like the algorithm in the article.
     
  25. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    The problem with that, whup, is what if you have a billion nodes in a million-level tree, each storing several megabytes of data? You're not gonna store that shit in memory, so you need to have a way to search it straight from primary storage. That's the whole point of even doing it in a database.

    I think I'd rather choose a database that implements its own internal tree structure, though, instead of trying to make it work manually.
     

Share This Page