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

From: "houzj(dot)fnst(at)fujitsu(dot)com" <houzj(dot)fnst(at)fujitsu(dot)com>
To: Greg Nancarrow <gregn4422(at)gmail(dot)com>
Cc: "tsunakawa(dot)takay(at)fujitsu(dot)com" <tsunakawa(dot)takay(at)fujitsu(dot)com>, 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-22 05:57:01
Message-ID: OS0PR01MB57166504AE683F116348B1A294659@OS0PR01MB5716.jpnprd01.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Thanks for the review.

> I noticed some things on the first scan through:
>
> Patch 0001:
> 1) Tidy up the comments a bit:
>
> Suggest the following update to part of the comments:

Changed.

> Patch 0002:
> 1) The new max_parallel_hazard_context member "pk_rels" is not being
> set (to
> NIL) in the is_parallel_safe() function, so it will have a junk value
> in that case - though it does look like nothing could reference it
> then (but the issue may be detected by a Valgrind build, as performed by the buildfarm).

Changed.

> 2) Few things to tidy up the patch comments:

Changed.

> 3) In target_rel_trigger_max_parallel_hazard(), you have added a
> variable declaration "int trigtype;" after code, instead of before:

Changed.

Attaching new version patch with these changes.

Also attaching the simple performance test results (insert into table with foreign key):
postgres=# explain (analyze, verbose) insert into fk select a,func_xxx() from data where a%2=0 or a%3 = 0;
workers | serial insert + parallel select | parallel insert | performace gain
-----------+---------------------------------+-----------------+--------
2 workers | 85512.153ms | 61384.957ms | 29%
4 workers | 85436.957ms | 39335.797ms | 54%

-------------data prepare-----------------------------
create table pk(a int primary key,b int);
create table fk(a int references pk,b int);
create table data(a int, b int);
insert into data select * from generate_series(1,10000000,1) t;
insert into pk select generate_series(1,10000000,1);
------------------------------------------------

Best regards,
houzj

Attachment Content-Type Size
v3-0001-skip-cci.patch application/octet-stream 11.2 KB
v3-0002-extend-safery-check-for-fk-relation.patch application/octet-stream 6.9 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message torikoshia 2021-03-22 06:09:58 Re: Get memory contexts of an arbitrary backend process
Previous Message Michael Paquier 2021-03-22 05:46:15 Re: Permission failures with WAL files in 13~ on Windows