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 1qxSv4-0013Ol-F0 for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Oct 2023 14:07:06 +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 1qxSv2-00EYHZ-PD for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Oct 2023 14:07:04 +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 1qxSv2-00EYHR-FO for pgsql-hackers@lists.postgresql.org; Mon, 30 Oct 2023 14:07:04 +0000 Received: from mail-yb1-xb34.google.com ([2607:f8b0:4864:20::b34]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qxSuv-003pxa-0q for pgsql-hackers@postgresql.org; Mon, 30 Oct 2023 14:07:03 +0000 Received: by mail-yb1-xb34.google.com with SMTP id 3f1490d57ef6-d9a58aa4983so3958627276.0 for ; Mon, 30 Oct 2023 07:06:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698674815; x=1699279615; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=s6AMq3BoIamZtLe8hToBk+t2Qt89EG0jLQ/NqtA1HdE=; b=PccKFRme/kRqv9tCJa4wEKP5qv38PRw9CcRLaMF+J8y4AKe8J7JMfDbcSQaFxRf8M/ h3QTyCvU/wVXwCU6xsYMcBTTkZKjY+vgcr24PxTD2ExZpauhejCWWDw5M3ozd516MLPL FaWOBhHcw8VegyfzfupQ1N0iHpZ3qN4Ej3BLlLApNVuL0wMyS4HnFJzLvGWYxcTam8ca IJj2VwFJQlCK5aMAXmKo2etJsgL+2tfO7w8Ir5kXhg6/KSXmYNJ3J4sOaX2ENG1jRVh6 LBTkFkR25IDbxwsvS9GMBomQ6oA1pECnbXCDWHuIBf8LN3yWqcBSQpGkpc0wYBBVJryR 7kZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698674815; x=1699279615; h=content-transfer-encoding:cc: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=s6AMq3BoIamZtLe8hToBk+t2Qt89EG0jLQ/NqtA1HdE=; b=t7brlG2zWyopSl0NMzmJnCAWF77lPWOudzM6qBeeJUb7Vj0ZSowHSlDnEhzUmu6L9w TLmRDCwBOidd38VHwA1XZH2QsUxtoJ4v86GS/aKl2gh3zsPql1d8aNSpzD5SbBf0JhFO RG+yVuL/DZEE0U9jK93ETzTcnxPlX655xVg1OssqQ7Q8hdHIBXSGUlKxsyrXiW+m4YiU tu8nAE70gvLyW+hmL3OvzVZ1F0zf9ygi6S36yMBBF9RNt2v+n48C6u5k40wTRMiveGSH nuvnQQkN2ENFBQ9nXZ2YAIshar2pZC3SFv71fYf6mNb8vcvgkMN5BPM7ftusgVknEasb jWYQ== X-Gm-Message-State: AOJu0YwSKR4i1Z2zrCrmvAjshA1TCUDRvT6dx2kvZDPvlxG0edMwb7Lg bouMkJ98tjnLXONROTMwbXysxv8bN7XhtLptaCQ= X-Google-Smtp-Source: AGHT+IHC4gjn9UWACX5KfX+azOm+XKL11OunOQm89QeWBqyvwVSo8h5Y+dumOZ/M4/ox73w9qMIXj5jmmEK3mNqpkR4= X-Received: by 2002:a25:ccd2:0:b0:da0:4d4d:da6a with SMTP id l201-20020a25ccd2000000b00da04d4dda6amr9657897ybf.42.1698674814649; Mon, 30 Oct 2023 07:06:54 -0700 (PDT) MIME-Version: 1.0 References: <567ED6CA.2040504@sigaev.ru> <4bac271d-1700-db24-74ac-8414f2baf9fd@postgrespro.ru> <89fb769c-7d45-f0c5-a9b3-b706c9661c57@postgrespro.ru> <668892c1-fb11-3a79-ce5e-1c194b7b3263@postgrespro.ru> In-Reply-To: From: Alexander Korotkov Date: Mon, 30 Oct 2023 16:06:41 +0200 Message-ID: Subject: Re: POC, WIP: OR-clause support for indexes To: Robert Haas Cc: Peter Geoghegan , Alena Rybakina , pgsql-hackers@postgresql.org, "Finnerty, Jim" , Marcos Pegoraro , Andrey Lepikhov , teodor@sigaev.ru, Ranier Vilela , Tomas Vondra , Peter Eisentraut Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Oct 30, 2023 at 3:40=E2=80=AFPM Robert Haas = wrote: > On Thu, Oct 26, 2023 at 5:05=E2=80=AFPM Peter Geoghegan wrot= e: > > On Thu, Oct 26, 2023 at 12:59=E2=80=AFPM Robert Haas wrote: > > > Alexander's example seems to show that it's not that simple. If I'm > > > reading his example correctly, with things like aid =3D 1, the > > > transformation usually wins even if the number of things in the OR > > > expression is large, but with things like aid + 1 * bid =3D 1, the > > > transformation seems to lose at least with larger numbers of items. S= o > > > it's not JUST the number of OR elements but also what they contain, > > > unless I'm misunderstanding his point. > > > > Alexander said "Generally, I don't see why ANY could be executed > > slower than the equivalent OR clause". I understood that this was his > > way of expressing the following idea: > > > > "In principle, there is no reason to expect execution of ANY() to be > > slower than execution of an equivalent OR clause (except for > > noise-level differences). While it might not actually look that way > > for every single type of plan you can imagine right now, that doesn't > > argue for making a cost-based decision. It actually argues for fixing > > the underlying issue, which can't possibly be due to some kind of > > fundamental advantage enjoyed by expression evaluation with ORs". > > > > This is also what I think of all this. > > I agree with that, with some caveats, mainly that the reverse is to > some extent also true. Maybe not completely, because arguably the > ANY() formulation should just be straight-up easier to deal with, but > in principle, the two are equivalent and it shouldn't matter which > representation we pick. > > But practically, it may, and we need to be sure that we don't put in > place a translation that is theoretically a win but in practice leads > to large regressions. Avoiding regressions here is more important than > capturing all the possible gains. A patch that wins in some scenarios > and does nothing in others can be committed; a patch that wins in even > more scenarios but causes serious regressions in some cases probably > can't. +1 Sure, I've identified two cases where patch shows regression [1]. The first one (quadratic complexity of expression processing) should be already addressed by usage of hash. The second one (planning regression with Bitmap OR) is not yet addressed. Links 1. https://www.postgresql.org/message-id/CAPpHfduJtO0s9E%3DSHUTzrCD88BH0eik= 0UNog1_q3XBF2wLmH6g%40mail.gmail.com ------ Regards, Alexander Korotkov