X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 954683A433F for ; Wed, 24 Nov 2004 08:07:10 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 61058-04 for ; Wed, 24 Nov 2004 08:07:06 +0000 (GMT) Received: from bluebamboo.ph (unknown [202.175.252.53]) by svr1.postgresql.org (Postfix) with ESMTP id D00CB3A436D for ; Wed, 24 Nov 2004 08:07:04 +0000 (GMT) Received: from irridescens ([192.168.0.180]) by bluebamboo.ph (8.11.6/8.11.6) with ESMTP id iAO882i28819 for ; Wed, 24 Nov 2004 16:08:06 +0800 From: "BBI Edwin Punzalan" To: Subject: FW: FW: Index usage Date: Wed, 24 Nov 2004 16:07:37 +0800 Message-ID: <001d01c4d1fc$ab997060$b400a8c0@bluebamboo.ph> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.4510 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 Importance: Normal X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200411/368 X-Sequence-Number: 9322 Thanks, Tim. I tried adding an upper limit and its still the same as follows: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D db=3D# explain analyze select date from chatlogs where = date>=3D'11/24/04'; NOTICE: QUERY PLAN: Index Scan using chatlogs_date_idx on chatlogs (cost=3D0.00..145.72 = rows=3D37 width=3D4) (actual time=3D0.18..239.69 rows=3D10737 loops=3D1) Total runtime: 246.22 msec EXPLAIN db=3D# explain analyze select date from chatlogs where = date>=3D'11/23/04' and date<'11/24/04'; NOTICE: QUERY PLAN: Seq Scan on chatlogs (cost=3D0.00..24763.19 rows=3D9200 width=3D4) = (actual time=3D0.44..4447.01 rows=3D13029 loops=3D1) Total runtime: 4455.56 msec EXPLAIN db=3D# explain analyze select date from chatlogs where = date>=3D'11/23/04' and date<'11/25/04'; NOTICE: QUERY PLAN: Seq Scan on chatlogs (cost=3D0.00..24763.19 rows=3D9200 width=3D4) = (actual time=3D0.45..4268.00 rows=3D23787 loops=3D1) Total runtime: 4282.81 msec =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D How come a query on the current date filter uses an index and the others does not? This makes indexing to speed up queries quite difficult. -----Original Message----- From: Leeuw van der, Tim [mailto:tim.leeuwvander@nl.unisys.com]=20 Sent: Wednesday, November 24, 2004 3:35 PM To: BBI Edwin Punzalan; pgsql-performance@postgresql.org Subject: RE: [PERFORM] FW: Index usage Well you just selected a whole lot more rows... What's the total number = of rows in the table? In general, what I remember from reading on the list, is that when = there's no upper bound on a query like this, the planner is more likely to = choose a seq. scan than an index scan. Try to give your query an upper bound = like: select date from chatlogs where date>=3D'11/23/04' and date < = '12/31/99'; select date from chatlogs where date>=3D'10/23/04' and date < = '12/31/99'; This should make it easier for the planner to give a proper estimate of = the number of rows returned. If it doesn't help yet, please post 'explain analyze' output rather than 'explain' output, for it allows much better investigation into why the planner chooses what it chooses. cheers, --Tim -----Original Message----- From: pgsql-performance-owner@postgresql.org [mailto:pgsql-performance-owner@postgresql.org]On Behalf Of BBI Edwin Punzalan Sent: Wednesday, November 24, 2004 7:52 AM To: pgsql-performance@postgresql.org Subject: [PERFORM] FW: Index usage Hi everyone, Can anyone please explain postgres' behavior on our index. I did the following query tests on our database: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D db=3D# create index chatlogs_date_idx on chatlogs (date); CREATE db=3D# explain select date from chatlogs where date>=3D'11/23/04'; NOTICE: QUERY PLAN: Index Scan using chatlogs_date_idx on chatlogs (cost=3D0.00..144.11 = rows=3D36 width=3D4) EXPLAIN db=3D# explain select date from chatlogs where date>=3D'10/23/04'; NOTICE: QUERY PLAN: Seq Scan on chatlogs (cost=3D0.00..23938.06 rows=3D253442 width=3D4) EXPLAIN=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Date's datatype is date. Its just odd that I just change the actual = date of search and the index is not being used anymore. ---------------------------(end of broadcast)--------------------------- TIP 6: Have you searched our list archives? http://archives.postgresql.org