Re: Query tuning help

Поиск
Список
Период
Сортировка
От Josh Berkus
Тема Re: Query tuning help
Дата
Msg-id 200505081906.47731.josh@agliodbs.com
обсуждение исходный текст
Ответ на Re: Query tuning help  (Dan Harris <fbsd@drivefaster.net>)
Ответы Re: Query tuning help  (Dan Harris <fbsd@drivefaster.net>)
Список pgsql-performance
Dan,

> While I believe you, I'm confused by this line in my original EXPLAIN
>
> ANALYZE:
> >> ->  Index Scan using ea1 on ea  (cost=0.00..2736.43 rows=42 width=47)
> >> (actual time=2.085..2.309 rows=2 loops=473)
> >>                                         Index Cond:
> >> ((ea.incidentid)::text = ("outer".incidentid)::text)
> >>                                         Filter: (((recordtext)::text
> >> ~~ '%RED%'::text) OR ((recordtext)::text ~~ '%CORVETTE%'::text))

The index named is matching based on incidentid -- the join condition.  The
"filter" is applied against the table rows, i.e. a scan.

> If I were to use tsearch2 for full-text indexing, would I need to
> create another table that merges all of my recordtext rows into a
> single 'text' field type?

No.   Read the OpenFTS docs, they are fairly clear on how to set up a simple
FTS index. (TSearch2 ~~ OpenFTS)

> If so, this is where I run into problems, as
> my logic also needs to match multiple words in their original order.

You do that by doubling up ... that is, use the FTS index to pick all rows
that contain "RED" and "CORVETTE", and then check the order.  I'll also note
that your current query is not checking word order.

Example:
WHERE recordtext_fti @@ to_tsquery ('default', 'RED && CORVETTE')
    AND recordtext LIKE '%RED%CORVETTE%'

I'm doing something fairly similar on one of my projects and it works very
well.

The limitations on TSearch2 indexes are:
1) they are expensive to update, so your data loads would be noticably slower.
2) they are only fast when cached in RAM (and when cached, are *very* fast).
So if you have a variety of other processes that tend to fill up RAM between
searches, you may find them less useful.
3) You have to create a materialized index column next to recordtext, which
will increase the size of the table.

--
Josh Berkus
Aglio Database Solutions
San Francisco

В списке pgsql-performance по дате отправления:

Предыдущее
От: Dan Harris
Дата:
Сообщение: Re: Query tuning help
Следующее
От: Geoffrey
Дата:
Сообщение: Re: Whence the Opterons?