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 1oGZoY-0002Jm-Mn for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Jul 2022 05:42:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oGZoX-0004A0-HO for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Jul 2022 05:42:33 +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 1oGZoX-00049r-1l for pgsql-hackers@lists.postgresql.org; Wed, 27 Jul 2022 05:42:33 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oGZoU-0006mv-Ss for pgsql-hackers@postgresql.org; Wed, 27 Jul 2022 05:42:32 +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 A477121C2640; Wed, 27 Jul 2022 08:42:28 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1658900549; bh=gE7BmGOPplXwA888F3LJL3OoUzAe81J7+0vQtGYVKfA=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=JoS3E5POK/rfSyXbLM/hyHj3e2Hn9Paz42Q0hWP3I7mkewW94mhsU1v4NFYuHSg/j kBW9WfyNcW5dX8ObOcgRq6pPM29LIHzc/xceLYa1aziZIGS1A1d2Zt4tZlPkbKIDfz LphEsnog0+UHxT1wl3biDt/Wd9t8fwQkv4TJlbTE= Message-ID: Date: Wed, 27 Jul 2022 10:42:28 +0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: Fast COPY FROM based on batch insert Content-Language: en-US To: Etsuro Fujita Cc: Justin Pryzby , Zhihong Yu , Amit Langote , tanghy.fnst@fujitsu.com, Ashutosh Bapat , Pg Hackers , Tomas Vondra , houzj.fnst@fujitsu.com References: <20210323032322.GW4203@telsasoft.com> <20210409004956.GN6592@telsasoft.com> <45ad1b94-339b-a841-8885-67ebe6fc5bc1@postgrespro.ru> <57733596-5fd6-07ec-d65c-67411411f10e@postgrespro.ru> <05bc8819-3e53-d884-a0d0-a17ffa5febef@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 7/22/22 13:14, Etsuro Fujita wrote: > On Fri, Jul 22, 2022 at 3:39 PM Andrey Lepikhov > wrote: >> Analyzing multi-level heterogeneous partitioned configurations I >> realized, that single write into a partition with a trigger will flush >> buffers for all other partitions of the parent table even if the parent >> haven't any triggers. >> It relates to the code: >> else if (insertMethod == CIM_MULTI_CONDITIONAL && >> !CopyMultiInsertInfoIsEmpty(&multiInsertInfo)) >> { >> /* >> * Flush pending inserts if this partition can't use >> * batching, so rows are visible to triggers etc. >> */ >> CopyMultiInsertInfoFlush(&multiInsertInfo, resultRelInfo); >> } >> >> Why such cascade flush is really necessary, especially for BEFORE and >> INSTEAD OF triggers? > > BEFORE triggers on the chosen partition might query the parent table, > not just the partition, so I think we need to do this so that such > triggers can see all the rows that have been inserted into the parent > table until then. if you'll excuse me, I will add one more argument. It wasn't clear, so I've made an experiment: result of a SELECT in an INSERT trigger function shows only data, existed in the parent table before the start of COPY. So, we haven't tools to access newly inserting rows in neighboring partition and don't need to flush tuple buffers immediately. Where am I wrong? -- Regards Andrey Lepikhov Postgres Professional