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 1rkMQo-00CACw-Mp for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Mar 2024 11:05:59 +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 1rkMQn-000j9D-3w for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Mar 2024 11:05:57 +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.94.2) (envelope-from ) id 1rkMQm-000j8i-Qs for pgsql-hackers@lists.postgresql.org; Wed, 13 Mar 2024 11:05:57 +0000 Received: from mail-yb1-xb2a.google.com ([2607:f8b0:4864:20::b2a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rkMQj-004HEk-KH for pgsql-hackers@postgresql.org; Wed, 13 Mar 2024 11:05:56 +0000 Received: by mail-yb1-xb2a.google.com with SMTP id 3f1490d57ef6-dd02fb9a31cso4862883276.3 for ; Wed, 13 Mar 2024 04:05:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710327954; x=1710932754; 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=OdtPV2+hChYoBbak9nRlYevT0xElqVZlWBbAxYdu9UY=; b=NrJt3fHuWJFMmGX3EyIKoK2LL0YAdXaUEStgmGLrvLJgHvGnRHgdmYE9v6Ixsl7nE6 VIkfO690u/eOepXK/zRGsOKMTJVjeJGmii564P/hXGko33FQ0bVZqfONeU6DOdKs7tuh fOQT6CUf/dcVsOr9L3EJKvgC7uQxdoSY1GQ++zD6e3xpeqZyDDYXGSnreG5pkT/U9Fhj ATWzTlwO162eNJyWNOCmZp9q8WDnl6gIX9hmPdKtKciQQcFcz2c4SKecKegoFgQajSg4 J8dtL7tQ+Ir8Rft7w7NUJHQH6iZ/FFKwseZRVnrNt8Iz+VTbr8vQQ2CLHfdeN4xZFT/l 1p3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710327954; x=1710932754; 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=OdtPV2+hChYoBbak9nRlYevT0xElqVZlWBbAxYdu9UY=; b=eEASoLsNCSQ4IkcNG2Oqdg7RqyfzGbtoGfQS5ohVlEcKKZcGKJd5ayfYp9xV7+sNbU FRtIYWsDu28PRIcJcJgMM4qc3UqcKaetxW7rK7xZFSiagfLJHr44FSXXCt2dWjdMro8T X9zvIQbnURrb7mi4nclPINmxkmWDrL04/MP0NclHEixoJXlKeAXDPejUULufKNc+Qkcp XwlYZ7lZLbv/oUVUG2E8HiMckcE9DDC1aRCg8OcXBc7CF9V0LGbMbs6scEvjbT8xgXXs Y400hAauR2iJTz6OLrxu/ZOt1NiFOKHbR2oE+O+abs4MOhLFz62QuO7HaWJwRrkdx710 k5Gg== X-Forwarded-Encrypted: i=1; AJvYcCUClOGjqrkjpVeYwRxHBvR2oNMjpXB+SzaCdtk99C32fMGBPwP5Ctb2/X4P6oWJYkvVXsyG76DNcpK15S1aVLzMO7GSaDceuJfdhE4u X-Gm-Message-State: AOJu0Ywf91jUlnC164mhQUbCXeQaBZIaMlgqFFOWCnoHF4tAHZs2MUOV KVJ/uE2AKgcOWEp6akhNsQoIwm8LqIYdfMeLGJM3e7kb2RMVIejVxN9c9mCVEa/LfZSCvsYpRdD 3JQa7rUWSCfVxThZS2P7/46QuMMk= X-Google-Smtp-Source: AGHT+IH7ZjB3gRSvVgCCVZuko4SbDnyOMCZywRKfeOvfVXJbfTUd3rG0nAYK/ayftGhIWd3vzg42sB9QFnabdZo8AJE= X-Received: by 2002:a25:8392:0:b0:dc7:45df:a04c with SMTP id t18-20020a258392000000b00dc745dfa04cmr1947249ybk.43.1710327953868; Wed, 13 Mar 2024 04:05:53 -0700 (PDT) MIME-Version: 1.0 References: <567ED6CA.2040504@sigaev.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> <74e3c8bc-dccd-45e5-ad2d-6a6e96fc5864@postgrespro.ru> In-Reply-To: From: Alexander Korotkov Date: Wed, 13 Mar 2024 13:05:41 +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 On Wed, Mar 13, 2024 at 7:52=E2=80=AFAM Andrei Lepikhov wrote: > On 12/3/2024 22:20, Alexander Korotkov wrote: > > On Mon, Mar 11, 2024 at 2:43=E2=80=AFPM Andrei Lepikhov > >> I think you are right. It is probably a better place than any other to > >> remove duplicates in an array. I just think we should sort and remove > >> duplicates from entry->consts in one pass. Thus, this optimisation > >> should be applied to sortable constants. > > > > Ok. > New version of the patch set implemented all we have agreed on for now. > We can return MAX_SAOP_ARRAY_SIZE constraint and Alena's approach to > duplicates deletion for non-sortable cases at the end. > > > >> Hmm, we already tried to do it at that point. I vaguely recall some > >> issues caused by this approach. Anyway, it should be done as quickly a= s > >> possible to increase the effect of the optimization. > > > > I think there were provided quite strong reasons why this shouldn't be > > implemented at the parse analysis stage [1], [2], [3]. The > > canonicalize_qual() looks quite appropriate place for that since it > > does similar transformations. > Ok. Let's discuss these reasons. In Robert's opinion [1,3], we should do > the transformation based on the cost model. But in the canonicalize_qual > routine, we still make the transformation blindly. Moreover, the second > patch reduces the weight of this reason, doesn't it? Maybe we shouldn't > think about that as about optimisation but some 'general form of > expression'? > Peter [2] worries about the possible transformation outcomes at this > stage. But remember, we already transform clauses like ROW() IN (...) to > a series of ORs here, so it is not an issue. Am I wrong? > Why did we discard the attempt with canonicalize_qual on the previous > iteration? - The stage of parsing is much more native for building SAOP > quals. We can reuse make_scalar_array_op and other stuff, for example. > During the optimisation stage, the only list partitioning machinery > creates SAOP based on a list of constants. So, in theory, it is possible > to implement. But do we really need to make the code more complex? As we currently do OR-to-ANY transformation at the parse stage, the system catalog (including views, inheritance clauses, partial and expression indexes, and others) would have a form depending on enable_or_transformation at the moment of DDL execution. I think this is rather wrong. The enable_or_transformation should be run-time optimization which affects the resulting query plan, its result shouldn't be persistent. Regarding the ROW() IN (...) precedent. 1. AFAICS, this is not exactly an optimization. This transformation allows us to perform type matching individually for every value. Therefore it allows the execute some queries which otherwise would end up with error. 2. I don't think this is a sample of good design. This is rather hack, which is historically here, but we don't want to replicate this experience. Given all of the above, I think moving transformation to the canonicalize_qual() would be the right way to go. ------ Regards, Alexander Korotkov