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 1l1MXt-0007hn-PM for pgsql-hackers@arkaria.postgresql.org; Mon, 18 Jan 2021 04:53:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l1MXs-0005UZ-KC for pgsql-hackers@arkaria.postgresql.org; Mon, 18 Jan 2021 04:53:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l1MXs-0005UR-8c for pgsql-hackers@lists.postgresql.org; Mon, 18 Jan 2021 04:53:40 +0000 Received: from mail-io1-xd32.google.com ([2607:f8b0:4864:20::d32]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1l1MXn-00069N-7t for pgsql-hackers@postgresql.org; Mon, 18 Jan 2021 04:53:39 +0000 Received: by mail-io1-xd32.google.com with SMTP id u17so30532818iow.1 for ; Sun, 17 Jan 2021 20:53:34 -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=5okkA3dm//uXEhHXAAoxP36rjl7KiajEJB85ifdTrKU=; b=hjXUFvqLPlGDKHT9hXi/CypxUwagi0G7M7xwcBImgCODbBUDF36/4qDJjRW9WDpty5 nxtmVeb30Lr53AsMIJj9+J6zqCKKW8XVblYCqxlEXIEFy1P7RLM6U87r34mry/uyv60v 7E2o7hvtQn7sm53iD9o3/QmdfbdLDyAzXSlyQeFHU6HUhocZLafjqG4hALbipBFQM2/e nUymtA/KVdNVhzjF1EKPfeKnqfQJwHuwBhYXKFhRdFHQg22gxtXKejPhNlmnKtQYnB3n vJ7cKbObzMVR94YHftJ9awb9z+xEe1FiFpEDhMqA5Ksn1J29qgq4+CkNO+YGqJXzhMmT r9dQ== 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=5okkA3dm//uXEhHXAAoxP36rjl7KiajEJB85ifdTrKU=; b=B8UbDGcvXeaeI3/qeeHZXe/Ct/KR9nrF3N1MIAJ9oebTiqAhQ22339LOnBe5XjL+EN mVYLCv7zZHn1ZIRFklYQRYoyIiT7jGhYddj3ZQiI52hdz1UqgDQKceS06ZgfJUzA4BOr HnZPhQmdJpzS8Z7P9JgtnnEnW1P9++IR+AhTsHotXVrt1Rpp9buTlmiwlDHEcsbC3C3x BDnxCyYGnFrTcD0H/gqNtfoClHbSXf8GQbXwRMkXWCOmD3gdPULPymNX1y71MIa7ts82 CPiEHdA7Mj66udkUBcytWN8ntIAWD2tmVfK939C93+kFOJTM0Jk6hdP5LojMdKhEkAIR ojDQ== X-Gm-Message-State: AOAM530sksa2yvcEuMtvOjjO9AyTWTtE/Vsu1SDQUSIdeSEkiAC7mWxj CkboxXsvLqlqmuM9msDL3HJMCw== X-Google-Smtp-Source: ABdhPJxCnGZfXlq3DKVCz7FG9mvDl0ke77mrZ4McM0aVyXjTZAyv646CVbjOMJM3gI6OAgnvsxMtjg== X-Received: by 2002:a5d:8909:: with SMTP id b9mr16104097ion.175.1610945613412; Sun, 17 Jan 2021 20:53:33 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id f20sm9392904ilr.85.2021.01.17.20.53.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 17 Jan 2021 20:53:32 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 77E6780095C; Sun, 17 Jan 2021 22:53:31 -0600 (CST) Date: Sun, 17 Jan 2021 22:53:31 -0600 From: Justin Pryzby To: Tomas Vondra Cc: Dean Rasheed , pgsql-hackers@postgresql.org Subject: Re: PoC/WIP: Extended statistics on expressions Message-ID: <20210118045331.GF8560@telsasoft.com> References: <2567ae7e-e1dd-48b5-054d-ed6ff81c0335@enterprisedb.com> <20210108023537.GA19743@telsasoft.com> <5305f9cf-3927-06c4-cd5b-e46cbc58bc7f@enterprisedb.com> <20210116232208.GB8560@telsasoft.com> <2f2a3b3b-93e4-723f-144e-bc21f10d6b61@enterprisedb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2f2a3b3b-93e4-723f-144e-bc21f10d6b61@enterprisedb.com> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sun, Jan 17, 2021 at 01:23:39AM +0100, Tomas Vondra wrote: > > CREATE TABLE t AS SELECT generate_series(1,9) AS i; > > CREATE STATISTICS s ON (i+1) ,(i+1+0) FROM t; > > ANALYZE t; > > SELECT i+1 FROM t GROUP BY 1; > > ERROR: corrupt MVNDistinct entry > > Thanks. There was a thinko in estimate_multivariate_ndistinct, resulting in > mismatching the ndistinct coefficient items. The attached patch fixes that, > but I've realized the way we pick the "best" statistics may need some > improvements (I added an XXX comment about that). That maybe indicates a deficiency in testing and code coverage. | postgres=# CREATE TABLE t(i int); | postgres=# CREATE STATISTICS s2 ON (i+1) ,(i+1+0) FROM t; | postgres=# \d t | Table "public.t" | Column | Type | Collation | Nullable | Default | --------+---------+-----------+----------+--------- | i | integer | | | | Indexes: | "t_i_idx" btree (i) | Statistics objects: | "public"."s2" (ndistinct, dependencies, mcv) ON FROM t on ... what ? -- Justin