Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iyG9p-00089r-V6 for pgsql-performance@arkaria.postgresql.org; Sun, 02 Feb 2020 14:23:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iyG9o-0002cx-OX for pgsql-performance@arkaria.postgresql.org; Sun, 02 Feb 2020 14:23:28 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iyG9o-0002cj-8K for pgsql-performance@lists.postgresql.org; Sun, 02 Feb 2020 14:23:28 +0000 Received: from mail-yw1-xc43.google.com ([2607:f8b0:4864:20::c43]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iyG9k-0001f6-T5 for pgsql-performance@lists.postgresql.org; Sun, 02 Feb 2020 14:23:26 +0000 Received: by mail-yw1-xc43.google.com with SMTP id a125so10630806ywe.12 for ; Sun, 02 Feb 2020 06:23:24 -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=a9VP7DXCFKmSo6zYXl6t+VDordDTr5PGl0dDhNutyu0=; b=jHq8x3kR/YIRecwkIK1FgO4R8J/ZZskJSO4QWS15b4l+AWIyuSSp/+VcqbLJaWf5zH cpCXXt50P/k4zM8TelAsXVdWVxpHDKfFHu3loCddEe1X4p5GfOawSUI7mac4YPZDfP5Z KjT3fbzS6OFHG8I4m/3BQ5wmTGzUnpd5TbNB+tq5ZA+diJYjAMnJMg2oQgljOxjQWuOZ 40gMNTGcZBNzji4a0rWUPmXsCZ4LvwvpfIjN03BaaFyt0vZvGdrz5Lj9R9P1eojhiRQl fpZooaN9kLIqgQgiNfTci53cfK8X9B/RRlLL+YaUCRvjPk4lkVbLW7LJOS2SYVB4gAnl zZcg== 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=a9VP7DXCFKmSo6zYXl6t+VDordDTr5PGl0dDhNutyu0=; b=i7JIHqtu2TMvTZlkOJyS3fJUqSh2H60AC01ZtlLc12hJYuC6cmjgOvPg/k6YHxuZqm WfGow1eT5g9U9MA9GHQ55pokvY4DUY5gmzC7+9/XR3V80+Fg2Ffy5Y1FeUdN98T36FJD dOUI2jnMtaaS/5R7om7QdO/X+UjlqG3pwYoV3Q+P1Q3ROSHXIkXSuqzvBAnURPPq5aFa MCaUiskLzS6Vs4NEO8fidgToeaDIyt8ZLbaaNXoLyxLWrR3Qt6IHvyv7IV+Ls8BJS/25 EbAsZYq1j6Hpbwr0MlVe/4PRwliMqpv1RjtTRwVhFBm1G9RbckMx+XXvqTKFrcFiRkfV uX9Q== X-Gm-Message-State: APjAAAXJVolPglsWz4dj/b1pfaXocFp4aE/EgT1wvdEUUJqSizMufqru DXj2fT7wsvJLneb3JR80jPN3LQ== X-Google-Smtp-Source: APXvYqwFud1aGPhs0UUmHxUlG9WC6fCBvBdc6b55YtjTfpx31Uxzrqlv8SvrHucUhlHgaV/2EB1CdQ== X-Received: by 2002:a25:56:: with SMTP id 83mr8142983yba.80.1580653403399; Sun, 02 Feb 2020 06:23:23 -0800 (PST) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id l37sm7505053ywa.103.2020.02.02.06.23.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 02 Feb 2020 06:23:22 -0800 (PST) Received: by pryzbyj (Postfix, from userid 1000) id 608E8800925; Sun, 2 Feb 2020 08:23:21 -0600 (CST) Date: Sun, 2 Feb 2020 08:23:21 -0600 From: Justin Pryzby To: Marco Colli Cc: pgsql-performance@lists.postgresql.org Subject: Re: Statistics on array values Message-ID: <20200202142321.GH13621@telsasoft.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sun, Feb 02, 2020 at 03:18:19PM +0100, Marco Colli wrote: > Hello! > > Let's say that you have a simple query like the following on a large table > (for a multi-tenant application): > SELECT "subscribers".* FROM "subscribers" WHERE "subscribers"."project_id" > = 123 AND (tags @> ARRAY['de']::varchar[]); > > If you run EXPLAIN ANALYZE you can see that stats are completely wrong. > For example I get an expected count of 3,500 rows whereas the actual > result is 20 rows. This also results in bad query plans... https://www.postgresql.org/message-id/CAMkU%3D1z%2BQijUWAYgeqeyw%2BAvD7adPgOmEnY%2BOcTw6qDVFtD7cQ%40mail.gmail.com On Fri, Jan 10, 2020 at 12:12:52PM -0500, Jeff Janes wrote: > Why is the estimate off by so much? If you run a simple select, what the > actual and expected number of rows WHERE project_id = 12345? WHERE tags @> > '{crt:2018_11}'? Is one of those estimates way off reality, or is it only > the conjunction which is deranged? Could you respond to Jeff's inquiry ? Justin