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 1mlbNA-0001Hz-Ik for pgsql-performance@arkaria.postgresql.org; Fri, 12 Nov 2021 18:34:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mlbN8-0004xF-0h for pgsql-performance@arkaria.postgresql.org; Fri, 12 Nov 2021 18:33:58 +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 1mlbN7-0004x6-H5 for pgsql-performance@lists.postgresql.org; Fri, 12 Nov 2021 18:33:57 +0000 Received: from mail-io1-xd30.google.com ([2607:f8b0:4864:20::d30]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mlbN4-0004x6-0Q for pgsql-performance@lists.postgresql.org; Fri, 12 Nov 2021 18:33:56 +0000 Received: by mail-io1-xd30.google.com with SMTP id f9so12232326ioo.11 for ; Fri, 12 Nov 2021 10:33:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=JfbLz21butDycnXDEpjDTyIVQWeHL5fouJ8HFkT4Occ=; b=rHn0eDEhuEsj1zrVq4nFJpGtz3CAzKVy8nPBoe/WXpon/sjMWIDXAgN9C3YmkjNwhZ w0nwbXuuRb+KTSpgM29fzb6mn9A88qcM1sxYnzizujvXqLjyXPBj7IDwA1cqNbI/JyrD KjIfmwkwobLKi6C2abxXLpc34BCbUswTKXoS0F3V4n2s9CjdRBjBhJaC+fAXA8hm4mY4 IuxWVKCvNWPHTD/xLWnA/tVsrgRntuFfVIfBsM8psKfPmlCAjDO+tC/laAYF6UNvrIpH Rud2RDkyhAUl7OKoHbYsvIMUzUghKDtNkQOpj0dwkXdwk8DwDsBwDpI8yOHJDzVFoJUL cpkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=JfbLz21butDycnXDEpjDTyIVQWeHL5fouJ8HFkT4Occ=; b=ppIrZERrY8YN1XTemp9zzuQeDWPnI4/CuKUNolvhZONnkWi4aE6Hbe8X9IMDb3YHye 7OleJ9ey0TE4yGYH+RP1kHLVYRZ2dcHAUJAPgbnuHUFLtW/E/V+IiKsUNGlGEKFmO1w6 N5V6pa5oyJz8mXUwe7Cqnuo4TZbqUS4XgMDO4K4bEiP+vC8Gr7lbnazrhyh1z2ycKjEE 2Pg8oCuNMLBe9jeI5vYncM6REuk+FJa4eN4dlXcPAZkLKIBCKWWsuJHizDBO857K+AQu zZVjlA6BeYTcTHe2+eh/6sv10uiAbBMJ/737i3WW5HKn2AZ3tlsZYjlL+lQEw+uepsrP pjrg== X-Gm-Message-State: AOAM532WfWYLrvWv9wm9pYmd42YGCYbsuzGXra4CDwF/6mImzNVUQkwk z36N+mPl2MRkPW5HLEnyhT7cSQ== X-Google-Smtp-Source: ABdhPJxCUjdXUJxgOOCVMTP5Rkd3BqKnNYOuhyXMgq9wibSEEkwz3QB48nM9DUZOqlRotrC4yUPaQw== X-Received: by 2002:a05:6602:1549:: with SMTP id h9mr6993930iow.30.1636742032135; Fri, 12 Nov 2021 10:33:52 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id h15sm4620802ili.26.2021.11.12.10.33.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Nov 2021 10:33:51 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 5AED88009C6; Fri, 12 Nov 2021 12:33:50 -0600 (CST) Date: Fri, 12 Nov 2021 12:33:50 -0600 From: Justin Pryzby To: Michael Lewis Cc: =?utf-8?B?SmnFmcOt?= Fejfar , pgsql-performance@lists.postgresql.org Subject: Re: performance of analytical query Message-ID: <20211112183350.GJ17618@telsasoft.com> References: <20211112024151.GF17618@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Nov 12, 2021 at 10:55:53AM -0700, Michael Lewis wrote: > On Thu, Nov 11, 2021 at 7:42 PM Justin Pryzby wrote: > > > BTW, we disable nested loops for the our analytic report queries. I have > > never > > been able to avoid pathological plans any other way. > > Curious, do you see any problems from that? Are there certain nodes that > really are best suited to a nested loop like a lateral subquery? When I first disabled it years ago, I did it for the entire database, and it caused issues with a more interactive, non-analytic query, on a non-partitioned table. So my second attempt was to disable nested loops only during report queries, and I have not looked back. For our report queries on partitioned tables, the overhead of hashing a handful of rows is of no significance. Any query that finishes in 1sec would be exceptionally fast. BTW, Jiří's inquiry caused me to look at the source of one of our historic mis-estimates, and to realize that it's resolved in pg14: https://www.postgresql.org/message-id/20211112173102.GI17618%40telsasoft.com I doubt that's enough to avoid catastrophic nested loop plans in every case (especially CTEs on top of CTEs). There was a discussion about discouraging nested loop plans that weren't provably "safe" (due to returning at most one row, due to a unique index). https://www.postgresql.org/message-id/CA%2BTgmoYtWXNpj6D92XxUfjT_YFmi2dWq1XXM9EY-CRcr2qmqbg%40mail.gmail.com -- Justin