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 1shRSW-001S5l-Ku for pgsql-hackers@arkaria.postgresql.org; Fri, 23 Aug 2024 10:23:56 +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 1shRSU-00BbeM-Md for pgsql-hackers@arkaria.postgresql.org; Fri, 23 Aug 2024 10:23:55 +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 1shRSU-00BbeC-Cr for pgsql-hackers@lists.postgresql.org; Fri, 23 Aug 2024 10:23:54 +0000 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1shRSR-0015ym-FD for pgsql-hackers@postgresql.org; Fri, 23 Aug 2024 10:23:54 +0000 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-42809d6e719so13501265e9.3 for ; Fri, 23 Aug 2024 03:23:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724408631; x=1725013431; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=ynhA1mDXfnC43VKq+D5EZ/MiShPH92ugp2b+zBqPFAU=; b=Tfv/hvY5FZ/mq8KCAOaEAK844w8a/GQQurHMIGhvUbFQX1+6Yn/dvlp+63fhrD83YI 8A73D011gLtaTtk7xfgl+974gY+84wcJFElB+n7HwziYb8AWo+S9Q3Z76jU2I4VgLd4m TJ3aDloG2S6ncqwd7W8gHDCmVGvuZI0yBzN/kIM8ffkbvsnhA2O/Ae2PdukbO1nFrFx7 7PZnZ3poMh4xD/4Dc/M76zJ0/v+IsVGhgOqk9cjrn3GgVUjWZLSwHdRB2uW7MKCx6T7a +PWxonS48BSRDftzKF8adDzoYWY1we4fYszv83aUJMlahAwtifZgZE6uiCOKNdjrWGR0 jzuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724408631; x=1725013431; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ynhA1mDXfnC43VKq+D5EZ/MiShPH92ugp2b+zBqPFAU=; b=FjUQzqehq/k3HNqsmioVObfakF3ynmJ0Xv+WTkzACwzfagBtXsSs7Z7zz59DKHf/qN pjK5C5URFzWG6jp1FfANJGTebj9xK2JxvHhaCwY7WMLnd+ePRq87gVjXLonPHpuTng2R JJuGnfB+s6xld+2fSd76ZpaVYgR7UlaJdhveDrvqWHXs6pByiioPJICyY3OzwDt+N8rw nH/Wr/NiL3up8Ul/ikk/YPffX8xc7klvL9Aac9FYx9hAcDd+LCp/vbSRpeVOBBCluuKx wYWrCNc4CiTDuQY6hsvSUkMA0JNhV/R+qaMoezYa0m+xg3/lHig6rkNFb11MTMQfvfJX sUXA== X-Forwarded-Encrypted: i=1; AJvYcCWz5l4QnEPp7B2lU1j3JbppVo/aT57AsJwujHPTga0bEWpc0mkpZtUnDxLK9xCNGDTAxQNs2veckJvlZY7e@postgresql.org X-Gm-Message-State: AOJu0YwL/7W4n712I3kAn3/1HBPdcdqX3+wyvhDgKsBOJVcIeU7zglZR NjN8+Xp98c/K1U5LGesEKikUR4iKH/19i+rsmB3qex0r1Auc+3bs X-Google-Smtp-Source: AGHT+IGnIlAMEORAgwWDzJSz/4rCLNHEXf+5Se3vTQ/E8GlYEu0jJd6aYHhIMwuSuvPKGlJln8cW9w== X-Received: by 2002:a05:600c:17d6:b0:42a:a70e:3108 with SMTP id 5b1f17b1804b1-42acc8ff914mr12935375e9.24.1724408630956; Fri, 23 Aug 2024 03:23:50 -0700 (PDT) Received: from ?IPV6:2a0c:5a83:4c09:9d00:e0ec:ccb3:c7cc:53a7? ([2a0c:5a83:4c09:9d00:e0ec:ccb3:c7cc:53a7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42ac5162347sm54386435e9.23.2024.08.23.03.23.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 23 Aug 2024 03:23:50 -0700 (PDT) Message-ID: <670d1dc2-a280-4cf6-bc29-e2eafb107081@gmail.com> Date: Fri, 23 Aug 2024 12:23:49 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: POC, WIP: OR-clause support for indexes To: Alexander Korotkov Cc: Alena Rybakina , Nikolay Shaplov , pgsql-hackers@lists.postgresql.org, jian he , Robert Haas , pgsql-hackers@postgresql.org, Peter Geoghegan , Marcos Pegoraro , teodor@sigaev.ru, Peter Eisentraut , Ranier Vilela References: <567ED6CA.2040504@sigaev.ru> <8969055.VV5PYv0bhD@thinkpad-pgpro> <38289f6c-b8c0-4713-8fb5-703fe771872a@postgrespro.ru> <759292d5-cb51-4b12-89fa-576c1d9b374d@postgrespro.ru> <531fc0ab-371e-4235-97e3-dd2d077b6995@postgrespro.ru> <65bfdcb6-0f0c-4d4c-a721-cb38a0ba91c7@postgrespro.ru> Content-Language: en-US From: Andrei Lepikhov In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 21/8/2024 16:52, Alexander Korotkov wrote: >> /* Only operator clauses scan match */ >> Should it be: >> /* Only operator clauses can match */ >> ? > > Corrected, thanks. I found one more: /* Only operator clauses scan match */ - in the second patch. Also I propose: - “might match to the index as whole” -> “might match the index as a whole“ - Group similar OR-arguments intro dedicated RestrictInfos -> ‘into’ > >> The second one: >> When creating IndexClause, we assign the original and derived clauses to >> the new, containing transformed array. But logically, we should set the >> clause with a list of ORs as the original. Why did you do so? > > I actually didn't notice that. Corrected to set the OR clause as the > original. That change turned recheck to use original OR clauses, > probably better this way. Also, that change spotted misuse of > RestrictInfo.clause and RestrictInfo.orclause in the second patch. > Corrected this too. New findings: ============= 1) if (list_length(clause->args) != 2) return NULL; I guess, above we can 'continue' the process. 2) Calling the match_index_to_operand in three nested cycles you could break the search on first successful match, couldn't it? At least, the comment "just stop with first matching index key" say so. 3) I finally found the limit of this feature: the case of two partial indexes on the same column. Look at the example below: SET enable_indexscan = 'off'; SET enable_seqscan = 'off'; DROP TABLE IF EXISTS test CASCADE; CREATE TABLE test (x int); INSERT INTO test (x) SELECT * FROM generate_series(1,100); CREATE INDEX ON test (x) WHERE x < 80; CREATE INDEX ON test (x) WHERE x > 80; VACUUM ANALYZE test; EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF) SELECT * FROM test WHERE x=1 OR x = 79; EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF) SELECT * FROM test WHERE x=91 OR x = 81; EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF) SELECT * FROM test WHERE x=1 OR x = 81 OR x = 83; The last query doesn't group clauses into two indexes. The reason is in match_index_to_operand which classifies all 'x=' to one class. I'm not sure because of overhead, but it may be resolved by using predicate_implied_by to partial indexes. -- regards, Andrei Lepikhov