Seq scan vs. Index scan with different query conditions

11 <eleven@ludojad.itpp.pl>

From: eleven@ludojad.itpp.pl
To: pgsql-performance@postgresql.org
Date: 2004-07-05T10:15:15Z
Lists: 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'::time without 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 without time 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