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.92) (envelope-from ) id 1jEEHL-0004EL-UK for pgsql-hackers@arkaria.postgresql.org; Tue, 17 Mar 2020 15:37:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jEEHK-0008QJ-Ft for pgsql-hackers@arkaria.postgresql.org; Tue, 17 Mar 2020 15:37:14 +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 1jEEHJ-0008QB-UO for pgsql-hackers@lists.postgresql.org; Tue, 17 Mar 2020 15:37:14 +0000 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jEEHG-00048B-On for pgsql-hackers@lists.postgresql.org; Tue, 17 Mar 2020 15:37:12 +0000 Received: by mail-wr1-x435.google.com with SMTP id v11so26324796wrm.9 for ; Tue, 17 Mar 2020 08:37:10 -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; bh=uw2HSokLr/6lJhnFsEQt7NEXrJdQ+Ozhyz1KxC4kFJ0=; b=kBstao5YV25+hWE9GiiLo4I/1XRTTaaHIPxzFlUWaUjbpVGrIaS3+WkhWbwyTJmWFV MHeTegRCFRIxdd8LZK9g06+WPhoKDugeSYJpGQh3atdaXf5hGzAwbMjHOuWNhQu5coZ6 JgypQI5pKo2TrqEVk2pRwvlgWe8aDJIRnZu6R7hfNovF9QA4v0OkHaNU25G4RV/yBHFq PzUcWAUw2tD9E7ABmM3tk0IwZdLJnN0JKjiITsa2EMI27uiEa4m6rS8YQ89z+hAaCHaW dsQAuQy5d5VY2JONnFZIrSXEDQ4xZuLcVW7FJorICFUHcdTaOFmTMrKLQOxOrPAA4Bht kDHg== 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; bh=uw2HSokLr/6lJhnFsEQt7NEXrJdQ+Ozhyz1KxC4kFJ0=; b=WI8/J6JkwYIhqL+xUfi4JtzrvtEBqV1idRNbxmhBnv0DalBRWN1Srm2SQ70yeB5dV3 Bctezo886Y4Rr2LyRlTp5NUOmLFzcVZTQlo8CXEV2P3WNgz5HT6cZRN/vriT+m+KfOeP YG6TfMRqsXYvgcdcVynSZzdYjeH7djbIBLZ55nYEsw5ze2ZTwnyJ0nlpjtBdTBD96A4j JzKKUWCw6Mz1lx45nVSFl2SKBI3eVn52MonfvcdmwgafWf2QANTU6XE2+1wgrI+zMX9i Mj7TkHrc16gQyUoS0dvmJwx+fWqmIl9i8l9c9cdxHyzGYQFvLl4wANTNZ8dKj10ZG4oF hd5g== X-Gm-Message-State: ANhLgQ0lIqb/Vi7PbljYBLYZH4e7xB0MmRA+QlfMFMw7bvwTHw0+bwdu qNr49Lxp6refsOYuMQForMTW/w== X-Google-Smtp-Source: ADFU+vszEwLoVKMtd57ECSErlUkyxWZqDCBr+zlwd1xJQ+iIhX/SA7KvIThDuULVEnK/VCzWXY352Q== X-Received: by 2002:adf:e502:: with SMTP id j2mr6640633wrm.259.1584459429206; Tue, 17 Mar 2020 08:37:09 -0700 (PDT) Received: from localhost (ip-86-49-253-92.net.upcbroadband.cz. [86.49.253.92]) by smtp.gmail.com with ESMTPSA id n2sm5217936wrr.62.2020.03.17.08.37.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Mar 2020 08:37:08 -0700 (PDT) Date: Tue, 17 Mar 2020 16:37:06 +0100 From: Tomas Vondra To: Dean Rasheed Cc: Pierre Ducroquet , PostgreSQL Hackers Subject: Re: PATCH: add support for IN and @> in functional-dependency statistics use Message-ID: <20200317153706.z6pdtijr25iyr424@development> References: <20200201142446.aq5zf3gawj3ynrc2@development> <3937607.jCdSCb7NGl@pierred-pdoc> <20200202184134.swoqkqlqorqolrqv@development> <20200312173047.stp55sxoj4sipn7q@development> <20200313160944.aqrbkyf7tkasoxfk@development> <20200314152159.5webesf6pfluatqj@development> <20200314184535.4jgkxcyg5yprvsra@development> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, Mar 17, 2020 at 12:42:52PM +0000, Dean Rasheed wrote: >On Sat, 14 Mar 2020 at 18:45, Tomas Vondra wrote: >> >> I realized there's one more thing that probably needs discussing. >> Essentially, these two clause types are the same: >> >> a IN (1, 2, 3) >> >> (a = 1 OR a = 2 OR a = 3) >> >> but with 8f321bd1 we only recognize the first one as compatible with >> functional dependencies. It was always the case that we estimated those >> two clauses a bit differently, but the differences were usually small. >> But now that we recognize IN as compatible with dependencies, the >> difference may be much larger, which bugs me a bit ... >> >> So I wonder if we should recognize the special form of an OR clause, >> with all Vars referencing to the same attribute etc. and treat this as >> supported by functional dependencies - the attached patch does that. >> MCV lists there's already no difference because OR clauses are >> supported. >> > >Makes sense, and the patch looks straightforward enough. > >> The question is whether we want to do this, and whether we should also >> teach the per-column estimates to recognize this special case of IN >> clause. > >I'm not convinced about that second part though. I'd say that >recognising the OR clause for functional dependencies is sufficient to >prevent the large differences in estimates relative to the equivalent >IN clauses. The small differences between the way that OR and IN >clauses are handled have always been there, and I think that changing >that is out of scope for this work. > Not sure. I think the inconsistency between plan and extended stats may be a bit surprising, but I agree that issue may be negligible. >The other thing that I'm still concerned about is the possibility of >returning estimates with P(a,b) > P(a) or P(b). I think that such a >thing becomes much more likely with the new types of clause supported >here, because they now allow multiple values from each column, where >before we only allowed one. I took another look at the patch I posted >on the other thread, and I've convinced myself that it's correct. >Attached is an updated version, with some cosmetic tidying up and now >with some additional regression tests. > Yeah, I agree that's something we need to fix. Do you plan to push the fix, or do you want me to do it? regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services