我想在这样的查询中对某些列进行排序:
SELECT "created",
pgp_pub_decrypt(username, dearmor('-----BEGIN PGP PRIVATE KEY BLOCK----- XXXXXXX -----END PGP PRIVATE KEY BLOCK-----'), 'password') AS "username"
FROM "users"
ORDER BY created
无论我使用什么列进行排序,都需要很长时间来计算。我知道我可以将这个选择包装在另一个中并在那里进行排序,但这不能是其他原因的解决方案。为什么这需要这么长时间?难道我做错了什么?
这是查询计划:
QUERY PLAN
-----------------------------------------------------------------------
Sort (cost=1261.92..1273.00 rows=4433 width=40)
Sort Key: created
-> Seq Scan on users (cost=0.00..993.41 rows=4433 width=40)
EXPLAIN 的结果(分析,缓冲):
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------
Sort (cost=1261.92..1273.00 rows=4433 width=40) (actual time=313515.489..313516.446 rows=4433 loops=1)
Sort Key: created
Sort Method: quicksort Memory: 531kB
Buffers: shared hit=2037
-> Seq Scan on users (cost=0.00..993.41 rows=4433 width=40) (actual time=70.300..313499.510 rows=4433 loops=1)
Buffers: shared hit=2037
Planning time: 0.115 ms
Execution time: 313517.322 ms