Skip to content

feat: side-effect SELECT #158

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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

denysvitali
Copy link
Contributor

@denysvitali denysvitali commented May 12, 2025

Fixes #134.

FYI: This is just an attempt at fixing the issue - I'm by no means a PostgreSQL expert, and I've used Claude 3.7 Sonnet + Gemini 2.5 Pro to come up with a somewhat working solution.

I'll test this further before marking it as "Ready to Review"

// Check for side-effect functions in the target list
if Self::has_side_effect_function(stmt) {
debug!("Query contains side-effect function, routing to primary.");
return Ok(Command::Query(Route::write(None)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

This makes it a cross-shard query. I don't think we want that, necessarily, especially for advisory locks. You'd probably want to pick a shard that handles it, since advisory locks on different shards won't actually mutually exclude queries.

@denysvitali
Copy link
Contributor Author

Unfortunately despite Query contains side-effect function is correctly printed when Immich (see immich-app/immich#18236) starts and tries to lock via SELECT pg_advisory_lock($1) - the application hangs.

I think this is due to the fact that the lock can't be acquired - but I wasn't able to find any additional information on the real reason this happens. From a code perspective, I don't see why my approach shouldn't work (tried both by sending to all instances and to just one shard).

Any tip is appreciated - I would really love to use pgdog so that I can load-balance Immich.

@levkk
Copy link
Collaborator

levkk commented May 13, 2025

Cool, I will take a look!

@levkk
Copy link
Collaborator

levkk commented May 21, 2025

Haven't forgotten about this, just trying to find the time. Sorry for the delay.

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.

SELECT pg_advisory_lock
2 participants