一个数据库有很多项目与动态制作的许多数据库 [英] One database that has a lot of items vs. many databases that are made dynamically

查看:148
本文介绍了一个数据库有很多项目与动态制作的许多数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MySQL的新手。



我正在使用MySQL创建一些Web服务,但我不知道使用数据库的最佳方式是什么。



其中一个数据库有很多项目,并且不断地进行行跟踪查询。
另一个动态地使数据库数据库。



数据库数据库由每个用户的一些问题组成,问题数量尚未解决。

解决方案

在数据库中动态创建新表是众所周知的反模式



对于一个,它实际上使得编码更加困难,因为您需要满足查询中的动态表名。 p>

其次,可能更重要的是,它可能对DB性能造成极大的不利影响。根据您使用的存储引擎,每当查询表时,MySQL需要从1(InnoDB)打开,最多可以打开3个(MyISAM)文件。当您需要在短时间内查询许多表格时,这将对您的文件系统造成压力。



另一方面,如果您的数据全部在一个表中,当您第一次查询MySQL时,MySQL将尝试将其加载到内存中,并且所有连续读取将使用内存访问而不是磁盘访问,这使得事情变得更快。


I am new to MySQL.

I am creating some web services using MySQL but I am not sure what is the best way to use the database.

One is the one database that has a lot of items and continually make row following query. Another one is making db database dynamically.

Database database is consist of some questions for each user and the number of questions is not fixed.

解决方案

Dynamically creating new tables in database is a well known antipattern.

For one, it actually makes it more difficult to code, since you need to cater for dynamic table names in your query.

Second, and probably more importantly, it can be extremely detrimential on DB performance. Depending on which storage engine you use, whenever you query a table MySQL needs to open from 1 (InnoDB) up to 3 (MyISAM) files on disk. This will put a lof of strain on your filesystem, when you need to query many tables in short time.

On the other hand, if you have all your data in one table, MySQL will try to load it to memory when you query it for the first time, and all successive reads will be using memory access rather than disk access, which makes things a lot faster.

这篇关于一个数据库有很多项目与动态制作的许多数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆