Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ljhPY-0006x0-Gl for pgsql-bugs@arkaria.postgresql.org; Thu, 20 May 2021 12:04:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ljhPW-0005nI-G0 for pgsql-bugs@arkaria.postgresql.org; Thu, 20 May 2021 12:04:18 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ljhPW-0005nA-19 for pgsql-bugs@lists.postgresql.org; Thu, 20 May 2021 12:04:18 +0000 Received: from mxout1.routing.net ([2a03:2900:1:a::a]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ljhPR-0001iZ-U3 for pgsql-bugs@postgresql.org; Thu, 20 May 2021 12:04:17 +0000 Received: from mxbox3.masterlogin.de (unknown [192.168.10.78]) by mxout1.routing.net (Postfix) with ESMTP id 0EA7B3FC27; Thu, 20 May 2021 12:04:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailerdienst.de; s=20200217; t=1621512249; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=qgYgrXTs93aKK5PQYstCDLPv8dYw9p4DH6zgrAKzYwU=; b=W/JicYPmaDBThvepA2+Jcd5dPSRiURd072ji+A01/8GyEKi4EMy/6kryjF0WYV4UOEJUNl qtjb+l+mgQctVcOhGLpwasK9o7/cfgnL7Vbd+r8WixoO4VhyAJJIj9Sm4aby4TNOa+b9u3 +wILZxBqIIDf1iBiSX0CBEXcp6rphBw= Received: from remote.index.de (business-90-187-114-221.pool2.vodafone-ip.de [90.187.114.221]) by mxbox3.masterlogin.de (Postfix) with ESMTPSA id 860723602D1; Thu, 20 May 2021 12:04:08 +0000 (UTC) Received: from acedia.index-gruppe.local (192.168.3.121) by acedia.index-gruppe.local (192.168.3.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 20 May 2021 14:04:07 +0200 Received: from acedia.index-gruppe.local ([fe80::ecd1:5d0a:a834:dd56]) by acedia.index-gruppe.local ([fe80::51b2:7a56:550c:10b7%13]) with mapi id 15.01.2176.012; Thu, 20 May 2021 14:04:07 +0200 From: Arne Roland To: David Rowley , "pg@bowt.ie" CC: Tom Lane , Pg Bugs , "James Coleman" Subject: Re: Less selective index chosen unexpectedly Thread-Topic: Less selective index chosen unexpectedly Thread-Index: AQHXTCWtfiWEMvopoUaGTnzv2xVJ/qrpoU0AgAEihgCAAKsXgIAAt2tA Date: Thu, 20 May 2021 12:04:07 +0000 Message-ID: <6172fc42175b46a88eb3c9e08c253f1a@index.de> References: , In-Reply-To: Accept-Language: en-US, de-DE Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.255.1.33] Content-Type: multipart/alternative; boundary="_000_6172fc42175b46a88eb3c9e08c253f1aindexde_" MIME-Version: 1.0 X-Mail-ID: e4eba969-3bd6-4ad4-ac2a-330ce5ae2312 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --_000_6172fc42175b46a88eb3c9e08c253f1aindexde_ Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable David Rowley wrote: > The planner does often take plenty of other risks. The situation you > describe here is just one of many. Another example is that if we do a > join on say 3 or more conditions that those conditions could be > correlated. We currently always assume they're independent and just > multiply individual selectivities. We could end up thinking that the > join will produce far fewer rows than it actually will. Problems can > arise in subsequent joins. We may end up doing a subsequent join using > a nested loop thinking that only 1 row will be produced from the first > join. That is likely to turn bad if the innermost join instead > produces millions of rows. The n_distinct case is another especially hard one. I go around and set tho= se values by hand all the time. Or how about the gazillion of fallback case= s where the planner gives up estimating any selectivity and just pulls up a= nother constant? We are still living in a world where even the simplest function could cause= one of these "I don't know the selectivity...let's say X0%"-cases. And I am still surprised how well these broad estimates tend to work. While we progressed a lot on that front, and I am grateful for all these fo= lks who worked on the planner, the general problem is way to hard. Getting to a point where I as a human cannot easily find a case where I can= say "Ugh, that cliff is dangerous, don't go ther..." seems impossible to m= e. The underlying problem here is more severe. We make systematic errors and t= he more complex the query gets the more likely it is that we will find a cl= iff to jump. It's not just that we stumble upon one, no we actively search for it. Think= ing about predicate pushing: That stuff can alter the estimated rows of a s= ubquery.