Hm, I have pgcli returning me the "first 1000 rows" in very few seconds. If I try to limit the rows with LIMIT in my application, it takes forever ...
How is pgcli figuring out anything so quickly?
I'm probably timing the connection creation as well, as I'm just giving jdbc/query a map with params, though I doubt that's the issue, as it's pretty quick to do eg SELECT 42.
Just tried using limit 5 with PG CLI as well, and it seems to be noticably slower. Like, 7 secs with limit 5 and ~1 sec without.
Can you share the exact SQL you're running in both cases and how you're running the SQL in your application?
Something like this:
select distinct(a_id) from search s, jsonb_array_elements(snapshot->'bs')
with ordinality arr(b, index) where s.a_id in
(select a_id from a_table where group_id = 123)
and b->b_id not in ([list of maybe 100 ints]) limit 5;
I'm running it locally from a repl against a RDS PostgreSQL DB, versus running it locally from pgcli (without the limit 5 part) against same DB.I tried removing the distinct, thinking it might to scan the whole table s, but it didn't seem to make a difference.
Right, but how exactly are you running it in the REPL? Are you getting a Connection first and just timing the execute! call?
What happens with the PG CLI if you use limit 5?