I want to ORDER BY some column in such a query:
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
Whatever column I use to sort it takes very long time to compute. I know that I can wrap this select in another one and do the sorting there, but this cannot be solution from other reasons. Why this is taking so long? Am I doing something wrong?
This is query plan:
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)
Result of EXPLAIN (analyze, buffers):
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