Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 88617633718 for ; Thu, 22 Apr 2010 13:51:40 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 27012-01-4 for ; Thu, 22 Apr 2010 16:51:28 +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 9C95063712A for ; Thu, 22 Apr 2010 11:42:43 -0300 (ADT) Received: by vws20 with SMTP id 20so289315vws.19 for ; Thu, 22 Apr 2010 07:42:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:received:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=qKT4UgwQA8CheCzd+BGmGxrRRBB8HAl9SapUFVhIfGU=; b=eUXNaWqEL/54QJHjiLX4awqTPlT4621GKEmLc2LmdovYuRQWDzf+uwcuqmbhcv9ovz 2iYSiCk5GrypcW5fkZJI9i0JEauLL12vDAAzroSAn4Qzm9RELUWr1vNKLjH3YSW1l453 wP3y36XhGEWrYUtiR9X8IoW6FBiKmCsL15tdM= 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=e7x5qixGICeslBtdjp8TU8JfAzZCbMpkWQa3QXIfvGIhnhVpt1FfZRO0/CKvMJ9Y+O c3hseQexQw8jX678drLZN00I1cupW9cbbhKirpqnupN5+Wa1LfFWlz9S1dBaj90Mtm0B p9uGd7LHOZnysMPxGvA+7+AU9TmfhY7d3+mt8= MIME-Version: 1.0 Received: by 10.220.99.10 with HTTP; Thu, 22 Apr 2010 07:42:42 -0700 (PDT) In-Reply-To: References: Date: Thu, 22 Apr 2010 10:42:42 -0400 Received: by 10.220.125.25 with SMTP id w25mr6870367vcr.92.1271947362157; Thu, 22 Apr 2010 07:42:42 -0700 (PDT) Message-ID: Subject: Re: Replacing Cursors with Temporary Tables From: Merlin Moncure To: Eliot Gable Cc: pgsql-performance@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.157 tagged_above=-10 required=5 tests=AWL=-1.156, BAYES_40=-0.001 X-Spam-Level: X-Archive-Number: 201004/289 X-Sequence-Number: 38539 On Thu, Apr 22, 2010 at 10:11 AM, Merlin Moncure wrote= : > The timings are similar, but the array returning case: > *) =A0runs in a single statement. =A0If this is executed from the client > that means less round trips > *) can be passed around as a variable between functions. =A0temp table > requires re-query > *) make some things easier/cheap such as counting the array -- you get > to call the basically free array_upper() > *) makes some things harder. =A0specifically dealing with arrays on the > client is a pain UNLESS you expand the array w/unnest() or use > libpqtypes > *) can nest. you can trivially nest complicated sets w/arrays > *) does not require explicit transaction mgmt I neglected to mention perhaps the most important point about the array met= hod: *) does not rely on any temporary resources. If you write a lot of plpsql, you will start to appreciate the difference in execution time between planned and unplanned functions. The first time you run a function in a database session, it has to be parsed and planned. The planning time in particular for large-ish functions that touch a lot of objects can exceed the execution time of the function. Depending on _any_ temporary resources causes plan mgmt issues because the database detects that a table in the old plan is gone ('on commit drop') and has to re-plan. If your functions are complex/long and you are counting milliseconds, then that alone should be enough to dump any approach that depends on temp tables. merlin