I am doing listing for my gallery (using next / prev). Problem is, that if I select next/prev with every change of foto, query takes up to 0.1 s. That is bad, considering two things a) Vistors will be browsing gallery pretty much b) Rest of my queries is in time os 0.005s
我正在为我的画廊上市(使用next / prev)。问题是,如果我在每次更改foto时选择next / prev,查询最多需要0.1秒。这很糟糕,考虑到两件事情a)Vistors将很多浏览图库b)我的其余查询在时间上显示为0.005
But If I select all IDs of fotos in one query, I got lets say 1000 results (time of query is about 0.15s). I can built tree from those and find easily next / prev within it. But it takes memory. On my server, I have problems with performance (CPU, not memory), so it will be probably better solution. Am I right ?
但是,如果我在一个查询中选择了所有fotos的ID,我可以说1000个结果(查询时间约为0.15秒)。我可以从那些建造树,并在其中轻松找到下一个/上一个。但它需要记忆。在我的服务器上,我遇到性能问题(CPU,而不是内存),所以它可能是更好的解决方案。我对吗 ?
And if so, how or where can I store that tree ? I can have many different ones, because all images are in one table and browsing is per user (eg. their uploaded fotos) and with different ordering (time, type, score...). So I can´t cache all trees beforehead, it will be just huge (and it can change, while different users are uploading fotos almost instantly). I though of building new tree for every user, when he opens specific gallery. Storing it in SESSION seems "stupid", because thats not optimised for such a thing.. is tehre something else ?
如果是这样,我该如何或在哪里存储那棵树?我可以有许多不同的,因为所有图像都在一个表中,每个用户浏览(例如,他们上传的照片)和不同的排序(时间,类型,分数......)。因此,我无法在前面缓存所有树,它将是巨大的(它可以改变,而不同的用户几乎立即上传fotos)。我为每个用户构建新树,当他打开特定的画廊时。将它存储在SESSION中似乎是“愚蠢的”,因为那些没有针对这样的事情进行优化......还有其他的东西吗?
1 个解决方案
#1
0
Often, the MySQL query cache is a quick way to make SELECT
queries faster. The query cache will save the results of recent queries and return them when the same query is repeated. That means, that after the first time you run a query, subsequent identical queries will be much faster. The query cache does not return stale data. When tables are modified, any relevant entries in the query cache are flushed.
通常,MySQL查询缓存是一种快速进行SELECT查询的方法。查询缓存将保存最近查询的结果,并在重复相同查询时返回它们。这意味着,在您第一次运行查询后,后续相同的查询将更快。查询缓存不返回过时数据。修改表时,将刷新查询缓存中的所有相关条目。
Source: http://dev.mysql.com/doc/refman/5.1/en/query-cache.html
To check whether the query cache is being used, execute the following query:
要检查是否正在使用查询缓存,请执行以下查询:
SHOW VARIABLES LIKE 'query_cache_type';
If the value is OFF
or 0
, add these two lines to your MySQL configuration:
如果值为OFF或0,请将这两行添加到MySQL配置中:
query_cache_type = 1
query_cache_size = 64M
Afterwards, restart your MySQL server.
然后,重新启动MySQL服务器。
#1
0
Often, the MySQL query cache is a quick way to make SELECT
queries faster. The query cache will save the results of recent queries and return them when the same query is repeated. That means, that after the first time you run a query, subsequent identical queries will be much faster. The query cache does not return stale data. When tables are modified, any relevant entries in the query cache are flushed.
通常,MySQL查询缓存是一种快速进行SELECT查询的方法。查询缓存将保存最近查询的结果,并在重复相同查询时返回它们。这意味着,在您第一次运行查询后,后续相同的查询将更快。查询缓存不返回过时数据。修改表时,将刷新查询缓存中的所有相关条目。
Source: http://dev.mysql.com/doc/refman/5.1/en/query-cache.html
To check whether the query cache is being used, execute the following query:
要检查是否正在使用查询缓存,请执行以下查询:
SHOW VARIABLES LIKE 'query_cache_type';
If the value is OFF
or 0
, add these two lines to your MySQL configuration:
如果值为OFF或0,请将这两行添加到MySQL配置中:
query_cache_type = 1
query_cache_size = 64M
Afterwards, restart your MySQL server.
然后,重新启动MySQL服务器。