You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.)
The text was updated successfully, but these errors were encountered:
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:
which seems to have solved the performance issues, but likely will not handle all cases corectly (ex: autogenerated sequences.)
The text was updated successfully, but these errors were encountered: