Forum: Ruby on Rails No column information caching?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fad90847c8c55cd4e61513fbfc9bc227?d=identicon&s=25 Michael Kintzer (Guest)
on 2011-08-01 20:41
(Received via mailing list)
I have recently been investigating using PosgreSQL (server version
8.3.12), with the 'pg' gem '0.11.0', with our Rails 3.0.7 app.  I've
noticed in the development.log that column information queries are
made after each request.  After inspecting the code for the
postgresql_adapter and the mysql_adapter I noticed that the
mysql_adapter executes a similar query but with the :skip_logging
flag, while the postgresql_adapter goes ahead noisily and logs the
query:

In PostgreSQL, the queries are similar to:

SQL (4.4ms)   SELECT a.attname, format_type(a.atttypid, a.atttypmod),
d.adsrc, a.attnotnull
 FROM pg_attribute a LEFT JOIN pg_attrdef d
 ON a.attrelid = d.adrelid AND a.attnum = d.adnum
 WHERE a.attrelid = '"users"'::regclass
 AND a.attnum > 0 AND NOT a.attisdropped
 ORDER BY a.attnum

These queries take real time in development mode, so being worried
about performance I added some extra logging in both adapters to see
if these queries are also being made in production mode, and to my
surprise they were made repeatedly for tables with both adapters.   I
was under the impression that ActiveRecord caches table column
information (at least in production mode) for a given table after the
first query, and does not need to re-query this information unless the
client calls the ActiveRecord::Base.reset_column_information method.

What's going on here?  Am I missing a configuration option that
enables table column information caching?  Or am I just
misunderstanding the basic concept?

Thanks,

Michael
A47e0a6beeb9d048ff054fc1c3a97418?d=identicon&s=25 Walter Davis (walterdavis)
on 2011-08-01 20:45
(Received via mailing list)
On Aug 1, 2011, at 2:39 PM, Michael Kintzer wrote:

>
> if these queries are also being made in production mode, and to my
> surprise they were made repeatedly for tables with both adapters.   I
> was under the impression that ActiveRecord caches table column
> information (at least in production mode) for a given table after the
> first query, and does not need to re-query this information unless the
> client calls the ActiveRecord::Base.reset_column_information method.
>
> What's going on here?  Am I missing a configuration option that
> enables table column information caching?  Or am I just
> misunderstanding the basic concept?

I think you'll find that (the local equivalent of) these queries
happen all the time in all database servers when you're in development
mode. Production mode enables all the caches, and you won't see them
any more, or certainly not as often!

Walter
Fad90847c8c55cd4e61513fbfc9bc227?d=identicon&s=25 Michael Kintzer (Guest)
on 2011-08-01 22:59
(Received via mailing list)
I guess what I'm saying is I'm seeing it far more in production mode
than I would expect.
This topic is locked and can not be replied to.