Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id E301D9FA2D3 for ; Tue, 24 Jul 2007 05:42:01 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 74685-06-2 for ; Tue, 24 Jul 2007 05:41:55 -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.183]) by postgresql.org (Postfix) with ESMTP id 599C89FA2AB for ; Tue, 24 Jul 2007 05:41:58 -0300 (ADT) Received: by wa-out-1112.google.com with SMTP id k40so2678917wah for ; Tue, 24 Jul 2007 01:41:57 -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=OOIL3vAPpk1eRV0cpuRuYzF5HOMjrep7UAmGpp6efKKJ581urFpo9+LsYQhmWQxHhRjMIxQFHaZIJsgcG2X5tRs0cy87KaAuzQvLPPlvjgdG/GqAsVncu8I5DizXeC+bXBHREXeJt/qD/SuQL3V4DgwQsy4crqatPo+wEdOt9ug= 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=JXNkUKrj6mQ/+fQJM3IFAHLA7zbzNHIPM9urEuytMefbjtpuFEOu98GNL2gxYRL/RtitTlj1u1MGPKXty1YYe9+VC7h3OqYhBJky7JFmd/iUc/jI3aaOF3TxI6dRenpNFnLoOBpu+Sl9sLqVtmHdlIUKJuY8amnDQUrqS6OTjJQ= Received: by 10.115.32.1 with SMTP id k1mr3840016waj.1185266517030; Tue, 24 Jul 2007 01:41:57 -0700 (PDT) Received: from ?10.1.1.14? ( [203.217.18.65]) by mx.google.com with ESMTPS id m28sm16749988poh.2007.07.24.01.41.55 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 24 Jul 2007 01:41:56 -0700 (PDT) Message-ID: <46A5BBD4.8040509@gmail.com> Date: Tue, 24 Jul 2007 18:44:04 +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> In-Reply-To: <0f1701c7cdc6$f9cc1a30$ed644e90$@com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/311 X-Sequence-Number: 25995 Jonathan Gray wrote: > We’re experiencing a query performance problem related to the planner > and its ability to perform a specific type of merge. > > > > We have created a test case (as attached, or here: > http://www3.streamy.com/postgres/indextest.sql) which involves a > hypothetical customer ordering system, with customers, orders, and > customer groups. > > > > If we want to retrieve a single customers 10 most recent orders, sorted > by date, we can use a double index on (customer,date); Postgres’s query > planner will use the double index with a backwards index scan on the > second indexed column (date). > > > > However, if we want to retrieve a “customer class’s” 10 most recent > orders, sorted by date, we are not able to get Postgres to use double > indexes. You don't have any indexes on the 'customerclass' table. Creating a foreign key doesn't create an index, you need to do that separately. Try create index cc_customerid_class on indextest.customerclass(classid, customerid); -- Postgresql & php tutorials http://www.designmagick.com/