pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
ways to force index use?
5+ messages / 4 participants
[nested] [flat]

* ways to force index use?
@ 2003-10-13 23:48  Seth Ladd <seth@picklematrix.net>
  0 siblings, 2 replies; 5+ messages in thread

From: Seth Ladd @ 2003-10-13 23:48 UTC (permalink / raw)
  To: pgsql-performance

Hello,

Thanks to all the previous suggestions for my previous question.  I've  
done a lot more research and playing around since then, and luckily I  
think I have a better understanding of postgresql.

I still have some queries that don't use an index, and I was wondering  
if there were some other tricks to try out?

My system: RH9, PG 7.3.4, IDE, 1 gig RAM, celeron 1.7
My Table Columns (all bigints): start, stop, step1, step2, step3
My Indexes: btree(start), btree(stop), btree(start, stop)
Size of table: 16212 rows
Params: shared_buffers = 128, effective_cache_size = 8192

The Query: explain analyze select * from path where start = 653873 or  
start = 649967 or stop = 653873 or stop = 649967

The Result:
Seq Scan on "path"  (cost=0.00..450.22 rows=878 width=48) (actual time=0 
.08..40.50 rows=1562 loops=1)
 Filter: (("start" = 653873) OR ("start" = 649967) OR (stop = 653873) OR 
 (stop = 649967))
Total runtime: 42.41 msec

Does anyone have a suggestion on how to get that query to use an index?  
  Is it even possible?  I did run vacuum analyze right before this test.

I'm only beginning to customize the parameters in postgresql.conf  
(mainly from tips from this list).

Thanks very much!
Seth




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: ways to force index use?
@ 2003-10-13 23:55  Josh Berkus <josh@agliodbs.com>
  parent: Seth Ladd <seth@picklematrix.net>
  1 sibling, 0 replies; 5+ messages in thread

From: Josh Berkus @ 2003-10-13 23:55 UTC (permalink / raw)
  To: Seth Ladd <seth@picklematrix.net>; pgsql-performance

Seth,

> The Query: explain analyze select * from path where start = 653873 or  
> start = 649967 or stop = 653873 or stop = 649967

you need to cast all those numbers to BIGINT:

select * from path where start = 653873::BIGINT or  
start = 649967::BIGINT or stop = 653873::BIGINT or stop = 649967::BIGINT

Then an index on start or stop should be used by the planner.

-- 
-Josh Berkus
 Aglio Database Solutions
 San Francisco




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: ways to force index use?
@ 2003-10-14 00:01  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Seth Ladd <seth@picklematrix.net>
  1 sibling, 1 reply; 5+ messages in thread

From: Tom Lane @ 2003-10-14 00:01 UTC (permalink / raw)
  To: Seth Ladd <seth@picklematrix.net>; +Cc: pgsql-performance

Seth Ladd <seth@picklematrix.net> writes:
> My Table Columns (all bigints): start, stop, step1, step2, step3
                    ^^^^^^^^^^^

> The Query: explain analyze select * from path where start = 653873 or  
> start = 649967 or stop = 653873 or stop = 649967

> Does anyone have a suggestion on how to get that query to use an index?  

Coerce the constants to bigint, for starters.  However, a query that is
selecting almost 10% of the table, as your example is, probably
*shouldn't* be using an index.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: ways to force index use?
@ 2003-10-14 00:20  Gaetano Mendola <mendola@bigfoot.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Gaetano Mendola @ 2003-10-14 00:20 UTC (permalink / raw)
  To: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>

Tom Lane wrote:
> Seth Ladd <seth@picklematrix.net> writes:
> 
>>My Table Columns (all bigints): start, stop, step1, step2, step3
> 
>                     ^^^^^^^^^^^
> 
> 
>>The Query: explain analyze select * from path where start = 653873 or  
>>start = 649967 or stop = 653873 or stop = 649967
> 
> 
>>Does anyone have a suggestion on how to get that query to use an index?  
> 
> 
> Coerce the constants to bigint, for starters.  However, a query that is
> selecting almost 10% of the table, as your example is, probably
> *shouldn't* be using an index.

I think that for 10% is still better and Index scan.
There is around a way to calculate this elbow ?



Regards
Gaetano Mendola




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: ways to force index use?
@ 2003-10-14 08:18  Seth Ladd <seth@picklematrix.net>
  0 siblings, 0 replies; 5+ messages in thread

From: Seth Ladd @ 2003-10-14 08:18 UTC (permalink / raw)
  To: pgsql-performance


On Monday, Oct 13, 2003, at 21:24 Pacific/Honolulu, mila wrote:

> Seth,
>
>> My system: RH9, PG 7.3.4, IDE, 1 gig RAM, celeron 1.7
> ...
>> Size of table: 16212 rows
>> Params: shared_buffers = 128, effective_cache_size = 8192
>
> Just in case,
> the "shared_buffers" value looks a bit far too small for your system.
> I think you should raise it to at least 1024, or so.
>
> Effective cache size could be (at least) doubled, too ==> this might
> help forcing the index use.

Thanks!  I'm just beginning to play with these numbers.  I'll 
definitely try them out.

I can't wait to try out the script that will help set these parameters! 
:)

Seth




^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2003-10-14 08:18 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-10-13 23:48 ways to force index use? Seth Ladd <seth@picklematrix.net>
2003-10-13 23:55 ` Josh Berkus <josh@agliodbs.com>
2003-10-14 00:01 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-10-14 00:20   ` Gaetano Mendola <mendola@bigfoot.com>
2003-10-14 08:18 Re: ways to force index use? Seth Ladd <seth@picklematrix.net>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox