# Query performance boost

**URL:** <https://www.ruby-forum.com/t/query-performance-boost/157869>\
**Category:** Rails\
**Created:** [January 16, 2009, 5:09am UTC](https://www.ruby-forum.com/t/query-performance-boost/157869 "2009-01-16T05:09:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ukarick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/e19b73/32.png) [@ukarick](https://www.ruby-forum.com/u/ukarick)\
**Post date:** [January 16, 2009, 5:09am UTC](https://www.ruby-forum.com/t/query-performance-boost/157869/1 "2009-01-16T05:09:52Z")

</div>

I’ve a table with structure like this:

id: int  
field1: varchar(255)  
field2: int(11)  
field3: text  
field4: text  
field5: varchar(255)  
field6: varchar(255)

assume that this table contains massive contents on field 3 and 4  
So any way that I will be able to access this table quicker than my  
current query?

And this is the way I’m access this table:

Table.find(:all, :include=\> “relate\_table”)

please give me some hint (and I need all fields to display on page)

---

<div class="post-metadata">

**Author:** ![ukarick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/e19b73/32.png) [@ukarick](https://www.ruby-forum.com/u/ukarick)\
**Post date:** [January 16, 2009, 9:47am UTC](https://www.ruby-forum.com/t/query-performance-boost/157869/2 "2009-01-16T09:47:02Z")

</div>

Ukrit H. wrote:

> I’ve a table with structure like this:
> 
> id: int  
> field1: varchar(255)  
> field2: int(11)  
> field3: text  
> field4: text  
> field5: varchar(255)  
> field6: varchar(255)
> 
> assume that this table contains massive contents on field 3 and 4  
> So any way that I will be able to access this table quicker than my  
> current query?
> 
> And this is the way I’m access this table:
> 
> Table.find(:all, :include=\> “relate\_table”)
> 
> please give me some hint (and I need all fields to display on page)

would anyone mind giving some idea?

---

<div class="post-metadata">

**Author:** ![ukarick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/e19b73/32.png) [@ukarick](https://www.ruby-forum.com/u/ukarick)\
**Post date:** [January 16, 2009, 10:08am UTC](https://www.ruby-forum.com/t/query-performance-boost/157869/3 "2009-01-16T10:08:25Z")

</div>

Assuming you’re using MySQL these might help you.

[http://dev.mysql.com/doc/refman/5.1/en/static-format.html](http://dev.mysql.com/doc/refman/5.1/en/static-format.html)  
[http://dev.mysql.com/doc/refman/5.1/en/dynamic-format.html](http://dev.mysql.com/doc/refman/5.1/en/dynamic-format.html)

–  
Shiv N Gautam

On Fri, Jan 16, 2009 at 2:17 PM, Ukrit H. \<  
removed\_email\_address@domain.invalid\> wrote:

> > field6: varchar(255)  
> > please give me some hint (and I need all fields to display on page)
> 
> ## would anyone mind giving some idea?
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–

Robert Orben - “To err is human - and to blame it on a computer is even  
more so.”

---

<div class="post-metadata">

**Author:** ![ukarick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/e19b73/32.png) [@ukarick](https://www.ruby-forum.com/u/ukarick)\
**Post date:** [January 17, 2009, 5:22am UTC](https://www.ruby-forum.com/t/query-performance-boost/157869/4 "2009-01-17T05:22:15Z")

</div>

Quoting Ukrit H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> assume that this table contains massive contents on field 3 and 4  
> So any way that I will be able to access this table quicker than my  
> current query?
> 
> And this is the way I’m access this table:
> 
> Table.find(:all, :include=\> “relate\_table”)

Table.connection.select\_row(“SELECT \* FROM table, relate\_table  
WHERE table.relate\_table\_id = relate\_table.id”)

Returns an array of strings. This is from memory. The function name  
may not be quite correct.

HTH,  
Jeffrey

---

<div class="post-metadata">

**Author:** ![ukarick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/e19b73/32.png) [@ukarick](https://www.ruby-forum.com/u/ukarick)\
**Post date:** [January 18, 2009, 8:41pm UTC](https://www.ruby-forum.com/t/query-performance-boost/157869/5 "2009-01-18T20:41:20Z")

</div>

On Thu, Jan 15, 2009 at 8:09 PM, Ukrit H.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> assume that this table contains massive contents on field 3 and 4  
> So any way that I will be able to access this table quicker than my  
> current query?
> 
> And this is the way I’m access this table:
> 
> Table.find(:all, :include=\> “relate\_table”)
> 
> please give me some hint (and I need all fields to display on page)

You can use :select in your calls to find to select specific fields to  
retrieve data for. Here is a quick writeup on it.

- [http://www.geekskillz.com/articles/11](http://www.geekskillz.com/articles/11)

Good luck!

Cheers,  
Robby

–  
Robby R.  
Chief Evangelist, Partner

PLANET ARGON, LLC  
design // development // hosting w/Ruby on Rails

> **[Planet Argon](https://www.planetargon.com/)**
>
> Planet Argon is a Ruby on Rails development agency specializing in maintenance and support for existing Rails apps. Based in Portland, OR, Planet Argon has been a member of the Rails community since 2004.

[http://www.robbyonrails.com/](http://www.robbyonrails.com/)  
aim: planetargon

+1 503 445 2457  
+1 877 55 ARGON [toll free]  
+1 815 642 4068 [fax]
