一个查找表,存储在 MySQL 或 PHP 中
我对存储在 MySQL(独立表)或 PHP(数组)中的查找表之间的性能有疑问,所以这是我的数据(以数组形式)
$users = array(
array(name => 'a', address => 'abc', age => '14'),
array(name => 'b', address => 'def', age => '12'),
array(name => 'c', address => 'ghi', age => '13'),
array(name => 'd', address => 'jkl', age => '14'),
array(name => 'd', address => 'mno', age => '11'),
);
这是 facebook 平台上的游戏,可能有机会玩很多人同时访问。
实际上,该表应该有〜100行,但所有数据都是静态的,如果所有数据都存储在MySQL中,我可以轻松地执行任何“选择”,考虑到对MySQL的查询太多,因此我考虑存储在php数组中,但是,我不知道如何在特定条件下选择行(我知道它应该有其他方法而不是for循环)就像选择所有age = 14到另一个数组中一样。
那么,哪一款的性能更好呢? (MySQL 还是 PHP 查找表?)
I have a question regarding to the performance between a lookup table stored in MySQL (standalone table) or PHP (array), so here is my data (in array form)
$users = array(
array(name => 'a', address => 'abc', age => '14'),
array(name => 'b', address => 'def', age => '12'),
array(name => 'c', address => 'ghi', age => '13'),
array(name => 'd', address => 'jkl', age => '14'),
array(name => 'd', address => 'mno', age => '11'),
);
It is a game on the facebook platform, may have a chance with a lot people access in same time.
Actually, the table should have ~100 rows, but all data is static, if all data store in MySQL, I can do any "select" easily, consider with too much query to MySQL, therefore I consider store in php array, however, I don't know how to select rows in a specific condition (I know it should have other other method rather than for loop) just like select all age = 14 in to another array.
So, which one have the better performance? (MySQL or PHP lookup table?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您知道:
...那么我肯定会将逻辑放在纯 PHP 中。 “删除不必要的数据库查询”始终是提高性能的第一步,我认为,仅仅因为不想编写简单的 foreach 循环而将这些简单的行放入 MySQL 中是一个坏主意。 。这太过分了。如果您使用像 APC 这样的操作码缓存(您就是这样,对吧?)那么我认为性能比较不会很接近。 (尽管我总是建议您自己对它们进行实际基准测试以确保确定。)
If you know:
... then I'd definitely put the logic in pure PHP. "Remove unnecessary database queries" is always going to be your first step in improving performance, and dropping these dead-simple rows into MySQL for no other reason than you don't want to write a simple foreach loop is a bad idea, I think. It's overkill. If you're using a opcode cache like APC (which you are, right?) then I don't think the performance comparison will even be close. (Though I'll always recommend actually benchmarking them both yourself to be sure.)
PHP在性能方面肯定会更快。但查询会很难维护代码。由于网络的原因,将数据保存在 mysql 中会产生一定的开销。但是您可以通过使用 MyIASM 表并使用服务器端缓存的查询来优化它。
我投票支持启用查询缓存的 MySql 上的 MyIASM 表。
PHP will be definitely faster in terms of performance. But querying will be difficult to maintain code. Keeping data in mysql will be a overhead because of network. But you can optimize that by using MyIASM tables and using query cached on server side.
My vote is for MyIASM table on MySql with query cache enabled.