Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 35CE79FB607 for ; Fri, 9 Mar 2007 10:38:34 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 90120-04 for ; Fri, 9 Mar 2007 10:38:28 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by postgresql.org (Postfix) with ESMTP id 458249FB735 for ; Fri, 9 Mar 2007 10:38:29 -0400 (AST) Received: from server3.office.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id 3E8C276686; Fri, 9 Mar 2007 14:38:23 +0000 (GMT) Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id 1FCA427401E; Fri, 9 Mar 2007 14:38:23 +0000 (GMT) Message-ID: <45F1715E.1050000@archonet.com> Date: Fri, 09 Mar 2007 14:38:22 +0000 From: Richard Huxton User-Agent: IceDove 1.5.0.9 (X11/20061220) MIME-Version: 1.0 To: =?UTF-8?B?TWV6ZWkgWm9sdMOhbg==?= Cc: pgsql-performance@postgresql.org Subject: Re: Deceiding which index to use References: <45F15F0F.8080403@telefor.hu> In-Reply-To: <45F15F0F.8080403@telefor.hu> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.203 tagged_above=0 required=5 tests=AWL, BAYES_50, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200703/193 X-Sequence-Number: 23598 Mezei Zoltán wrote: > Hi! > > I have two tables with some indices on them: > > CREATE TABLE subscriber > ( > id serial NOT NULL, > anumber character varying(32) NOT NULL, > CONSTRAINT subscriber_pk PRIMARY KEY (id) > ) > > CREATE INDEX anumber_idx_numeric > ON subscriber > USING btree > (anumber::numeric); > I would like to run a query like this one: > > select l.id > from output_message_log l join subscriber s on l.subscriber_id = s.id > where s.anumber::numeric = 5555555555 > order by l.crd desc > limit 41 > offset 20 Q1. Why are you storing a numeric in a varchar? Q2. How many unique values does anumber have? And how many rows in subscriber? Q3. What happens if you create the index on plain (anumber) and then test against '555555555'? -- Richard Huxton Archonet Ltd