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 1kZftk-0002Uk-3Y for pgsql-performance@arkaria.postgresql.org; Mon, 02 Nov 2020 19:53:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kZftj-00061i-2A for pgsql-performance@arkaria.postgresql.org; Mon, 02 Nov 2020 19:53:47 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kZfti-00061W-My for pgsql-performance@lists.postgresql.org; Mon, 02 Nov 2020 19:53:46 +0000 Received: from mail-il1-x135.google.com ([2607:f8b0:4864:20::135]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kZftf-0006q0-TF for pgsql-performance@postgresql.org; Mon, 02 Nov 2020 19:53:46 +0000 Received: by mail-il1-x135.google.com with SMTP id n5so14034686ile.7 for ; Mon, 02 Nov 2020 11:53:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=gasI+e/DtPa4rKKS/eZODrA/t2UyDoAFys97yiPelUo=; b=INtcvHj3Qq3DQUc2rnsJISbDcOMle1tvbc5gXeEV+3pY6+x223tLabQKdh/3q80Jlg I6B3z14nqPPYshxxQm3ZU/UuYdwuQPWSIjsgWxt2jWkoTjLxMApYS2xNKKlFcybNv9wg r2w9Jgm7xJXHoaE/qVMG87XO4Mx7x0y+huhiUDkylKmCltjCy3uSTOM5cdrCgujjwHG2 d3wj1LQPiA8288FP5M2FQ3h3Ujur6Poq9NDbefh2jCZI/Mzqxjl6HybFK0yyY3YPhJlj X0WVzRV+Xai3KyZDbZCq4dkMbWvu+Po7pqf5rwE8KqteCkDNvDmtAPMgi04eM9OwxXbH NcjA== 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:in-reply-to:user-agent; bh=gasI+e/DtPa4rKKS/eZODrA/t2UyDoAFys97yiPelUo=; b=QdF6Wk/DZiPHJkeRN6CIXvJM6fUogrqRiySEgF8Eu1c8+EiXmukBPbtZizs+INsDZ6 635gdNMLqLieQBDhaQgzDSm57BgDMEpx1Ecrp3T7LERVMrlHm1kVEnWnStawUPzDd5As XxwXfgroTGvL0cOGg77ZBncwwVcnwcqKbKoWQa1LJcZ8AxcKGw7417hTAmxdoY268lmM nabKQQFi4jut/oWYwc7yTS8U1/y8Zd25jfZwjjOysauYd5D3rsuS8lopqI+J6QAAKYyG 93xJ5SS2dD8T1RWpJJaBNvBtcSNDuJrjCyl7tXbm+eFakUwYH+uNWowpzfMX+yzcKixd EIxg== X-Gm-Message-State: AOAM533o09N/dU7ZkcWrCMnUak4+HWAQZTfHICa7jLoazqzTUB/PEohK g7RNxCFN5EOnPuC1tFEfTiqASA== X-Google-Smtp-Source: ABdhPJxyFkBE9lSpMh7ONe/t1tpeL31CD1qD1dOBASK0L55hIqAEN5GGKBYmSL7MJHnukXOqaetztQ== X-Received: by 2002:a05:6e02:1202:: with SMTP id a2mr10894014ilq.89.1604346822081; Mon, 02 Nov 2020 11:53:42 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id y17sm11257205ilj.7.2020.11.02.11.53.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Nov 2020 11:53:41 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 9CAA280084D; Mon, 2 Nov 2020 13:53:39 -0600 (CST) Date: Mon, 2 Nov 2020 13:53:39 -0600 From: Justin Pryzby To: Philip Semanchuk Cc: Guillaume Lelarge , Tomas Vondra , Michael Lewis , pgsql-performance@postgresql.org Subject: Re: Understanding bad estimate (related to FKs?) Message-ID: <20201102195339.GK22691@telsasoft.com> References: <7AC7104E-E233-4CCA-B99E-12197D61A4DD@americanefficient.com> <20201026170405.GT9241@telsasoft.com> <20201029011343.GO5380@telsasoft.com> <20201029224845.ptteqhzq65bh6jsh@development> <44E8D04E-A362-409B-AD2B-1D5860D01B61@americanefficient.com> <482DBA7F-1094-4768-8D45-40936E0D1F63@americanefficient.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <482DBA7F-1094-4768-8D45-40936E0D1F63@americanefficient.com> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Nov 02, 2020 at 02:09:03PM -0500, Philip Semanchuk wrote: > Bien merci, yes, I've visited most of those links and learned an enormous amount from them. I've downloaded many of them for re-reading, including yours. :-) It's helpful to be reminded of them again. > > EXPLAIN ANALYZE tells me what choices the planner made, but it doesn't tell me why the planner made those choices. For instance, Tomas Vondra's post enabled me to calculate how the planner arrived at its estimate of 7 rows for one node of my query. I would prefer not to reverse engineer the planner's calculation, but instead have the planner just tell me. > > If I was able to combine that information with a summary of the planner's algorithm (a lot to ask for!), then I could understand how the planner chose its plan. > > The query I asked about in the original post of this thread has 13 relations in it. IIUC, that's 13! or > 6 billion possible plans. How did the planner pick one plan out of 6 billion? I'm curious, both for practical purposes (I want my query to run well) and also because it's fascinating. I hestitate to suggest it, but maybe you'd want to use ./configure CFLAGS='-DOPTIMIZER_DEBUG=1' which will print out costs of each plan node considered. You could also read in selfuncs.c and costsize.c and related parts of the source. -- Justin