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 1rjdsQ-006sTK-Oe for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Mar 2024 11:31:31 +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 1rjdsO-00CZbo-7f for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Mar 2024 11:31:28 +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 1rjdsN-00CZbg-Uc for pgsql-hackers@lists.postgresql.org; Mon, 11 Mar 2024 11:31:28 +0000 Received: from mail-yb1-xb32.google.com ([2607:f8b0:4864:20::b32]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rjdsL-003vHn-W1 for pgsql-hackers@postgresql.org; Mon, 11 Mar 2024 11:31:27 +0000 Received: by mail-yb1-xb32.google.com with SMTP id 3f1490d57ef6-dd02fb9a31cso2612961276.3 for ; Mon, 11 Mar 2024 04:31:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710156684; x=1710761484; 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=x/YKrFz58DYilHV851Zno9y/aV5CPAwRNG35n/+sXog=; b=TDD5nIX5TapQvOzxi7bUc+ydfLYsUrQqVUVW/TJuLY522wREMVPFwBHD7OhxJFE3s8 QHV4pcYV8FfpzWpWyAEwnZGL2eFkBU7FK6Qhd/S9tgiJMsmXQqGsMjZoBeD1bC0aXhgp Ho33lVmcYJrlRi5Goq5+/taoMYyPis/mfpEt2awDDUAosa73WVzwWu0lZM0b2sksUB0F wUwIzRcwsr1lKtRhcABvsRGpcRJGmJJnrIxfm60iC0Jbdpmx3ijgz/P4KuGCa1v+qsyC ge5F3dr0dMcLAMdcv043FTE+6AywgK266oxAaNjmTr9/rV2y6ER2FS50tAKvINn4XsB0 R/yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710156684; x=1710761484; 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=x/YKrFz58DYilHV851Zno9y/aV5CPAwRNG35n/+sXog=; b=M7paq+pUlTzQDVrKm5lC4cNyyGkHVIrkCwMr9ykUyAJXnKuKu1VRv4DQXzesOwTh22 nAPDdaDeq3v4pY3xw9Ee+/omh8mXVwzSitJwRVwZMFY52L2kIn8B6FMutuZTTe7TCsdi 9joYAMKDcUlv2Ibhy8hMBpxOsHaOGby+KeZ8TLPvQtKBsisN4IFSfMKrRTZ0OTQsdfZM rgtbUUZ+aCd7UoZhA/vm/Nz7kkXgw35JK4AHgE1eyl5+DYEEf00pknAjaMSroBwihkEk KVrSSwwkC8PbQw4a0+LSqBkuVE0u1RYI7V4ZAJRaezElbzH8gYmpmnZF0939DJPZoeLU R1kg== X-Forwarded-Encrypted: i=1; AJvYcCUObnESwNdmr9GhqW24hRXiTQr/TnwuGBZCsfqOwHZwLeHFL3HF205P07ioclCcp1yW/altxjFniEm2Lj4OH6PX6C3sXsdr05l+uhED X-Gm-Message-State: AOJu0YxojgLsSUHAPeHqaEtxH2f8gzRSWQ25Mlf4mPfKgEknrwd6e0bO Q5GG+WfzgiVhgT9r2gU6Asj9xv1NLkxhCtcZpjtcnz//7hOzVgzq0KgLvKDSbxxkxKKTq8c4JbZ 1h9vQ66gjoiaOiBj+RliXkvkZvJtXb37+UcQ= X-Google-Smtp-Source: AGHT+IH1nMNUXpaKyiXf18XGZWLgH+QknUmYaZ1wpAO8PRZnfmaz934vD5U5qB4aAKWn1pYNhk4m9j5N+Sv96BuNZFk= X-Received: by 2002:a25:bcd1:0:b0:dcb:be59:25e1 with SMTP id l17-20020a25bcd1000000b00dcbbe5925e1mr3824629ybm.30.1710156684393; Mon, 11 Mar 2024 04:31:24 -0700 (PDT) MIME-Version: 1.0 References: <567ED6CA.2040504@sigaev.ru> <21088129-7cd3-424a-bcce-6a3427ba3276@postgrespro.ru> <11ee9c04-281f-43c8-a0ff-d481c1e01c09@postgrespro.ru> <54009ba5-4aea-4344-a30d-e3558a59e2a9@postgrespro.ru> <380e5683-cdfd-4220-ab9b-7cccb9d3e480@postgrespro.ru> <7389d0dd-05d5-41b7-a12d-2e73f939f851@postgrespro.ru> In-Reply-To: <7389d0dd-05d5-41b7-a12d-2e73f939f851@postgrespro.ru> From: Alexander Korotkov Date: Mon, 11 Mar 2024 13:31:12 +0200 Message-ID: Subject: Re: POC, WIP: OR-clause support for indexes To: Andrei Lepikhov Cc: jian he , Alena Rybakina , Robert Haas , pgsql-hackers@postgresql.org, Peter Geoghegan , "Finnerty, Jim" , Marcos Pegoraro , teodor@sigaev.ru, Tomas Vondra , Peter Eisentraut , Ranier Vilela 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 Hi Andrei, Thank you for your response. On Mon, Mar 11, 2024 at 7:13=E2=80=AFAM Andrei Lepikhov wrote: > On 7/3/2024 21:51, Alexander Korotkov wrote: > > Hi! > > > > On Tue, Mar 5, 2024 at 9:59=E2=80=AFAM Andrei Lepikhov > > > wrote: > > > On 5/3/2024 12:30, Andrei Lepikhov wrote: > > > > On 4/3/2024 09:26, jian he wrote: > > > ... and the new version of the patchset is attached. > > > > I made some revisions for the patchset. > Great! > > 1) Use hash_combine() to combine hash values. > Looks better > > 2) Upper limit the number of array elements by MAX_SAOP_ARRAY_SIZE. > > I'm not convinced about this limit. The initial reason was to combine > long lists of ORs into the array because such a transformation made at > an early stage increases efficiency. > I understand the necessity of this limit in the array decomposition > routine but not in the creation one. The comment near MAX_SAOP_ARRAY_SIZE says that this limit is because N^2 algorithms could be applied to arrays. Are you sure that's not true for our case? > > 3) Better save the original order of clauses by putting hash entries an= d > > untransformable clauses to the same list. A lot of differences in > > regression tests output have gone. > I agree that reducing the number of changes in regression tests looks > better. But to achieve this, you introduced a hack that increases the > complexity of the code. Is it worth it? Maybe it would be better to make > one-time changes in tests instead of getting this burden on board. Or > have you meant something more introducing the node type? For me the reason is not just a regression test. The current code keeps the original order of quals as much as possible. The OR transformation code reorders quals even in cases when it doesn't eventually apply any optimization. I don't think that's acceptable. However, less hackery ways for this is welcome for sure. > > We don't make array values unique. That might make query execution > > performance somewhat worse, and also makes selectivity estimation > > worse. I suggest Andrei and/or Alena should implement making array > > values unique. > The fix Alena has made looks correct. But I urge you to think twice: > The optimizer doesn't care about duplicates, so why do we do it? > What's more, this optimization is intended to speed up queries with long > OR lists. Using the list_append_unique() comparator on such lists could > impact performance. I suggest sticking to the common rule and leaving > the responsibility on the user's shoulders. I don't see why the optimizer doesn't care about duplicates for OR lists. As I showed before in an example, it successfully removes the duplicate. So, currently OR transformation clearly introduces a regression in terms of selectivity estimation. I think we should evade that. > At least, we should do this optimization later, in one pass, with > sorting elements before building the array. But what if we don't have a > sort operator for the type? It was probably discussed before, but can we do our work later? There is a canonicalize_qual() which calls find_duplicate_ors(). This is the place where currently duplicate OR clauses are removed. Could our OR-to-ANY transformation be just another call from canonicalize_qual()? ------ Regards, Alexander Korotkov