Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UfAAn-000505-Em for pgsql-performance@arkaria.postgresql.org; Wed, 22 May 2013 14:37:49 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UfAAm-0006Kc-Ve for pgsql-performance@arkaria.postgresql.org; Wed, 22 May 2013 14:37:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UfAAm-0006KX-8f for pgsql-performance@postgresql.org; Wed, 22 May 2013 14:37:48 +0000 Received: from mail-bk0-x235.google.com ([2a00:1450:4008:c01::235]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UfAAe-0007t2-LM for pgsql-performance@postgresql.org; Wed, 22 May 2013 14:37:47 +0000 Received: by mail-bk0-f53.google.com with SMTP id mx1so1179029bkb.12 for ; Wed, 22 May 2013 07:37:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:content-type:content-transfer-encoding:subject:message-id:date :to:mime-version:x-mailer:x-gm-message-state; bh=7h5s3En+iyE7lDQrgVWe8NUN+CPNgxbmTitYj8IWg3k=; b=U0qYsXbRuNwjkdseeJEeNuJTR9xayQZGtpOhGehKOcllpkBYOCJnizOGH6WiGRUFlm wZOkJ5WUlx/jetQk9QkJAs6YO9N6mojk/2hP0l1x1m7L72sLXEvbL+tKBJCVOJTWAE1q ZGvnmHs5XbTCmjNowNUhhcYpsXeYGMyCTsg2AJHO2j8QTFlBlkq4GClfqjgUmpNKaPsX 7n985EY5EGqOAHsJp7z65McR7glDb/uNYBj4+LZpquSNUDSOaPsBUNmv5oCGciOgNeF0 Xf7sp6P7+aGweV9k8owJO4h4gNIglhI5WbIQlfbEQsGL6zy11Pu2r0oSQj0BHvHkRxCJ JIiQ== X-Received: by 10.204.228.136 with SMTP id je8mr4032449bkb.93.1369233459788; Wed, 22 May 2013 07:37:39 -0700 (PDT) Received: from [192.168.1.61] (0905ds8-ar.0.fullrate.dk. [90.185.25.212]) by mx.google.com with ESMTPSA id tc9sm2098444bkb.18.2013.05.22.07.37.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 22 May 2013 07:37:38 -0700 (PDT) From: =?iso-8859-1?Q?Niels_Kristian_Schj=F8dt?= Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Subject: Advice on optimizing select/index Message-Id: <39DB3954-1DDF-4551-B794-E65AF48F2C96@autouncle.com> Date: Wed, 22 May 2013 16:37:36 +0200 To: pgsql-performance@postgresql.org Mime-Version: 1.0 (Mac OS X Mail 6.3 \(1503\)) X-Mailer: Apple Mail (2.1503) X-Gm-Message-State: ALoCoQlF23k1Dk9Sw1QxUcV41zsy+VxCtqxIQ1ApGhyYMMjcr+OJLuH8Si2j1tvxF8o0MMHbZibG X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Hi, I have a database where one of my tables (Adverts) are requested a LOT.= It's a relatively narrow table with 12 columns, but the size is growing pr= etty rapidly. The table is used i relation to another one called (Car), and= in the form of "cars has many adverts". I have indexed the foreign key car= _id on Adverts. However the performance when doing a "SELECT .* FROM cars LEFT OUTER JOIN a= dverts on cars.id =3D adverts.car_id WHERE cars.brand =3D 'Audi'" is too po= or. I have identified that it's the Adverts table part that performs very b= ad, and it's by far the biggest of the two. I would like to optimize the qu= ery/index, but I don't know if there at all is any theoretical option of ac= tually getting a performance boost on a join, where the foreign key is alre= ady indexed? One idea I'm thinking of my self is that I have a column called state on th= e adverts which can either be 'active' or 'deactivated'. The absolute amoun= t of 'active adverts are relatively constant (currently 15%) where the rema= ining and growing part is 'deactivated'. In reality the adverts that are selected is all 'active'. I'm hence wonderi= ng if it theoretically (and in reality of cause) would make my query faster= if I did something like: "SELECT .* FROM cars LEFT OUTER JOIN adverts on = cars.id =3D adverts.car_id WHERE cars.brand =3D 'Audi' AND adverts.state = =3D 'active'" with a partial index on "INDEX adverts ON (car_id) WHERE stat= e =3D 'active'"? Regards Niels Kristian --=20 Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance