Skip to content
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

Prepared queries for inbox #3078

Merged
merged 7 commits into from
Apr 15, 2021
Merged

Prepared queries for inbox #3078

merged 7 commits into from
Apr 15, 2021

Conversation

chrzaszcz
Copy link
Member

@chrzaszcz chrzaszcz commented Apr 9, 2021

  • Use prepared queries in mod_inbox_rdbms
  • Make it possible to include update expressions like 'value = column.value + 1' in upsert queries
  • Simplify some queries, e.g. property updates

Details in commit messages

@codecov
Copy link

codecov bot commented Apr 9, 2021

Codecov Report

Merging #3078 (d715eb6) into master (b63783b) will increase coverage by 0.00%.
The diff coverage is 98.36%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3078   +/-   ##
=======================================
  Coverage   78.82%   78.83%           
=======================================
  Files         379      376    -3     
  Lines       31234    31266   +32     
=======================================
+ Hits        24620    24648   +28     
- Misses       6614     6618    +4     
Impacted Files Coverage Δ
src/inbox/mod_inbox_rdbms.erl 90.62% <98.09%> (+2.10%) ⬆️
src/rdbms/rdbms_queries.erl 90.90% <100.00%> (+0.66%) ⬆️
src/ejabberd.erl 45.00% <0.00%> (-10.00%) ⬇️
src/pubsub/node_hometree.erl 77.77% <0.00%> (-5.56%) ⬇️
src/rdbms/mongoose_rdbms_pgsql.erl 88.23% <0.00%> (-2.95%) ⬇️
src/ejabberd_local.erl 62.68% <0.00%> (-1.50%) ⬇️
src/wpool/mongoose_wpool.erl 81.00% <0.00%> (-1.00%) ⬇️
src/rdbms/mongoose_rdbms.erl 61.22% <0.00%> (-0.82%) ⬇️
src/inbox/mod_inbox.erl 89.79% <0.00%> (-0.52%) ⬇️
... and 13 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b63783b...d715eb6. Read the comment docs.

Make prepared upserts work with literal expressions
  e.g. unread_count = unread_count + 1
- Ue two queries in a transaction to guarantee atomicity
- Do not use RETURNING/OUTPUT as they are DB-specific
    and would require preparing different queries for each DB.
  This is consistent with what we did for previous modules.
  In the future we might add a function to mongoose_rdbms
    that would prepare such queries automatically (like upserts).
@chrzaszcz chrzaszcz marked this pull request as ready for review April 14, 2021 11:54
@chrzaszcz chrzaszcz requested a review from leszke April 14, 2021 11:55
Copy link
Contributor

@arcusfelis arcusfelis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me

-spec prepare_upsert(Host :: mongoose_rdbms:server(),
QueryName :: atom(),
TableName :: atom(),
InsertFields :: [binary()],
UpdateFields :: [binary()],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be an extra argument UpdateSQL, which is empty by default.
And so we would have prepare_upsert/6 and prepare_upsert/7.

But not thaaat critical, it's called once per statement anyway.

Copy link
Member Author

@chrzaszcz chrzaszcz Apr 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I admit I avoided adding the extra argument. I could do it like you suggest to make it more obvious for the user. It's not just any SQL though, it has to be column = value separated by commas... or a list. Maybe I will leave it as it is for now.

Copy link
Contributor

@leszke leszke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@leszke leszke merged commit cee0ba0 into master Apr 15, 2021
@leszke leszke deleted the prepared-queries-inbox branch April 15, 2021 08:08
@leszke leszke added this to the 4.2.0 milestone Apr 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants