sql

grav 2023-07-15T12:37:29.181699Z

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?

grav 2023-07-18T15:15:31.025529Z

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.

seancorfield 2023-07-15T17:12:39.002029Z

Can you share the exact SQL you're running in both cases and how you're running the SQL in your application?

grav 2023-07-15T18:23:31.758789Z

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.

grav 2023-07-15T18:25:01.211779Z

I tried removing the distinct, thinking it might to scan the whole table s, but it didn't seem to make a difference.

seancorfield 2023-07-15T18:59:07.147329Z

Right, but how exactly are you running it in the REPL? Are you getting a Connection first and just timing the execute! call?

seancorfield 2023-07-15T19:00:16.427199Z

What happens with the PG CLI if you use limit 5?