[英]MySQL multiple tables vs rows
I have read many posts on here about this discussion but my question is specific. 我在这里读了很多关于这个讨论的帖子,但我的问题是具体的。
Please read in entirety before replying. 请在回复前完整阅读。
I am wondering whether it is best to have potentially hundreds if not thousands of rows in a database or to split it across multiple tables. 我想知道在数据库中是否最好有数百行甚至数千行,或者在多个表中拆分它。
The scenario is: I have a user who can be in ONE AND ONLY ONE city at a time. 场景是:我有一个用户,一次只能在一个城市中。 (There are multiple cities eg Paris, Berlin and London) Now in each city are lots of areas (potentially several hundred). (有多个城市,例如巴黎,柏林和伦敦)现在每个城市都有很多地区(可能有几百个)。 I was thinking that giving each city its own table would be more efficient. 我在想,给每个城市提供自己的桌子会更有效率。
EG: 例如:
rooms_london rooms_london
- All areas of london in here as rows - 伦敦的所有地区都在这里
rooms_berlin rooms_berlin
- all areas of berlin in here as rows - 这里的所有柏林地区都是行
And so on for Paris and any other cities that I add in future. 对于巴黎以及我将来添加的任何其他城市等等。
Then in PHP I could construct a query similar to: 然后在PHP中我可以构造一个类似于的查询:
SELECT * FROM rooms_$playerCity WHERE roomID = $playerRoom
Is this an efficient method or should I just add an extra column to a central rooms table. 这是一种有效的方法,还是应该在中心房间表中添加一个额外的列。
If I've not been clear enough I will do my best to clarify anything that you need. 如果我不够清楚,我会尽力澄清你需要的任何东西。
Many Thanks 非常感谢
I would not split rooms into different tables. 我不会把房间分成不同的桌子。
If performance becomes a problem I would use partitioning http://dev.mysql.com/doc/refman/5.5/en/partitioning.html 如果性能成为问题,我会使用分区http://dev.mysql.com/doc/refman/5.5/en/partitioning.html
+------+ +------+
| City | 1 ---- * | Room |
+------+ +------+
whether ... thousands of rows in a database or to split it across multiple tables. 是...数据库中的数千行还是跨多个表拆分。
performance will not be a problem before few million rows with complex queries and insufficient indexing 在具有复杂查询和索引不足的几百万行之前,性能不会成为问题
I don't use MY SQL but my SQL Server table design would look like this 我不使用MY SQL,但我的SQL Server表设计看起来像这样
Create Table Player (
PlayerID int
...
)
Create Table City (
CityID int
...
)
Crate Table Rooms (
RoomID int
CityID int
...
)
Create Table PlayerRoom (
PlayerID int
RoomID int
ChaeckIn DateTime
CheckOut DateTime
...
)
Then to get the last player in a room you could query by 然后要获得一个房间中的最后一个玩家,你可以查询
Select Top 1 * from PlayerRoom where Roomid = @roomID order by CheckIn Desc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.