While trying to tag a blog post with a single SQL statement, the following ideas crossed my mind: Relation table Tag 2 post that references the tag according to the id is not necessary:
Tag + ------- + ----------- + | Tagged | Tag | + ------- + ----------- + | 1 | News | | 2 | Top Story | + ------- + ----------- + Tag 2 post + ---- + -------- + ------- + | ID | Postid | Tagged | + ---- + -------- + ------- + | 0 | 322 | 1 | + ---- + -------- + ------- +
Why not By using only the following models, Where do you index tags themselves are as follows? The name of the tag has never been changed, but added and removed, it can understand, is not it? What do you think?
Tag 2 posts + ---- + -------- + ------- + | ID | Postid | Tag | + ---- + -------- + ------- + | 1 | 322 | Sun | + ---- + -------- + ------- + | 2 | 322 | Moon | + ---- + -------- + ------- + | 3 | 4443 Sun | + ---- + -------- + ------- + | 4 | 2567 | Love | + ---- + -------- + ------- +
PS: I have a id , I
This works, easily display the last n tags To do this, but it is not normalized, because your tag is overlapping, you also lose the ability to use "similar" tags to tag additional things in post, for small n, optimization does not matter So, if you Area to walk along so I have no problem.
Practically, your indexes will be large (assuming you are going to the index on the tag for search, you are now indexing duplicates and index strings). In the normalized version, the index of the table of the table will be small, it will not duplicate, and the index will be small on the table tagged on Tag 2. In addition, the fixed size Intel Columns are very efficient for indexing and you can also avoid some fragmentation based on your clustering options.
I know that you have not changed any name, but in general, in both cases, still need to change (or delete) the name of the tag, all words need to be changed Need to think about the words, or the tag is divided in some way. Because it is a batch operation in the worst case of transaction (All tags have to change the name of the post), I really do not classify it as important from a design point view.
Comments
Post a Comment