21.05.2014 Views

PostgreSQL as a secret weapon for high-performance ... - PGCon

PostgreSQL as a secret weapon for high-performance ... - PGCon

PostgreSQL as a secret weapon for high-performance ... - PGCon

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Rails Per<strong>for</strong>mance > Attribute Preloading<br />

The conventional Rails way:<br />

T<strong>as</strong>ks Tags T<strong>as</strong>ks_Tags<br />

id serial id serial tag_id integer<br />

name varchar name varchar t<strong>as</strong>k_id integer<br />

t<strong>as</strong>ks = T<strong>as</strong>k.find(:all, :include => :tags)<br />

> 0.058 sec<br />

2 SQL queries<br />

select * from t<strong>as</strong>ks<br />

select * from tags inner join t<strong>as</strong>ks_tags<br />

on tags.id = t<strong>as</strong>ks_tags.tag_id<br />

where t<strong>as</strong>ks_tags.t<strong>as</strong>k_id in (1,2,3,..)<br />

Rals creates an object <strong>for</strong> each tag,<br />

that's not f<strong>as</strong>t and takes memory<br />

Gleb Arshinov & Alex Dymo ● <strong>PostgreSQL</strong> <strong>as</strong> a <strong>secret</strong> <strong>weapon</strong> <strong>for</strong> <strong>high</strong>-per<strong>for</strong>mance Ruby on Rails applications ● <strong>PGCon</strong> 2010 30 / 58

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!