postgresql - pgcrypto 和 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
解决方案
推荐阅读
- ajax - 带有时间参数的 Ajax 请求不起作用
- javascript - 我如何访问本地IP地址中的文件
- vim - vim:键入时打开标签栏窗口
在正常模式下 - asp.net-core - ASP.NET Core 3 中 .csproj 文件中的 PackageReference 条目在哪里?
- flutter - Flutter ListView 在 itemCount 参数中获取一些项目
- vb.net - 如何在 Visual Basic 中将 1 天添加到 DateTime 变量?
- python - 在 Python 中舍入时忽略逗号后的零
- thymeleaf - 如何在 Thymeleaf 中计算和显示百分比?
- ios - SWIFT:是否可以访问其扩展内的类的存储属性?
- javascript - 从JS中的回调函数调用类方法