I have a cms which stores comments against articles. These comments can be both threaded and non threaded. Although technically they are the same just with the reply column left blank when it's not threaded. My application works on sqlLite, MySQL and pgsql so I need fairly standard SQL.
I currently have a comment table
comment_id
article_id
user_id
comment
timestamp
thread (this is the reply column)
My question is to figure out how to best represent the threaded comments in the database. Perhaps in a separate table that supports the tree set without the content and a simple table to hold the text? Perhaps in the way it already is? Perhaps another way?
If the comments are un-threaded I can easily just order by the timestamp.
If they are threaded I sort like this
ORDER BY SUBSTRING(c.thread, 1, (LENGTH(c.thread) - 1))
As you can see from the ORDER BY, the commenting queries will not ever use an index as function based indexes only really live in Oracle. Help me have lightening fast comment pages.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…