-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parallel workers not used on Postgres #3673
Comments
https://www.postgresql.org/docs/current/when-can-parallel-query-be-used.html
This is an extremely unfortunate coincidence. We currently send an Execute with a limit of 1 for The only way to escape this requires closing the connection or calling We do send a fetch limit of zero for This must be what I would personally consider this a Postgres bug, although I can sort of understand why they punted on this. Having to enforce a limit would require additional synchronization between the workers. Though it makes me wonder how it handles For aggregate queries like The fix is theoretically trivial, as we could just always send a zero for the limit on Execute: sqlx/sqlx-postgres/src/connection/executor.rs Line 250 in 6b33766
This wouldn't likely be an issue for For Ultimately, it'd be nice if Postgres just handled this correctly, but someone would have to put in that work. |
Thank you for sharing your thoughts on this. Indeed, this is a subtle implementation detail. So my understanding is that without limit = 0, the db will send all the selected rows. Even if It is tricky because while |
I have found these related issues/pull requests
I could not find any issues in sqlx repo related to parallel workers not being launched. However, this issue seems somewhat related to brianc/node-postgres#3344. The issue is showing very similar logs as the ones as I'm seeing and mentions that streaming query does not use parallel workers for some reason.
Description
Sqlx query is not taking advantage of parallel workers decided by query plan. It is taking double the time to execute query than other tools which are using parallel workers.
Reproduction steps
Db logs from running query with sqlx with the above script
Db logs from running query with psql
Workers Launched: 2
SQLx version
"0.8.2"
Enabled SQLx features
"runtime-tokio-native-tls", "postgres", "time"
Database server and version
{ "version": "PostgreSQL 14.5 on aarch64-apple-darwin21.3.0, compiled by clang version 11.1.0, 64-bit" }
Operating system
MacOS 15.11
Rust version
rustc 1.82.0 (f6e511eec 2024-10-15) (built from a source tarball)
The text was updated successfully, but these errors were encountered: