Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sjkq8-003dfi-2P for pgsql-hackers@arkaria.postgresql.org; Thu, 29 Aug 2024 19:29:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sjkq5-006knz-Tv for pgsql-hackers@arkaria.postgresql.org; Thu, 29 Aug 2024 19:29:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sjkq5-006knr-GE for pgsql-hackers@lists.postgresql.org; Thu, 29 Aug 2024 19:29:50 +0000 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sjkq2-00284K-1N for pgsql-hackers@postgresql.org; Thu, 29 Aug 2024 19:29:49 +0000 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-201e64607a5so8104855ad.2 for ; Thu, 29 Aug 2024 12:29:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20230601.gappssmtp.com; s=20230601; t=1724959785; x=1725564585; darn=postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=fm9YycsRlhcRgTbH6L/5O/svDgGPqPxtkLLTQ9ikg58=; b=sKSFozoHpPuAdFOYL4Lvhvo2nM1qcFEeg1WqIcdZVzLWC85NyPqnvO9ANZKFkWZr58 Kh+tzHRejs0S6l1ugZlQwUy8a63Wb5NANsl1bHqxMcpn2fgxF3agp2bl8pDOESagXnZe Wf4VPjekUMLiu2Umazm0tdCkfEHNXu/ucMiCSjx0F2DfTvIan2+F912Xy3YCp/Y/RtY4 Y5qP4pIw8YWSiOBUjy2OqGPQZVdH9k3vJQtch4wuV7l7TyM9unETRuoe9i7hFskZHUmB gau+8Cf3oHEMBUzm34Fu9Ry/LV2vbWu6q/KKcmIG1w8/LBC/IIeArFjwWhlYUP6pyOSb Ag6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724959785; x=1725564585; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=fm9YycsRlhcRgTbH6L/5O/svDgGPqPxtkLLTQ9ikg58=; b=Uiv0EXzCFdMJ3kNNrOG2nUNNxyiCYK8TKrrWBtDppfx8J73b7k5wjMyL/IzeYaIS8s I1vZQLVqdHaVuJ82g1jzyzx8nV1i8SbiEZdqBtJSRnMHKvX/nPPJHkDUbCHXebb2KF92 K1S743s4ogK6S8c0REHomzebq5UrTena9xoF+lW+Uk6nt+U7qCjWXzi8SmCK1RvXOuiL cRUJZIVnSb/9e5ZCbGf78zY3TvHYmcAHRIaauKm29g1KImtkPr+CMvCfQKxQF3aIICG7 0GO1Fh6xecocLog9C4trF/ZreuuZALgIWLDQKzKY8J0qUxM5Ry6ft51Fl2p9R1tRMjYo mZxQ== X-Forwarded-Encrypted: i=1; AJvYcCX0kjRs88yCxgvpMcNzkJof2xxmCrnfs2k6shs3asfsJ232ZDWYDKqBEnKcNBPtbcisBWRaYaMaUHQOQuun@postgresql.org X-Gm-Message-State: AOJu0YwoTr7Q/zEgkyjJKSSzbJwqbZT6fHfGN4NhBkODsdf9QuBmDATO x02oY0HM5gdz3I/h/BtDe6ToNLVDHhO3P8LJvi01FDis6odgFJ+i8m0GI4wOofZB1qKG94Rrfuw = X-Google-Smtp-Source: AGHT+IGugW5xZh+/qxxhS/G4ZvNJLdhi+0mHlNe+Mo8Y02RQ7dG4yNZ6tw/sH7qxVkIb5c+bfCQyMg== X-Received: by 2002:a17:902:cec7:b0:1fa:abda:cf7b with SMTP id d9443c01a7336-2050c2068edmr52641695ad.9.1724959784639; Thu, 29 Aug 2024 12:29:44 -0700 (PDT) Received: from [172.18.11.17] ([12.126.244.130]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-205152d0410sm14852665ad.69.2024.08.29.12.29.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2024 12:29:44 -0700 (PDT) Message-ID: Subject: Re: Introduce new multi insert Table AM and improve performance of various SQL commands with it for Heap AM From: Jeff Davis To: Bharath Rupireddy Cc: Masahiko Sawada , PostgreSQL-development , Andres Freund , Dilip Kumar , Luc Vlaming , Justin Pryzby , Michael Paquier , Matthias van de Meent , Alexander Korotkov Date: Thu, 29 Aug 2024 12:29:43 -0700 In-Reply-To: References: <20230603223824.o7iyochli2dwwi7k@alap3.anarazel.de> <6be6f58815dc0844fbe058edf56b4e735a6efc1c.camel@j-davis.com> <2280bf7241119bb88cbe0fe5eb36490cbd04c0c0.camel@j-davis.com> <12f1a2d8dd3b6305c0354f1c701f44b7be5e54eb.camel@j-davis.com> <8633171cb034aafc260fdf37df04b6c779aa1e2f.camel@j-davis.com> <229c4f7219ed164088dadc935df21e1cf125e191.camel@j-davis.com> <23a29125a2d07f96d49f97c31fcdb09a7f0ff6c1.camel@j-davis.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu2 MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 2024-08-29 at 12:55 +0530, Bharath Rupireddy wrote: > IMO, every caller branching out in the code like if (rel->rd_tableam- > > > tuple_modify_buffer_insert !=3D NULL) then multi insert; else single > insert; doesn't look good. IMO, the default implementation approach > keeps things simple which eventually can be removed in *near* future. > Thoughts? I believe we need the branching in the caller anyway: 1. If there is a BEFORE row trigger with a volatile function, the visibility rules[1] mean that the function should see changes from all the rows inserted so far this command, which won't work if they are still in the buffer. 2. Similarly, for an INSTEAD OF row trigger, the visibility rules say that the function should see all previous rows inserted. 3. If there are volatile functions in the target list or WHERE clause, the same visibility semantics apply. 4. If there's a "RETURNING ctid" clause, we need to either come up with a way to return the tuples after flushing, or we need to use the single-tuple path. (Similarly in the future when we support UPDATE ... RETURNING, as Matthias pointed out.) If we need two paths in each caller anyway, it seems cleaner to just wrap the check for tuple_modify_buffer_insert in table_modify_buffer_enabled(). We could perhaps use a one path and then force a batch size of one or something, which is an alternative, but we have to be careful not to introduce a regression (and it still requires a solution for #4). Regards, Jeff Davis [1]=20 https://www.postgresql.org/docs/devel/trigger-datachanges.html