Answer the question
In order to leave comments, you need to log in
How to reduce planning time in postgresql?
The site server uses laravel and postgresql.
For search, full-text search (tsearch2) using Russian dictionaries is used.
The problem is that the search for Russian text takes longer than the search for Latin characters.
I'll show you an example
Request with Russian text
explain analyze
SELECT *
FROM lots
WHERE search_index @@@ to_tsquery('рус:*')
LIMIT 100
OFFSET 100
Planning time: 494.529 ms
Execution time: 3.871 ms
explain analyze
SELECT *
FROM lots
WHERE search_index @@@ to_tsquery('eng:*')
LIMIT 100
OFFSET 100
Planning time: 2.229 ms
Execution time: 0.700 ms
Answer the question
In order to leave comments, you need to log in
I think because the plan gets into the cache.
As an option - use prepared queries or do not break the connection (pgbouncer to the rescue).
It would be nice to see the full output of EXPLAIN ANALYZE, but I assume that the reason is that the first query pulls all the data from the disk, and when running the second query, postgresql already cached some of the data. Well, as He11ion said, the query plan is also cached for the session. Accordingly, the comparison is not correct. If you start the search with English words first, and then in Russian, I think the result of the experiment will be the opposite.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question