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 1m2vbf-0000tZ-DU for pgsql-hackers@arkaria.postgresql.org; Mon, 12 Jul 2021 13:04:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m2vbd-00042M-8f for pgsql-hackers@arkaria.postgresql.org; Mon, 12 Jul 2021 13:04:17 +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 1m2vbd-00042E-0e for pgsql-hackers@lists.postgresql.org; Mon, 12 Jul 2021 13:04:17 +0000 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1m2vbZ-0002Mv-E2 for pgsql-hackers@lists.postgresql.org; Mon, 12 Jul 2021 13:04:16 +0000 Received: by mail-ed1-x536.google.com with SMTP id t3so27851291edt.12 for ; Mon, 12 Jul 2021 06:04:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=ySSGoy2jHRpgj5y1IzbgBqVg5evt1ebLhvqeZ7FPZH4=; b=ck9nxVD6Lz1d+zImyX/A+Z4LB5Lh+X5C+J9Jmu/Vx2ORKPDpJsK6F3PHsDrGTmTL8k OJZf8aPrtv0ghmAsta5x1AZl7AfpZkZVbb204ltx0DjiMGOX/uRKE28dxPIAzgKvICaf fCw8MDGKCjtv7gyWZ+4/BbQ1Ew20Qa8/PafmkJPZTwdfNc4tk7kFnrGPnBw6SZC5m40N 6kU6cQgJddQIwUIydsPt47qqQjd6NZBEu6feDINW5N7Ygy5ZmuTT/kmRkjOVrsaLaSyr uQ1IGvBB4+uy4PPebmec2gvNv1R6deLEr1UiONkqx8rSbCHO9ltQ0W4wPx81glNhlb6o ReBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=ySSGoy2jHRpgj5y1IzbgBqVg5evt1ebLhvqeZ7FPZH4=; b=gdgMJ8kAqIPrd069R4Skaw2Hn8QrEcqPi3MA7hXBqDnzk9/ZHRHwrEMG9t0HBT/lyf /Ti6R+KQwQtAWFwAOni2CSOJbq8+i5LFWRfnTmJuXzzDsnp2I6vKPzDrC2FwceB0sj/e cZ/BZtYwab8wyNbt6d++OAS9fBigMFYjxfCBWpSVFj8jxnL1DHlgjxO1Fm1jiJIKijn/ V2BmEoTTyb89auad7ddNmwt2Ap0eKikvSmWtxk1ZmcxLvdU+SFSJ6KMGTpNgVyQSIKH/ gnYttrmmoGJAT2tR+ZJ/CBrtQqzAijPbBJyXV2+HeQvh8w956CgJd10ARsiAGNS17M92 qo2w== X-Gm-Message-State: AOAM533WFItf6k5h+akWmyVdmoZe/YjWjyNTU1RxInDcuNiFSsuKccMz ZXhh3GBa5cKfdsKxez+Nw8d8t8Nk3nnt0DW01tuTFe+UBaCNbrQsFAsqb1Wyq3+4o3H0pcWC/Fv qf+KDvcrT/QnlNCGM3f4bAe6iGIQXmSs9rF/kgKPXwyXb6TtIIbQEJPVxNuil04kHoM1osRQfBt i5PnZ/MutvZ3WckJfMhoE9lqWp9wBrFRYFTx3coG5EU0m81YbGO7lF/IINC7qMQf8jKlz8t1E20 GO+PB8+59ZY/RqYFQSMMlQqje40gsAJCjl4jou3XIecR2ce6lZasQ== X-Google-Smtp-Source: ABdhPJzkciIBLsufHM4DjMH9hk4N+MbsBGavaOOpLpk1+58yBv/u9ASWWD/lfKxT8FaLymFkzVq1WA== X-Received: by 2002:aa7:d8d0:: with SMTP id k16mr17371180eds.202.1626095051759; Mon, 12 Jul 2021 06:04:11 -0700 (PDT) Received: from [10.137.0.19] (ip-86-49-254-183.net.upcbroadband.cz. [86.49.254.183]) by smtp.gmail.com with ESMTPSA id h17sm2296952ejl.37.2021.07.12.06.04.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 12 Jul 2021 06:04:10 -0700 (PDT) Subject: Re: pg_stats and range statistics To: Egor Rogov , Soumyadeep Chakraborty Cc: PostgreSQL Hackers References: <55c8ecd4-57d0-5c63-6fe3-1b81e8caea9d@enterprisedb.com> From: Tomas Vondra Message-ID: Date: Mon, 12 Jul 2021 15:04:08 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 7/12/21 1:10 PM, Egor Rogov wrote: > Hi, > > thanks for the review and corrections. > > On 11.07.2021 21:54, Soumyadeep Chakraborty wrote: >> Hello, >> >> This should have been added with [1]. >> >> Excerpt from the documentation: >> "pg_stats is also designed to present the information in a more readable >> format than the underlying catalog — at the cost that its schema must >> be extended whenever new slot types are defined for pg_statistic." [2] >> >> So, I added a reminder in pg_statistic.h. > > Good point. > > >> Attached is v2 of this patch with some cosmetic changes. > > I wonder why "TODO: catalog version bump"? This patch doesn't change > catalog structure, or I miss something? > It changes system_views.sql, which is catalog change, as it redefines the pg_stats system view (it adds 3 more columns). So it changes what you get after initdb, hence catversion has to be bumped. > >> Renamed the columns a >> bit and updated the docs to be a bit more descriptive. >> (range_length_empty_frac -> empty_range_frac, range_bounds_histogram -> >> range_bounds_histograms) > > I intended to make the same prefix ("range_") for all columns concerned > with range types, although I'm fine with the proposed naming. > Yeah, I'd vote to change empty_range_frac -> range_empty_frac. > >> One question: >> >> We do have the option of representing the histogram of lower bounds >> separately >> from the histogram of upper bounds, as two separate view columns. >> Don't know if >> there is much utility though and there is a fair bit of added >> complexity: see >> below. Thoughts? > > I thought about it too, and decided not to transform the underlying data > structure. As far as I can see, pg_stats never employed such > transformations. For example, STATISTIC_KIND_DECHIST is an array > containing the histogram followed by the average in its last element. It > is shown in pg_stats.elem_count_histogram as is, although it arguably > may be splitted into two fields. All in all, I believe pg_stats's job is > to "unpack" stavalues and stanumbers into meaningful fields, and not to > try to go deeper than that. > Not firm opinion, but the pg_stats is meant to be easier to read/understand for humans. So far the transformation were simple because all the data was fairly simple, but the range stuff may need more complex transformation. For example we do quite a bit more in pg_stats_ext views, because it deals with multi-column stats. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company