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 3796978
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:19:39+00:00 2026-05-19T13:19:39+00:00

I have tables setup as such: A message is sent out to a group

  • 0

I have tables setup as such:
A message is sent out to a group of users.

This message is put in the parent_message table
This table contains id | sender_id | date

each message that is sent in that group is put in the child_message table
this table contains id | parent_id | message | date_sent

when a reply is received it is put into the reply_message table
this table contains id | child_id | message | date_received.

Now I have a few questions about this setup.


1) Every time the page is loaded I need to show how many child messages each parent message has.
Would you add a column to the parent_message table called child_count or work it out in your query.
why, why not?

Example query

select *, 
count(select parent_id from child_message c where c.parent_id = p.parent_id ) child_count 
from parent_message;

2) If the user chooses they can view all reply messages to a parent message.
would you add the parent_id to the reply reply_message table or work it out in your query?
Why, why not?

Example query

select * from reply_message 
where child_id in(select id from child_message where parent_id = '66')
  • 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-19T13:19:40+00:00Added an answer on May 19, 2026 at 1:19 pm

    I’d say it very much depends on the amount of messages. If you have like a million messages in the system, a join to child_message can become very expensive. In that case adding a child_count to the parent table can be beneficial for your performance. Same goes for your second use case. Of course that is some de-normalization of your data, so if your system allows for reshaping topics and replies (like splitting a topic) you have to do additional bookkeeping in that case.

    Another approach would be creating index tables, which hold the information you need and update them offline in an asynchronous way, if you don’t need the information to be 100% accurate all the time e.g.

    table message_counts (parent_id, child_count)

    And then schedule updates on these when a new message is added to the system, e.g. by using a trigger.

    So bottom line, unless you encounter performance issues, keep your tables normalized, just like they are. When you expect millions of messages and replies, some de-normalization can help speed up things. Index tables can help creating aggregated statistics offline, unless you need them to be accurate and up-to-date.

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

Sidebar

Related Questions

I have a setup where I am deleting entries from a table. It is
I have these tables: DimDate (PK: DateKey, other attributes) FactActivationCodes (PK: ActivationCode, IssuedDateKey (FK
I have a table view class called RootViewController and a class providing WiFi functionality
I have a setup on a EC2 instance that uses Whirr to spin up
I have a need to search names in our table, but we don't have
Spring ROO have built-in email support So you can setup email sending properties with
I have a simple function that shows and hides elements if a user clicks
I apologize, I am new to this and assume that I will mix some
I'm trying to set up the following tables using JPA/Hibernate: User: userid - PK
I'm trying to create a work schedule creator with multiple stores and each store

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.