Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 808F963350E for ; Tue, 6 Jul 2010 17:00:47 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 72694-06-5 for ; Tue, 6 Jul 2010 20:00:36 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from joeconway.com (wsip-72-214-29-243.sd.sd.cox.net [72.214.29.243]) by mail.postgresql.org (Postfix) with ESMTP id A516F63444F for ; Tue, 6 Jul 2010 17:00:35 -0300 (ADT) Received: from [192.168.4.40] (account jconway HELO dev.joeconway.com) by joeconway.com (CommuniGate Pro SMTP 4.1.8) with ESMTP-TLS id 9879855; Tue, 06 Jul 2010 13:00:33 -0700 Message-ID: <4C338B61.60409@joeconway.com> Date: Tue, 06 Jul 2010 13:00:33 -0700 From: Joe Conway User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.0.12) Gecko/20071019 Fedora/1.5.0.12-3.fc6 pango-text Thunderbird/1.5.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 To: Eliot Gable CC: Robert Haas , Merlin Moncure , Craig Ringer , Craig James , pgsql-performance@postgresql.org Subject: Re: Highly Efficient Custom Sorting References: <4C2D574E.5030308@postnewspapers.com.au> <4767.1278043730@sss.pgh.pa.us> <4C2E1587.70001@emolecules.com> <4C2E9606.8050903@postnewspapers.com.au> In-Reply-To: X-Enigmail-Version: 1.0.1 OpenPGP: id=B699434A Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enig4A0C8574963E33DA4CF6853D" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.782 tagged_above=-10 required=5 tests=BAYES_50=0.8, RDNS_DYNAMIC=0.982 X-Spam-Level: * X-Archive-Number: 201007/66 X-Sequence-Number: 39455 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig4A0C8574963E33DA4CF6853D Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 07/06/2010 12:42 PM, Eliot Gable wrote: > Thanks for suggesting array_unnest(). I think that will actually prove > more useful to me than the other example I'm using for extracting my > data from an array. I was actually planning on computing the order on > the first call and storing it in a linked list which gets returned one > item at a time until all rows have been returned. Also, I found a code > example using Google that showed someone storing data across function > calls using that pointer. I used their example to produce this: >=20 > > if(SRF_IS_FIRSTCALL()) { > funcctx =3D SRF_FIRSTCALL_INIT(); >=20 > /* This is where we stick or sorted data for returning later */= > funcctx->user_fctx =3D > MemoryContextAlloc(funcctx->multi_call_memory_ctx, sizeof(sort_data)); > oldcontext =3D MemoryContextSwitchTo(funcctx->multi_call_memory= _ctx); > data =3D (sort_data*) funcctx->user_fctx; > >=20 > I have a structure set up that is typedef'd to "sort_data" which stores= > pointers to various things that I need to survive across the calls. > Since this seems to be what you are suggesting, I assume this is the > correct approach. This approach works, but you could also use the SFRM_Materialize mode and calculate the entire result set in one go. That tends to be simpler. See, for example crosstab_hash() in contrib/tablefunc for an example. FWIW, there are also some good examples of array handling in PL/R, e.g. pg_array_get_r() in pg_conversion.c HTH, Joe --=20 Joe Conway credativ LLC: http://www.credativ.us Linux, PostgreSQL, and general Open Source Training, Service, Consulting, & Support --------------enig4A0C8574963E33DA4CF6853D Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (GNU/Linux) Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/ iQIcBAEBCAAGBQJMM4thAAoJEDfy90M199hlMMwQAKY6P/cNzNAluo2qx5iPjM+D Ito1DA0JFA5xIwjLq9/x/AP8YkW71zyvaLfKU8hN1arlLY0nFHAnfk/ag0e19IPt Vyz9w2R76LGm3bTrmlW4Fd/8/NZXgxdZc85KABYi4UgWDsEgTsfFWYfi3w8RRFG/ Ojhxr/lI23wbnH/ANWfHh17BLpqMJj4N2X25ALddC/Dqqi8vHP/kmxWwe5d4Tp6/ iDr06w6wYcxRr/+y5njdOKaYbFbeWW5emab7zuDQ/v18+CYpCtyhGPYU73WuEBTE GHiDcodFqAUch5bpC3o4Cjjr+0SlUtMmIlsEcSyuGwzLN4uFoMIlhE1qkRX+Lhsb IdEfSo/eyo6dXpIo9yg6xjKcNXkkPmCm6wMIzp8KS3b1ycoEPLa/k86xhWPKZ+EC smWQUtcOn1tPdNZYw9//13G4MSikWYIldzbOjBDY/Gn2EGYXZIF5XSuGFX7fntRJ X40t7hxRNoRhhpR+aphgC0JTMGqg7OIaLMJFsphENegHjAJWMKB9e4W4WYMHH0ft lpWUVuS4+rolCdpImZC5cSD9Lzgmt+dzRRSP2otCrBneY9yRbF7EzHdWumyG9Xjc pSEqFLhqtIqvYRAeJ6+vIr7rIfszfdo9o1NmTR0TUMcO4P3Eg7Ha3DmXgTZNodfr pwvRHrPcyfYjNDoyPeZX =gd5Y -----END PGP SIGNATURE----- --------------enig4A0C8574963E33DA4CF6853D--