Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 838889FB1CB for ; Wed, 18 Oct 2006 08:21:22 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 50193-07 for ; Wed, 18 Oct 2006 11:21:16 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from serveurmail01.codata.be (125.123.146.82.ipv4.evonet.be [82.146.123.125]) by postgresql.org (Postfix) with ESMTP id 0FDB89FA240 for ; Wed, 18 Oct 2006 08:21:15 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by serveurmail01.codata.be (Postfix) with ESMTP id 6E786183877A for ; Wed, 18 Oct 2006 13:21:10 +0200 (CEST) X-DSPAM-Result: Innocent X-DSPAM-Processed: Wed Oct 18 13:21:09 2006 X-DSPAM-Confidence: 0.5823 X-DSPAM-Probability: 0.0000 X-DSPAM-Signature: 45360e25146511222944467 X-DSPAM-Factors: 27, X-Virus-Scanned: amavisd-new at Received: from serveurmail01.codata.be ([127.0.0.1]) by localhost (serveurmail01.codata.be [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PKhS8Q79NbZU for ; Wed, 18 Oct 2006 13:21:09 +0200 (CEST) Received: from [127.0.0.1] (147.186-112-217.adsl.belcenter.be [217.112.186.147]) by serveurmail01.codata.be (Postfix) with ESMTP id 8D1F2183876E for ; Wed, 18 Oct 2006 13:21:09 +0200 (CEST) Message-ID: <45360E25.9010403@freesurf.fr> Date: Wed, 18 Oct 2006 13:21:09 +0200 From: Arnaud Lesauvage User-Agent: Thunderbird 1.5.0.7 (Windows/20060909) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Index on two columns not used Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 0642-1, 18/10/2006), Outbound message X-Antivirus-Status: Clean X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.335 tagged_above=0 required=5 tests=DNS_FROM_RFC_ABUSE, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200610/345 X-Sequence-Number: 21474 Hi list ! I have two table with a 2-column index on both of them. In the first table, the first colum of the index is the primary key, the second one is an integer field. In the second table, the two columns are the primary key. When I join these two tables, the 2-column index of the first table is not used. Why does the query planner think that this plan is better ? ALTER TABLE geo.subcities_names ADD CONSTRAINT subcities_names_pkey PRIMARY KEY(subcity_gid, language_id); CREATE INDEX subcities_gid_language_id ON geo.subcities USING btree (gid, official_language_id); EXPLAIN ANALYZE SELECT * FROM geo.subcities sc, geo.subcities_names scn WHERE sc.gid = scn.subcity_gid AND sc.official_language_id = scn.language_id; Result : Merge Join (cost=0.00..4867.91 rows=37917 width=240) (actual time=0.037..149.022 rows=39323 loops=1) Merge Cond: ("outer".gid = "inner".subcity_gid) Join Filter: ("outer".official_language_id = "inner".language_id) -> Index Scan using subcities_pkey on subcities sc (cost=0.00..1893.19 rows=39357 width=200) (actual time=0.015..43.430 rows=39357 loops=1) -> Index Scan using subcities_names_pkey on subcities_names scn (cost=0.00..2269.39 rows=40517 width=40) (actual time=0.012..35.465 rows=40517 loops=1) Total runtime: 157.389 ms (6 rows) Thanks for your suggestions ! Regards -- Arnaud