Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lKPcD-0005Ec-6Y for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Mar 2021 18:00:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lKPcC-0002CY-2N for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Mar 2021 18:00:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lKPcB-00029S-Re for pgsql-hackers@lists.postgresql.org; Thu, 11 Mar 2021 18:00:51 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lKPc9-0002hn-4c for pgsql-hackers@lists.postgresql.org; Thu, 11 Mar 2021 18:00:51 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 12BI0ijH2309261; Thu, 11 Mar 2021 13:00:44 -0500 From: Tom Lane To: "houzj.fnst@fujitsu.com" cc: Greg Nancarrow , Amit Kapila , PostgreSQL Hackers , vignesh C , David Rowley , "tsunakawa.takay@fujitsu.com" , "tanghy.fnst@fujitsu.com" , Amit Langote Subject: Re: Parallel INSERT (INTO ... SELECT ...) In-reply-to: References: Comments: In-reply-to "houzj.fnst@fujitsu.com" message dated "Thu, 11 Mar 2021 13:01:42 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2309259.1615485644.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 11 Mar 2021 13:00:44 -0500 Message-ID: <2309260.1615485644@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The buildfarm has revealed that this patch doesn't work under CLOBBER_CACHE_ALWAYS: https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=3Dhusky&dt=3D2021-= 03-10%2021%3A09%3A32 I initially thought that that was a problem with c3ffe34863, but after reproducing it here I get this stack trace: #0 target_rel_trigger_max_parallel_hazard (context=3D0x7fff9cbfc220, = trigdesc=3D0x7fdd7dfa9718) at clauses.c:971 #1 target_rel_max_parallel_hazard_recurse (command_type=3DCMD_INSERT, = context=3D0x7fff9cbfc220, rel=3D0x7fdd7df819e0) at clauses.c:929 #2 target_rel_max_parallel_hazard_recurse (rel=3D0x7fdd7df819e0, = command_type=3D, context=3D0x7fff9cbfc220) at clauses.c= :893 #3 0x000000000075d26e in target_rel_max_parallel_hazard ( context=3D0x7fff9cbfc220) at clauses.c:884 #4 max_parallel_hazard_walker (node=3Dnode@entry=3D0x146e590, = context=3Dcontext@entry=3D0x7fff9cbfc220) at clauses.c:831 #5 0x0000000000700812 in range_table_entry_walker (rte=3D0x146e590, = walker=3D0x75cf00 , context=3D0x7fff9cbfc2= 20, = flags=3D16) at nodeFuncs.c:2467 #6 0x0000000000700927 in range_table_walker (rtable=3D0x11fdd70, = walker=3Dwalker@entry=3D0x75cf00 , = context=3Dcontext@entry=3D0x7fff9cbfc220, flags=3D16) at nodeFuncs.c:2= 446 #7 0x0000000000700ada in query_tree_walker (flags=3D, = context=3D0x7fff9cbfc220, walker=3D0x75cf00 , = query=3D0x11fdc58) at nodeFuncs.c:2423 #8 query_tree_walker (query=3Dquery@entry=3D0x700927 , = walker=3Dwalker@entry=3D0x75cf00 , = context=3Dcontext@entry=3D0x11fdc58, flags=3D) at nodeF= uncs.c:2336 #9 0x000000000075d138 in max_parallel_hazard_walker ( node=3Dnode@entry=3D0x11fdc58, context=3D0x11fdc58, context@entry=3D0x= 7fff9cbfc220) at clauses.c:853 #10 0x000000000075dc98 in max_parallel_hazard (parse=3Dparse@entry=3D0x11f= dc58, = glob=3Dglob@entry=3D0x11fdb40) at clauses.c:585 #11 0x000000000074cd22 in standard_planner (parse=3D0x11fdc58, = query_string=3D, cursorOptions=3D256, = boundParams=3D) at planner.c:345 #12 0x0000000000814947 in pg_plan_query (querytree=3D0x11fdc58, = query_string=3D0x11fc740 "insert into fk_notpartitioned_pk (a, b)\n s= elect 2048, x from generate_series(1,10) x;", cursorOptions=3D256, boundPa= rams=3D0x0) at postgres.c:809 #13 0x0000000000814a43 in pg_plan_queries (querytrees=3D0x14725d0, = query_string=3Dquery_string@entry=3D0x11fc740 "insert into fk_notparti= tioned_pk (a, b)\n select 2048, x from generate_series(1,10) x;", = cursorOptions=3DcursorOptions@entry=3D256, boundParams=3DboundParams@e= ntry=3D0x0) at postgres.c:900 #14 0x0000000000814d35 in exec_simple_query ( query_string=3D0x11fc740 "insert into fk_notpartitioned_pk (a, b)\n s= elect 2048, x from generate_series(1,10) x;") at postgres.c:1092 The problem is that target_rel_trigger_max_parallel_hazard and its caller think they can use a relcache TriggerDesc field across other cache accesses, which they can't because the relcache doesn't guarantee that that won't move. One approach would be to add logic to RelationClearRelation similar to what it does for tupdescs, rules, etc, to avoid moving them when their contents haven't changed. But given that we've not needed that for the past several decades, I'm disinclined to add the overhead. I think this code ought to be adjusted to not make its own copy of the trigdesc pointer, but instead fetch it out of the relcache struct each time it is accessed. There's no real reason why target_rel_trigger_max_parallel_hazard shouldn't be passed the (stable) Relation pointer instead of just the trigdesc pointer. BTW, having special logic for FK triggers in target_rel_trigger_max_parallel_hazard seems quite loony to me. Why isn't that handled by setting appropriate proparallel values for those trigger functions? regards, tom lane