Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ahRU8-0005ka-VO for pgsql-hackers@arkaria.postgresql.org; Sun, 20 Mar 2016 00:44:49 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1ahRU8-00024O-EY for pgsql-hackers@arkaria.postgresql.org; Sun, 20 Mar 2016 00:44:48 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ahRU5-00023Z-LY for pgsql-hackers@postgresql.org; Sun, 20 Mar 2016 00:44:45 +0000 Received: from mail-wm0-x22c.google.com ([2a00:1450:400c:c09::22c]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1ahRU1-0002tP-Ue for pgsql-hackers@postgresql.org; Sun, 20 Mar 2016 00:44:43 +0000 Received: by mail-wm0-x22c.google.com with SMTP id l68so81993372wml.1 for ; Sat, 19 Mar 2016 17:44:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=vGs5/QpCnjiAqdFw9+jpDbLAVqHAUsqTRyhSdX194oI=; b=AiQKD+ccEMO54UfMb/Ux9nbMOgTsBf3goqafZx10J9t731+0GcyMhQ4REXVvm15m+C Hdfe/QCtJ+equa+GouopQmQ0pcNkBB5qEV5y1wmzRm90y2BvAwzG5UnQw8kU1OK7RHhn Tbw2yaKUyTxqZEtl/4d6FN+D8Ic8B6qFPrcYFsqIBirW8IWQTE/9Fs8WAN1ATBpHorTF gJ0ZLOgSyRjSnaKTDFmMipT59/KHbK/+nLmjKGYOTM1tshmYxuOEagn0Gpm4jdoV136G z+ID2eVraIoEJE34IE9IqJmNB7/Lmck1yyehyONCB6oFfsSFdZJZPMfaLrUKvF2hpkD9 ITZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=vGs5/QpCnjiAqdFw9+jpDbLAVqHAUsqTRyhSdX194oI=; b=Mi96JoOqdnKuIO0II+/IFmP5NLeRpgru3j/qdROm/6de9LSxltgMrPafenD7wQZzMh puwYQxLdw+7BYFMeP0K/bVNeoGsDTZtEkFqcwp1IXCBEpej9/iVTMnd7Ma1ocaysQKJp qp6OhEN3n4pLfpjnv7wOIE3sTktvk66+3y77SIYkWPWKG/3JbUt6sPJAkYuGP8dEJDr+ do/XEQGVGibgy+ub68DesE+28kA7bXV0fPrC02JDPM36ubox3Bw4aDGWnVkSJeKfEpRq 61WsVADH8xpuR9Fl15lZse1wVxTU52ZH59nKISrs9ha9XHQJpb198yEV3NgW0PAP63XO SJ3g== X-Gm-Message-State: AD7BkJImrOL/cG2sh4lBPmYDvMPuRJRHy/BHRWVTC47K5jnD0d1RLfyYZmhXjOJL+rM5rcLx+97ZhFKrL5qQgTIAKYR9eqflEFIWW5gYMSJnVw2IG6J8E/xy7CrxNMSkqP5Vwm0pwJU8zRVkVMJkkFDjiP5wrt34sOIm5onfHJlHLNGXtzGSBirfXOkYZQrPsO8fFJQvOq9G X-Received: by 10.28.174.8 with SMTP id x8mr6427137wme.49.1458434680192; Sat, 19 Mar 2016 17:44:40 -0700 (PDT) Received: from [10.137.2.17] (ip-78-45-216-26.net.upcbroadband.cz. [78.45.216.26]) by smtp.gmail.com with ESMTPSA id t7sm18584562wjf.39.2016.03.19.17.44.38 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 19 Mar 2016 17:44:39 -0700 (PDT) Subject: Re: POC, WIP: OR-clause support for indexes To: Teodor Sigaev References: <567ED6CA.2040504@sigaev.ru> <56D48836.4040301@sigaev.ru> <1457615077.31876.51.camel@2ndquadrant.com> <56EAE73B.3010603@sigaev.ru> Cc: David Rowley , Pgsql Hackers From: Tomas Vondra Message-ID: <0c2fb2ac-332d-6c70-3128-34ba9d13f7e5@2ndquadrant.com> Date: Sun, 20 Mar 2016 01:44:37 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:46.0) Gecko/20100101 Thunderbird/46.0a2 MIME-Version: 1.0 In-Reply-To: <56EAE73B.3010603@sigaev.ru> Content-Type: text/plain; charset=koi8-r; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) 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 Hi Teodor, Sadly the v4 does not work for me - I do get assertion failures. For example with the example Andreas Karlsson posted in this thread: CREATE EXTENSION btree_gin; 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; It seems working, but only until I run ANALYZE on the table. Once I do that, I start getting crashes at this line *qualcols = list_concat(*qualcols, list_copy(idx_path->indexqualcols)); in convert_bitmap_path_to_index_clause. Apparently one of the lists is T_List while the other one is T_IntList, so list_concat() errors out. My guess is that the T_BitmapOrPath branch should do oredqualcols = list_concat(oredqualcols, li_qualcols); ... *qualcols = list_concat(qualcols, oredqualcols); instead of oredqualcols = lappend(oredqualcols, li_qualcols); ... *qualcols = lappend(*qualcols, oredqualcols); but once I fixed that I got some other assert failures further down, that I haven't tried to fix. So the patch seems to be broken, and I suspect this might be related to the broken index condition reported by Andreas (although I don't see that - I either see correct condition or assertion failures). On 03/17/2016 06:19 PM, Teodor Sigaev wrote: ... >> >> 7) I find it rather ugly that the paths are built by converting BitmapOr >> paths. Firstly, it means indexes without amgetbitmap can't benefit from >> this change. Maybe that's reasonable limitation, though? > I based on following thoughts: > 1 code which tries to find OR-index path will be very similar to existing > generate_or_bitmap code. Obviously, it should not be duplicated. > 2 all existsing indexes have amgetbitmap method, only a few don't. > amgetbitmap > interface is simpler. Anyway, I can add an option for generate_or_bitmap > to use any index, but, in current state it will just repeat all work. I agree that the code should not be duplicated, but is this really a good solution. Perhaps a refactoring that'd allow sharing most of the code would be more appropriate. >> >> But more importantly, this design already has a bunch of unintended >> consequences. For example, the current code completely ignores >> enable_indexscan setting, because it merely copies the costs from the >> bitmap path. > > I'd like to add separate enable_indexorscan That may be useful, but why shouldn't enable_indexscan=off also disable indexorscan? I would find it rather surprising if after setting enable_indexscan=off I'd still get index scans for OR-clauses. > >> That's pretty dubious, I guess. So this code probably needs to be made >> aware of enable_indexscan - right now it entirely ignores startup_cost >> in convert_bitmap_path_to_index_clause(). But of course if there are >> multiple IndexPaths, the enable_indexscan=off will be included multiple >> times. ... and it does not address this at all. I really doubt a costing derived from the bitmap index scan nodes will make much sense - you essentially need to revert unknown parts of the costing to only include building the bitmap once, etc. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers