Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eLLWF-0001uc-T0 for pgsql-performance@arkaria.postgresql.org; Sun, 03 Dec 2017 04:04:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eLLWE-000750-A2 for pgsql-performance@arkaria.postgresql.org; Sun, 03 Dec 2017 04:04:42 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eLLWD-00074p-Sm for pgsql-performance@lists.postgresql.org; Sun, 03 Dec 2017 04:04:42 +0000 Received: from mail-it0-x22d.google.com ([2607:f8b0:4001:c0b::22d]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eLLW6-0004N8-4J for pgsql-performance@lists.postgresql.org; Sun, 03 Dec 2017 04:04:40 +0000 Received: by mail-it0-x22d.google.com with SMTP id z6so6568658iti.4 for ; Sat, 02 Dec 2017 20:04:33 -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=SKYhQ4Ua0NiUOICmdQfLq0rkT8RqR+QzMWWmIvL2/n0=; b=i1r49JZqnvZhicyLRJv9h5gbDxVXaIQMU1409vCMAbVDa2kvm1o+AakFQP8xAWpfwu /68PBaIR6ykqdu8NqA+hgIQr4KX3Nkfs37EbPU/ztLeAXHRGiZRoRKCzNohV+SeXrKtw OOqMZGZneqCq8Cq7PhKXBm9I3Yz/VLTy81F+C8LSfYTO1LUb+8k38jgFuuvJ4166O3/8 jbv2tk1i9Gd7e3R5hgWK3WuMt/5MYV6RFX30UKUfcdJAFVdnZTqAp9V69muM8zGL30Kz wAq+0b2SWI2GwzcKdxmHmyQ+KKWw30UrW5bBbBeYtUy0mkFgsZ6Dt6sFPvJEujaUjVcA xacw== 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=SKYhQ4Ua0NiUOICmdQfLq0rkT8RqR+QzMWWmIvL2/n0=; b=MvT6Xu8tUCjtINA2IInqMSpO20ZNlH1JttF1Af/3Vy/wNg9PxiD7RjR1sFf1kic+Oe wBzc5K7PTDI4nblr/IiqtvrI5xuEy6BnsLswVmMt+UUw/8hIA5oHopC+IH2b8kGSbZFn k1jhsfYOikBpl5O4i0s9IyVBwEcTfVpcX0Z/tJx4eaKntPgbfjZg8MW4ge6QYoP222kk 7qMVOYMLJ7cpZ0ojdwDdr5dkEEzHD8iwHVEDQhFxdSU0LyeTRm41KXug4FKjPH1/jh3m uNSonOUW1QwoEiNJRDZbpIx4phcN2b/ZGg4SWaSvfNOnBjUCbM7OGSGZCWnuKFkHq/Op MxVw== X-Gm-Message-State: AJaThX4gvVIVutTMJPL4H6Mb+cRr2Uyfd98/JIFdSbYWZjKUdi8qi3he JANsxiXrH2LoRCVI2dp0CsVIMw== X-Google-Smtp-Source: AGs4zMbkbTdyR27MSMKmCuMTPc7OdZHnHG9jx1Nc1NiwoSDW3GSvCL7iYB6FmmwxPY8Sck56u+Tf5w== X-Received: by 10.36.4.144 with SMTP id 138mr8590088itb.78.1512273872253; Sat, 02 Dec 2017 20:04:32 -0800 (PST) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id b195sm4779139ioa.43.2017.12.02.20.04.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Dec 2017 20:04:31 -0800 (PST) Received: by pryzbyj (Postfix, from userid 1000) id AA545800FD6; Sat, 2 Dec 2017 22:04:30 -0600 (CST) Date: Sat, 2 Dec 2017 22:04:30 -0600 From: Justin Pryzby To: Jeff Janes Cc: Tom Lane , Vitaliy Garnashevich , pgsql-performance@lists.postgresql.org Subject: Re: Bitmap scan is undercosted? - boolean correlation Message-ID: <20171203040430.GC14008@telsasoft.com> References: <73a4936d-2814-dc08-ed0c-978f76f435b0@gmail.com> <20171201183427.GK18413@telsasoft.com> <20171201231104.GN18413@telsasoft.com> <18188.1512258290@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sat, Dec 02, 2017 at 05:27:51PM -0800, Jeff Janes wrote: > I think the non-extended stats code also has trouble with booleans. > pg_stats gives me a correlation of 0.8 or higher for the flag column. It's not due to the boolean though; you see the same thing if you do: CREATE INDEX aaa_f ON aaa((flag::text)); ANALYZE aaa; correlation | 0.81193 or: ALTER TABLE aaa ADD flag2 int; UPDATE aaa SET flag2= flag::int correlation | 0.81193 I think it's caused by having so few (2) values to correlate. most_common_vals | {f,t} most_common_freqs | {0.9014,0.0986} correlation | 0.822792 It thinks there's somewhat-high correlation since it gets a list of x and y values (integer positions by logical and physical sort order) and 90% of the x list (logical value) are the same value ('t'), and the CTIDs are in order on the new index, so 90% of the values are 100% correlated. It improves (by which I mean here that it spits out a lower number) if it's not a 90/10 split: CREATE TABLE aaa5 AS SELECT (id%100)::int num, (id%10>5)::bool flag FROM generate_series(1, 10000000) id; CREATE INDEX ON aaa5 (flag); tablename | aaa5 attname | flag correlation | 0.522184 Justin