ruby-on-rails - Rails postgis 适配器在表 "geometry_columns"中进行了大量查询

标签 ruby-on-rails ruby-on-rails-3.2 gis postgis rails-postgresql

我想通过 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/

相关文章:

gis - Bing map 在 Openlayers 中的 WrapDateLine

ruby-on-rails - 通过子域共享一个Cookie

ruby-on-rails-3.2 - 使用 Active Admin Rails,过滤器部分中的日期选择器不显示 created_at 和 updated_at 字段

ruby-on-rails - 如何操作输入/粘贴到文本字段中的内容并将结果保存到 ruby​​ on rails 中的数据库中?

android - 仅允许 Android 应用程序访问 Rails API 的最佳实践

javascript - 切换 map 类型时显示 "no map data for this scale"而不是更改缩放比例

node.js - 如何在 Nodejs 中处理 KML/GeoJSON?

ruby-on-rails - rails 和 ActiveRecord : DRY use same logic in scope and boolean method

sql - 对 Rails/Heroku 上的 Postgres 数据库的意外 SQL 查询

ruby-on-rails - rails : NoMethodError in production only