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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:06:05+00:00 2026-05-18T21:06:05+00:00

I am thinking of database schema for post and its comments, in context of

  • 0

I am thinking of database schema for post and its comments, in context of a social networking application and im wandering which of these two would give better performance:

I am storing comments of a post in “Comments” Table and posts in the “Posts” Table.
Now my schema for the comments table looks like this:

postId commentId postedBy Date CommentBody

Since in order to retrieve the comments of a post I would be required to search all posts whose postId matches postId of this specific post and even my postId could not become primary key since the postId would be non unique within the column(since several comments for a single post), therefore I was thinking if I could merge postId and commentId into one single commentId (this becomes primary key) using which postId could also be retrieved. This is how I am thinking:

CommentId would be generated as postId*100+i (where i is the ith comment on the post)

thus in order to retrieve comments for a post(say with postId=8452 ) I would search all posts with commentId(that would be primary key), lying between 845200 & 845299.. instead of searching all comments with postId=8452.. (of course this limits the maximum no of comments to 100). But will this lead to any performance gains?

  • 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-18T21:06:06+00:00Added an answer on May 18, 2026 at 9:06 pm

    Here’s what you do. Load up a database with representative data at (for example) twice the size you ever expect it to get.

    Then run your queries and test them against both versions of the schema.

    Then, and this is the good bit, retest this every X weeks with new up-to-date data to ensure the situation hasn’t changed.

    That’s what being a DBA is all about. Unless your data will never change, database optimisation is not a set-and-forget operation. And the only way to be sure is to test under representative conditions.

    Everything else is guesswork. Educated guesswork, don’t get me wrong, but I’d rather have a deterministic answer in preference to anyone’s guess, especially since the former will adapt to changes.

    My favorite optimisation mantra is “Measure, don’t guess!”

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

Sidebar

Related Questions

I am having trouble thinking of how I should build my simple database, its
Fairly new to database schema (plan to use SQLite). Having said that, I'm thinking
I'm thinking of designing a database schema similar to the following: Person ( PersonID
I am developing a Codeigniter (2.0.2) Application, which will utilise a Master database for
I am thinking about providing a version of say, the database schema and the
I have an existing MySQL database schema in production for an PHP5 application. The
In my previous question , I asked how I would design the database schema
I want to design a fast database schema which can handle sorting and filtering
I'm thinking about porting a database from Sql Server 2005 to MySQL. I've become
I'd like to keep my database clean of stale almost-accounts, and I was thinking

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.