brettwooldridge / HikariCP

光 HikariCP・A solid, high-performance, JDBC connection pool at last.
Apache License 2.0
19.91k stars 2.92k forks source link

[Question] Select rows batch #2128

Closed furstenheim-goodnotes closed 11 months ago

furstenheim-goodnotes commented 11 months ago

Hi, I'd like to select multiple rows at the same time. Say I have the following query:

select * from car where user_id = ? and car = ?

In the application I'm selecting thousands of cars, which I would like to consolidate to one query and avoid 1k roundtrips to the db To select several rows at the same time I could do:

select * from car where user_id = ? and car = ?
union
select * from car where user_id = ? and car = ?
...

For postgres I could use values which is nicer to read, and I expect faster as there is only one select to the table

 select * from car, (values (?, ?), (?, ?)) as input(user_id, car) where input.user_id = car.user_id and input.car_id = car.car 

The problem with this is that I would need to build the values string dynamically depending on the size of my array. Is there a way to do this in the hikari interface? For inserts and updates it does work, but that is because it implements batchExec which is not supported for select queries.

Thanks

lfbayer commented 11 months ago

This is outside the scope of a connection pool. HikariCP provides no such functionality.