Rails postgis adapter makes a lot of queries in the geometry_columns table

I would like to optimize the Rails 3.2.13 application that currently uses postgis via gem.

The problem is that when I make a query in a table, even if it has only regular fields (without geography / geometry / this kind of material), this query is preceded by another query in the postgis table "geometry_columns".

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 table / user model.

Does anyone know how I can avoid unnecessary queries?

Thanks to everyone.

+4
source share
1 answer

I believe this answers your question: https://github.com/rgeo/rgeo/issues/29 . From the problem:

Activerecord adapters provide these selections to determine the database structure. They are not worthless. In the case of the selection indicated above, it is necessary to determine whether or not this table has any geospatial columns (and if so, which columns they are and how they are configured). If you are using a postgis adapter, then you will probably also notice a choice from pg_attribute, and possibly a few others. They are all part of how activerecord does its magic.

The good news is that it seems to me that activerecord caches all the structural information it collects in non-working environments, so you should see that they are selected only once for each table for each rails process. They should be quite harmless even for tables without spatial columns.

0
source

Source: https://habr.com/ru/post/1486803/


All Articles