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 1swoZp-006B59-VL for pgsql-general@arkaria.postgresql.org; Fri, 04 Oct 2024 20:07:02 +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 1swoYp-005NBX-5M for pgsql-general@arkaria.postgresql.org; Fri, 04 Oct 2024 20:05:59 +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 1swoYo-005NBO-QV for pgsql-general@lists.postgresql.org; Fri, 04 Oct 2024 20:05:58 +0000 Received: from mail-yw1-x112d.google.com ([2607:f8b0:4864:20::112d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1swoYh-002Yky-25 for pgsql-general@lists.postgresql.org; Fri, 04 Oct 2024 20:05:58 +0000 Received: by mail-yw1-x112d.google.com with SMTP id 00721157ae682-6e23b300bf9so23465777b3.3 for ; Fri, 04 Oct 2024 13:05:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728072350; x=1728677150; darn=lists.postgresql.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=o0oVbhOKxR3RUJOxiXflkXALmy5IIhlmC8uzNlcR7WI=; b=VL7SyhxdN+p+/JFcH8KtW4laM9ZUqoT+T3GZThe/1e/4nIOGO1l11aNMPCISDpL8Gf k5nANvg9XaPloIsNjAQN++1qhWuYFAu/dTLaw72F2tCM/vDT517Nmmk81q2BqcmiHCGl MyCU5vCG13AwNbUhnVDoz0UXxop5aBFnqN1azF68fCCLdLycnlqMg9homwysC/IuJE3T /eEu647DmWarn9kj8dNG2Iu60XGuI9c7uGpoN75gb/VIVI4AEfL+7kpPXTEjHTxMfjuZ YaZp91wUE2VEXsnZUtgDW6aJKpLMS3gg9f3lTSB0EQyV/cbT9UOOUkNm/48G0eqdR2p3 ibng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728072350; x=1728677150; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=o0oVbhOKxR3RUJOxiXflkXALmy5IIhlmC8uzNlcR7WI=; b=RvP7pKMNrrlsUCIjWZdfHyD6FkFBe592fLofOzkFoGmbkRqpCuhLzKA0FbaahQ7D7K MxEufRENEiseat3EtE0M+ZK3GIcSHsOx5SVrewxGJ7gvQ2zZin7ZgalZ4WFEsIfk5i9L 7xcuYqwvUnbx84lteuGYRHNoHd2WGoCrw8RGvUwzRSmOpvXAiWkEtcKs+z4sZ6arSQTJ nZ3sANnqYpXb2jCOQ3FytoKS/NWqLMxihXLG8mMrqLqm4kEf2cGkegOKHqHnWwrK0nr9 yuc2Je9UMqeMZAAXTas3+zKWQFJV4oLx8nFmRR399EZlxjl9MseuDjoP71HN1KThioSE m8sg== X-Gm-Message-State: AOJu0Yx1cdx7q1Dt6jfod/hsKbSc7//I6SwbuTJQrhSbo6jx/lVFrva8 n4yx0bBUawF/m0fgcNvT6mkT7EYUftvrfH9CK80P+mDW21ojUMZEYhZFzMJKtwzqojM+8EzXo56 luSEQnepnz4iFGWOaVUkenOvy66a+1Q32 X-Google-Smtp-Source: AGHT+IEBHtBARijNnM9ujoua3gbMiTbIU79H/UXThkFId9Rk+Hmq+ECMpBoIDSaQpXZX7N3+DeeuAleG7MH5TYpzNak= X-Received: by 2002:a05:690c:e20:b0:6db:e368:3ff3 with SMTP id 00721157ae682-6e2c72aff7dmr41856077b3.40.1728072350427; Fri, 04 Oct 2024 13:05:50 -0700 (PDT) MIME-Version: 1.0 References: <4178E73A-24F5-4E3C-92F6-1532D8102C3E@kleczek.org> <20240921143629.t2x37xfczeeunpnf@hjp.at> <20240922192321.kpbe3p4ixmoid3ma@hjp.at> In-Reply-To: <20240922192321.kpbe3p4ixmoid3ma@hjp.at> From: Lok P Date: Sat, 5 Oct 2024 01:35:38 +0530 Message-ID: Subject: Re: How batch processing works To: pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="00000000000097f6960623ac322b" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000097f6960623ac322b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Sep 23, 2024 at 12:53=E2=80=AFAM Peter J. Holzer = wrote: > > > Thank you so much. > > I was expecting method-3(batch insert) to be the fastest or atleast as > you said > > perform with similar speed as method-2 (row by row insert with batch > commit) > > Oops, sorry! I wrote that the wrong way around. Method 3 is the fastest. > I guess I meant to write "method2 takes about twice as long as method3" > or something like that. > > As in case of batch insert below is the fastest one as it inserts multiple rows in one statement. Similarly I understand, Delete can be batched as below. However, can you suggest how an Update can be batched in a simple/generic fashion in JDBC for an input data stream with multiple input values. As because for an update if we write as below , it will just do one row update at a time? Update SET column1=3D?, column2=3D?, column3=3D? where =3D? ; INSERT INTO VALUES (1, 'a'), (2, 'a'),(3,'a'); Delete from where column_name in (, ,...); --00000000000097f6960623ac322b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Mon, Sep 23, 2024 at 12:53=E2=80= =AFAM Peter J. Holzer <hjp-pgsql@hjp= .at> wrote:

> Thank you so much.
> I was expecting method-3(batch insert) to be the fastest or atleast as= you said
> perform with similar speed=C2=A0as method-2 (row by row insert with ba= tch commit)

Oops, sorry! I wrote that the wrong way around. Method 3 is the fastest. I guess I meant to write "method2 takes about twice as long as method3= "
or something like that.


As in case = of batch insert below=C2=A0is the fastest one as it inserts multiple=C2=A0r= ows in one statement. Similarly I understand, Delete=C2=A0can be batched as= below. However, can you suggest how an Update can be batched in a simple/g= eneric fashion in JDBC for an input data stream with multiple input values.= As because=C2=A0for an update if we write as below , it will just do one r= ow update at a time?

Update <table_name> SET= column1=3D?, =C2=A0 column2=3D?, column3=3D? where <PK_Column>=3D? ;=


INSERT INTO <table_name> VALU= ES =C2=A0(1, 'a'), (2, 'a'),(3,'a');
Delete from <table_name> where column_name=C2=A0 in= (<value1>, <value2>,<value3>...);

=C2=A0
--00000000000097f6960623ac322b--