X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B5BED56710 for ; Thu, 17 Mar 2005 08:39:56 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 42232-01 for ; Thu, 17 Mar 2005 08:39:47 +0000 (GMT) Received: from ns.aprote.ee (ns.aprote.ee [80.235.78.106]) by svr1.postgresql.org (Postfix) with ESMTP id BF9B0566CF for ; Thu, 17 Mar 2005 08:39:45 +0000 (GMT) Received: Message by Barricade ns.aprote.ee with ESMTP id j2H8eaOx020316 for ; Thu, 17 Mar 2005 10:40:36 +0200 content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-MimeOLE: Produced By Microsoft Exchange V6.0.6556.0 Subject: Re: How to force subquery scan? Date: Thu, 17 Mar 2005 10:39:43 +0200 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [SQL] How to force subquery scan? Thread-Index: AcUqPtC2bGAQ6UbBRW2sFj2I8HdmxwAjTJOw From: "Tambet Matiisen" To: "Tom Lane" Cc: , X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.004 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200503/234 X-Sequence-Number: 20713 > -----Original Message----- > From: Tom Lane [mailto:tgl@sss.pgh.pa.us]=20 > Sent: Wednesday, March 16, 2005 5:42 PM > To: Tambet Matiisen > Cc: ch@rodos.fzk.de; pgsql-sql@postgresql.org > Subject: Re: [SQL] How to force subquery scan?=20 >=20 >=20 > "Tambet Matiisen" writes: > > It seems that subquery scan is only used, when the query can not be=20 > > translated into single flat query. Which is mostly good, I assume. >=20 > The planner thinks so anyway ;-) >=20 > If you're desperate you can put in an optimization fence, for=20 > instance LIMIT or OFFSET. >=20 > SELECT * FROM (SELECT ... OFFSET 0) ss; >=20 > In principle the planner could figure out that this offset is=20 > a no-op, throw it away, and then flatten the query. But it=20 > doesn't at the moment, and I doubt we'll teach it to do so in=20 > the future. >=20 > regards, tom lane >=20 Thanks, that did the trick. It was a bit more strict than expected, because WHERE of the outer query is not optimized into subquery. But considering the semantics of OFFSET that seems reasonable and I can work around it for now. Tambet