Seq scan vs. Index scan with different query conditions - Mailing list pgsql-performance

From eleven@ludojad.itpp.pl
Subject Seq scan vs. Index scan with different query conditions
Date
Msg-id 20040705101515.GA12879@ludojad.itpp.pl
Whole thread Raw
Responses Re: Seq scan vs. Index scan with different query conditions
Re: Seq scan vs. Index scan with different query
List pgsql-performance
Hello,

Can anybody suggest any hint on this:

temp=> EXPLAIN SELECT DISTINCT "number" FROM "tablex" WHERE "Date" BETWEEN '2004-06-28'::date AND '2004-07-04'::date
AND"Time" BETWEEN '00:00:00'::time AND '18:01:00'::time; 

Unique  (cost=305669.92..306119.43 rows=89 width=8)
    ->  Sort  (cost=305669.92..305894.67 rows=89903 width=8)
        Sort Key: "number"
            ->  Index Scan using "DateTimeIndex" on "tablex"  (cost=0.00..298272.66 rows=89903 width=8)
                Index Cond: (("Date" >= '2004-06-28'::date) AND ("Date" <= '2004-07-04'::date) AND ("Time" >=
'00:00:00'::timewithout time zone) AND ("Time" <= '18:01:00'::time without time zone)) 


temp=> EXPLAIN SELECT DISTINCT "number" FROM "tablex" WHERE "Date" BETWEEN '2004-06-28'::date AND '2004-07-04'::date
AND"Time" BETWEEN '00:00:00'::time AND '19:01:00'::time; 

Unique  (cost=315252.77..315742.27 rows=97 width=8)
    ->  Sort  (cost=315252.77..315497.52 rows=97900 width=8)
        Sort Key: "number"
            ->  Seq Scan on "tablex"  (cost=0.00..307137.34 rows=97900 width=8)
            Filter: (("Date" >= '2004-06-28'::date) AND ("Date" <= '2004-07-04'::date) AND ("Time" >= '00:00:00'::time
withouttime zone) AND ("Time" <= '19:01:00'::time without time zone)) 

Basically, the difference is in upper "Time" value (as you can see, it's
18:01:00 in the first query and 19:01:00 in the other one).
The question is - why does it use index in first case and
it tries to do full sequential scan when the upper "Time" value
is different?

DateTimeIndex was created on both columns (Date/Time):
CREATE INDEX "DateTimeIndex" ON "tablex" USING btree ("Date", "Time");

--
wr

pgsql-performance by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: BUG #1186: Broken Index?
Next
From: Richard Huxton
Date:
Subject: Re: Seq scan vs. Index scan with different query conditions