I am creating a system where users can join and create groups. Within these groups, members can create topics and respond to topics already created, so I'd like to know your opinion on which of the following methods is best: Create two tables, groups_posts and group_topics:
--group_topics
id PK
group_id int FK
user_id int FK
title varchar(50)
content varchar(500)
status int
--group_posts
id PK
topic_id int FK
user_id int FK
content varchar(500)
status int
or create a unique table, group_tposts:
--group_tposts
id PK
group_id int FK
user_id int FK
is_topic boolean
title varchar(50)
content varchar(500)
status int
Based on your description, seems to me that a bit more may be needed. Maybe something something like:
Note: add the content field to the Post
.
It really depends:
Case for the combined table
Given the fact that the boolean only takes one byte, the combined table is not a bad idea.
Do note however that creating an index on the field is_topic
will not work because of its low cardinality.
MySQL (or any other database) will refuse to use an index on that field, but do a table scan instead.
Case for separate tables
If you plan use posts separate from topics often, I'd suggest separate tables.
Because the selects on those will be faster, MySQL does not have to do a full table scan to separate the posts from the topics.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With