I'd like to optimize my Rails 3.2.13 application that's currently using postgis through activerecord-postgis-adapter gem.
The problem is that when I make a query in a table, even if there are only regular fields in it (no geography/geometry/this kind of stuff), this query is preceded by another query on postgis "geometry_columns" table.
Example:
(5.6ms) SELECT * FROM geometry_columns WHERE f_table_name='srlzd_infos'
SrlzdInfo Load (1.1ms) SELECT "srlzd_infos".* FROM "srlzd_infos" WHERE "srlzd_infos"."user_id" = 1009 LIMIT 1
But I use postgis only in my Users table/model.
Does anyone know how can I avoid those unnecessary queries?
Thank you all.
I belive this answers your question: https://github.com/rgeo/rgeo/issues/29. From the issue:
The activerecord adapters issue these selects to determine the structure of the database. They're not useless. In the case of the select you note above, it is precisely to determine whether that table does or does not include any geospatial columns (and if so, which columns they are and how they are configured). If you're using the postgis adapter, then you'll probably also notice selects against pg_attribute, and possibly a few others. They're all part of the way activerecord does its magic.
The good news is, I believe activerecord caches all the structural information it gathers in non-development environments, so you should see these selects only once per table, per rails process. They should be pretty much harmless, even for tables with no spatial columns.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With