PHP 相交与 MySQL 相交
我在表 (1) 中有一列数据,我必须将其与数百(或数千)个其他表中的数据列进行检查。
作为一个与两个表相交的mysql查询来执行此操作会更快,还是将表(1)中的数据获取到数组中,然后将其他数据列设置为数组并相交会更快吗?
它是MySQL和PHP5.2。
I have a column of data in a table (1) which I have to check against the column of data in several hundred (or thousand) other tables.
Would it be faster to do this as a mysql query intersecting both tables, or to get the data from table (1) into an array, and then set the other columns of data as arrays and intersect?
It's MySQL and PHP5.2.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除了将数据加载到 PHP 中的内存占用之外,您还应该考虑在执行交集之前将数据从 MySQL 传输到 PHP 中的事实。如果 PHP 和 MySQL 不在同一个机器上,则需要考虑这种性能差异。
数据库针对此类操作进行了优化 - 在 MySQL 中执行查询还将最大限度地减少传输到 PHP 的数据量。
Besides the memory hit to load the data into PHP, you should consider the fact of transferring the data out of MySQL to move it into PHP before the intersection can be performed. That's a performance difference that needs to be considered if PHP and MySQL are not on the same box.
Databases are optimized for operations like this - performing the query in MySQL will also minimize the amount of data that is transferred to PHP.
如果您在单个查询中完成它肯定会更快。让你的 RDBMS 完成他的工作,尽量少用 PHP!
It would certainly be faster if you do it in a single query. Let your RDBMS do his job, try to use PHP as less as possible!