DevLog.at

Database Tips

When designing a SQL table polymorphic references, it's preferable to create a composite index with the type column first. For example:

CREATE INDEX my_poly_ref ON upvote (target_type, target_id);

This is preferable because you'll more likely to query by a type without an id than by an id without a type. In fact I can't think of reason to do the latter, personally.

Source: https://stackoverflow.com/a/42242003

16d

Welcome to DevLog

The open thought platform for developers.

Share your work as you work on it. Easier than a blog, handier than Twitter.

Sign in and write down valuable thoughts that would otherwise be forgotten.