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

prefetch_primary_key? performance issues #2292

Open
ioev opened this issue May 19, 2022 · 0 comments
Open

prefetch_primary_key? performance issues #2292

ioev opened this issue May 19, 2022 · 0 comments

Comments

@ioev
Copy link

ioev commented May 19, 2022

Expected behavior

prefetch_primary_key? should not impact performance much when saving

Actual behavior

prefetch_primary_key? is calling queries for sequence and primary key on every save, impacting performance

System configuration

Rails version: 7.0.2.2

Oracle enhanced adapter version: 7.0.2

Ruby version: 3.1.0

Oracle Database version: Oracle Database 12c Standard Edition 12.2.0.1.0 - 64bit

We were noticing some performance issues in an application where saving was taking a very long time. I traced this down to the .prefetch_primary_key? method, which calls @connection.describe and eventually calls pk_and_sequence_for on every save, which triggers some very slow (on this particular db) schema related queries.

I'm using a schema cache dump, which populates the primary_key and sequence_name for tables, so I'd assume this method could make use of this as well but it doesn't seem to. For the time being I've overridden this via:

ActiveRecord::Base.class_eval do
  def self.prefetch_primary_key?
    sequence_name.present?
  end
end

which seems to have solved the performance issues, but likely will not handle all cases corectly (ex: autogenerated sequences.)

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

No branches or pull requests

1 participant