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

Optimize fulltext queries #235

Merged
merged 1 commit into from
Dec 7, 2023
Merged

Optimize fulltext queries #235

merged 1 commit into from
Dec 7, 2023

Conversation

jsuchal
Copy link
Member

@jsuchal jsuchal commented Dec 6, 2023

pred indexom:

Limit  (cost=145.79..146.07 rows=1 width=560) (actual time=8206.233..8206.236 rows=1 loops=1)
  ->  Result  (cost=145.79..146.07 rows=1 width=560) (actual time=8206.231..8206.233 rows=1 loops=1)
        ->  Sort  (cost=145.79..145.79 rows=1 width=528) (actual time=8205.067..8205.068 rows=1 loops=1)
"              Sort Key: searchable_message_threads.last_message_delivered_at DESC, searchable_message_threads.message_thread_id DESC"
              Sort Method: quicksort  Memory: 25kB
              ->  Nested Loop  (cost=0.14..145.78 rows=1 width=528) (actual time=4310.646..8205.059 rows=1 loops=1)
                    ->  Seq Scan on searchable_message_threads searchable_message_threads_1  (cost=0.00..137.48 rows=1 width=8) (actual time=4310.628..8205.039 rows=1 loops=1)
"                          Filter: ((((to_tsvector('simple'::regconfig, COALESCE(title, ''::text)) || to_tsvector('simple'::regconfig, COALESCE(content, ''::text))) || to_tsvector('simple'::regconfig, COALESCE((note)::text, ''::text))) || to_tsvector('simple'::regconfig, COALESCE(tag_names, ''::text))) @@ '''nases'''::tsquery)"
                          Rows Removed by Filter: 123
                    ->  Index Scan using searchable_message_threads_pkey on searchable_message_threads  (cost=0.14..8.17 rows=1 width=516) (actual time=0.010..0.010 rows=1 loops=1)
                          Index Cond: (id = searchable_message_threads_1.id)
"                          Filter: ((tag_ids && '{1,2,3,4,5,6,8,9,10}'::integer[]) AND (last_message_delivered_at < '2023-12-06 14:03:04.794991'::timestamp without time zone) AND (tenant_id = 1) AND (box_id = 1))"
Planning Time: 0.457 ms
Execution Time: 8206.281 ms

po indexe:

Limit  (cost=29.33..29.61 rows=1 width=560) (actual time=1.206..1.209 rows=1 loops=1)
  ->  Result  (cost=29.33..29.61 rows=1 width=560) (actual time=1.205..1.207 rows=1 loops=1)
        ->  Sort  (cost=29.33..29.34 rows=1 width=528) (actual time=0.029..0.030 rows=1 loops=1)
"              Sort Key: searchable_message_threads.last_message_delivered_at DESC, searchable_message_threads.message_thread_id DESC"
              Sort Method: quicksort  Memory: 25kB
              ->  Nested Loop  (cost=16.15..29.32 rows=1 width=528) (actual time=0.022..0.023 rows=1 loops=1)
                    ->  Bitmap Heap Scan on searchable_message_threads searchable_message_threads_1  (cost=16.00..21.02 rows=1 width=8) (actual time=0.013..0.014 rows=1 loops=1)
"                          Recheck Cond: ((((to_tsvector('simple'::regconfig, COALESCE(title, ''::text)) || to_tsvector('simple'::regconfig, COALESCE(content, ''::text))) || to_tsvector('simple'::regconfig, COALESCE((note)::text, ''::text))) || to_tsvector('simple'::regconfig, COALESCE(tag_names, ''::text))) @@ '''nases'''::tsquery)"
                          Heap Blocks: exact=1
                          ->  Bitmap Index Scan on idx_searchable_message_threads_fulltext  (cost=0.00..16.00 rows=1 width=0) (actual time=0.010..0.011 rows=1 loops=1)
"                                Index Cond: ((((to_tsvector('simple'::regconfig, COALESCE(title, ''::text)) || to_tsvector('simple'::regconfig, COALESCE(content, ''::text))) || to_tsvector('simple'::regconfig, COALESCE((note)::text, ''::text))) || to_tsvector('simple'::regconfig, COALESCE(tag_names, ''::text))) @@ '''nases'''::tsquery)"
                    ->  Index Scan using idx_on_id_box_id_last_message_delivered_at_5a4090c55e on searchable_message_threads  (cost=0.14..8.17 rows=1 width=516) (actual time=0.006..0.006 rows=1 loops=1)
                          Index Cond: ((id = searchable_message_threads_1.id) AND (box_id = 1) AND (last_message_delivered_at < '2023-12-06 14:03:04.794991'::timestamp without time zone))
"                          Filter: ((tag_ids && '{1,2,3,4,5,6,8,9,10}'::integer[]) AND (tenant_id = 1))"
Planning Time: 0.498 ms
Execution Time: 1.244 ms

@jsuchal jsuchal requested a review from luciajanikova December 6, 2023 20:17
@jsuchal jsuchal merged commit a835f27 into main Dec 7, 2023
3 checks passed
@jsuchal jsuchal deleted the optimize-fulltext branch December 7, 2023 10:06
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

Successfully merging this pull request may close these issues.

2 participants