Skip to content

Remove early return from set_cursor_tuple_fraction#63

Open
xathien wants to merge 1 commit intoafair:masterfrom
xathien:xathien/fix-cursor-tuple-fraction
Open

Remove early return from set_cursor_tuple_fraction#63
xathien wants to merge 1 commit intoafair:masterfrom
xathien:xathien/fix-cursor-tuple-fraction

Conversation

@xathien
Copy link
Copy Markdown

@xathien xathien commented 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 #49

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
@Alex-450
Copy link
Copy Markdown

Alex-450 commented Apr 8, 2026

Hey! First of all I wanted to voice some appreciation for this gem, we've been using it for a long time 🙌

We ran into this issue in our app and it was causing postgres to create some inefficient query plans, as the default fraction being set to 0.1 resulted in sequential scans rather than index scans. We ended up patching it like so:

PostgreSQLCursor::Cursor.prepend(
  Module.new do
    def set_cursor_tuple_fraction(frac = 1.0)
      frac = @options.fetch(:fraction, frac)

      @connection.execute("set cursor_tuple_fraction to #{frac}")
    end
  end,
)

I've tested this and it works as expected - fraction is set to 1.0 for these queries. This PR would be a good fix, if there's anything I can do to help releasing let me know :)

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.

cursor_tuple_fraction doesn't get set

2 participants