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 1l0TfR-0005Kl-Ne for pgsql-general@arkaria.postgresql.org; Fri, 15 Jan 2021 18:17:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l0TfQ-0004Ur-7P for pgsql-general@arkaria.postgresql.org; Fri, 15 Jan 2021 18:17:48 +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 1l0TfO-0004Uj-Ks for pgsql-general@lists.postgresql.org; Fri, 15 Jan 2021 18:17:47 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l0TfJ-0001kl-Vr for pgsql-general@lists.postgresql.org; Fri, 15 Jan 2021 18:17:45 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 283A64D5; Fri, 15 Jan 2021 13:17:38 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Fri, 15 Jan 2021 13:17:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=B t7maLI8dHRDSYdQYZ71cae/tnjC46Zm1R1xo4tYv8w=; b=Lzf8ZB9c00MjYdZWK 6pLgYH+GGEBWZG8Z7cuZpU3AfPi0FDcGtblSmSQxbISqkNDh2L3dYugvzex1C2/j PWtoZY9Xa0Co2XdZAXCTU2/O2BrLY0W/HMJH13Ybl6IpqsMwjd77M6lT++RKJ0gr SRs8Irv0YvzZ2OhonWVr9hzL6YtBfhaHm15BxVNEzXqlZGlB0xlXanSn5OWDXl28 vWR8EDTd+arzogsAnFsy1hyW3BTrfpgKq6VjHwIZfl7V4PcdYQvRVvXwrYrK6VML wGRHv4iMfUkfa5rrESt8KWyCOhAxIxd0xR/DAn1JXsEaCEczSChF6g8HUV0It5AI p4hjw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=Bt7maLI8dHRDSYdQYZ71cae/tnjC46Zm1R1xo4tYv 8w=; b=bctuQpZk+vEgK0mL01V+6lttDh91FAU94T6mgognlcxSZjpwuK88H3Lzo pNc+KQP/TyHRnRXQGu9YRzubrdE/3rTuHVJD7Uzisn1AOTmF85Ap02CT0trNwqDJ 6AymcDa6+rpaDGhWSszLYerynE+KiEPMEDs7+w7N8W8ogaYgdtsDspF1uNEnD+hC E3MNx9oP4M5vzq1efAvQdWj0hxaVdP5n0WHVoGdNQrqjpEB9rk+zO4yT29HuJaiv rOII0yjzvlJhlNwBhyoVz/OvuW1/SLiXELjk1Tst1KlV38/4CumVeEkYXS04aTxt 1JndlessLFwubrWd3h6XGKiX/Plfg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrtddvgdekiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefuvfhfhffkffgfgggjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughrihgr nhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh eqnecuggftrfgrthhtvghrnhepveevfeevfeeugeffkeekhfegieeufffgteeujedvgffh ueejjefhkeejleegtdegnecukfhppeejgedrleegrdejfedrvddvvdenucevlhhushhtvg hrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghv vghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Received: from ranger.suse (unknown [74.94.73.222]) by mail.messagingengine.com (Postfix) with ESMTPA id CD416108005B; Fri, 15 Jan 2021 13:17:36 -0500 (EST) Subject: Re: Accounting for between table correlation To: Alexander Stoddard , "David G. Johnston" Cc: Thomas Kellerer , "pgsql-generallists.postgresql.org" References: From: Adrian Klaver Message-ID: <65a6db71-9182-1f0a-02c7-39cd011b34dd@aklaver.com> Date: Fri, 15 Jan 2021 10:17:35 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 1/15/21 9:21 AM, Alexander Stoddard wrote: > Unfortunately I'm not free to share the specific schema or the query > plans. They derive from an upstream vendor that is 'protective' of their > data model. To get to a proper example I'll need to recreate the > behavior with generic data in a generified schema. > > I apologize for being frustratingly vague. I do feel like an idiot for > not at least saying this was with version PG 11.10. > It has been beneficial to me that the replies so far appear to validate > my understanding that no version of postgres has cross table correlation > statistics in the planner. > > Analyze is done frequently, and I think at sufficient sample size. The > context is in a large data analysis setting and the data is changed via > bulk ETL not OLTP. The effect on analyzing is just instability - the > plan can flip in either direction (without underlying data changing) > between giving an answer in minutes and timing out after 10s of hours. > That could be indicative of too small a sample but I think in this case > it is more the statistics aren't useful because it is cross table > correlation that can't be accounted for. So to be clear, the process imports the data, then you run a query and it completes in x time, you then ANALYZE the same data and it runs in y time. Is that correct? > > The 'fast plans' use parallel seq scans. The 'slow plans' is using index > scans. It appears a good query plan correctly predicts it should be bulk > processing the tables but bad ones get fooled into trashing (hard disk, > not SSD) by mispredicting too few rows to join between the tables. > > If anyone has similar experiences and is generous enough with their time > to share possible solutions/work arounds then I'm most grateful. If my > description is too vague to be worthwhile answering then I quite > understand and apologize for the time wasted in reading. > > Thank you. > > > > > > On Fri, Jan 15, 2021 at 10:26 AM David G. Johnston > > wrote: > > On Fri, Jan 15, 2021 at 9:10 AM Thomas Kellerer > wrote: > > Atul Kumar schrieb am 15.01.2021 um 16:29: > > As per Ron, you are not supposed to ask your questions here. > > > > As According to him, we should keep on doing research on internet > > rather than asking for support directly even you have done enough > > research and until unless “Ron” won’t be satisfied you have to do > > keep on researching. > > Ron's question was perfectly valid. > > Missing and wrong statistics are one reason for the planner to > choose a bad execution plan. > > > Yeah, at first blush I didn't think analyze really mattered (and it > mostly doesn't because while you can keep the statistics up-to-date > the multi-table nature of the problem means they are only marginally > helpful here), but that just points out the under-specified nature > of the original posting.  Taken as a simple question of "is there a > way to work around the lack of multi-table statistics" the analyze, > and even the specific queries, don't matter all that much.  But it > also would be much more useful if the OP would choose a single > problematic query and show the schema, query, and explain results, > hopefully both good and bad, and comment on how analyze seems to > affect the plan choice.  But for the general question about > overcoming our statistics limitations the analyze point is not relevant. > > David J. > -- Adrian Klaver adrian.klaver@aklaver.com