Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id D7E649FA43D for ; Tue, 24 Jul 2007 06:34:22 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 73466-09 for ; Tue, 24 Jul 2007 06:34:19 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.179]) by postgresql.org (Postfix) with ESMTP id CBCC69FA425 for ; Tue, 24 Jul 2007 06:34:19 -0300 (ADT) Received: by wa-out-1112.google.com with SMTP id k40so2692194wah for ; Tue, 24 Jul 2007 02:34:18 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; b=e4wFsh3Dcy4CUWiWnhfCSB5IZzvUE3izzPwiRqWi9KuwsTI9BmFS74eteRw0QCu6NqcA+d/Djqt62Q3URJxkYm+4qBTK9gpcPznPzfmA4uELm+g2ZjLDTLecdjvUgeOn8swgiE4YB14Bt34JtQmuOKUkz1q5xPiv90Bm6flhbCs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; b=apyqIZnZk3ozXZVFy7NR1dm2asp5HEn3+FcrS2FSzhhZpMz8iqdJrHwtaSgVIIZa+gommSiQ+FGyFRLGOUtluIn4r788aYXQMMZ6zpwhPVULY8DmAgtJxg+sE0d78fA4GpJ9GVvz0nxuLX9rfVeLpOpzcoK4qJvaVep1lMoTdG0= Received: by 10.114.13.1 with SMTP id 1mr3861473wam.1185269658127; Tue, 24 Jul 2007 02:34:18 -0700 (PDT) Received: from ?10.1.1.14? ( [203.217.18.65]) by mx.google.com with ESMTPS id n22sm16821079pof.2007.07.24.02.34.16 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 24 Jul 2007 02:34:17 -0700 (PDT) Message-ID: <46A5C819.80707@gmail.com> Date: Tue, 24 Jul 2007 19:36:25 +1000 From: Chris User-Agent: Thunderbird 2.0.0.5 (Windows/20070716) MIME-Version: 1.0 To: Jonathan Gray CC: pgsql-performance@postgresql.org Subject: Re: Query performance issue References: <0f1701c7cdc6$f9cc1a30$ed644e90$@com> <46A5BBD4.8040509@gmail.com> <46A5BD6F.7000108@gmail.com> <0f3001c7cdd3$a7db7740$f79265c0$@com> In-Reply-To: <0f3001c7cdd3$a7db7740$f79265c0$@com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/314 X-Sequence-Number: 25998 Jonathan Gray wrote: > Chris, > > Creating indexes on the customerclass table does speed up the queries but > still does not create the plan we are looking for (using the double index > with a backward index scan on the orders table). Stupid question - why is that particular plan your "goal" plan? > The plans we now get, with times on par or slightly better than with the > plpgsql hack, are: > > EXPLAIN ANALYZE > SELECT o.orderid,o.orderstamp FROM indextest.orders o > INNER JOIN indextest.customerclass cc ON (cc.classid = 2) > WHERE o.customerid = cc.customerid ORDER BY o.orderstamp DESC LIMIT 5; Didn't notice this before... Shouldn't this be: INNER JOIN indextest.customerclass cc ON (o.customerid = cc.customerid) WHERE cc.classid = 2 ie join on the common field not the classid one which doesn't appear in the 2nd table? > As I said, this is a hypothetical test case we have arrived at that > describes our situation as best as we can given a simple case. We're > interested in potential issues with the approach, why postgres would not > attempt something like it, and how we might go about implementing it > ourselves at a lower level than we currently have (in SPI, libpq, etc). > > If it could be generalized then we could use it in cases where we aren't > pulling from just one table (the orders table) but rather trying to merge, > in sorted order, results from different conditions on different tables. > Right now we use something like the plpgsql or plpythonu functions in the > example and they outperform our regular SQL queries by a fairly significant > margin. I'm sure if you posted the queries you are running with relevant info you'd get some help ;) -- Postgresql & php tutorials http://www.designmagick.com/