执行大型查询在PHP数组或DB? [英] Performing large queries on Array or DB in php?

查看:108
本文介绍了执行大型查询在PHP数组或DB?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有10000用户的数组,每个用户我需要存储他们做了100最后的行动,也是该行动的时候。

Suppose I have an array of 10000 users, for each user I need to store 100 last actions they did, also the time of that action.

这些数据存储在MySQL数据库上了。
对于每一秒,我需要检查100用户操作,这意味着我需要遍历所有的100行动,并为每分钟100个用户的操作时间。

These data are stored on a mysql database too. For every second, I need to check 100 user actions, It means I need to iterate all those 100 actions and time of actions for 100 users per minute.

那么,哪一个是更快?查询数据库每分钟100次?或检查这些阵列的100倍。

So which one is faster? Query database 100 times per minute? or check those arrays 100 times.

我要问这里,一般来说,如果你在哪里,你需要对大量数据(10000 * 200 = 2,000,000个记录上执行大量每秒的数据库查询(每秒100)的情况),您还可以在阵列数据和搜索存储在localY坐标这些阵列,你会选择哪种方法?另外,假定在阵列和数据库两种搜索优化方法。 (例如,它不是泡沫数组排序和搜索;))

What I'm asking here is, generally speaking, if you were in a situation where you need to perform large amount of database queries per second (100 per second) on a large amount of data (10000*200 = 2,000,000 records), you can also store that data in arrays and search in those arrays localy, which method will you pick? Also suppose both search in array and database are optimized methods. ( for example it's not bubble array sort and search ;) )

推荐答案

数据库连接将是该算法的最昂贵的部分,因此,最小化的时间每个连接将持续的量。

Database connections are going to be the most expensive part of the algorithm, so minimize the amount of time each connection will last.

从数据库中遍历数组拉出。

Pull it from the database and loop through the array.

除非你是做这将是在数据库非常快的函数(即 - 排序上的索引,分组等),你应该这样做在PHP

Unless you are doing a function that would be very quick in a database (ie- sorting on an index, grouping, etc) you should do it in PHP

这篇关于执行大型查询在PHP数组或DB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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