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 1p7jtN-0007OZ-Tn for pgsql-performance@arkaria.postgresql.org; Tue, 20 Dec 2022 21:11:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p7jtM-0001tO-D0 for pgsql-performance@arkaria.postgresql.org; Tue, 20 Dec 2022 21:11:16 +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 1p7jtM-0001sZ-00 for pgsql-performance@lists.postgresql.org; Tue, 20 Dec 2022 21:11:16 +0000 Received: from mail-io1-xd35.google.com ([2607:f8b0:4864:20::d35]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1p7jtJ-0007Ea-Kk for pgsql-performance@lists.postgresql.org; Tue, 20 Dec 2022 21:11:15 +0000 Received: by mail-io1-xd35.google.com with SMTP id r72so7067339iod.5 for ; Tue, 20 Dec 2022 13:11:13 -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=U3jLSOmiFQj4TuWcOKd0ovJqgBjtRzDdexomj8I/CPw=; b=guWEiZUHXpbyqxG4zsKhhqOxFYEqX36A3UKKY0px1C4NsIR25DHI1T0DqafvXYJQgv xGnkIt6wHW59terRQTOp/6OszSPmuzlxATFjzl2LvzxIwl8ZvWBSy40/XYcb5lQimS6L PZCiF9tsDCx+z/Na+YF1qD0G6dsPgyg2rpooTEtvxbZ+GUqo+2tmB3XNiy+Qypl075De Fuc63K18XzWz1oHOBSkofpMtUUl9f8t+HI2LRhezBG/uUv0CO8KCSy9J8Ron/ShQ9jSF ZFR1qRCPla64bA6j2aXlle4TkaBZ0plSlrNEoxlHJ2Xkhe32yridn271zfXE9nPVbjfJ saMw== 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=U3jLSOmiFQj4TuWcOKd0ovJqgBjtRzDdexomj8I/CPw=; b=Y7iim3xXxUKHdD2e1APg09zLMQbxUGlBDp/aRMQzEKLRvwSn+3dL08DUBE/iaXjBMQ AFjY1uuofjLDXnApc1m48wfTc+BDKFKQrnuI0IYyHxWLPSWDrvFuTaaMFU+CqdMq92pU FJu0XfvqZzUNPV7QJZGoTuqtOHSry0kDLNM9lgGkgnWteCn5vPXRNu97TamjU6+nkXH1 +MbfzQVnYffqE9yQ98qN5fKMUoo0H3Uu2dvVFH2ddKCV1UxGYDah9nayDsCkEVdrptwc zHkFm9yIXoNsyrEtVZm7V+v/MW82tSh65PeZ4E1lr2ifFmBvvQtPPDTGR9c6MFyTE3TL okjw== X-Gm-Message-State: AFqh2krMEvlo/GmTBH4Pabs7m2jIAB4iiUbovxpS+LjP05B5g5yKJOeK hAT+C0hHXmwZ0wy/tdDO5UyLSw== X-Google-Smtp-Source: AMrXdXuT4kfJ9+RZUFzCJdsQZR6qknVzD86vKiJIer0yCkJtU9tlKKNo1fRig1tdbsXpVA9V+TaX6w== X-Received: by 2002:a05:6602:4243:b0:6de:383e:4141 with SMTP id cc3-20020a056602424300b006de383e4141mr7513710iob.11.1671570671479; Tue, 20 Dec 2022 13:11:11 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id h25-20020a02c739000000b0038acb163042sm4996907jao.19.2022.12.20.13.11.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Dec 2022 13:11:10 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 1571C8008DE; Tue, 20 Dec 2022 15:11:10 -0600 (CST) Date: Tue, 20 Dec 2022 15:11:09 -0600 From: Justin Pryzby To: Frits Jalvingh Cc: pgsql-performance@lists.postgresql.org Subject: Re: Fwd: temp_file_limit? Message-ID: <20221220211109.GI1153@telsasoft.com> References: <20221218155705.GT1153@telsasoft.com> <20221219195003.GE1153@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 Mon, Dec 19, 2022 at 09:10:27PM +0100, Frits Jalvingh wrote: > @justin > > I tried the create statistics variant and that definitely improves the > estimate, and with that one of the "bad" cases (the one with the 82 minute > plan) now creates a good plan using only a few seconds. > That is a worthwhile path to follow. A bit hard to do, because those > conditions can be anything, but I can probably calculate the ones used per > customer and create those correlation statistics from that... It is > definitely better than tweaking the "poor man's query hints" enable_xxxx > 8-/ which is really not helping with plan stability either. > > That will be a lot of work, but I'll let you know the results ;) Yeah, if the conditions are arbitrary, then it's going to be more difficult. Hopefully you don't have too many columns. :) I suggest enabling autoexplain and monitoring for queries which were slow, and retroactively adding statistics to those columns which are most-commonly queried, and which have correlations (which the planner doesn't otherwise know about). You won't want to have more than a handful of columns in a stats object (since it requires factorial(N) complexity), but you can have multiple stats objects with different combinations of columns (and, in v14, expressions). You can also set a lower stats target to make the cost a bit lower. You could try to check which columns are correlated, either by running: | SELECT COUNT(1),col1,col2 FROM tbl GROUP BY 2,3 ORDER BY 1; for different combinations of columns. Or by creating a tentative/experimental stats object on a handful of columns at a time for which you have an intuition about their correlation, and then checking the calculated dependencies FROM pg_stats_ext. You may need to to something clever to use that for arbitrarily columns. Maybe this is a start. | SELECT dep.value::float, tablename, attnames, dep.key, exprs FROM (SELECT (json_each_text(dependencies::text::json)).* AS dep, * FROM pg_stats_ext)dep WHERE dependencies IS NOT NULL ORDER BY 1 DESC ; -- AND regexp_count(key, ',') < 2 -- Justin