Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ah46J-0007zC-8I for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Mar 2016 23:46:39 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1ah46I-0006Y5-Bp for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Mar 2016 23:46:38 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ah46G-0006Xw-KU for pgsql-hackers@postgresql.org; Fri, 18 Mar 2016 23:46:36 +0000 Received: from smtp2.scorpionshops.com ([82.118.24.231] helo=kilimanjaro.scorpionshops.com) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ah469-0007Wu-Gc for pgsql-hackers@postgresql.org; Fri, 18 Mar 2016 23:46:35 +0000 Received: from [192.168.1.4] (92-32-205-89.tn.glocalnet.net [92.32.205.89]) by kilimanjaro.scorpionshops.com (Postfix) with ESMTPSA id 2A5D37BC0D2; Sat, 19 Mar 2016 00:46:27 +0100 (CET) Subject: Re: POC, WIP: OR-clause support for indexes To: Teodor Sigaev , Tomas Vondra References: <567ED6CA.2040504@sigaev.ru> <56D48836.4040301@sigaev.ru> <1457615077.31876.51.camel@2ndquadrant.com> <56EC2EED.5070000@sigaev.ru> Cc: David Rowley , Pgsql Hackers From: Andreas Karlsson Message-ID: <56EC9352.1080807@proxel.se> Date: Sat, 19 Mar 2016 00:46:26 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.6.0 MIME-Version: 1.0 In-Reply-To: <56EC2EED.5070000@sigaev.ru> Content-Type: text/plain; charset=koi8-r; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org I gave this patch a quick spin and noticed a strange query plan. CREATE TABLE test (a int, b int, c int); CREATE INDEX ON test USING gin (a, b, c); INSERT INTO test SELECT i % 7, i % 9, i % 11 FROM generate_series(1, 1000000) i; EXPLAIN ANALYZE SELECT * FROM test WHERE (a = 3 OR b = 5) AND c = 2; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------- Bitmap Heap Scan on test (cost=829.45..4892.10 rows=21819 width=12) (actual time=66.494..76.234 rows=21645 loops=1) Recheck Cond: ((((a = 3) AND (c = 2)) OR ((b = 5) AND (c = 2))) AND (c = 2)) Heap Blocks: exact=5406 -> Bitmap Index Scan on test_a_b_c_idx (cost=0.00..824.00 rows=2100 width=0) (actual time=65.272..65.272 rows=21645 loops=1) Index Cond: ((((a = 3) AND (c = 2)) OR ((b = 5) AND (c = 2))) AND (c = 2)) Planning time: 0.200 ms Execution time: 77.206 ms (7 rows) Shouldn't the index condition just be "((a = 3) AND (c = 2)) OR ((b = 5) AND (c = 2))"? Also when applying and reading the patch I noticed some minor issues/nitpick. - I get whitespace warnings from git apply when I apply the patches. - You have any insconstent style for casts: I think "(Node*)clause" should be "(Node *) clause". - Same with pointers. "List* quals" should be "List *quals" - I am personally not a fan of seeing the "isorderby == false && index->rd_amroutine->amcanorclause" clause twice. Feels like a risk for diverging code paths. But it could be that there is no clean alternative. Andreas -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers