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 1lnvpa-0007bp-Hy for pgsql-performance@arkaria.postgresql.org; Tue, 01 Jun 2021 04:16:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lnvpZ-0002YT-Eo for pgsql-performance@arkaria.postgresql.org; Tue, 01 Jun 2021 04:16:41 +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 1lnvpZ-0002YK-2n for pgsql-performance@lists.postgresql.org; Tue, 01 Jun 2021 04:16:41 +0000 Received: from mail-il1-x130.google.com ([2607:f8b0:4864:20::130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lnvpW-00027v-6Y for pgsql-performance@lists.postgresql.org; Tue, 01 Jun 2021 04:16:39 +0000 Received: by mail-il1-x130.google.com with SMTP id h11so11684640ili.9 for ; Mon, 31 May 2021 21:16:37 -0700 (PDT) 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=6s0QOCkZpgX92eulNt5r5M2P3zXAx1CaXo6kDDAtLxk=; b=UHlsH9Jt9gHe7AmmiHX0wz748L5OrRBbZbVBXNyJMf3JNlPauc0tBSU9MO5z8mAmD9 1hYLO/u8ficQ61x7pglJbo5nimQSnMC2tHS/aDCb+HXa7PylnUjjLVIbIt7/QYCIRhRr z9X1N0b4lDEmQU6/dT6kQ3cK20OGQqAeOL8WIvrTd75ShGNiT4Nr55i1Jv9w+eGKyovA WCOcnVLKc/+EtA/Pf3ojRzyQ+XIBhP5RfBD3rYiomMdMNCAsxcRTX3Owu1Ptmcbb+u/6 wpQ0dYZ7LzH48YMOmAKCobZfDggqXfh9zrRGXcSbWJCG2sV4Ra8UxVQGprx5/mtaZXC1 qlPw== 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=6s0QOCkZpgX92eulNt5r5M2P3zXAx1CaXo6kDDAtLxk=; b=kJ2ggyP6jDSSrvCxcXgqJfWPx+IUBGsykzmuW7Oc6mbnYG5Nkg4UxiJ3ORX0E8R2fg ZHLtDG6zQmRvCNfOhA1C6+3avbyU009HpSi+iWPRS5HjHgLCpG+5eGTPwwVZOhdeBd4S 8gpKeyf2QlxgbAXMCww38kiCjGYnB/NfwTwPERS7OQYtp+ViA2pmXvVBAKJBdpJ2GeOZ qKIyN+ER4RjkU1vdc7pYmMfCM1k4+LZcqiz/oFvpkmJ2rnvBLjaK1vIxuBBQH33E4j3T jhZbqDtbeIS1i/ngOOEndCTQJyz4tKg7FURRwEcH1V/RqYc1A5d/evgY/byghAIO2DYA CWqA== X-Gm-Message-State: AOAM533F025p4+YADduSIMUmzHd/iNr3k4KIkKvoBFE26bsCgDtYbM4E t3Xg908PiRVczywG2cqu5/WLOvlV7+pGRw== X-Google-Smtp-Source: ABdhPJxz/ly6CbUFGqDSrWzF+vf1YLmSSsg1klUc/IviDDtUoO23iBI8gteNLiWAcRaCYOh8zRrN3g== X-Received: by 2002:a05:6e02:10d4:: with SMTP id s20mr3935806ilj.37.1622520996912; Mon, 31 May 2021 21:16:36 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id j12sm9377759ils.42.2021.05.31.21.16.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 31 May 2021 21:16:36 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 73D958009D6; Mon, 31 May 2021 23:16:35 -0500 (CDT) Date: Mon, 31 May 2021 23:16:35 -0500 From: Justin Pryzby To: "Dean Gibson (DB Administrator)" Cc: pgsql-performance@lists.postgresql.org Subject: Re: AWS forcing PG upgrade from v9.6 a disaster Message-ID: <20210601041635.GQ2082@telsasoft.com> References: <88dec70b-eb63-0b72-0b5d-253851ef127b@mailpen.com> <92cc8563-195f-8727-d887-5f2bb63f231f@mailpen.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <92cc8563-195f-8727-d887-5f2bb63f231f@mailpen.com> 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 > Here's the FROM clause that bit me: > > FROM lic_en > JOIN govt_region USING (territory_id, country_id) > LEFT JOIN zip_code USING (territory_id, country_id, zip5) > LEFT JOIN "County" USING (territory_id, country_id, fips_county); I'm guessing that there's a dependency/correlation between territory/country/county, and that's probably related to a misestimate causing a bad plan. > The first two JOINs are not the problem, & are in fact retained in my > solution. The problem is the third JOIN, where "fips_county" from "County" is > actually matched with the corresponding field from the "zip_code" VIEW. Works > fine, if you don't mind the performance impact in v10 & above. It has now > been rewritten, to be a sub-query for an output field. Voila ! Back to > sub-second query times. What version of 9.6.X were you upgrading *from* ? v9.6 added selectivity estimates based on FKs, so it's not surprising if there was a plan change migrating *to* v9.6. ...but there were a number of fixes to that, and it seems possible the plans changed between 9.6.0 and 9.6.22, and anything backpatched to 9.X would also be in v10+. So you might've gotten the bad plan on 9.6.22, also. I found these commits that might be relevant. https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=1f184426b https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=7fa93eec4 https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=770671062 ad1c36b07 wasn't backpatched and probably not relevant to your issue. -- Justin