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

cursor_tuple_fraction doesn't get set #49

Open
jcoleman opened this issue Nov 8, 2019 · 1 comment · May be fixed by #63
Open

cursor_tuple_fraction doesn't get set #49

jcoleman opened this issue Nov 8, 2019 · 1 comment · May be fixed by #63

Comments

@jcoleman
Copy link

jcoleman commented Nov 8, 2019

Looking at https://github.com/afair/postgresql_cursor/blob/master/lib/postgresql_cursor/cursor.rb#L298, the comment explains that the gem prefers to override PostgreSQL's default cursor_tuple_fraction = 0.1 to 1.0.

However because the arg frac=1.0 and there's an default on the options lookup @cursor_tuple_fraction ||= @options.fetch(:fraction) { 1.0 }, I believe the early return return @cursor_tuple_fraction if frac == @cursor_tuple_fraction will always fire unless you set a custom value not equal to 1.0.

This means both that the 1.0 default never gets applied, and also that it's impossible to apply a configuration value of 1.0.

I think the early return probably is an unnecessary optimization in terms of speed, and having any early return will possibly cause bugs since the default config on a given Postgres install might not be 0.1 anyway, so it's not possible to fully fix by changing to only return early if the desired value is 0.1.

Finally, the gem doesn't reset the value after the cursor is done, so it's potentially poisoning the connection settings for any other use not going through the gem.

@antulik
Copy link

antulik commented Dec 22, 2020

Had a quick dig, and can confirm it by just looking at gem's code.

the gem doesn't reset the value after the cursor is done, so it's potentially poisoning the connection settings for any other use not going through the gem.

The good news if you don't explicitly pass :fraction to cursor it won't be set but also it won't poison the connection.

xathien added a commit to xathien/postgresql_cursor that referenced this issue Mar 9, 2023
The early return removed the ability to override Postgres' default fraction of `0.1` with `1.0`. A workaround was to use `0.99999` but that's a little bit ugly, so let's just always set the tuple fraction.

Alternatively, we could check the current fraction on the `@connection` and only change it if it's different, which would also allow us to revert the temporary fraction change afterward, but that's an adjustment for another PR.

Partially fixes afair#49
@xathien xathien linked a pull request Mar 9, 2023 that will close this issue
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 a pull request may close this issue.

2 participants