Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在Rails中索引hstore字段?(PG::ProgramLimitExcelled:错误:索引行大小3112超过最大值2712)_Ruby On Rails_Postgresql_Activerecord - Fatal编程技术网

Ruby on rails 如何在Rails中索引hstore字段?(PG::ProgramLimitExcelled:错误:索引行大小3112超过最大值2712)

Ruby on rails 如何在Rails中索引hstore字段?(PG::ProgramLimitExcelled:错误:索引行大小3112超过最大值2712),ruby-on-rails,postgresql,activerecord,Ruby On Rails,Postgresql,Activerecord,我在Postgres中使用Rails 4.0,我的_记录表如下: id -> Integer data -> hstore 请注意,数据字段包含一个长散列,如: { "key1" => "val1", "key2" => "val2", .....etc } 现在,当我尝试查询表时,我有大约500000条记录和数据字段中的大散列,这需要很长时间: MyRecord.where("data -> 'key1' = 'val1'") 现在,我尝试使用以下方法

我在Postgres中使用Rails 4.0,我的_记录表如下:

id   -> Integer 
data -> hstore
请注意,数据字段包含一个长散列,如:

{ "key1" => "val1", "key2" => "val2", .....etc }
现在,当我尝试查询表时,我有大约500000条记录和数据字段中的大散列,这需要很长时间:

MyRecord.where("data -> 'key1' = 'val1'")
现在,我尝试使用以下方法为数据字段编制索引:

add_index :my_records, :data, using: :gin
但当我尝试运行迁移时,出现了以下错误:

PG::ProgramLimitExceeded: ERROR:  index row size 3112 exceeds maximum 2712 for index "index_my_records_on_data"
: CREATE  INDEX  "index_my_records_on_data" ON "my_records" USING gin ("data")

有什么帮助吗

看起来您的语法是正确的-您刚刚超出了GIN索引大小限制。本网站详细描述了该问题,并提供了一些备选方案:

您可能还想后退一步,重新思考您的设计。使用传统的NoSQL数据库可能会更好,尤其是在数据相对动态的情况下


希望这有帮助。

什么postgres版本?psql PostgreSQL 9.3.5