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
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 > Preloading Attributes<br />
F<strong>as</strong>ter with Postgres arrays:<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, :select => "*,<br />
array(select tags.name 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_t<strong>as</strong>ks.t<strong>as</strong>k_id=t<strong>as</strong>ks.id) <strong>as</strong> tag_names<br />
")<br />
puts t<strong>as</strong>ks.first.tag_names<br />
> "{Foo,Bar,Zee}"<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 32 / 58