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 1hgzlQ-0005aE-CH for pgsql-hackers@arkaria.postgresql.org; Fri, 28 Jun 2019 22:54:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hgzlO-0008VB-U6 for pgsql-hackers@arkaria.postgresql.org; Fri, 28 Jun 2019 22:54:38 +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 1hgzlO-0008V4-Ef for pgsql-hackers@lists.postgresql.org; Fri, 28 Jun 2019 22:54:38 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hgzlH-0006hL-JB for pgsql-hackers@lists.postgresql.org; Fri, 28 Jun 2019 22:54:37 +0000 Received: by mail-wm1-x344.google.com with SMTP id w9so10255292wmd.1 for ; Fri, 28 Jun 2019 15:54:31 -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=b1UbIbBrIBOAU02mu+nAjIWuBygugBbCZ7jd37QjpkE=; b=aC/5JYUZRdAThK/we8n0CAkyudzj+4eSGv8g75Zh/qkfEFXd3eIuUE38uxI5mRW76K iSj0i0Ri0PVYkvNbMW5dRs9bl4mR9oAtzJvBIYHaOrF3SZWm3wxbc95/iHRKeOLiX3zc 5RKI8Vti0sQtCxzL03Pncs2y9typLci7RABAyHW4JvaFKRI3ePKiR3SiRveBLUVjB65k VejJ+8foYrqMy3OkuIIhbq2ouCTaJEdZXlWV7EzW4+VYRQkNO/vlaWJWIHkJcc0mkKHP HZ8IcIBxWGMau+dAlePdlq9LkiWmZGtVZVp2ORTEbGUdfAe0tS3XM3G/swJXYHZDnxD5 XxHA== 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=b1UbIbBrIBOAU02mu+nAjIWuBygugBbCZ7jd37QjpkE=; b=SjVysv2UqvmrSA+LnUN++ISbGuiX++jOJoWEZ1myvhqebTbZNiDrOYSVRhNOz03K44 7nOclMyhtPnQMvlkqMmVe2BxD/enQQkoVKcfVghNHx+gUfVTd9O1xOWXlttRZSMTEeix eB8zuENumNSUg8tpAjx68UnYwUonAPYyjUeYYMYLWRlWgXeEY0/tFrnFQapaire0c2NV PyENDfrpfBqnNIsLyQ2JC/ZUmAD3fCIBLY1dCvsuWaHW/SwQDRS7tvOjMQGlcsIxb74z bt8cufak/YyEXTGcT2amKF6Orj9WO0smHm8+T/2HNgpSjFJiFhaidkYtfksbKt0mCEt5 N0pw== X-Gm-Message-State: APjAAAXi4Clf72FRz0AXFHdY1zv3+AfNuca/QsQEGHqXjfuRJuB/1YLf bIzG14gc2l7RqhnuxAGhO2hFVA== X-Google-Smtp-Source: APXvYqxn18Ii7Iq5UH0aYt7G4FYtu0xOBDoDhW8myyU+867yIYNq6FeaxAUXh2qoD/9IH5L0pm7G5g== X-Received: by 2002:a1c:2c41:: with SMTP id s62mr8593788wms.8.1561762468630; Fri, 28 Jun 2019 15:54:28 -0700 (PDT) Received: from localhost (ip-86-49-253-160.net.upcbroadband.cz. [86.49.253.160]) by smtp.gmail.com with ESMTPSA id f12sm7159815wrg.5.2019.06.28.15.54.24 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 28 Jun 2019 15:54:24 -0700 (PDT) Date: Sat, 29 Jun 2019 00:54:23 +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: <20190628225423.dgtyyux7tlk7p3fk@development> References: <20190628161051.szk2kxmue6yjdmra@development> <4547.1561748599@sss.pgh.pa.us> <20190628195401.frwhcga76rrytbc4@development> <7773.1561752983@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <7773.1561752983@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 04:16:23PM -0400, Tom Lane wrote: >Tomas Vondra writes: >> On Fri, Jun 28, 2019 at 03:03:19PM -0400, Tom Lane wrote: >>> 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. > >Uh ... we already determined that the qual is indexable (ie is a member >of the index's opclass), or allowed the index AM to derive an indexable >clause from it, so I'm not sure what you envision would happen >additionally there. If I understand what Julien is concerned about >--- and I may not --- it's that the set of indexable clauses *as a whole* >may have or lack properties of interest. So I'm thinking the answer >involves some callback that can do something to the whole list, not >qual-at-a-time. We've already got facilities for the latter case. > I'm not sure I understand the problem either. I don't think "indexable" is the thing we care about here - in Julien's original example the qual with '%a%' is indexable. And we probably want to keep it that way. The problem is that evaluating some of the quals may be inefficient with a given index - but only if there are other quals. In Julien's example it makes sense to just drop the '%a%' qual, but only when there are some quals that work with the trigram index. But if there are no such 'good' quals, it may be better to keep al least the bad ones. So I think you're right we need to look at the list as a whole. >> But that kinda resembles stuff we already have - selectivity/cost. So >> why shouldn't this be considered as part of costing? > >Yeah, I'm not entirely convinced that we need anything new here. >The cost estimate function can detect such situations, and so can >the index AM at scan start --- for example, btree checks for >contradictory quals at scan start. There's a certain amount of >duplicative effort involved there perhaps, but you also have to >keep in mind that we don't know the values of run-time-determined >comparison values until scan start. So if you want certainty rather >than just a cost estimate, you may have to do these sorts of checks >at scan start. > Right, that's why I suggested doing this as part of costing, but you're right scan start would be another option. I assume it should affect cost estimates in some way, so the cost function would be my first choice. But does the cost function really has enough info to make such decision? For example, ignoring quals is valid only if we recheck them later. For GIN that's not an issue thanks to the bitmap index scan. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services