Re: [GENERAL] Catching errors inside a LOOP is causing performance issues - Mailing list pgsql-general

From David G. Johnston
Subject Re: [GENERAL] Catching errors inside a LOOP is causing performance issues
Date
Msg-id CAKFQuwZ_88me2heiJ6=5S1oyNDK0OcVvJO=xM1y20Oy9WKhJtA@mail.gmail.com
Whole thread Raw
In response to [GENERAL] Catching errors inside a LOOP is causing performance issues  (Denisa Cirstescu <Denisa.Cirstescu@tangoe.com>)
Responses Re: [GENERAL] Catching errors inside a LOOP is causing performance issues  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
On Mon, Sep 25, 2017 at 9:13 AM, Denisa Cirstescu <Denisa.Cirstescu@tangoe.com> wrote:


Can someone please explain to me why this worked?

What happened behind the scenes?

I suspect that when you catch exceptions inside of a LOOP and the code ends up generating an exception, Postgres can’t use cached plans to optimize that code so it ends up planning the code at each iteration and this causes performance issues.

Is my assumption correct?



​Not sure how much detail you are looking for but the docs say this:

"​Tip: A block containing an EXCEPTION clause is significantly more expensive to enter and exit than a block without one. Therefore, don't use EXCEPTION without need."


I'm somewhat doubting "plan caching" has anything to do with this; I suspect its basically that there is high memory and runtime overhead to deal with the possibilities of needing to convert a exception into a branch instead of allowing it to be fatal.

David J.

pgsql-general by date:

Previous
From: George Neuner
Date:
Subject: Re: [GENERAL] Speed of conversion from int to bigint
Next
From: Igor Polishchuk
Date:
Subject: [GENERAL] Rsync to a recovering streaming replica?