Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 027CC9F949C for ; Sun, 4 Nov 2007 12:59:47 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 74551-08 for ; Sun, 4 Nov 2007 12:59:44 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by postgresql.org (Postfix) with SMTP id 09D919F9430 for ; Sun, 4 Nov 2007 12:59:43 -0400 (AST) Received: (qmail invoked by alias); 04 Nov 2007 16:59:42 -0000 Received: from port-87-234-85-108.dynamic.qsc.de (EHLO [192.168.89.164]) [87.234.85.108] by mail.gmx.net (mp004) with SMTP; 04 Nov 2007 17:59:42 +0100 X-Authenticated: #18841147 X-Provags-ID: V01U2FsdGVkX18AjqhF9coADt74ctHj4aUpHl9FVRwvqK1Oo9qaSX Hj70Q1H0vQB9aL Message-ID: <472DFA7F.5040709@gmx.de> Date: Sun, 04 Nov 2007 17:59:43 +0100 From: Jens-Wolfhard Schicke User-Agent: Mozilla-Thunderbird 2.0.0.6 (X11/20071008) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: Unfortunate expansion of composite types in union References: <472AF02D.10809@gmx.de> <162867790711020332h7eddf94pbdd44f98e7ce59d7@mail.gmail.com> In-Reply-To: <162867790711020332h7eddf94pbdd44f98e7ce59d7@mail.gmail.com> X-Enigmail-Version: 0.95.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200711/47 X-Sequence-Number: 27462 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Pavel Stehule wrote: > PostgreSQL doesn't support Common Table Expressions - you can write > SRF function: > > CREATE OR REPLACE FUNCTION c(integer) > RETURNS SETOF something AS $$ > DECLARE r RECORD; > o something; > BEGIN > FOR r IN SELECT * FROM link WHERE link.s = $1 LOOP > o := (1, r.id, NULL, NULL, NULL); > RETURN NEXT o; > o := (2, r.id, r.s, r.e, r.intensity, NULL); > RETURN NEXT o; > o := (3, r.id, r.o, r.format, NULL, r.data); > RETURN NEXT o; > RETURN; > END LOOP; > END; > $$ LANGUAGE plpgsql; > > SELECT * FROM c(8692); This is a completely different query from my one. (That is, the results are different.) My problem is that I have a schema like fastgraph=# \d object Table "public.object" Column | Type | Modifiers - --------+--------+---------------------------------------------- id | bigint | not null default nextval('id_seq'::regclass) Indexes: "object_id_idx" UNIQUE, btree (id) fastgraph=# \d link Table "public.link" Column | Type | Modifiers - -----------+------------------+---------------------------------------------- id | bigint | not null default nextval('id_seq'::regclass) s | bigint | not null e | bigint | not null intensity | double precision | not null Indexes: "link_id_idx" UNIQUE, btree (id) "link_e_idx" btree (e) "link_s_idx" btree (s) "link_se_idx" btree (s, e) Inherits: object fastgraph=# \d representation Table "public.representation" Column | Type | Modifiers - --------+--------+---------------------------------------------- id | bigint | not null default nextval('id_seq'::regclass) o | bigint | not null format | bigint | not null data | bytea | not null Indexes: "representation_id_idx" UNIQUE, btree (id) "representation_o_idx" btree (o) "representation_text" hash (data) WHERE format = 1 Inherits: object now I want those "objects" (with inheritance) which are connected to some other. So I tried the query in the original post, and found the execution plan to be suboptimal. Today I tried to do it with OUTER JOINs but failed utterly. So what is the best way to get the results? The original query is exactly what I need, only the plan is bad. Any Ideas? Regards, Jens-Wolfhard Schicke -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFHLfp+zhchXT4RR5ARAorgAKDr2grqWnxbvFMYOPiLJuHpjco30ACgswQB 9/qW9rz+ZngkBYdR0RLsils= =LdBJ -----END PGP SIGNATURE-----