简体   繁体   English

Postgresql - 慢“select * from table limit 1”查询

[英]Postgresql - slow “select * from table limit 1” query

I'm using PostgreSQL 9.3. 我正在使用PostgreSQL 9.3。 I have database with one table, and this table have over 600 milions rows. 我有一个表的数据库,这个表有600多万行。 When I connect to this database first query is really slow: 当我连接到这个数据库时,第一个查询真的很慢:

explain analyze select * from request_log limit 1;
Limit  (cost=0.00..0.02 rows=1 width=61) (actual time=481439.127..481439.129 rows=1 loops=1)
   ->  Seq Scan on request_log  (cost=0.00..13996870.79 rows=651159679 width=61) (actual time=481439.123..481439.123 rows=1 loops=1)
Total runtime: 481440.488 ms

I don't understand that - why seq scan just don't stop after reading first row? 我不明白 - 为什么seq扫描只是在读完第一行后不停止?

I think that you mis-reading the output from explain analyse. 我认为你误读了解析分析的输出。

The line "Limit (cost=0.00..0.02 rows=1 width=61) (actual time=481439.127..481439.129 rows=1 loops=1)" shows that it has limited the sequential scan. “限制(成本= 0.00..0.02行= 1宽度= 61)(实际时间= 481439.127..481439.129行= 1个循环= 1)”行表明它限制了顺序扫描。

If you try it without the limit 如果你没有限制地尝试它

EXPLAIN ANALYSE SELECT * FROM request_log;

you will (probably) see that it takes a lot longer. 你会(可能)看到它需要更长的时间。

The problem is something to do with data retrieval in your database. 问题与数据库中的数据检索有关。 Check your postgresql.conf file under RESOURCE USUAGE and QUERY TUNING - look for anything unusual. 检查RESOURCE USUAGE和QUERY TUNING下的postgresql.conf文件 - 查找异常。 Check you postgresql log for anything unusual. 检查postgresql日志是否有异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM