postgresql_cursor icon indicating copy to clipboard operation
postgresql_cursor copied to clipboard

cursor_tuple_fraction doesn't get set

Open jcoleman opened this issue 5 years ago • 1 comments

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.

jcoleman avatar Nov 08 '19 20:11 jcoleman

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.

antulik avatar Dec 22 '20 05:12 antulik