Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pg_search_scope : how to prevent auto builded nested queries ? #307

Open
itkin opened this issue May 25, 2016 · 1 comment
Open

pg_search_scope : how to prevent auto builded nested queries ? #307

itkin opened this issue May 25, 2016 · 1 comment

Comments

@itkin
Copy link

itkin commented May 25, 2016

Hello,

I've the pg_search implemtentation :

class Product
  include PgSearch
  pg_search_scope :search_by_title, against: :title,
    using:{
      tsearch: {
        dictionary: 'simple',
        prefix: true,
        tsvector_column: 'tsv'
      }
}
end

here is the query produced by Porduct.search_by_title('windo') :

SELECT "products".* FROM "products" 
INNER JOIN (SELECT "products"."id" AS pg_search_id, (ts_rank(("products"."tsv"), (to_tsquery('simple', ''' ' || 'windo' || ' ''' || ':*')), 0)) AS rank FROM "products" WHERE ((("products"."tsv") @@ (to_tsquery('simple', ''' ' || 'windo' || ' ''' || ':*'))))) AS pg_search_0a3e27b8ca818264d75c8d 
ON "products"."id" = pg_search_0a3e27b8ca818264d75c8d.pg_search_id  
ORDER BY pg_search_0a3e27b8ca818264d75c8d.rank DESC, "products"."id" ASC

I'm wondering why is pg_search nesting queries (killing the perf) instead of building something like that :

SELECT "products".*, (ts_rank(("products"."tsv"), (to_tsquery('simple', ''' ' || 'wind' || ' ''' || ':*')), 0)) AS rank 
FROM "products" 
WHERE ((("products"."tsv") @@ (to_tsquery('simple', ''' ' || 'wind' || ' ''' || ':*'))))
ORDER BY rank DESC, "products"."id" ASC

What am i missing ? thx for the help ...

@itkin itkin changed the title pg_search_scope : how to prevent pg_search_0a3e27b8ca818264d75c8d ? pg_search_scope : how to prevent auto builded nested queries ? May 25, 2016
@jjohnson
Copy link

In support of more ActiveRecord::Relation methods, according to changelog, https://github.com/Casecommons/pg_search/blob/master/CHANGELOG.md#100

Explained more here, #292 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants