Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eBwAZ-0004WR-Ro for pgsql-performance@arkaria.postgresql.org; Tue, 07 Nov 2017 05:11:28 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1eBwAY-00068W-Vl for pgsql-performance@arkaria.postgresql.org; Tue, 07 Nov 2017 05:11:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eBwAX-000678-MU for pgsql-performance@postgresql.org; Tue, 07 Nov 2017 05:11:25 +0000 Received: from mail-it0-x229.google.com ([2607:f8b0:4001:c0b::229]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1eBwAP-0001IM-Kq for pgsql-performance@postgresql.org; Tue, 07 Nov 2017 05:11:24 +0000 Received: by mail-it0-x229.google.com with SMTP id n195so956802itg.0 for ; Mon, 06 Nov 2017 21:11:17 -0800 (PST) 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=koggLquTTzizgY4DdfQW6mJdvEW3z1qFkH23j0pjYCQ=; b=rK1iRrVAVLth8upQdLwGfjLJVGPauFLFPo/d3dBbORsoxIhg59+ZbiOB9hyNvOIaGc O3VB+XJoK/ymyi+keo+Svt9fl86CqjjhgMxpty5zWSVfUmFazhKF0sr/akrsEY9Xqq0s hloGTrum7RSQ40b0wFKWT/PNXnunGmskwctaIN1rziczaP/wmJyqcpgP5gcyyiZK3O5o uBFG/03LepVh68N1BMDvpsGE2U/u1ZuEUrxUFWK4syXBpGOO2W9istMADw0c+lj9BVbr Z6ei/8ZIMLTVm+oFhZGvWHIoJdklfc6k/2JBP7aSn1tyYBv/MVx89v20JuCwVbq3E0kd 6cYg== 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=koggLquTTzizgY4DdfQW6mJdvEW3z1qFkH23j0pjYCQ=; b=d7xAGZT0vDkAwVo9mmSEjk21jPZ8uKJKsE3YGAlDwJPmTLfJQqqHyJAuM23ytmpVd7 vhpZXqQqC/rTHYlOZE43n089Kcpv/4H3wqp7OskNUboqkaTqQ9/eTvnVrgDJO+OW/rcs OsHBc22EVQbJKVhBsT+AP8GiF6BnaJOn0yCGhoBFUibhrhQfqmyO5uH8aQHmsuXmjXbg wSdaHkYO/OgOdoSyoClglPolS1tC9Fh/p/AJGJuw6/ByKce7RvVxEz9PCH2zhR9WgQZm 6EtjqL++TJ8aDHnUTmqVRZIksn7T+mGJPtkKiLlu6UJRVuAOkHSW2EvhRtVU0Os3H+n3 mirQ== X-Gm-Message-State: AJaThX4vwMXFrbSA7zb7YsrobKHWIHRXJmn2EU5rD+E034uW7mhBBV7z RmaRmt/oUYAkHVLQjMTTsJBJDy8O3T0= X-Google-Smtp-Source: ABhQp+QtveiBchFMGdFAhSHkFlibwLlp1gQ4dUmc41ywP3KjNqFtGoIq0eDTQuCE/k0VBNBila8GAg== X-Received: by 10.36.112.143 with SMTP id f137mr672532itc.84.1510031475254; Mon, 06 Nov 2017 21:11:15 -0800 (PST) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id z2sm352332ite.26.2017.11.06.21.11.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Nov 2017 21:11:14 -0800 (PST) Received: by pryzbyj (Postfix, from userid 1000) id 2A5CF80102F; Mon, 6 Nov 2017 23:11:14 -0600 (CST) Date: Mon, 6 Nov 2017 23:11:14 -0600 From: Justin Pryzby To: Adam Torres Cc: "pgsql-performance@postgresql.org" Subject: Re: Performance loss upgrading from 9.3 to 9.6 Message-ID: <20171107051114.GU14205@telsasoft.com> References: <68F12CAE-BFD8-4E21-8B39-AECB0C5E5A8F@contoso.com> <20171106142142.GD14205@telsasoft.com> <23D1DA58-FE4A-40BB-83CA-AFEE687D99A6@amplify-nation.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <23D1DA58-FE4A-40BB-83CA-AFEE687D99A6@amplify-nation.com> User-Agent: Mutt/1.5.23 (2014-03-12) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On 11/6/17, 9:21 AM, "Justin Pryzby" wrote: > see if statistics improve: > SELECT (SELECT sum(x) FROM unnest(most_common_freqs) x) frac_MCV, tablename, attname, n_distinct, array_length(most_common_vals,1) n_mcv, > FROM pg_stats WHERE attname~'customers_customer' AND tablename='id' GROUP BY 1,2,3,4,5 ORDER BY 1 On Mon, Nov 06, 2017 at 09:12:01PM +0000, Adam Torres wrote: > I changed the statistics on av.customer_id as suggested and the number > returned by pg_stats went from 202,333 to 904,097. Do you mean n_distinct ? It' be useful to see that query on pg_stats. Also I don't know that we've seen \d output for the tables (or at least the joined columns) or the full query ? > There are 11.2 million distinct customer_ids on the 14.8 million vehicle > records. If there's so many distinct ids, updating stats won't help the rowcount estimate (and could even hurt) - it can only store 10000 most-common-values. Are there as many distinct values for cc.id ? I would try to reproduce the rowcount problem with a minimal query: explain analyze SELECT FROM av JOIN cc ON av.customer_id=cc.id; --WHERE cc.id<99; Maybe the rows estimate is okay for some values and not for others, so maybe you need to try various WHERE (with JOIN an additional tables if need be...but without reimplementing the whole query). I just noticed there are two conditions on dealer_id, one from table av and one from table cc_1. It seems likely those are co-related/non-independent conditions..but postgres probably doesn't know that (unless you used PG96 FK logic, or PG10 multi-variable stats). As a test, you could try dropping one of those conditions, or maybe a hacky change like ROW(av.dealer_id, cc_1.dealer_id)=ROW('EC000079', 'EC000079'), which postgres estimates as no more selective than a single equality test. BTW this is all from src/backend/utils/adt/selfuncs.c. Justin -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance