X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 122C59DCC2B for ; Wed, 15 Feb 2006 18:47:17 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 36680-09 for ; Wed, 15 Feb 2006 18:47:19 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id DCB069DCB6E for ; Wed, 15 Feb 2006 18:47:14 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k1FMlFTl020472; Wed, 15 Feb 2006 17:47:15 -0500 (EST) To: "Daniel Caune" cc: "Andrew Sullivan" , pgsql-sql@postgresql.org Subject: Re: How to force PostgreSQL using an index In-reply-to: <1E293D3FF63A3740B10AD5AAD88535D20190926B@UBIMAIL1.ubisoft.org> References: <1E293D3FF63A3740B10AD5AAD88535D20190926B@UBIMAIL1.ubisoft.org> Comments: In-reply-to "Daniel Caune" message dated "Wed, 15 Feb 2006 17:26:57 -0500" Date: Wed, 15 Feb 2006 17:47:15 -0500 Message-ID: <20471.1140043635@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.11 required=5 tests=[AWL=0.110, UPPERCASE_25_50=0] X-Spam-Score: 0.11 X-Spam-Level: X-Archive-Number: 200602/192 X-Sequence-Number: 24202 "Daniel Caune" writes: > SELECT > FROM GSLOG_EVENT > WHERE EVENT_NAME = 'player-status-update' > AND EVENT_DATE_CREATED >= > AND EVENT_DATE_CREATED < > I have an index on EVENT_DATE_CREATED that does it job. But I though > that I can help my favourite PostgreSQL if I create a composite index on > EVENT_DATE_CREATED and EVENT_NAME (in that order as EVENT_DATE_CREATED > is more dense that EVENT_NAME). Wrong ... should be EVENT_NAME first. Think about the sort order of the data to see why --- your query represents a contiguous subset of the index if EVENT_NAME is first, but not if EVENT_DATE_CREATED is first. regards, tom lane