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 1oEmKC-0001uY-8Q for pgsql-hackers@arkaria.postgresql.org; Fri, 22 Jul 2022 06:39:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oEmKA-0006nx-NT for pgsql-hackers@arkaria.postgresql.org; Fri, 22 Jul 2022 06:39:46 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oEmKA-0006jC-6z for pgsql-hackers@lists.postgresql.org; Fri, 22 Jul 2022 06:39:46 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oEmK7-0000dM-2t for pgsql-hackers@postgresql.org; Fri, 22 Jul 2022 06:39:45 +0000 Received: from [192.168.129.213] (unknown [91.205.25.86]) (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 42FFC21C1F4D; Fri, 22 Jul 2022 09:39:39 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1658471979; bh=eKoJsPgUzN5RBz9DSSEqijUUoZzkkbUG6m9k3nTscPk=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=ijSY5ZooUCgABIs1cOT5llH84pacGjSfZa8/a3Vd0/ZdbAyDKJXsh/BKa15Rfp6Dq I+Hf7IoHDM/gJmGlT+Pm6MSk+G2/tGey1Re75MzslN07U9NIX/ViOKSjIf0R/AvjLb h0nxaOkchzEgULs9sxwzekG+S6iskvQoKhHrMnr4= Message-ID: <05bc8819-3e53-d884-a0d0-a17ffa5febef@postgrespro.ru> Date: Fri, 22 Jul 2022 11:39:23 +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> 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/20/22 13:10, Etsuro Fujita wrote: > On Tue, Jul 19, 2022 at 6:35 PM Andrey Lepikhov > wrote: >> On 18/7/2022 13:22, Etsuro Fujita wrote: >>> I rewrote the decision logic to something much simpler and much less >>> invasive, which reduces the patch size significantly. Attached is an >>> updated patch. What do you think about that? > >> maybe you forgot this code: >> /* >> * If a partition's root parent isn't allowed to use it, neither is the >> * partition. >> */ >> if (rootResultRelInfo->ri_usesMultiInsert) >> leaf_part_rri->ri_usesMultiInsert = >> ExecMultiInsertAllowed(leaf_part_rri); > > I think the patch accounts for that. Consider this bit to determine > whether to use batching for the partition chosen by > ExecFindPartition(): Agreed. 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? AFTER Trigger should see all rows of the table, but if it isn't exists for parent, I think, we wouldn't obligate to guarantee order of COPY into two different tables. -- Regards Andrey Lepikhov Postgres Professional