Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails postgis adapter makes lot of queries in table "geometry_columns"

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.

like image 646
Gozup Avatar asked Nov 12 '22 03:11

Gozup


1 Answers

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.

like image 144
Georgi Mitev Avatar answered Nov 15 '22 07:11

Georgi Mitev