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 1qXqfL-000AWk-MF for pgsql-hackers@arkaria.postgresql.org; Sun, 20 Aug 2023 22:12: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 1qXqeK-0010YW-LB for pgsql-hackers@arkaria.postgresql.org; Sun, 20 Aug 2023 22:11:56 +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 1qXqeJ-0010YM-Tw for pgsql-hackers@lists.postgresql.org; Sun, 20 Aug 2023 22:11:55 +0000 Received: from mail-vk1-xa34.google.com ([2607:f8b0:4864:20::a34]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qXqeG-0002Fy-26 for pgsql-hackers@postgresql.org; Sun, 20 Aug 2023 22:11:53 +0000 Received: by mail-vk1-xa34.google.com with SMTP id 71dfb90a1353d-48d0e739e32so174904e0c.3 for ; Sun, 20 Aug 2023 15:11:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bowt-ie.20221208.gappssmtp.com; s=20221208; t=1692569510; x=1693174310; 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=MgZKocwX7RwWEIFfN8BbDqsI64l/M3PMQzJqAG+qGMY=; b=JakHHnSogAUgSwyfWnf/JzNpnA6/j6SrMGSkh1qkW1+KLHP5anwqBwpg7I3/SErvFQ tsNGIAYlbjAXeFIJXSPHncZe15F3R3uPLbVoEdk2jaYa27D5idE1m6mnVNWIW1n1ajld DZzlqbtImKoCmkzhdq0L/tBk6+X3GsMeSRpcR1RR4fHetCGk+zBfNzZtEKKqDhCO3bO1 E76mABWACmbJl2cpE8uLnkc2z8YjrP8lISjNU0LErCs3UNinlvMPiyKEwd2GzOpbS9uc slfF6uF+GZtDMWIdk37+Hpk5x5dl01vkVTtguAyogNOM+jtaRvBCFtUJPVfAyRs6yFn1 Xbog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692569510; x=1693174310; 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=MgZKocwX7RwWEIFfN8BbDqsI64l/M3PMQzJqAG+qGMY=; b=HmoOi4b7IQp+ktzvEcgyA6lSgXqvfaS1T8cxtcg7D+hiRgDOLJcKiVeeam722dgbXc tZU0bHq7LwjVzqKNMsg/qLsix0cPtDRtspYDf+SSqdwnn9VCT0YLDPok+6rM6hi45JhD Ig4Q+GuSG/xo73QIp5hZcUAEyEkm4kC1/TQdVXRPekCwjh7JKZl4AJGtn88JUpipdHp8 qC01JjtZ1WP60z9YEsgSzoJFLYjI7YMGFBSyM14x+L9uRbOHKCXL+5LJC6rLuW3/Ean8 Dw2pCgdSeJ6ghFbw4iHYD5RcRFZWxGVSTycSvUl+3OV1+d2NGI2QqdZeN0nHhZ4cLa+A aJ8w== X-Gm-Message-State: AOJu0Yxlk0pu8mOg0yAdigq45JsQPg9rRHb//edX1SR1vRTg9vw24HON LsNZUL9HjepmImefSgiV1pFL6dpDy+0WUB0+Xc+Brg== X-Google-Smtp-Source: AGHT+IG4Dxx3aaIoSmwGFADOnPvcSxIZulQTyYZR4IHExP6JWzESeXvEC+iS4MSsV5qe3Isw627z7sIjynsALMJqLao= X-Received: by 2002:a1f:e2c1:0:b0:48d:1ad:c896 with SMTP id z184-20020a1fe2c1000000b0048d01adc896mr2873036vkg.4.1692569510580; Sun, 20 Aug 2023 15:11:50 -0700 (PDT) MIME-Version: 1.0 References: <567ED6CA.2040504@sigaev.ru> <7829312a-eb6b-b9ba-9719-71c9bc410884@yandex.ru> <9ea35f18-419d-efb7-b7c8-2e641a61f020@yandex.ru> <08f5ff34-1497-2123-8701-461a299035c9@yandex.ru> <8d714510-af73-a908-99c8-fc14536f2669@yandex.ru> <4bac271d-1700-db24-74ac-8414f2baf9fd@postgrespro.ru> In-Reply-To: <4bac271d-1700-db24-74ac-8414f2baf9fd@postgrespro.ru> From: Peter Geoghegan Date: Sun, 20 Aug 2023 15:11:24 -0700 Message-ID: Subject: Re: POC, WIP: OR-clause support for indexes To: "a.rybakina" Cc: "Finnerty, Jim" , Marcos Pegoraro , Andrey Lepikhov , pgsql-hackers@postgresql.org, teodor@sigaev.ru, Ranier Vilela , Tomas Vondra 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 Thu, Aug 17, 2023 at 3:08=E2=80=AFAM a.rybakina wrote: > This is an interesting feature. I didn't notice this function before, I s= tudied many times consider_new_or_cause, which were called there. As far as= I know, there is a selectivity calculation going on there, but as far as I= remember, I called it earlier after my conversion, and unfortunately it di= dn't solve my problem with calculating selectivity. I'll reconsider it agai= n, maybe I can find something I missed. Back in 2003, commit 9888192f removed (or at least simplified) what were then called "CNF/DNF CONVERSION ROUTINES". Prior to that point the optimizer README had something about leaving clause lists un-normalized leading to selectivity estimation problems. Bear in mind that this is a couple of years before ScalarArrayOpExpr was first invented. Apparently even back then "The OR-of-ANDs format is useful for indexscan implementation". It's possible that that old work will offer some hints on what to do now. In a way it's not surprising that work in this area would have some impact on selectivies. The surprising part is the extent of the problem, I suppose. I see that a lot of the things in this area are just used by BitmapOr clauses, such as build_paths_for_OR() -- but you're not necessarily able to use any of that stuff. Also, choose_bitmap_and() has some stuff about how it compensates to avoid "too-small selectivity that makes a redundant AND step look like it reduces the total cost". It also mentions some problems with match_join_clauses_to_index() + extract_restriction_or_clauses(). Again, this might be a good place to look for more clues. --=20 Peter Geoghegan