Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id CD7F59FB229 for ; Wed, 18 Oct 2006 09:12:42 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 82245-04 for ; Wed, 18 Oct 2006 09:12:32 -0300 (ADT) 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 6DE789FA219 for ; Wed, 18 Oct 2006 09:12:32 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by serveurmail01.codata.be (Postfix) with ESMTP id DA4E0183876E; Wed, 18 Oct 2006 14:12:30 +0200 (CEST) X-DSPAM-Result: Innocent X-DSPAM-Processed: Wed Oct 18 14:12:30 2006 X-DSPAM-Confidence: 0.5801 X-DSPAM-Probability: 0.0000 X-DSPAM-Signature: 45361a2e26071766910596 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 dkSGast0nhHW; Wed, 18 Oct 2006 14:12:30 +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 D61BE18386A0; Wed, 18 Oct 2006 14:12:29 +0200 (CEST) Message-ID: <45361A2D.6080702@freesurf.fr> Date: Wed, 18 Oct 2006 14:12:29 +0200 From: Arnaud Lesauvage User-Agent: Thunderbird 1.5.0.7 (Windows/20060909) MIME-Version: 1.0 To: Heikki Linnakangas CC: pgsql-performance@postgresql.org Subject: Re: Index on two columns not used References: <45360E25.9010403@freesurf.fr> <45361295.9050504@enterprisedb.com> In-Reply-To: <45361295.9050504@enterprisedb.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit 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.235 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200610/349 X-Sequence-Number: 21478 Heikki Linnakangas a écrit : > Arnaud Lesauvage wrote: >> 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 ? > > You'd think that the system could do the merge using just the indexes, > and only fetch the heap tuples for matches. If that were the case, using > the 2-column index would indeed be a good idea. However, PostgreSQL > can't use the values stored in the index to check the join condition, so > all the heap tuples are fetched anyway. There was just recently > discussion about this on this list: > http://archives.postgresql.org/pgsql-performance/2006-09/msg00080.php. > Thanks for your answer Heikki. I did not know that joins were not using index values, and that PostgreSQL had to fecth the heap tuples anyway. Does this mean that this 2-column index is useless ? (I created it for the join, I don't often filter on both columns otherwise) This query was taken from my "adminsitrative areas" model (continents, countries, etc...). Whenever I query this model, I have to join many tables. I don't really know what the overhead of reading the heap-tuples is, but would it be a good idea to add data-redundancy in my tables to avoid joins ? (adding country_id, continent_id, etc... in the "cities" table) Regards -- Arnaud