关于数据库的一般问题

发布于 2024-10-19 22:29:50 字数 176 浏览 4 评论 0原文

我有一个有点愚蠢的问题。我有一个小型社区网站。我正在考虑制作只有获得许可的成员才能查看的特定页面。所以我想我将在数据库中添加每个会员ID,当会员尝试访问该页面时,我将首先检查该会员是否已登录,然后我将检查用户ID(如果它存在于数据库表中)有权查看该内容的用户。现在我只是想知道数据库是否增长,在加载页面之前检查所有内容是否会花费很长时间?

I've kinda silly question. I have a small community website. I'm thinking to make specific pages which can be viewed only by the members who have permission. So I suppose i will add each member ID in the database and when a member will try to access the page then i will first check if the member is logged in and then i will check the user ID, if it exists in the database table of users which have permission to view that content. Now Im just wondering if the database grows up, wont it take a long time to check everythng before loading the page?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

随遇而安 2024-10-26 22:29:50

过早优化是万恶之源 (Donald Knuth)

您可以轻松处理数百万个用户使用单个数据库,因此在您的社区规模庞大之前这不会成为问题。当您到达该步骤时,您可以切换到更具可扩展性的数据库解决方案,例如 Cassandra

话虽如此,请考虑 Brad Christie 的评论,并使用合理的身份管理,不会不必要地破坏您的数据库。

Premature optimization is the root of all evil (Donald Knuth)

You can easily handle several millions of users with a single database, so that won't be a problem until your community is huge. When you reach that step, you can switch to more scalable DB solutions like Cassandra.

Having that said, take Brad Christie's comment into account, and use a reasonable identity management that won't thrash your database unnecessarily.

锦爱 2024-10-26 22:29:50

“很长一段时间”是主观的,取决于很多因素。对于小型社区网站,您所描述的方法可能不会遇到任何问题。尽管如此,它仍然被认为是最佳实践,如果您使用正确的索引,它将显着加快查询速度。应该对要查询的列(例如用户 ID)建立索引。不使用索引意味着 MySQL 必须读取表中的每条记录并检查它是否符合您的条件。

本文可能对您有用:

http://www.databasejournal.com/features/mysql/article.php/1382791/Optimizing-MySQL-Queries-and-Indexes.htm

另外,如果您担心您的网站在以下情况下的表现您的数据集会增长,请考虑用一堆虚拟数据填充它并运行一些测试。该网站将帮助您生成一堆数据并放入数据库中。

http://www.generateata.com/#about

最后,如果页面不特定于特定内容个人或一小群人,请考虑使用更通用的存储桶进行访问控制。例如,如果只有管理员可以查看某个页面,则将该页面与“管理员”权限相关联,并记下哪些用户是管理员。然后,您可以快速检查特定人员的用户类型,并决定是否向他们显示该页面。这种类型的系统通常称为访问控制列表(ACL)。

http://en.wikipedia.org/wiki/Access_control_list

"a long time" is subjective and depends on many factors. For a small community website, you will likely not run into any issues with the method you've described. Still, it is considered best practice, and will speed up queries significantly, if you make use of proper indexes. Columns that will be queried against, such as the user ID, should be indexed. Not using an index means that MySQL has to read every record in your table and check to see if it matches your criteria.

This article may be of use to you:

http://www.databasejournal.com/features/mysql/article.php/1382791/Optimizing-MySQL-Queries-and-Indexes.htm

Also, if you are concerned about how your site will perform when your dataset grows, consider populating it with a bunch of dummy data and running a few tests. This site will help you generate a bunch of data to put in your database.

http://www.generatedata.com/#about

Lastly, if pages are not specific to a particular person or small group of people, consider using more general buckets for access control. For example, if only admins can view a page, tie that page to an "admin" permission and note which users are admins. Then, you can do a quick check to see what type or types of user a particular person is, and decide to show them the page or not. This type of system is typically refered to as an Access Control List (ACL).

http://en.wikipedia.org/wiki/Access_control_list

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文