RE: Avoid CommandCounterIncrement in RI trigger when INSERT INTO referencing table

From: "tsunakawa(dot)takay(at)fujitsu(dot)com" <tsunakawa(dot)takay(at)fujitsu(dot)com>
To: "houzj(dot)fnst(at)fujitsu(dot)com" <houzj(dot)fnst(at)fujitsu(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: RE: Avoid CommandCounterIncrement in RI trigger when INSERT INTO referencing table
Date: 2021-03-04 02:52:11
Message-ID: TYAPR01MB299076334FF2290AE2C88A11FE979@TYAPR01MB2990.jpnprd01.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Excuse me for asking probably stupid questions...

From: houzj(dot)fnst(at)fujitsu(dot)com <houzj(dot)fnst(at)fujitsu(dot)com>
> As far as I can see, it’s only necessary to increment command id when the
> INSERT command modified the referenced table.

Why do we have to increment the command ID when the INSERT's target table is a referenced table?

> And INSERT command only have one target table, the modification on other
> tables can happen in the following cases.
>
> 1) has modifyingcte which modifies the referenced table
> 2) has modifying function which modifies the referenced table.
> (If I missed something please let me know)

Also, why do we need CCI in these cases? What kind of problem would happen if we don't do CCI?

> Since the above two cases are not supported in parallel mode(parallel unsafe).
> IMO, It seems it’s not necessary to increment command id in parallel mode, we
> can just skip commandCounterIncrement when in parallel mode.
>
> + /*
> + * We do not need to increment the command counter
> + * in parallel mode, because any other modifications
> + * other than the insert event itself are parallel unsafe.
> + * So, there is no chance to modify the pk relation.
> + */
> + if (IsInParallelMode())
> + needCCI = false;

I'm worried about having this dependency in RI check, because the planner may allow parallel INSERT in these cases in the future.

Regards
Takayuki Tsunakawa

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2021-03-04 03:21:14 Re: n_mod_since_analyze isn't reset at table truncation
Previous Message Zhihong Yu 2021-03-04 02:51:39 Re: [POC] Fast COPY FROM command for the table with foreign partitions