我想通过 activerecord-postgis-adapter gem 优化当前使用 postgis 的 Rails 3.2.13 应用程序。
问题是,当我在表中进行查询时,即使其中只有常规字段(没有地理/几何/这种东西),此查询之前还有对 postgis“geometry_columns”表的另一个查询。
例子:
(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
但我只在我的用户表/模型中使用 postgis。
有谁知道我怎样才能避免那些不必要的查询?
谢谢你们。
最佳答案
我相信这可以回答您的问题:https://github.com/rgeo/rgeo/issues/29 .来自问题:
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.
关于ruby-on-rails - Rails postgis 适配器在表 "geometry_columns"中进行了大量查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17167523/