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 1iVMUJ-0001y1-UW for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Nov 2019 21:17:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iVMUH-0004Ii-Bk for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Nov 2019 21:17:09 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1iVMUH-0004Ib-0L for pgsql-hackers@lists.postgresql.org; Thu, 14 Nov 2019 21:17:09 +0000 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iVMUE-0007yc-Bu for pgsql-hackers@postgresql.org; Thu, 14 Nov 2019 21:17:08 +0000 Received: by mail-pl1-x631.google.com with SMTP id ay6so3230205plb.0 for ; Thu, 14 Nov 2019 13:17:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=QBJWNu3HmyiCq2EBrr4ossZJx9mw5H8L2H1ucH5RoOQ=; b=l1RemZa4B2QjaLWFzrnw/AB1tlg5q0wDHy0FsYjeQ7H8QVnIB1q5LwsMYLfKLDGzL6 KD4mGIZ1YM1vWQ2TRIkiDFFfpac8AY5vFCEa8sUQV0ZRIoKamNepQ4BTLhwaSo0JTgXH /51gvCMvRv0/a1G0hYZm0Tzh2eSoP+K2T2zh7SK/w9P89Hs/Qh0+a1W/sBApBDQKOReI bFXCv9psOvZv69Q7yBa8dkAv9fPaIXjVmCSpyUGeWxwkmyqlLJfVyhpFHK3KyvWHSgiN 9XWYhaPmrQ72WCBsVyupFMBJdl602Xby45Zz6iuB0B0co6x60FU2RP7/MfTTWva2RFV+ QlQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=QBJWNu3HmyiCq2EBrr4ossZJx9mw5H8L2H1ucH5RoOQ=; b=IbPaHXtO/R3eL/EL5mYlAaSs2ROMnP+fkv+RmWqP7oL5KiVPczGk/V4g75VIix4ZzX 0njkz3V4nbOimRUKSlJhwazB1EK7NESyo1kjhN3rpc8hoSuRmUNKfmzmurheO3WtmYiH JIm9mAVmmTI6MknoNpce74lnDX0WhL/uVh21R0jeVbQd7QNKZHVk51eykHVXCv5v8W4s aMLcniCmUkXwCEJv8rDDNztMqvRFl0n68c7coVfhinCW40/bBVY4uWbN57/c/tu+1Ee8 Whwx6gEda8EFdP/+SWBUkW3vFhtUcwB2+IB7rh6jl9HpwwMTSxAWRp0rloPxkBANXmjn 3AjQ== X-Gm-Message-State: APjAAAWPTmrpSsn64qK87vpYRuZSOBQUm3yzK0hsI03hpPP/jMO59eQ/ rrRC3X4eF/TaAA4n+Ig633fTDbhk X-Google-Smtp-Source: APXvYqx/QIK9y2EWmbk3g71HXGCADuOeehh6ryhwfQgFQVcWG9DigzlCvFXSTVM+TbU29XYnIN9pWA== X-Received: by 2002:a17:902:bb83:: with SMTP id m3mr2064800pls.94.1573766223846; Thu, 14 Nov 2019 13:17:03 -0800 (PST) Received: from [192.168.0.17] (24-113-193-150.wavecable.com. [24.113.193.150]) by smtp.gmail.com with ESMTPSA id l93sm6821907pjb.6.2019.11.14.13.17.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Nov 2019 13:17:03 -0800 (PST) Subject: Re: Using multiple extended statistics for estimates To: Tomas Vondra Cc: PostgreSQL Hackers References: <20191028152048.jc6pqv5hb7j77ocp@development> <20191106195440.wtxsyhiwdidl37hv@development> <20191106195849.odhhc66xd23hw6hf@development> <97932e1d-53f1-bad3-efc2-1d98cab70727@gmail.com> <0da76f1f-5f9c-3ce3-3ac6-042d2a18430a@gmail.com> <20191110173428.w5klequcmb6gawaa@development> <20191113152823.jdpertc73gfo2mk7@development> <2e183f8d-1304-6024-90de-1017a861a235@gmail.com> <20191114155541.zliellgi2if4bb5f@development> <20191114200420.c3x2jf7ywzs23uzo@development> From: Mark Dilger Message-ID: <63781298-77de-bfff-f390-b4bfcdfb720b@gmail.com> Date: Thu, 14 Nov 2019 13:17:02 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.1 MIME-Version: 1.0 In-Reply-To: <20191114200420.c3x2jf7ywzs23uzo@development> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 11/14/19 12:04 PM, Tomas Vondra wrote: > Aha, I think I understand now - thanks for the explanation. You're right > the comment is trying to explain why just taking the last clause for a > given attnum is fine. I'll try to make the comment clearer. > > For the case with equal Const values that should be mostly obvious, i.e. > "a=1 AND a=1 AND a=1" has the same selectivity as "a=1". > > The case with different Const values is harder, unfortunately. It might > seem obvious that "a=1 AND a=2" means there are no matching rows, but > that heavily relies on the semantics of the equality operator. And we > can't simply compare the Const values either, I'm afraid, because there > are cases with cross-type operators like > >  a = 1::int AND a = 1.0::numeric > > where the Consts are of different type, yet both conditions can be true. > > So it would be pretty tricky to do this, and the current code does not > even try to do that. > > Instead, it just assumes that it's mostly fine to overestimate, because > then at runtime we'll simply end up with 0 rows here. I'm unsure whether that could be a performance problem at runtime. I could imagine the planner short-circuiting additional planning when it finds a plan with zero rows, and so we'd save planner time if we avoid overestimating. I don't recall if the planner does anything like that, or if there are plans to implement such logic, but it might be good not to rule it out. Tom's suggestion elsewhere in this thread to use code in predtest.c sounds good to me. I don't know if you want to expand the scope of this particular patch to include that, though. -- Mark Dilger