Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Designing a threaded commenting system [closed]

Tags:

sql

What would be the best way to design a threaded commenting system so that it doesn't hammer the database?

like image 435
Glass Robot Avatar asked Mar 01 '23 08:03

Glass Robot


2 Answers

Modified pre-order tree traversal (or what Matt refers to as "nested set") is the way to go.

If you happen to be working in Django, there's a third-party app, django-mptt, that makes implementing MPTT in your models a one-liner.

like image 151
Carl Meyer Avatar answered Mar 12 '23 00:03

Carl Meyer


SELECT ... START WITH ... CONNECT BY

Oracle has an extension to SELECT that allows easy tree-based retrieval.

This query will traverse a table where the nesting relationship is stored in parent and child columns.

select * from my_table
    start with parent = :TOP_ARTICLE
    connect by prior child = parent;

http://www.adp-gmbh.ch/ora/sql/connect_by.html

like image 33
Mark Harrison Avatar answered Mar 11 '23 23:03

Mark Harrison