我想在这样的查询中对某些列进行ORDER BY:
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