Postgres full text search across multiple related tables Postgres full text search across multiple related tables postgresql postgresql

Postgres full text search across multiple related tables


Your best answer is probably to have a separate tsvector column in each table (with an index on, of course). If you aggregate the data up to a shared tsvector, that'll create a lot of updates on that shared one whenever the individual ones update.

You will need one index per table. Then when you query it, obviously you need multiple WHERE clauses, one for each field. PostgreSQL will then automatically figure out which combination of indexes to use to give you the quickest results - likely using bitmap scanning. It will make your queries a little more complex to write (since you need multiple column matching clauses), but that keeps the flexibility to only query some of the fields in the cases where you want.

You cannot create one index that tracks multiple tables. To do that you need the separate tsvector column and triggers on each table to update it.