请教一个数据库设计的问题!
请教一个数据库设计的问题!
我假设一个应用。 比如说论坛
我们发一个帖子 我们建一张 帖子表 topic
然后 支持让游客们回复 准备一张 回复表 reply
我的问题是:
假设我们要知道每一个帖子 的 回复数 我们应该如何去统计比较好呢?
1.在帖子topic表 准备一个字段 回复数(reply_count) 我们直接select这个字段 得出回复数
2.用表关联,然后去select count(reply)数 得到回复数
我是这样想的:
方法1:按正常的业务逻辑走是可行的。并且在效率上是占优势的。但是可能会出现数据的不一致性啊。我的意思是数据库不排斥我记录的是10个回复数 但实际上reply回复表是13个记录。
方法2:数据结构感觉比较严谨,但是就牺牲了搜索效率。
不知道有没其他好的做法,或者说这两个方法哪个更可行一些?
回复讨论(解决方案)
在方法1中,对 reply 的 insert 和 delete 操作成功后,都需要对 topic.reply_count 做 update
其实要看你对:“要知道每一个帖子 的 回复数”的使用频率。
1、如果只是在后台一个月统计一次的话,很显然可以用第二种。
2、如果是浏览帖子就需要显示出来的话,那肯定是第一种啦。
建议具体问题具体分析,reply_count,字段要建立
建议具体问题具体分析,reply_count,字段要建立
对冗余设计 实际使用看情况。
数据库我才开始看,不过这个问题貌似很简单,就是两个表都要更新,做关联。
我在赶集网发了简历,才要2000,居然没人理我,一个电话都没有,是我简历写的不好吗,帮忙看看吧
姓名:襟绾打唠唬
网址:http://bj.ganji.com/jianli/564717047x.htm?_rtm=1
不要为了节约一个字段而失去效率呵呵。
看看DISCUZ 的表的设计。缓存回帖数是必须的。
数据库我才开始看,不过这个问题貌似很简单,就是两个表都要更新,做关联。
我在赶集网发了简历,才要2000,居然没人理我,一个电话都没有,是我简历写的不好吗,帮忙看看吧
姓名:襟绾打唠唬
网址:http://bj.ganji.com/jianli/564717047x.htm?_rtm=1
不要尝试压低自己的薪资去“乞讨”一份工作,这是一种对自己不自信,不负责任的态度。
朋友,我看了你的简历。
没有真实名字,用人单位如何称呼你?
没有直接的联系电话,你可以加在备注中。
没有一个比较正面的自我描述,对方如何大致了解你?
还有,哥,你也27岁了。只有23 24刚从大学毕业的朋友才可能会真正意义上的责怪自己的大学不好。你都出来社会有一段时间了吧?再继续抱怨自己的大学,你的青春年华也就只是用来抱怨了。
你说希望有个人能带,那么为什么别人不选择刚从大学毕业意气风发的应届生,而要选择你呢?你的优势在哪呢?
希望你好好准备。祝你好运!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

An official introduction to the non-blocking feature of ReactPHP in-depth interpretation of ReactPHP's non-blocking feature has aroused many developers' questions: "ReactPHPisnon-blockingbydefault...
