0

I have to query for example zips_of_state,state_names,county_names from a state table

select  zips_of_state,state_names,county_names 
from state 
where zips_of_state='something' 
   OR state_names='something' 
   OR county_names ='something';

Now I am indexing as

CREATE INDEX ind_zips 
   ON state 
   USING gin(to_tsvector('english', zips_of_state)); -- this works

But how do I do multi indexing like

CREATE INDEX ind_zips 
   ON state 
   -- this doesn't work
   USING gin(to_tsvector('english', zips_of_state)),state_names, county_names ;
2
  • Could you try CREATE INDEX ind_zips ON state USING gin(to_tsvector('english', zips_of_state),state_names, county_names);? Commented May 18, 2020 at 16:46
  • @zedfoxus it doesnt work - ERROR: data type character varying has no default operator class for access method "gin" Commented May 19, 2020 at 5:54

1 Answer 1

1

That query doesn't match the index at all.

If you don't want full text search, you'll need a regular B-tree index on each of the columns individually, so that you can get a bitmap or.

If you want full text search, write the query as

WHERE to_tsvector('english', zips_of_state) ||
      to_tsvector('english', state_names) ||
      to_tsvector('english', country_names)
   @@ to_tsquery('english', 'something')

anf use a GIN index on the expression on the left side of the @@ operator:

CREATE INDEX ON stat USING gin ((
   to_tsvector('english', zips_of_state) ||
   to_tsvector('english', state_names) ||
   to_tsvector('english', country_names)
));
Sign up to request clarification or add additional context in comments.

2 Comments

Tried this but didnt work. the query time does not see any improvement.
I have spelled out the CREATE INDEX. Is that what you tried?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.