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 1hydAo-000550-4f for pgsql-general@arkaria.postgresql.org; Fri, 16 Aug 2019 14:25:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hydAm-0001dF-Vc for pgsql-general@arkaria.postgresql.org; Fri, 16 Aug 2019 14:25:44 +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 1hydAm-0001d8-J7 for pgsql-general@lists.postgresql.org; Fri, 16 Aug 2019 14:25:44 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1hydAk-0000VT-7C for pgsql-general@lists.postgresql.org; Fri, 16 Aug 2019 14:25:43 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x7GEPejw011505; Fri, 16 Aug 2019 10:25:40 -0400 From: Tom Lane To: Peter Grman cc: pgsql-general@lists.postgresql.org Subject: Re: Bad Estimate for complex query with JOINS on subselects and OR in where conditions In-reply-to: References: <9725.1565963088@sss.pgh.pa.us> Comments: In-reply-to Peter Grman message dated "Fri, 16 Aug 2019 16:08:57 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <11503.1565965540.1@sss.pgh.pa.us> Date: Fri, 16 Aug 2019 10:25:40 -0400 Message-ID: <11504.1565965540@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Peter Grman writes: > yes, I think this query is right below the geqo_threshold. But as I said, > when I change only the WHERE condition to use AND instead of OR it's > resulting in a really fast and efficient query (same planning time, but > ~1/500th-1/1000th execution time). So there should be something different, > or? Don't really see why that would surprise you. Using AND means that the individual conditions can be applied as filters, if the planner knows how to use any one of them as (say) an indexscan or join qual. When you use OR, that isn't possible. regards, tom lane