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

[MCC-1138928] Ensure no mergejoin for operations_for_operation_sets #199

Merged
merged 3 commits into from
Jan 25, 2024

Conversation

kjerinsky-mdsol
Copy link
Contributor

@kjerinsky-mdsol kjerinsky-mdsol commented Jan 23, 2024

Notes are linked in the ticket

@mdsol/platform-scalability

@kjerinsky-mdsol kjerinsky-mdsol self-assigned this Jan 23, 2024
@ejinotti-mdsol
Copy link
Contributor

Looks good, needs version bump + changelog 👍

@@ -70,7 +70,10 @@ def self.operations_for_operation_sets(operation_set_ids, operation_names = nil)
# { 'operation_set_id' => 789, 'unique_identifier' => 'operation2' },
# { 'operation_set_id' => 789, 'unique_identifier' => 'operation3' },
# ]
connection.execute(sanitized_query)
connection.transaction do

Choose a reason for hiding this comment

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

Have you been able to test this out? I recall the behavior of AR transactions with these SET LOCAL commands being kind of hellish. I think it would be safer to just put the SET LOCAL enable_mergejoin TO FALSE at the top of the query string instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wrapping database calls inside an AR transaction block ensures those statements will be inside a database transaction. If a transaction is already open, it will use that one unless savepoints are created. SET LOCAL must be called within a transaction for it to be applied.

What is important is that SET LOCAL enable_mergejoin TO OFF and the recursive query are both called (in that order) inside the same transaction. I do like the idea of moving it into one though to save one round trip db call.

On a somewhat related note. I was considering running a check to see if enable_mergejoin was on before disabling and reverting back afterwards. I was have concerns about breaking later queries that are not explicitly disabling but rely on it being disabled. This is what dalton should be doing but isn't so I don't want to open that can or worms right now.

Choose a reason for hiding this comment

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

I think this should be okay. Since you're in a transaction, changing LOCAL mergejoin to off here will only apply within the scope of this query, and it should reset afterwards as expected, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing local will apply to the scope of the transaction

Copy link

@ccowdrey-mdsol ccowdrey-mdsol left a comment

Choose a reason for hiding this comment

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

Thanks for doing this; I do vaguely remember discussing this as something I could replace with simpler ActiveRecord queries in Dalton, but I don't remember why that fell through the cracks (maybe I was still figuring out whether I would enable pg_hint_plan?).

I should still look into that after enabling pg_hint_plan everywhere, but thanks for fixing this in the meantime. 😄

@ejinotti-mdsol ejinotti-mdsol merged commit b3964ea into develop Jan 25, 2024
2 checks passed
@ejinotti-mdsol ejinotti-mdsol deleted the feature/operations-opset-ensure-no-mergejoin branch January 25, 2024 18:36
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.

3 participants