Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hgwwn-0005eu-MJ for pgsql-hackers@arkaria.postgresql.org; Fri, 28 Jun 2019 19:54:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hgwwl-0001xI-3d for pgsql-hackers@arkaria.postgresql.org; Fri, 28 Jun 2019 19:54:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hgwwk-0001xB-Ju for pgsql-hackers@lists.postgresql.org; Fri, 28 Jun 2019 19:54:10 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hgwwg-00056E-B2 for pgsql-hackers@lists.postgresql.org; Fri, 28 Jun 2019 19:54:09 +0000 Received: by mail-wm1-x343.google.com with SMTP id 207so10182244wma.1 for ; Fri, 28 Jun 2019 12:54:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=sCy50N2RiDk6qSQDQsPp+/pLvv5x1+egipLhqoWvL7U=; b=mWruVBmTsiFyrBK0pczsdV3OmTDwv7piEU/HV0KaF3vAg3j4Br/x5o5kBra6b7vXAY hLLBCNhCBam7KjmuQV7ZrKQZOkUcmlRD3Y5Bjq3ezlc0qSFHz2bWRq7BrNYtoxBwtMaz a51vnETcPVj+OZp85jYLArz82a1wuKz4u/hvHFarxf2mHUi4D9mcFQLepHIHQQi818Vl 7LRwPk4O8sVl50HSP1jGRTT9+WFt+VwxWbTlx0Be419tJZhukZzt9wf2s2PzExAve8LH DaLrCzBWlxcAd1zNnbFcH6FU3jY4V0bK/jfOAHdXJL6anHuK3OgF6Q+NqvnlHHW8wX+A tIWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=sCy50N2RiDk6qSQDQsPp+/pLvv5x1+egipLhqoWvL7U=; b=KUA5VHRIyqn5NmDp/CYYiEOWYbyb9CCzN6vVK91V/yIBMmRYKEY07AVNOH9lllMnmV RD9yvnT2z2gS0xuMLNhFGRpedQLv8mqIdb3Tv/wG/8j6Ysjmei2MXFpPFER1PijzOER7 3scfWB1e2PIPEQdAwRShrdgqZTRw3ZlJbNRA3LAUW0Qhc139MGKUN4vrYujfuhk8krtB xNNnAqzcVqOGGUF+XovffrkIe3Mb9w+/+oeMEWaJQKbG8eH0/sZgQ9I0mhutyC9ZJlns N9/KtY0cf7DzGSqv3CanZ3siCi5xxqu5znrG7dvNRMT/tVIi/OviuTs79g0CkYo67ljN ++bw== X-Gm-Message-State: APjAAAUeDKyMHaCMmYh73WDczS7ECBi4r0q8LWbGoMhMaZQU9YrpID4m +TquQ/J6fHnkUPnJ6lDOOISI7w== X-Google-Smtp-Source: APXvYqxg0hcXwSSBTM2nrrQ/9ny4dDe8jBHZ2WdHEoAL9DGK7uo9/i7PICkc+dvnAKi3Xd8pqQOuNA== X-Received: by 2002:a1c:63d7:: with SMTP id x206mr8381629wmb.19.1561751644088; Fri, 28 Jun 2019 12:54:04 -0700 (PDT) Received: from localhost (ip-86-49-253-160.net.upcbroadband.cz. [86.49.253.160]) by smtp.gmail.com with ESMTPSA id s3sm4159208wmh.27.2019.06.28.12.54.03 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 28 Jun 2019 12:54:03 -0700 (PDT) Date: Fri, 28 Jun 2019 21:54:01 +0200 From: Tomas Vondra To: Tom Lane Cc: Julien Rouhaud , PostgreSQL Hackers , Marc Cousin Subject: Re: Avoid full GIN index scan when possible Message-ID: <20190628195401.frwhcga76rrytbc4@development> References: <20190628161051.szk2kxmue6yjdmra@development> <4547.1561748599@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <4547.1561748599@sss.pgh.pa.us> User-Agent: NeoMutt/20180716-1444-295967 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, Jun 28, 2019 at 03:03:19PM -0400, Tom Lane wrote: >Julien Rouhaud writes: >> On Fri, Jun 28, 2019 at 6:10 PM Tomas Vondra >> wrote: >>> 2) I'm not sure it's a good idea to add dependency on a specific AM type >>> into indxpath.c. At the moment there are only two places, both referring >>> to BTREE_AM_OID, do we really hard-code another OID here? >>> >>> I wonder if this could be generalized to another support proc in the >>> inde AM API, with just GIN implementing it. > >> Yes, this patch was more a POC than anything, to discuss the approach >> before spending too much time on infrastructure. I considered another >> support function, but I'm still unclear of how useful it'd be for >> custom AM (as I don't see any use for that for the vanilla one I >> think), or whether if this should be opclass specific or not. > >I just spent a lot of sweat to get rid of (most of) indxpath.c's knowledge >about specific AMs' capabilities; I'd be very sad if we started to put any >back. Aside from being a modularity violation, it's going to fall foul >of the principle that if index AM X wants something, some index AM Y is >going to want it too, eventually. > >Also, I'm quite unhappy about including index_selfuncs.h into indxpath.c >at all, never mind whether you got the alphabetical ordering right. >I have doubts still about how we ought to refactor the mess that is >*selfuncs.c, but this isn't going in the right direction. > Right. >>> 3) selfuncs.c is hardly the right place for gin_get_optimizable_quals, >>> as it's only for functions computing selectivity estimates (and funcs >>> directly related to that). And the new function is not related to that >>> at all, so why not to define it in indxpath.c directly? > >I not only don't want that function in indxpath.c, I don't even want >it to be known/called from there. If we need the ability for the index >AM to editorialize on the list of indexable quals (which I'm not very >convinced of yet), let's make an AM interface function to do it. > Wouldn't it be better to have a function that inspects a single qual and says whether it's "optimizable" or not? That could be part of the AM implementation, and we'd call it and it'd be us messing with the list. That being said, is this really a binary thing - if you have a value that matches 99% of rows, that probably is not much better than a full scan. It may be more difficult to decide (compared to the 'short trigram' case), but perhaps we should allow that too? Essentially, instead of 'optimizable' returning true/false, it might return value between 0.0 and 1.0, as a measure of 'optimizability'. But that kinda resembles stuff we already have - selectivity/cost. So why shouldn't this be considered as part of costing? That is, could gincostestimate look at the index quals and decide what will be used for scanning the index? Of course, this would make the logic GIN-specific, and other index AMs would have to implement their own version ... regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services