Query Optimization - Mailing list pgsql-novice

From Zach Calvert
Subject Query Optimization
Date
Msg-id 89af81ab0905270728n19b882e3hff8919a7c5006615@mail.gmail.com
Whole thread Raw
Responses Re: Query Optimization
List pgsql-novice
Sorry for the cross post - but I'm not sure my original posting to the
performance mailing list was the right place to send my question.  So,
let me try again at the novice list.

I have a query and I have run
explain analyze
select count(*)
from score
where leaderboardid=35 and score <= 6841 and active

The result is
"Aggregate  (cost=2491.06..2491.07 rows=1 width=0) (actual
time=38.878..38.878 rows=1 loops=1)"
"  ->  Seq Scan on score  (cost=0.00..2391.17 rows=39954 width=0)
(actual time=0.012..30.760 rows=38571 loops=1)"
"        Filter: (active AND (score <= 6841) AND (leaderboardid = 35))"
"Total runtime: 38.937 ms"

I have an index on score, I have an index on score, leaderboardid, and
active and still it does a sequential scan.  I can't seem to figure
out how to create an index that will
turn that "Seq Scan" into an index scan. The biggest problem is that
the query degrades very quickly with a lot more rows and I will be
getting A LOT MORE rows.  What can I do to improve the performance of
this query?



Thanks a bunch,
ZC

pgsql-novice by date:

Previous
From: "Just E. Mail"
Date:
Subject: Re: Read data from text file - SOLVED?
Next
From: Luiz Eduardo Cantanhede Neri
Date:
Subject: Re: Query Optimization