If I have a polymorphic association, such as:
create Transmission < ApplicationRecord
belongs_to :transmittable, polymorphic: true
end
create Contact < ApplicationRecord
has_many :transmissions, as: :transmittable
end
create Product < ApplicationRecord
has_many :transmissions, as: :transmittable
end
... then the following uses a bound variable for transmittable_type ...
Transmission.where(transmittable_type: 'Product')
When there's a large skew between the number of transmissions of Products and Contacts this can be undesirable, as the lack of an equivalent to Oracle's bind variable peeking can lead to bad estimates of result cardinality.
Question: Is there a way of avoiding the use of a bound variable in this case, other than with:
Transmission.where("transmittable_type = 'Product'")
... which I don't like because of the need in a complex query to identify the correct table alias for transmissions?
I've looked at plan_cache_mode as a database workaround for this but it didn't seem to offer a solution.