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 1oi8Pu-0001x5-QX for pgsql-hackers@arkaria.postgresql.org; Tue, 11 Oct 2022 06:07:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oi8Pt-000567-Nd for pgsql-hackers@arkaria.postgresql.org; Tue, 11 Oct 2022 06:07:01 +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 1oi8Pt-000534-7U for pgsql-hackers@lists.postgresql.org; Tue, 11 Oct 2022 06:07:01 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oi8Pq-0005wj-VY for pgsql-hackers@postgresql.org; Tue, 11 Oct 2022 06:07:00 +0000 Received: from [192.168.28.53] (cyclops.postgrespro.ru [93.174.131.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 81E5621C1657; Tue, 11 Oct 2022 09:06:57 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1665468417; bh=Q/1LNprS2OT+Pxar4upuqpHpN2dj1b5/QUtJvxlOByM=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=FoitXC6UCDVjY/RDamvLohxxgWHg6g+6ddf7QsFzHYQ8FP7ycJT40hhfCmGNk39qX 7I/RPQJ+fsLgHyVKJ1kEpg7pXPZobUoakY6Xl0yprsHoIjGz2kNsA2x2Tp2jf8eP+w 3aJVvGrlTSSuyzFMvzFhL9QuK8ns9nPAwexT0yGA= Message-ID: Date: Tue, 11 Oct 2022 11:06:57 +0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.1 Subject: Re: Fast COPY FROM based on batch insert Content-Language: en-US To: Etsuro Fujita , Zhihong Yu Cc: Justin Pryzby , Amit Langote , tanghy.fnst@fujitsu.com, Ashutosh Bapat , Pg Hackers , Tomas Vondra , houzj.fnst@fujitsu.com References: <45ad1b94-339b-a841-8885-67ebe6fc5bc1@postgrespro.ru> <57733596-5fd6-07ec-d65c-67411411f10e@postgrespro.ru> <05bc8819-3e53-d884-a0d0-a17ffa5febef@postgrespro.ru> <09ff35ff-291f-d9e9-a0ed-55e6bb9732fc@postgrespro.ru> From: Andrey Lepikhov Organization: Postgres Professional In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 10/7/22 11:18, Etsuro Fujita wrote: > On Tue, Sep 27, 2022 at 6:03 PM Etsuro Fujita wrote: >> I will review the patch a bit more, but I feel that it is >> in good shape. > > One thing I noticed is this bit added to CopyMultiInsertBufferFlush() > to run triggers on the foreign table. > > + /* Run AFTER ROW INSERT triggers */ > + if (resultRelInfo->ri_TrigDesc != NULL && > + (resultRelInfo->ri_TrigDesc->trig_insert_after_row || > + resultRelInfo->ri_TrigDesc->trig_insert_new_table)) > + { > + Oid relid = > RelationGetRelid(resultRelInfo->ri_RelationDesc); > + > + for (i = 0; i < inserted; i++) > + { > + TupleTableSlot *slot = rslots[i]; > + > + /* > + * AFTER ROW Triggers might reference the tableoid column, > + * so (re-)initialize tts_tableOid before evaluating them. > + */ > + slot->tts_tableOid = relid; > + > + ExecARInsertTriggers(estate, resultRelInfo, > + slot, NIL, > + cstate->transition_capture); > + } > + } > > Since foreign tables cannot have transition tables, we have > trig_insert_new_table=false. So I simplified the if test and added an > assertion ensuring trig_insert_new_table=false. Attached is a new > version of the patch. I tweaked some comments a bit as well. I think > the patch is committable. So I plan on committing it next week if > there are no objections. I reviewed the patch one more time. Only one question: bistate and ri_FdwRoutine are strongly bounded. Maybe to add some assertion on (ri_FdwRoutine XOR bistate) ? Just to prevent possible errors in future. -- Regards Andrey Lepikhov Postgres Professional