# Database optimization approach

**URL:** <https://www.ruby-forum.com/t/database-optimization-approach/149611>\
**Category:** Rails\
**Created:** [September 26, 2008, 6:48pm UTC](https://www.ruby-forum.com/t/database-optimization-approach/149611 "2008-09-26T18:48:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![elioncho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ed8c4c/32.png) [@elioncho](https://www.ruby-forum.com/u/elioncho)\
**Post date:** [September 26, 2008, 6:48pm UTC](https://www.ruby-forum.com/t/database-optimization-approach/149611/1 "2008-09-26T18:48:30Z")

</div>

Hello everyone,

I’ll like to hear your opinion on the following issue. I have a posts  
and post\_comments table. Posts belong to a group, so there is a  
group\_id column on it. I want to query for all the post\_comments of a  
user for a specific group, so what I am doing now is a INNER JOIN  
between the two tables. My question is: Is it better to have a  
group\_id column on the post\_comments table for optimize search or  
that’s redundant?

Thanks,

Elioncho

---

<div class="post-metadata">

**Author:** ![elioncho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ed8c4c/32.png) [@elioncho](https://www.ruby-forum.com/u/elioncho)\
**Post date:** [September 26, 2008, 7:37pm UTC](https://www.ruby-forum.com/t/database-optimization-approach/149611/2 "2008-09-26T19:37:26Z")

</div>

On Sep 27, 12:47 am, elioncho [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks,
> 
> Elioncho

Better that you keep your data struct as is, IMHO.

---

<div class="post-metadata">

**Author:** ![elioncho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ed8c4c/32.png) [@elioncho](https://www.ruby-forum.com/u/elioncho)\
**Post date:** [September 26, 2008, 10:18pm UTC](https://www.ruby-forum.com/t/database-optimization-approach/149611/3 "2008-09-26T22:18:54Z")

</div>

Agree with Erol. Leave the schema as it is, and use proper DB indexes  
to help with performance.

It is posts that belong to groups, not comments. Right?
