Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7071803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:43:55+00:00 2026-05-28T05:43:55+00:00

In my app, I have a unique id for each object (tables). Now, because

  • 0

In my app, I have a unique id for each object (tables).

Now, because of that, when using seeing the id, I know what object type it is, whether it’s a User or it’s a Hotel.

I was wondering if I could save the lookup for the item_type in polymorphic associations, patch the lookup with an id sequence lookup in memory thus saving the space in the DB and in the index.

Can this be done?

I am working with Rails 3.0.9, Ruby 1.9.2

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:43:56+00:00Added an answer on May 28, 2026 at 5:43 am

    This may not be the answer you’re looking for. I’m sure this is possible somehow, but you’d be fighting against the grain of how polymorphism was designed in ActiveRecord, and that would probably cause a load of pain.

    The first question that comes to me is why? You’re asking for a performance optimization. Are you seeing a performance problem? Have you verified with instrumentation, New Relic, the Ruby profiler and other tools that this second lookup is really what is killing your performance? If you haven’t done any of this, then you’re probably wasting your time. Predicting performance bottlenecks is an inaccurate science and subject to the 80-20 rule.

    If you really, really have this problem and you’ve been thorough in analyzing your logs, your New Relic charts, you’ve isolated the problem and run performance tests against it, if you’ve done all that, and you’re seeing a performance problem right with this issue, then I’d suggest that probably a denormalization solution of sorts will give you some improvement. Denormalization is a common tool to optimize database performance problems. You’d be storing data in more than one place, but your queries will to touch fewer tables (faster), at the extra overhead of keeping the multiple bits in sync when updating records (more complex application code).

    If you could post a bit more detail about your example, it would be easier to make some more concrete suggestions or give examples.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have single php dynamic page that load image each time app user is
For my app, I have a fairly complex set of configuration options that user
I'm modeling my app in Core Data. I have an object called 'stats' that
I have an iPhone app with a UITabBar, and each tab has a unique
I have a project that requires user-defined attributes for a particular object at runtime
While developing my app I have come to realize that the majority of my
In my qt app I have this object, filled before setting up my QTreeWidget's
Ok this is going to sound strange, but I have inherited an app that
I have made a Linux CUI app that communicates between processes via Message-quene. There
I have a web app that lets users create groups. On the front page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.