kipcole9 / money_sql

Money functions for the serialization of a money data type in Elixir
Other
27 stars 18 forks source link

enhancement enabling postgres parallel queries #25

Closed milangupta1 closed 2 years ago

milangupta1 commented 2 years ago

Fix to enable parallel queries for aggregate function.

This adds the combine function to the aggregate and the parallel = SAFE flag.

Significant gains in performance as expected based on postgres max_parallel_workers_per_gather (default 2) and max_parallel_workers config variables.

kipcole9 commented 2 years ago

Very much appreciated @milangupta1, thank you. Are there any Postgres version requirements for this version that you're aware of?

milangupta1 commented 2 years ago

Have tested this on postgres latest. sum function uses parallel queries instead of sequential scan. Double the speed of the sum function using default postgres config !

kipcole9 commented 2 years ago

Sounds great. I need to refactor the PR since you added directly to a migration and migrations are generated by mix tasks. Given other priorities its going to take me a few days to get to this and publish a new release.

milangupta1 commented 2 years ago

From what I can find ... I tested it on Postgres 14.4. Parallel queries has been supported since 9.6. - https://wiki.postgresql.org/wiki/First/last_(aggregate)

There is this post where someone had an issue w/ parallel = safe syntax on 13.3 (unconfirmed). https://stackoverflow.com/questions/68424332/custom-aggregate-function-parallel-safe-produces-syntax-in-postgres-13-3

Hope this helps. Thank YOU for the library. I did not want to give up on it and decided to figure out why it was so much slower. This really sped things up.

kipcole9 commented 2 years ago

It's great work and I learned something new today which is really helpful (I can use this technique in a couple of other libraries too!). I think I can squeeze in refactoring and getting this out the door in the next hour. Will post here when thats done.

kipcole9 commented 2 years ago

I have published ex_money_sql version 1.7.2 with the following changelog entry:

Bug Fixes

Thank very much for the collaboration and the great PR!