Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h9rwp-0005DA-Ru for pgsql-admin@arkaria.postgresql.org; Fri, 29 Mar 2019 13:53:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h9rwn-00047Y-5U for pgsql-admin@arkaria.postgresql.org; Fri, 29 Mar 2019 13:53:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h9rwm-00047L-SC for pgsql-admin@lists.postgresql.org; Fri, 29 Mar 2019 13:53:28 +0000 Received: from mx1.mailbox.org ([2001:67c:2050:104:0:1:25:1]) by magus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h9rwj-0008Fz-Gc for pgsql-admin@postgresql.org; Fri, 29 Mar 2019 13:53:28 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx1.mailbox.org (Postfix) with ESMTPS id AAEFA4C0E8; Fri, 29 Mar 2019 14:53:22 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter02.heinlein-hosting.de (spamfilter02.heinlein-hosting.de [80.241.56.116]) (amavisd-new, port 10030) with ESMTP id IDIDKtk_jDOg; Fri, 29 Mar 2019 14:53:11 +0100 (CET) Message-ID: <1bbde4f2929ef4f5cf145ccffaca3d3f6e27a7bd.camel@cybertec.at> Subject: Re: LIMIT OFFSET with DB view vs plain SQL From: Laurenz Albe To: Raj Gandhi , pgsql-admin@postgresql.org Date: Fri, 29 Mar 2019 14:53:10 +0100 In-Reply-To: References: Organization: Cybertec Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Raj Gandhi wrote: > I’m using LIMIT offset with DB view. Looks like query planner is applying the LIMIT for DB view at the end after processing all rows. > When running same SQL that was used to create the DB view, LIMIT is applied earlier so the query is much faster. > > Explain plan using DB view > https://explain.depesz.com/s/gzjQ > > Explain plan using raw SQL > https://explain.depesz.com/s/KgwO > > In both tests LIMIT was 100 with offset = 0. > Is there any way to force DB view to apply limit earlier? Please show - the view definition - the query on the view - the query without the view Yours, Laurenz Albe -- +43-670-6056265 Cybertec Schönig & Schönig GmbH Gröhrmühlgasse 26, A-2700 Wiener Neustadt Web: https://www.cybertec-postgresql.com