Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

分类及Tag数据库设计修改 #79

Open
zsxsoft opened this issue May 29, 2016 · 5 comments
Open

分类及Tag数据库设计修改 #79

zsxsoft opened this issue May 29, 2016 · 5 comments
Assignees
Milestone

Comments

@zsxsoft
Copy link
Contributor

zsxsoft commented May 29, 2016

为提升分类及Tag相关效率,现提出一种新的数据库设计方案。
现有方案是zbp_post内含log_CateIDlog_Tag两个字段,故只能支持单分类,Tag检索效率也极其低下。在这里提出一种新的解决方案,可完美解决多分类及Tag索引问题。同时也对各库内meta进行修改,解决meta查询问题。

解决方案

分类及Tags

  1. 建立新表:zbp_post_relationship,内含字段pr_postid, pr_cateid, pr_tagid
  2. 每次文章更新时,多条Insert写入,如:
INSERT INTO `zbp_post_relationship` (pr_postid, pr_cateid, pr_tagid) VALUES (1, 2, 0);
INSERT INTO `zbp_post_relationship` (pr_postid, pr_cateid, pr_tagid) VALUES (1, 3, 0);
INSERT INTO `zbp_post_relationship` (pr_postid, pr_cateid, pr_tagid) VALUES (1, 0, 2);
INSERT INTO `zbp_post_relationship` (pr_postid, pr_cateid, pr_tagid) VALUES (1, 0, 3);
  1. 查询时:
SELECT * FROM zbp_post_relationship WHERE (pr_tagid = 3);

即可查询出此Tag下所有文章。分类同理。

Meta

  1. 建立新表:zbp_meta,内含字段meta_type, meta_pointid, meta_name, meta_value
  2. 写入Meta:
INSERT INTO `zbp_meta` `meta_type`, `meta_pointid`, `meta_name`, `meta_value` VALUES ('post', 1, 'foo', 'bar')
  1. 查询同上

兼容性问题

  1. 需要废弃log_CateIdlog_Tag字段。
  2. $post->Category需要改为$post->Categories$post->Category指向Categories[0]
@rainbowsoft
Copy link
Contributor

关系表,最少还有一个“type”类别字段,用于区别category,tags,meta等不同的用途

@rainbowsoft
Copy link
Contributor

rainbowsoft commented Apr 1, 2020

pr_postid, pr_cateid, pr_tagid,是错误的,应该是id,postid,relationid,type,key,value这几个字段!

@zsxsoft
Copy link
Contributor Author

zsxsoft commented Apr 1, 2020

@rainbowsoft 都TM过去了四年了

@wdssmq
Copy link
Contributor

wdssmq commented Apr 21, 2022

现在 6 年了。。

@Song-HaiFeng
Copy link

现在7年了。。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants