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 1hycXJ-0003Zn-1v for pgsql-general@arkaria.postgresql.org; Fri, 16 Aug 2019 13:44:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hycXH-0002Za-R1 for pgsql-general@arkaria.postgresql.org; Fri, 16 Aug 2019 13:44:55 +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 1hycXH-0002Vt-F4 for pgsql-general@lists.postgresql.org; Fri, 16 Aug 2019 13:44:55 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hycXF-0001p1-A3 for pgsql-general@lists.postgresql.org; Fri, 16 Aug 2019 13:44:55 +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 x7GDim3N009726; Fri, 16 Aug 2019 09:44:49 -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: Comments: In-reply-to Peter Grman message dated "Fri, 16 Aug 2019 13:39:09 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <9724.1565963088.1@sss.pgh.pa.us> Date: Fri, 16 Aug 2019 09:44:48 -0400 Message-ID: <9725.1565963088@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Peter Grman writes: > our ORM with tenant separation enabled is creating the following query: Ugh. By my count there are nine joined tables in that query, which means you're hitting the default join_collapse_limit. Increasing that setting might improve matters somewhat, though it won't fix the bad rowcount estimate per se. regards, tom lane