Tag: 查询性能

为什么我的PostgreSQL数组索引没有被使用(Rails 4)?

我有一个PostgreSQL字符串数组作为表中的列。 我使用GIN方法创建了一个索引。 但是任何查询都不会使用索引(相反,他们使用filter对整个表进行顺序扫描)。 我错过了什么? 这是我的迁移: class CreateDocuments < ActiveRecord::Migration def up create_table :documents do |t| t.string :title t.string :tags, array: true, default: [] t.timestamps end add_index :documents, :tags, using: 'gin' (1..100000).each do |i| tags = [] tags << 'even' if (i % 2) == 0 tags << 'odd' if (i % 2) == 1 tags […]