How to increase the query performance on my fts query?


I’m pretty new to database world and I have the following table:

                        Table "public.so_rum"   Column   |          Type           | Collation | Nullable | Default  -----------+-------------------------+-----------+----------+---------  id        | integer                 |           |          |   title     | character varying(1000) |           |          |   posts     | text                    |           |          |   body      | tsvector                |           |          |   parent_id | integer                 |           |          |  Indexes:     "so_rum_body_idx" rum (body) 

I have dumped around 27M record. And I wanted to perform a full text search on my posts. body is a tsvector for posts and it is rum indexed.

However, when I run FTS, it is taking a long time. For example:

 EXPLAIN ANALYZE select count(*) from so_rum     where body @@ plainto_tsquery('english','not fast enough data is slow much') 

give back:

                                                                 QUERY PLAN                                                                  --------------------------------------------------------------------------------------------------------------------------------------------  Aggregate  (cost=188.01..188.02 rows=1 width=8) (actual time=42207.386..42207.387 rows=1 loops=1)    ->  Index Scan using so_rum_body_idx on so_rum  (cost=180.00..188.01 rows=1 width=0) (actual time=34716.047..42206.555 rows=497 loops=1)          Index Cond: (body @@ '''fast'' & ''enough'' & ''data'' & ''slow'' & ''much'''::tsquery)  Planning Time: 0.247 ms  Execution Time: 42208.211 ms (5 rows) 

Another similar query, but fetching post this time:

EXPLAIN ANALYZE select posts from so_rum     where body @@ plainto_tsquery('english',' why java type casting is throwing the exception? How to solve it') ;                                                               QUERY PLAN                                                                ---------------------------------------------------------------------------------------------------------------------------------------  Index Scan using so_rum_body_idx on so_rum  (cost=216.00..224.01 rows=1 width=614) (actual time=45155.186..45516.358 rows=31 loops=1)    Index Cond: (body @@ '''java'' & ''type'' & ''cast'' & ''throw'' & ''except'' & ''solv'''::tsquery)  Planning Time: 19.540 ms  Execution Time: 45517.985 ms (4 rows) 

How to reduce the query time here? What mistake I’m doing here?