Re: Question about indexing!

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Jeong Jaeick, 정재익 <advance(at)advance(dot)sarang(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Question about indexing!
Date: 2001-10-03 15:28:05
Message-ID: Pine.BSF.4.21.0110030823060.50902-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


On Wed, 3 Oct 2001, [euc-kr] Jeong Jaeick, wrote:

> pgsql_bbs table has about 15,000 rows!
> And almost of them are satify (topic='qna' and deleted<2) condition.

Ah, so it's getting it wrong. It *shouldn't* be using that index. :(
[Index scans over most of the table is slower than the sequence
scan.]

Have you run vacuum analyze on this database? In any case, does
running vacuum analyze change the explain at all (even the estimated
row counts)?

> This explain result have a large cost.
> I want to low this query cost.

BTW, do you mean a large cost in real time? The explain numbers
don't necessarily reflect an actual time.
Also, you may want to check your sort memory settings to make
sure you're allocating enough (the defaults are generally low).

> >> select * from pgsql_bbs where topic = 'qna' and deleted < 2
> >> order by gid desc, pos asc limit 20, 0;
> >>
> >> But this query is not using index!
> >>
> >> The next is result of explain of this query:
> >>
> >> dsn=# explain select * from pgsql_bbs where topic = 'qna' and deleted < 2
> >> dsn-# order by gid desc, pos asc limit 20, 0;
> >> NOTICE: QUERY PLAN:
> >>
> >> Limit (cost=15.71..15.71 rows=11 width=245)
> >> -> Sort (cost=15.71..15.71 rows=11 width=245)
> >> -> Index Scan using pgsql_topic_deleted on pgsql_bbs (cost=0.00..15.51 rows=11 widt
> >h=245)
> >
> >It appears to be using the topic_deleted index according to this
> >explain output.
> >How many rows actually have topic='qna' and deleted<2?
> --
> ====================================================
> mailto:advance(at)advance(dot)sarang(dot)net
> http://database.sarang.net
> Dept of Neurosurgery, Dong-eui Medical Center
> ====================================================
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Stephan Szabo 2001-10-03 15:36:17 Re: 7.0.3 and 7.1.3 different results?
Previous Message Josh Berkus 2001-10-03 14:48:51 Re: 7.0.3 and 7.1.3 different results?