请教一个数据库设计的问题!
我假设一个应用。 比如说论坛
我们发一个帖子 我们建一张 帖子表 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刚从大学毕业的朋友才可能会真正意义上的责怪自己的大学不好。你都出来社会有一段时间了吧?再继续抱怨自己的大学,你的青春年华也就只是用来抱怨了。
你说希望有个人能带,那么为什么别人不选择刚从大学毕业意气风发的应届生,而要选择你呢?你的优势在哪呢?
希望你好好准备。祝你好运!

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov


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

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

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

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
