Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 961F663292B for ; Sat, 24 Apr 2010 12:20:26 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 40849-04 for ; Sat, 24 Apr 2010 15:20:16 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-vw0-f46.google.com (mail-vw0-f46.google.com [209.85.212.46]) by mail.postgresql.org (Postfix) with ESMTP id 2946963269C for ; Sat, 24 Apr 2010 12:20:13 -0300 (ADT) Received: by vws17 with SMTP id 17so604503vws.19 for ; Sat, 24 Apr 2010 08:20:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=0zE8woVF/g5vPP0dyprlEVYM0MbQK4tM3Kw0rcFLr28=; b=d/ZZOLBGUe8o/rUGD9d8OuBJq1ejzwqJ53hn85hvV0vpBjv5aLfxc1NAsC1FP3Er32 5ghvopaU65PaHzmbUx5SydsNMdHk71LZp+sme3hBlbau1tDYJTBEiIRmPgK+rEdUFkPL pRvy4zCwPxf7K6yLjZOifEa5ek2rCPzpkJgZM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=YbEPOJ4xW2f/sJTtYZtV/T8FABR/wP0Wn5GrKXwS1q0qIulUGMkp5KS1S27vVdj8a8 X1lL7QWohPjQrp9bRTDEdAMzgu7a/K/VK3ZKr+cBeaL8ldSSOCBvC8LKFcjCfOzdXH0Z rlWAa+0swbogJ5g6LkfrrEMyY0FUTvAFuouvM= MIME-Version: 1.0 Received: by 10.220.47.219 with SMTP id o27mr945757vcf.189.1272122412525; Sat, 24 Apr 2010 08:20:12 -0700 (PDT) Received: by 10.220.99.10 with HTTP; Sat, 24 Apr 2010 08:20:12 -0700 (PDT) In-Reply-To: References: Date: Sat, 24 Apr 2010 11:20:12 -0400 Message-ID: Subject: Re: Replacing Cursors with Temporary Tables From: Merlin Moncure To: =?ISO-8859-2?Q?Grzegorz_Ja=B6kiewicz?= Cc: Eliot Gable , pgsql-performance@postgresql.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.801 tagged_above=-10 required=5 tests=BAYES_50=0.8, FREEMAIL_FROM=0.001 X-Spam-Level: X-Archive-Number: 201004/313 X-Sequence-Number: 38563 2010/4/24 Grzegorz Ja=C5=9Bkiewicz : > > > On Sat, Apr 24, 2010 at 2:23 PM, Merlin Moncure wrot= e: >> >> Well, you missed the most important part: not using cursors at all. >> Instead of declaring a cursor and looping it to build the array, build >> it with array(). =C2=A0That's what I've been saying: arrays can complete= ly >> displace both temp tables _and_ cursors when passing small sets around >> functions. >> > with huge emphasis on the word small. The rule of thumb I use is 10000 narrow records (scalars, or very small composites) or 1000 wide/complex records. I routinely pass extremely complex (3-4 levels nesting) nested composite arrays to the client for processing -- it is extremely efficient and clean. This of course is going to depend on hardware and other factors. merlin