LIMIT OFFSET with DB view vs plain SQL - Mailing list pgsql-admin

From Raj Gandhi
Subject LIMIT OFFSET with DB view vs plain SQL
Date
Msg-id CALU_HCMxM5m-Sxsn3fwhqwu23b3O2q+Rviv-fxdJM1EXG=A3fg@mail.gmail.com
Whole thread Raw
Responses Re: LIMIT OFFSET with DB view vs plain SQL  (Raj Gandhi <raj01gandhi@gmail.com>)
Re: LIMIT OFFSET with DB view vs plain SQL  (Raj Gandhi <raj01gandhi@gmail.com>)
Re: LIMIT OFFSET with DB view vs plain SQL  (Laurenz Albe <laurenz.albe@cybertec.at>)
List pgsql-admin

Hi everyone,

 

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?

 

Thanks,

Raj

pgsql-admin by date:

Previous
From: MichaelDBA
Date:
Subject: Re: Long running query in new production, not so long in old
Next
From: Raj Gandhi
Date:
Subject: Re: LIMIT OFFSET with DB view vs plain SQL