Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 63B219FA43D for ; Tue, 24 Jul 2007 05:48:52 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 88063-07 for ; Tue, 24 Jul 2007 05:48:44 -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.182]) by postgresql.org (Postfix) with ESMTP id 0CB149FA3A8 for ; Tue, 24 Jul 2007 05:48:48 -0300 (ADT) Received: by wa-out-1112.google.com with SMTP id k40so2680620wah for ; Tue, 24 Jul 2007 01:48:47 -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=rKXz47F9lxRRSuwGQdMO3d4JnPfeZ0sNjL0t43K+2EmfHc+7nhOaE3O6h9kvCvCG0FN7nAgbR2VcvBPB7kxXXXq78ktvR3qaJlN47rRcQ1ln1mwk2jCJzqeZJmTDLJvDzr+NVZANAPTnQRLdJ5kProqvxrU1GK7dVSCRPPMX6G0= 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=QjIjH42QFnxhCqijheI/bbLUKv+exTkEjumahYtO69NSmtnrVKBI6cr4I1jm6+aLrJxP3UWlCnjKqBgwgysHAaBq46t/5qlAIkThAX6adoRaGYacZpjWH+ht6IQrcJ7cjOJShFSXjV16aoW7dJLt3IZzyuO+fOk0qJSxV3++d/Q= Received: by 10.114.153.18 with SMTP id a18mr3834845wae.1185266926961; Tue, 24 Jul 2007 01:48:46 -0700 (PDT) Received: from ?10.1.1.14? ( [203.217.18.65]) by mx.google.com with ESMTPS id m28sm16760593poh.2007.07.24.01.48.45 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 24 Jul 2007 01:48:46 -0700 (PDT) Message-ID: <46A5BD6F.7000108@gmail.com> Date: Tue, 24 Jul 2007 18:50:55 +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> In-Reply-To: <46A5BBD4.8040509@gmail.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/312 X-Sequence-Number: 25996 Chris wrote: > 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); > It could also be that since you don't have very much data (10,000) rows - postgres is ignoring the indexes because it'll be quicker to scan the tables. If you bump it up to say 100k rows, what happens? -- Postgresql & php tutorials http://www.designmagick.com/