Re: LIMIT OFFSET with DB view vs plain SQL

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Raj Gandhi <raj01gandhi(at)gmail(dot)com>, pgsql-admin(at)postgresql(dot)org
Subject: Re: LIMIT OFFSET with DB view vs plain SQL
Date: 2019-03-29 13:53:10
Message-ID: 1bbde4f2929ef4f5cf145ccffaca3d3f6e27a7bd.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-performance

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

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Merlin Moncure 2019-03-29 15:28:20 Re: LIMIT OFFSET with DB view vs plain SQL
Previous Message Raj Gandhi 2019-03-28 22:43:45 Re: LIMIT OFFSET with DB view vs plain SQL

Browse pgsql-performance by date

  From Date Subject
Next Message Stephan Schmidt 2019-03-29 14:29:02 endless quere when upsert with ON CONFLICT clause
Previous Message Raj Gandhi 2019-03-28 22:43:45 Re: LIMIT OFFSET with DB view vs plain SQL