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 1hPUDv-0002yy-LH for pgsql-general@arkaria.postgresql.org; Sat, 11 May 2019 15:47:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hPUDr-0000xM-Vy for pgsql-general@arkaria.postgresql.org; Sat, 11 May 2019 15:47:39 +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 1hPUDr-0000qw-IR for pgsql-general@lists.postgresql.org; Sat, 11 May 2019 15:47:39 +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.89) (envelope-from ) id 1hPUDn-00044L-Eq for pgsql-general@postgresql.org; Sat, 11 May 2019 15:47:37 +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 x4BFlIMk032179; Sat, 11 May 2019 11:47:18 -0400 From: Tom Lane To: bb ddd cc: Adrian Klaver , pgsql-general@postgresql.org Subject: Re: Question about Expected rows value in EXPLAIN output for Nested Loop node In-reply-to: <288922811.129669.1557567206864@nm62.abv.bg> References: <1078310664.976303.1557490584037@nm63.abv.bg> <302576964.978332.1557491557322@nm63.abv.bg> <7ad0fba4-73b3-1459-93a7-a30cdcbb5bb9@aklaver.com> <2072988616.995164.1557503801848@nm63.abv.bg> <288922811.129669.1557567206864@nm62.abv.bg> Comments: In-reply-to bb ddd message dated "Sat, 11 May 2019 12:33:26 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <32177.1557589638.1@sss.pgh.pa.us> Date: Sat, 11 May 2019 11:47:18 -0400 Message-ID: <32178.1557589638@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk bb ddd writes: > Thanks, Adrian, but i was looking for something that goes into more depth. Use the source, Luke. git clone git://git.postgresql.org/git/postgresql.git Likely places to look for this purpose include src/backend/optimizer/README src/backend/optimizer/path/costsize.c src/backend/optimizer/path/clausesel.c src/backend/utils/adt/selfuncs.c The short answer to your question is that no, the size of the join relation is not estimated by multiplying the sizes of input paths for some particular nestloop plan. The join size estimate is made first and the same size is applied to all paths for the join. In the case of a nestloop where the entire join condition was pushed into the RHS path, you'd ideally expect that the LHS size times the estimated size of the filtered RHS path matches the previously-made join size estimate ... but those are different code paths using different estimators, and since this is all very approximate and full of heuristic guesses, sometimes they don't match very well. regards, tom lane