简体   繁体   中英

best mysql approach?

I'm writing an application that displays posts, much like a simple forum system. Posts can be marked as urgent by users when they submit the post, but a moderator must approve the "urgent" status. A post will still be displayed even if it has not been approved as urgent, but will just appear to be a normal post until the moderator approves the urgent status at which point the post will get special treatment.

I have considered two approaches for this:

1) have two flags in the posts tables. One to say the user has requested urgent status, and a second to indicate if admin has approved urgent status. Only if both are true will the post be show as being urgent.

2) have two tables. A requests pending table which holds all the pending urgent approvals. Once admin approves urgent status, I would delete the request from the pending table and update the posts table so that the urgent field becomes true for that post.

I'm not sure if either approach is better than the other.

The first solution means I only have one table to worry about, but it ends up with more fields in it. Not sure if this actually makes querying any slower or not, considering that the posts table will be the most queried table in the app.

The second solution keeps the posts table leaner but ads another table to deal with (not that this is hard).

I'm leaning towards the second solution, but wonder if I'm not over analysing hings and making my life more complicated than it needs to be. Advice?

There's another solution that comes in mind :)

You can have a table with post statuses and in your Posts table you will have a columnt which references a status..

This apporach has several advantages - like you can seamlessly add more statuses in the future.. or you can even have another table holding rules how statuses can be changed (workflow).

Definitely 1). The additional table just messes things up. One extra status field is enough, with values: 0=normal, 1=urgent_requested, 2=urgent_approved for example.

You could query with status=1 for queries needing approval, and if you order by status desc, you naturally get the urgent messages up front.

The second approach is cleanest in terms of design, and it will probably end up using less disk space. The first approach is less "pure", but from a maintenance and coding point of view it's simpler; hence I'd go with this approach.

Also, it's great to see someone thinking about design before they go off and write reams of code. :) Can't tell you how many messed-up projects I've seen, where a single hour of thinking about the design would've saved many hours of effort for all involved...

I think option 1 is the best. The only thing you need to do is make an index with the two fields. The option 2 add too much complexity

I have a mysql query just for things like this. I will post it as soon as I remember/find the correct syntax

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM