Database performance for polymorphic associations under high load

Hey guys,

I’ve been thinking lately about polymorphic associations, and I
wonder: is there a noticeable or tangible performance “hit” from doing
polymorphic associations when you’ve got your database under really
high query load?

So for example, maybe I have a “message” model, a “user” model and an
“administrator” model, without any subclassing or STI going on.
Message has a polymorphic interface called “message_author”, and both
“User” and “Administrator” use it. Say there wind up being ~1 million
messages in that message table. Assuming everything’s properly
indexed, do polymorphic associations add any significant overhead to
conducting database queries?

Thanks guys, appreciate the input.

I would stay away from polymorphic as there is no way to enforce DB FK
relationships.

That’s been my “official” stance for a while as well, and I’m fully
aware of that - but I’m also wondering about its performance, so I can
get a better perspective of the “full picture”, if you follow my
logic.

Still, your point is quite valid and has been taken under advisement.
Thank you.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs