Re: PG Query Planner

From: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
To: Kenny Bachman <kenny(dot)bachman17(at)gmail(dot)com>
Cc: Gaurav Anand <gaurav(dot)anand(at)saama(dot)com>, Pgsql-admin <pgsql-admin(at)lists(dot)postgresql(dot)org>
Subject: Re: PG Query Planner
Date: 2022-04-20 04:03:20
Message-ID: CAMkU=1wyoF64YXrkV83D5zyjq+T_cE+=h-vq2GLXGfn7wN4w6g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Tue, Apr 19, 2022 at 1:57 PM Kenny Bachman <kenny(dot)bachman17(at)gmail(dot)com>
wrote:

> Hello,
>
> My query is :
>
> SELECT subs.id AS id1_109,
> scriber_id AS subs_109
> FROM subscription subs
> LEFT OUTER JOIN offer offer1
> ON subs.offer_id = offer1.id
> WHERE offer1.is_external_lifecycle_management = FALSE
> AND subs.job_next_process_time < '2022-04-19 09:25:25.535'
> AND subs.job_in_progress = FALSE
> ORDER BY subs.id ASC LIMIT 1 ;
>

An easy (if you can control the queries) way to force the faster plan is to
prohibit it from using using the index to fulfill the ORDER BY, by changing
it to "ORDER BY subs.id+0 ASC LIMIT 1"

As for getting the planner to get a better plan on its own, I don't think
there is much hope. The difference between 0 rows with
is_external_lifecycle_management=FALSE, and 1 row meeting that, is the
smallest possible difference. Yet still the ratio between them is
infinite. Changing a histogram bin count or adding a multivariate
statistic is not going to change that.

Maybe the executor should be smart enough to cut off the nested loop once
it sees the Materialize will never return a row. But that is not a change
you can make in user-land.

Cheers,

Jeff

>

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Ram Pratap Maurya 2022-04-20 04:31:57 RE: Huge archive log generate in Postgresql-13
Previous Message David G. Johnston 2022-04-19 22:23:11 Re: PG Query Planner