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 1iVN1d-0003CN-B4 for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Nov 2019 21:51:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iVN1Z-0005iF-Ca for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Nov 2019 21:51:33 +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 1iVN1Z-0005i8-0O for pgsql-hackers@lists.postgresql.org; Thu, 14 Nov 2019 21:51:33 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iVN1V-000611-Js for pgsql-hackers@postgresql.org; Thu, 14 Nov 2019 21:51:31 +0000 Received: by mail-wr1-x444.google.com with SMTP id z10so8510688wrs.12 for ; Thu, 14 Nov 2019 13:51:29 -0800 (PST) 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:content-transfer-encoding:in-reply-to :user-agent; bh=SFACaLx8F1oi+bBFexjDSANJ9ShDbFPluV4b5+7fABY=; b=gaDfzfl0Bsp1t3c0xlvb5XuJ0OeJWl7bQUF1rustzH7rm9gyKkkwnWJnPkg4R0Rexr CsKCdfH+aNimDYvIUEbNpbCYJClbzVFfiR/Bylnw9OWGwdZZdIYA73p4yyGm6gXVMzyU lAHwBOJU8YRoaSboJl7GwPFt9fg1+6/ylRIU2bl8+XUhdzoyCYzkzzciECnBjDavkr3r Hk//p9L3r0P07SpgOpU9tSXp3r4FFi52vbzEPg8GV0/3gK+fYGoRrFpHbGLwSmqxqI4k u3yFfZMtxaVTA04fz8WmAoSF70YuSdDfrRxFjhipaAdz1dJA7AREeOAeZ0CCBXdIbSF2 MRLw== 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:content-transfer-encoding :in-reply-to:user-agent; bh=SFACaLx8F1oi+bBFexjDSANJ9ShDbFPluV4b5+7fABY=; b=qmZBZbzOuez5FS2XGAtNXCd9oeJ0Ikvj+kYbgnWUWyjp9rdG6iDrzdzDJz1dXKzGET Pv5kv9P2j+sx4l8jaLT1CuT0jNfhJ+nBtXU2ITbT3PSG9NyA1XI6svrCJrH9fywRXjq7 0Nk13RIWogNyTaHG6vqPhm41ZBLLA4RriEj3cuAPwpAnX0t/cE2GA0HPwlyBr/CSjf3z +4suPHm/w3WY9IEMRPcSdTQg29Z5jx/1mRXJYnHwlWgEjpAYLUMgEyqMy1RHYlUiIaxl W4heGg+00qA0mSowLvaW9gVnvmCNyqwn1hEIQU5VPgOaGyRqw1TwdON1HpHL7/wxQR8m PLXQ== X-Gm-Message-State: APjAAAXtcAlGqBFm8UyoLPrXbcvh1Jj0RMzRbQXbNHDFxD3EKJTjTAFB 60EY+/3lm01KkkYbzmwuQXoRCY3FEA8= X-Google-Smtp-Source: APXvYqyFVhJ69/p9OYdzXuoPgNrQwP2Ii/BBnZbgmVi8uo2RmWP5CKPWI33d6Csn3o/Ucp/jhqdixQ== X-Received: by 2002:adf:94a6:: with SMTP id 35mr10736500wrr.108.1573768287187; Thu, 14 Nov 2019 13:51:27 -0800 (PST) Received: from localhost (ip-86-49-253-92.net.upcbroadband.cz. [86.49.253.92]) by smtp.gmail.com with ESMTPSA id y78sm8001307wmd.32.2019.11.14.13.51.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2019 13:51:26 -0800 (PST) Date: Thu, 14 Nov 2019 22:51:25 +0100 From: Tomas Vondra To: Mark Dilger Cc: PostgreSQL Hackers Subject: Re: Using multiple extended statistics for estimates Message-ID: <20191114215125.awaa77vsihszguqk@development> References: <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> <63781298-77de-bfff-f390-b4bfcdfb720b@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <63781298-77de-bfff-f390-b4bfcdfb720b@gmail.com> User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Nov 14, 2019 at 01:17:02PM -0800, Mark Dilger wrote: > > >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. > No, AFAIK the planner does not do anything like that - it might probaly do that if it could prove there are no such rows, but that's hardly the case for estimates based on approximate information (i.e. statistics). If could do that based on the predicate analysis in predtest.c mentioned by Tom, although I don't think it does anything beyond tweaking the row estimate to ~1 row. >I don't know if you want to expand the scope of this particular patch to >include that, though. > Certainly not. It's an interesting but surprisingly complicated problem, and this patch simply aims to add different improvement. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services