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 1p7M9P-00027r-1D for pgsql-performance@arkaria.postgresql.org; Mon, 19 Dec 2022 19:50:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p7M9N-0003Fr-KJ for pgsql-performance@arkaria.postgresql.org; Mon, 19 Dec 2022 19:50:13 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p7M9N-0003EN-71 for pgsql-performance@lists.postgresql.org; Mon, 19 Dec 2022 19:50:13 +0000 Received: from mail-il1-x132.google.com ([2607:f8b0:4864:20::132]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1p7M9F-0002Vb-Hz for pgsql-performance@lists.postgresql.org; Mon, 19 Dec 2022 19:50:11 +0000 Received: by mail-il1-x132.google.com with SMTP id d10so5261878ilc.12 for ; Mon, 19 Dec 2022 11:50:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=JT0rJJaVsTZb5TVKKtykJBN6iGIafa+AWfk0N/SJIG4=; b=ahr1rkxgcQF3gAYO6iJRnn3BVxB4kfZHGicZ2/yYXUSoNxEGo17eDz1MpNieWBuv86 PBg+CE9uVoNhtcwd1EzyB9n8P6Po6L81gex+F0z4A6DIrMK4itolKVB5w7PNpCxIrtze oJITU66IJ9znMgBAGGNjOGkQj23LhAyiCp6flHKsX+kOr7CnrWe9Ne4zZg31FyCbKwWT TR0a3CkZRxee/EgwfRngtDN5rnHakMVLD/lxa8vVP7S/nSsfNm/aaKH6t+nMEnBWoAo9 JLAE5kNg/lis9cC8RnJC2KMrNQnqf9Y2RqPNdqIBtGdkLnCJ8zIv/zK3dqqsDb/SQpqB 6vkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JT0rJJaVsTZb5TVKKtykJBN6iGIafa+AWfk0N/SJIG4=; b=1KV8YRhHGu1+t5u4nWZ++hU9ms9W5sLckOcGvP5cSW0azNn2ZRLBjVX4sYsXLxscPi i4d758BB7x0KzMba9JMmBdSNf8FC75FmAQubhfxy7SrzOQdg/DnYCTkDXkz/UX/KCY+8 v/gx2BAytDbdtP/Leg1GFPjCf4apSi52BxPR+NTU+jPXb6vhn4u+Gg9gMKdPnP4SagjZ S/lLCc4oyQxuAQaaB8p6RfDr/3QmnBeSfdLTYjQIzH5smirvSjEiIDKzHUOW1rKhtaNU 0bMs9s3q829ewu56Ilr2x4ELru23hhDb/CWXE2f5n2cBPlhrp8AEYs2Zg1plW57gM+nA V2uQ== X-Gm-Message-State: AFqh2krvnZpJHf6YLVvME+eVWUtZ0o6ACyDwOlS5PCZtUKhgd262cBc7 puEQ7mavYz/937cyz9oy7AZIBg== X-Google-Smtp-Source: AMrXdXsvASJjjWLzK7lflFmTrSebeSKKu7pG5wy7griNsblwQerwfyx5bzIZ/3jWB971c92ezXRMYg== X-Received: by 2002:a92:cc46:0:b0:30b:1b33:cb9b with SMTP id t6-20020a92cc46000000b0030b1b33cb9bmr5128163ilq.9.1671479404831; Mon, 19 Dec 2022 11:50:04 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id u69-20020a022348000000b00392238fe4b2sm1245886jau.133.2022.12.19.11.50.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Dec 2022 11:50:04 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 6A85A8008DE; Mon, 19 Dec 2022 13:50:03 -0600 (CST) Date: Mon, 19 Dec 2022 13:50:03 -0600 From: Justin Pryzby To: Frits Jalvingh Cc: pgsql-performance@lists.postgresql.org Subject: Re: Fwd: temp_file_limit? Message-ID: <20221219195003.GE1153@telsasoft.com> References: <20221218155705.GT1153@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 Sun, Dec 18, 2022 at 06:29:41PM +0100, Frits Jalvingh wrote: > By itself I'm used to bad query performance in Postgresql; our application > only does bulk queries and Postgres quite often makes terrible plans for > those, but with set enable_nestloop=false set always most of them at least > execute. The remaining failing queries are almost 100% caused by bad join > sequences; I plan to work around those by forcing the join order from our > application. For instance, the exact same query above can also generate the > following plan (this one was created by manually setting > join_collapse_limit = 1, but fast variants also occur quite often when > disabling parallelism): I, too, ended up setting enable_nestloop=false for our report queries, to avoid the worst-case plans. But you should also try to address the rowcount misestimates. This underestimates the rowcount by a factor of 69 (or 138 in the plan you sent today): | (soort = 'MSL'::text) AND (code = 'DAE'::text) If those conditions are correlated, you can improve the estimate by adding extended stats object. | CREATE STATISTICS s_h_sturingslabel_ssm_stats soort,code FROM s_h_sturingslabel_ssm; ANALYZE s_h_sturingslabel_ssm; Unfortunately, stats objects currently only improve scans, and not joins, so that might *improve* some queries, but it won't resolve the worst problems: | Hash Join (cost=22,832.23..44,190.21 rows=185 width=47) (actual time=159.725..2,645,634.918 rows=28,086,472,886 loops=1) Maybe you can improve that by adjusting the stats target or ndistinct... -- Justin