Bonjour,
J'ai un problème de performance sur une requête utilisant Tsearch2, qui prend plusieurs minutes.
La requête est effectuée sur une table contenant un peu moins de 400.000 lignes, sur un champ contenant des textes longs (issus d'une reco OCR).
Le champ de type ts_vector a été créé en utilisant le dictionnaire fr_ispell uniquement sur les types lword, lpart_hword et lhword. Ce champ a été indexé.
D'après la fonction stat(), il n'y a que 42.590 racines de mots différentes indexées.
J'ai fait un VACUUM FULL ANALYZE.
Voici le résultat d'un EXPLAIN ANALYZE sur ma requête:
**************************************************************************
explain analyze SELECT idstruct, headline(zonetext, q), rank(zoneindex_test, q) FROM tab_ocr, tab_chemin, to_tsquery('partir') AS q WHERE tab_chemin.chemin like '%;2;%' AND tab_ocr.idstruct = tab_chemin.label AND zoneindex_test @@ q ORDER BY rank(zoneindex_test, q) DESC;
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Sort (cost=2345.54..2345.58 rows=16 width=308) (actual time=270638.774..270643.142 rows=7106 loops=1)
Sort Key: rank(tab_ocr.zoneindex_test, q.q)
-> Nested Loop (cost=80.04..2345.22 rows=16 width=308) (actual time=40886.553..270619.730 rows=7106 loops=1)
-> Nested Loop (cost=80.04..1465.76 rows=392 width=308) (actual time=38209.193..173932.313 rows=272414 loops=1)
-> Function Scan on q (cost=0.00..0.01 rows=1 width=32) (actual time=0.006..0.007 rows=1 loops=1)
-> Bitmap Heap Scan on tab_ocr (cost=80.04..1460.85 rows=392 width=276) (actual time=38209.180..173507.052 rows=272414 loops=1)
Filter: (tab_ocr.zoneindex_test @@ q.q)
-> Bitmap Index Scan on zoneindex_test_idx (cost=0.00..79.94 rows=392 width=0) (actual time=38204.261..38204.261 rows=283606 loops=1)
Index Cond: (tab_ocr.zoneindex_test @@ q.q)
-> Index Scan using tab_chemin_label_index on tab_chemin (cost=0.00..2.23 rows=1 width=4) (actual time=0.036..0.036 rows=0 loops=272414)
Index Cond: (tab_ocr.idstruct = tab_chemin.label)
Filter: ((chemin)::text ~~ '%;2;%'::text)
Total runtime: 270647.946 ms
**************************************************************************
Quelqu'un pourrait-il m'aider à analyser d'où vient le problème?
Je n'arrive pas à déterminer si cela vient du tuning de tsearch2, de postgresql, ou d'autre chose...
Remarque: je fais mes tests sur une requête filtrée (le temps de traitement de la requête non filtrée est tellement long que je perds patience et annule la requête), mais la requête sans filtrage doit être également performante:
SELECT idstruct, headline(zonetext, q), rank(zoneindex_test, q) FROM tab_ocr, tab_chemin, to_tsquery('partir') AS q WHERE zoneindex_test @@ q ORDER BY rank(zoneindex_test, q) DESC;
Partager