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

  • SEARCH
  • Home
  • 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 8924553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:27:05+00:00 2026-06-15T07:27:05+00:00

I have a Ruby on Rails app with a PostgreSQL database which has this

  • 0

I have a Ruby on Rails app with a PostgreSQL database which has this structure:

class A < ActiveRecord::Base
   has_many :B
end
class B < ActiveRecord::Base
    has_many :C
end
class C < ActiveRecord::Base
    attr_accessible :x, :y :z
end

The are only a few A’s, and they grow slowly (say 5 a month). Each A has thousands of B’s, and each B has tens of thousands of C’s (so each A has millions of C’s).

A’s are independent and B’s and C’s from different A’s will never be needed together (i.e. in the same query).

My problem is that now that I have only a couple of A’s, ActiveRecord queries take pretty long. When the table for C has tens of millions of rows, queries will take forever.

I am thinking about scaling the database horizontally (i.e a table for A’s, one table of B’s and one table of C’s for each A). But I don’t know how to do it. It is a kind of sharding i guess, but I can’t figure out how to create DB tables dynamically and use ActiveRecord to access the data if the table depends on which A im working with.

Thank you very much.

  • 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-06-15T07:27:06+00:00Added an answer on June 15, 2026 at 7:27 am

    If you have performance concerns with only a few rows, or even with several million rows, you need to take a step back before trying to atmosphere engineer a solution. The problem you are describing is very easily solved by indexing; there is no advantage to creating additional physical tables and you’d be introducing incredible complexity.

    As @mu-is-too-short already stated: pay attention to your query plans. Use your tools to analyze performance.

    That being said you can use table partitioning to physically and transparently house the storage of data into different sharded tables which is especially useful for data that grows very fast but is only useful in a given time box (like a month). You can also do this with an archive bit flag column to shuttle old or deleted records onto some slower storage (say, standard RAID comprised of spinning rust) while keeping active records on faster storage (like a RAID of SSDs).

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

Sidebar

Related Questions

I have a Ruby/Rails app. I have an artists table in my postgresql database
For a Ruby on Rails app, I'm having this Movie object which has several
In a Ruby on Rails app, we have some details which are stored as
I have a ruby (1.9.3) on rails (3.1) app where: app/models/list.rb class List <
I have a ruby on rails app that has a signup page. Different pages
Is it feasible to have a Ruby on Rails app, which is: a) deployed
I have a Ruby on Rails app that has a scheduled job I execute
Background: So I have roughly (Ruby on Rails app) class A def calculate_input_datetimes #
I have a Ruby on Rails app that I built myself, but which needs
I have a ruby on rails app in which I'm trying to find a

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.