Home postgresql full text search function syntax
Reply: 1

postgresql full text search function syntax

zhmaksat Published in 2013-07-25 09:48:46Z

In postgres database we have a table table1 and with column column1 which type is text. And we created an index to that column CREATE INDEX idx_column1 ON table1 USING gin (to_tsvector('english', column1));

question is, why when we execute this query

FROM table1
where to_tsvector('english', column1) @@ to_tsquery('searchedText')

index is used, but by this query index is not used

FROM table1
where ts_match_vq(to_tsvector('english', column1),to_tsquery('searchedText'))
DrColossos Reply to 2013-07-25 12:09:31Z

Wild guess:

vector @@ query is defined as

  PROCEDURE = ts_match_vq,
  LEFTARG = tsvector,
  RIGHTARG = tsquery,
  RESTRICT = tsmatchsel,
  JOIN = tsmatchjoinsel);

Looking at tsmatchjoinsel there is quite a lot going on (don't ask me what, this kind of C is way beyond me....) But if you go through the different functions, there are some calculations involved. When using ts_match_vq directly, you bypass these calculations. That's why ts_match_vq is never mentioned in the docs and you should always use @@ since it takes care of calling the right functions and all the stuff that goes with it.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.307576 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO