-
-
Notifications
You must be signed in to change notification settings - Fork 256
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
SpiClient::select
not seeing changes from Spi::run
in same transaction
#983
Comments
The issue appears to be the new way of handling the The flag starts as true and gets set to false as soon as an update is performed using e.g. Unfortunately this only works within the same As the postgres docs say, and was reported in the docs of
I believe the flag should either be managed at the transaction level (so ensuring consistency of visibility regardless of Spi session scope), but this could prove very difficult, or removed altogether, reverting to the previous behavior of always passing readonly=false. |
After some experimentation and looking through the Postgres sources for inspiration, this seems to fix things: impl<'conn> Drop for SpiClient<'conn> {
fn drop(&mut self) {
if self.readonly == false {
// Assume the user actually modified the database during this SpiClient's lifetime
// and push a new snapshot with an updated CommandId. This ensures that subsequent
// `readonly == true` SpiClients will see the changes made by this one
unsafe {
pg_sys::PushCopiedSnapshot(pg_sys::GetActiveSnapshot());
pg_sys::UpdateActiveSnapshotCommandId();
}
}
}
} Thoughts? |
@eeeebbbbrrrr I think it's an interesting workaround, indeed! |
A readonly SPI session can now see the database modifications of a previous non-readonly SPI session. This necessitates copying the active snapshot and incrementing its command id when a non-readonly SPI session is done. Thanks @EdMcBane for finding this and for the unit tests.
This was fixed in pr #984. Closing this issue. |
I don't think it's a "workaround" per se. After going through parts of the Postgres sources I think it's the right way to handle this. Postgres does the exact pattern in quite a few places with similar comments. We just missed it in #963 because we're not Tom Lane... and that's a really good excuse. |
This issue affects the current develop branch.
Queries executed with
SpiClient::select
do not see data changes applied within the same transaction by update queries executed usingSpi::run
.E.g. this fails, as
with_select
is zero, instead of 1 as expected:Using
SpiClient::update
in the same session works:Using
SpiClient::update
in a separate session does not work:The text was updated successfully, but these errors were encountered: