Re: Inadequate executor locking of indexes

From: Julien Rouhaud <rjuju123(at)gmail(dot)com>
To: David Rowley <david(dot)rowley(at)2ndquadrant(dot)com>
Cc: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>
Subject: Re: Inadequate executor locking of indexes
Date: 2019-02-10 12:23:44
Message-ID: CAOBaU_YWbrQgta8qT5fSM0BoJWJL3keSDwExjaiki3LLOY=9KQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Tue, Feb 5, 2019 at 5:16 AM David Rowley
<david(dot)rowley(at)2ndquadrant(dot)com> wrote:
>
> I've changed a couple of things:
>
> 1. Changed nodeBitmapIndexscan.c now properly uses the RangeTblEntry's
> idxlockmode field.
> 2. Renamed a few variables in finalize_lockmodes().
>
> I'm keen to get some feedback if we should go about fixing things this
> way. One thing that's still on my mind is that the parser is still at
> risk of lock upgrade hazards. This patch only fixes the executor. I
> don't quite see how it would be possible to fix the same in the
> parser.

+ /*
+ * If there are multiple instances of the same rel with varying lock
+ * strengths then set the strongest lock level to each instance of
+ * that relation.
+ */
+ if (applystrongest)
[...]

The patch is quite straightforward, so I don't have general comments
on it. However, I think that the idxlockmode initialization is
problematic: you're using the statement's commandType so this doesn't
work with CTE. For instance, with this artificial query

WITH s AS (UPDATE test set id = 1 WHERE id =1) select 1;

will take an AccessShareLock on test's index while it should have an
RowExclusiveLock. I guess that you have to code similar lock upgrade
logic for the indexes, inspecting the planTree and subplans to find
the correct command type.

>
> I was also looking at each call site that calls ExecOpenIndices(). I
> don't think it's great that ExecInitModifyTable() has its own logic to
> skip calling that function for DELETE. I wondered if it shouldn't
> somehow depend on what the idxlockmode is set to.

I don't think that it's great either. However for DELETE we shouldn't
simply call ExecOpenIndices(), but open only the used indexes right?

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2019-02-10 13:05:53 Re: Fixing findDependentObjects()'s dependency on scan order (regressions in DROP diagnostic messages)
Previous Message Dean Rasheed 2019-02-10 11:18:46 Re: BUG #15623: Inconsistent use of default for updatable view