On Wed, 23 Nov 2005, Stas Filippov wrote:
> Actually my output for EXPLAIN ANALYZE is similar, but because of poor
I don't think so. I don't see bitmaps are used in your case.
> performance it makes me wonder if the second half of the index is being
> used. Can you tell if the second half is used by looking at EXPLAIN
> ANALYZE?
I've seen only output of EXPLAIN ANALYZE for your toy database which is not
I want to spent my time on. Have you analyze performance with and without
final ORDER BY ? Are you sure the problem is here ? How many rows found ?
>
> In general, can the second part of a two-column index be used for a
> query such as:
>
> SELECT * FROM table WHERE col1='blabla' ORDER BY col2;
>
> where there is an index ON table (col1,col2). In my case instead of
> col1='blabla', it's vectors @@ to_tsquery('entry'), I don't know if that
> makes a difference.
it depends on distribution of real data. index is not always good thing.
Have you read about multicolumn indices ?
http://www.postgresql.org/docs/8.1/static/indexes-multicolumn.html
http://www.postgresql.org/docs/8.1/static/indexes-bitmap-scans.html
Also, do you really need multicolumn index ?
btw, do you have minimal test suite which illustrate your problem ?
>
> -Stas
>
>
> -----Original Message-----
> From: Oleg Bartunov [mailto:oleg@...]
> Sent: Wednesday, November 23, 2005 12:35 AM
> To: Stas Filippov
> Cc: openfts-general@...
> Subject: Re: [OpenFTS-general] GIST index and ORDER BY
>
> Stas,
>
> I don't have 8.1 available for playing but 8.2dev works as expected
>
> test=# explain analyze select tid, title from h_pages where fts @@
> 'printer' order by tid limit 10;
> QUERY PLAN
> ------------------------------------------------------------------------
> ----------------------------------------------------
> Limit (cost=16.62..16.63 rows=4 width=36) (actual time=10.301..10.316
> rows=5 loops=1)
> -> Sort (cost=16.62..16.63 rows=4 width=36) (actual
> time=10.296..10.301 rows=5 loops=1)
> Sort Key: tid
> -> Bitmap Heap Scan on h_pages (cost=2.01..16.58 rows=4
> width=36) (actual time=9.603..9.690 rows=5 loops=1)
> Filter: (fts @@ '''printer'''::tsquery)
> -> Bitmap Index Scan on fts_idx (cost=0.00..2.01
> rows=4 width=0) (actual time=0.277..0.277 rows=5 loops=1)
> Index Cond: (fts @@ '''printer'''::tsquery)
> Total runtime: 21.790 ms
> (8 rows)
>
> Time: 78.033 ms
>
> test=# \d h_pages
> Table "public.h_pages"
> Column | Type | Modifiers
> --------+-------------------+-----------
> tid | integer | not null
> path | character varying | not null
> body | character varying |
> title | character varying |
> fts | tsvector |
> Indexes:
> "h_pages_pkey" PRIMARY KEY, btree (tid)
> "h_pages_path_key" UNIQUE, btree (path)
> "fts_idx" gist (fts, tid)
>
> btw, your explain output looks like you disable bitmapscan. Did you ?
> Check postgresql.conf
>
>
> Oleg
>
> On Tue, 22 Nov 2005, Stas Filippov wrote:
>
>> Hello,
>>
>> I am unable to use GIST index in ORDER BY clause. I am trying to
>> utilize tsearch2 for searching a textfield in a table and the sort the
>> result set by another column. E.g:
>>
>> CREATE TABLE sample (
>> :
>> textfield text,
>> sortfield int,
>> :.
>> vectors tsvector
>> );
>>
>> UPDATE sample SET vectors = to_tsvector( textfield );
>> CREATE INDEX sample_vectors_sortfield_idx ON sample USING gist(
> vectors,
>> sortfield );
>>
>> SET enable_seqscan=off;
>>
>> EXPLAIN SELECT textfield FROM sample WHERE vectors @@
> to_tsquery('term')
>> ORDER BY sortfield LIMIT 10;
>>
>> QUERY PLAN
>>
>>
> ------------------------------------------------------------------------
>> --------------------------------
>> Limit (cost=3.69..3.70 rows=1 width=36)
>> -> Sort (cost=3.69..3.70 rows=1 width=36)
>> Sort Key: sortfield
>> -> Index Scan using sample_vectors_sortfield_idx on sample
>> (cost=0.00..3.68 rows=1 width=36)
>> Index Cond: (vectors @@ '''term'''::tsquery)
>> Filter: (vectors @@ '''term'''::tsquery)
>> (6 rows)
>>
>> As you can see, only the first part of the index is used - for
> searching
>> the term; it then sorts the results instead of using the second part
> of
>> the index which is sortfield. I tried reordering the index fields
> with
>> no effect
>>
>> It appears that GIST indexes cannot be used for ORDER BY clause in
>> general. Is that true? Why is there such limitation?
>>
>> I am comparing the results with MySQL fulltext search functionality
> and
>> it considerably outperforms Postgres in the case when sorting
> described
>> above is required. Without the sorting both MySQL and Postgres are
> very
>> fast.
>>
>> Thanks for any help in advance
>> -Stas
>>
>
> Regards,
> Oleg
> _____________________________________________________________
> Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
> Sternberg Astronomical Institute, Moscow University (Russia)
> Internet: oleg@..., http://www.sai.msu.su/~megera/
> phone: +007(095)939-16-83, +007(095)939-23-83
>
Regards,
Oleg
_____________________________________________________________
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: oleg@..., http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83
|