小编Ran*_*dle的帖子

如何加快对 2.2 亿行的大型表(9 个演出数据)的查询?

问题:

我们有一个社交网站,会员可以在其中相互评价兼容性或匹配度。该user_match_ratings表包含超过 2.2 亿行(9 演出数据或近 20 演出索引)。针对此表的查询通常显示在 slow.log(阈值 > 2 秒)中,并且是系统中记录最频繁的慢查询:

Query_time: 3  Lock_time: 0  Rows_sent: 3  Rows_examined: 1051
"select rating, count(*) as tally from user_match_ratings where rated_user_id = 395357 group by rating;"

Query_time: 4  Lock_time: 0  Rows_sent: 3  Rows_examined: 1294
"select rating, count(*) as tally from user_match_ratings where rated_user_id = 4182969 group by rating;"

Query_time: 3  Lock_time: 0  Rows_sent: 3  Rows_examined: 446
"select rating, count(*) as tally from user_match_ratings where rated_user_id = 630148 group by rating;"

Query_time: …
Run Code Online (Sandbox Code Playgroud)

mysql performance query-performance

40
推荐指数
1
解决办法
20万
查看次数

加速有索引但仍然很慢的 Postgres 查询

名为“messages”的表中有大约 5000 万行。问题是,即使使用索引,特定查询也运行得非常慢。我的背景更多是 Mysql,所以我更像是 Postgres (9.5) 的新手。任何解决此表查询缓慢问题的建议或帮助将不胜感激。

\n\n

该表的结构如下:

\n\n
mydatabase=# \\d+ messages\n\n\n id              | integer                     | not null default nextval(\'messages_id_seq\'::regclass) | plain    |              | \n conversation_id | integer                     |                                                       | plain    |              | \n user_id         | integer                     |                                                       | plain    |              | \n content         | text                        |                                                       | extended |              | \n attached_photos | text                        |                                                       | extended |              | \n attached_video  | text                        |                                                       | extended |              | \n status          | character varying(255)      |                                                       | extended |              | …
Run Code Online (Sandbox Code Playgroud)

postgresql performance query-performance slow-log

3
推荐指数
1
解决办法
7968
查看次数