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.96) (envelope-from ) id 1vvHrZ-00C62h-3D for pgsql-performance@arkaria.postgresql.org; Wed, 25 Feb 2026 16:35:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vvHrY-007JGX-2j for pgsql-performance@arkaria.postgresql.org; Wed, 25 Feb 2026 16:35:48 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vvHrY-007JGP-1F for pgsql-performance@lists.postgresql.org; Wed, 25 Feb 2026 16:35:48 +0000 Received: from mail-yx1-xb129.google.com ([2607:f8b0:4864:20::b129]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vvHrV-0000000196U-1xWo for pgsql-performance@lists.postgresql.org; Wed, 25 Feb 2026 16:35:47 +0000 Received: by mail-yx1-xb129.google.com with SMTP id 956f58d0204a3-64ae222d87dso6282636d50.2 for ; Wed, 25 Feb 2026 08:35:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1772037346; cv=none; d=google.com; s=arc-20240605; b=FCAXnSxAWjeadqy5rrPwCbuGMTTmf2dCfvISYU3ldf9Z4vgbga0esrwZyYXWxsj4y3 u1RZZbF/8+JnpxTIt7Eupzc46GoHfXyDT7Sk6rYGVZohsv7j8+uuQX83KQj1Vfehlngj CoiwVOAufwh/zpzqxIFQocro6riyy1Lq3cGbt25gRjpz+jbaLVqDFIy+2XOL3C4HkC3b W2rGxmO/TUL5zGLq2gD5Ynm/x1nTG5VWWpBllwtRPz81m18Da/yz+f0/kuU/L/2CCsJk C7dtiMamGJ40ZxvggYLMGF8/zCugT1QlKcUkO379zLG74syVcYHyB2SqpGMo4iDuR08y zVkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=f122A0dytlqopm5T2qC33jCQelGEP92vU7z2ogXX2Qc=; fh=BAk41HrZuucu92e7WA8+Mb0CPM4SpEYy3m0e7bWgdzw=; b=G2feUOjjYggsIyszZmlbKFNO3KC11mb5Gb+9hKKzz8xF1S0e0gCQ57g8/S1yzfovWa 4K9HnF2WJE9ZXLIWyhDxxsChtXjNGiN9EXT+eTuv6WEgx+U1L2vowdYLjkbF5ubg5hI8 GpGnGef57HpoNFMJ3BsVplr6yKj2r7aXr960bTTdI5inme0kB83+Pshe9wa4pvhpfhGY Uv+6z56IPooUZzrFYyb4T0I3w81fXprzp/21EEfW8nVScyC41QzbWcLug5Xm9YMIgTP8 +rp7MraR7l0XmWjixvXlroAVFNGXHjOoBfg8hSYmE1xq/xpUF+36ejDFWHgkxAxnsfFO A2eQ==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772037346; x=1772642146; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=f122A0dytlqopm5T2qC33jCQelGEP92vU7z2ogXX2Qc=; b=Vmq9En1mrm2+9k3q8WTQyRF7tXqnwQBgKxxokvcNdt6wjqQPZ6xnovQTc8cwS+gcQw 19vhg84IHwj71evZ8oZfzvpVnmxSWdgSAmXqmeJ3nKtwfdoqmBm7an7DMoUGIsIkCXzc ZoU+4FwHVWZEal/IfB95/B0YBbYS0Gaf9OLO2aLbM85/N9+t3LrvPOokPoK3omu4ztBm H2mqzlkrjj5lGBy+qONLTv7/YUn32eY6d6K4m+J40V3Zf/FJL/4pAdcMkJJHqkXq7Xvu jcgvhEfSk9fAdZVfXmM8sKqJ2ZEU7W867XQwwqKs1YrWbnANOCCu7u29z/vVEmxCo2zn hdtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772037346; x=1772642146; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=f122A0dytlqopm5T2qC33jCQelGEP92vU7z2ogXX2Qc=; b=UMccYNkbbAR8Tagya1fI74XfnSXhZwMG4CVCJRkKSpNCrwMg8oo8EMOQ/m0CpUFIjg DXhgTWyWdr5wDmIz1/V+gOnLbHvjh6fzR2sxLxfwkjs9+4opme5If4LXYoIFyKP40jZV 4/E0TpnfHKeS7dZz/yqcigAT3B/nJGm97Ut09ClMWI0OEN3QMNRIT3QdoxfiCn605Y1/ UOqGFIPuyCs8KJUIRzCItWU1JrVgMlT3GYJBvXVo5qAs6HjIinGb7yhLBY0dIeS99kQI YMSHDRn/dRSRCnhzLusTGdM8aXAvuD7vmOxx6MW6xLPu5Df2mKTRUMGwRDSjnAxesjtB LchA== X-Gm-Message-State: AOJu0YyjBaHyuov7vnBIQE8jEYjlAEynMpdA1ZGrAxsiTHbLY1/BBFlx 6p/uG1BKpg+bgCUHJQotmw4sSWpqbYiaJgrPNjx1kmzvrVrbwtoGf4qhgaaZP7jD+53cLfE/2jz ux+W8d1NmEfc+kF89SsjpZ9MEOUM1r7Y= X-Gm-Gg: ATEYQzyhD2LFkHY+8xfNK5ntHKAhIcXl1LRUQod8RPpaEvno10wWoFQ1dI4tgwj3A60 Ej2CJVYOqgLVWsLzl7xUXWcO6+vcoeDZeoaa4vo7tFeNdmuvlGeLL8yKlOWJqcFwfzej8u5zWM3 kZjgpQ5QNFdmTiQaDgm03ACgK2igYUMNE7AhrcylLlULfFSRfSMphdzDf87UkbW0oKyewwlSd8O dqsnKRewOq+skAQqXqL5Phd/xd4MVah55VHaWptRWuExklVQ0Q+jWp6+kpS4u3PbX8uw8MWkO31 psyqSsdSaqVqLBc= X-Received: by 2002:a05:690e:1686:b0:64a:db39:f010 with SMTP id 956f58d0204a3-64c7826a71fmr15170621d50.0.1772037345779; Wed, 25 Feb 2026 08:35:45 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Feike Steenbergen Date: Wed, 25 Feb 2026 17:35:34 +0100 X-Gm-Features: AaiRm52vt6KHd1RvYT0Ar2pB2F3MKkCAsyFHBxfwugxseKfh1Nxvcg4LlyuPlGs Message-ID: Subject: Re: MERGE INTO... WHEN NOT MATCHED BY SOURCE index usage To: =?UTF-8?Q?Lea_F=C3=BChrer?= Cc: pgsql-performance@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000008622c7064ba898bb" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000008622c7064ba898bb Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, 23 Feb 2026 at 15:19, Lea F=C3=BChrer wrote: > It seems to me like one very common use-case, and one I have bumped into > often, is to update a n:m resolution table, like this for example: Something similar was previously discussed in January 2025 as well: https://www.postgresql.org/message-id/flat/CAK_s-G0NrC_KH7kn85arfqkdzvs80GO= CCKvz9YbU2%3DE94qfdPA%40mail.gmail.com To summarize: Tom Lane wrote: > I may not have fully wrapped my head around this example, but I think > that the fact that "t.device_id =3D $1" appears in both the ON condition > and the WHEN NOT MATCHED BY SOURCE condition means that only t rows > meeting that condition are of interest, so that in principle we could > optimize by pushing that down to the scan of t. But as you can see, > we don't. Not sure if this pattern is common enough to be worth > trying to implement such an optimization. So at least there's 1 more who uses this pattern! Kind regards Feike --0000000000008622c7064ba898bb Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Mon, 23 Feb 2026 at 15:19, Lea F=C3=BChrer <lea@codecat.at> wrote:
> It seems t= o me like one very common use-case, and one I have bumped into
> ofte= n, is to update a n:m resolution table, like this for example:

Somet= hing similar was previously discussed in January 2025 as well:

https://www.postgresql.org/me= ssage-id/flat/CAK_s-G0NrC_KH7kn85arfqkdzvs80GOCCKvz9YbU2%3DE94qfdPA%40mail.= gmail.com

To summarize:

Tom Lane wrote:

> I may= not have fully wrapped my head around this example, but I think
> th= at the fact that "t.device_id =3D $1" appears in both the ON cond= ition
> and the WHEN NOT MATCHED BY SOURCE condition means that only = t rows
> meeting that condition are of interest, so that in principle= we could
> optimize by pushing that down to the scan of t.=C2=A0 But= as you can see,
> we don't.=C2=A0 Not sure if this pattern is co= mmon enough to be worth
> trying to implement such an optimization.
So at least there's 1 more who uses this pattern!

Kind reg= ards

Feike
--0000000000008622c7064ba898bb--