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 1kBV22-0007RU-3F for pgsql-hackers@arkaria.postgresql.org; Fri, 28 Aug 2020 03:26:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kBV20-0002c7-S1 for pgsql-hackers@arkaria.postgresql.org; Fri, 28 Aug 2020 03:26:24 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kBV1z-0002by-M8 for pgsql-hackers@lists.postgresql.org; Fri, 28 Aug 2020 03:26:23 +0000 Received: from mail-qk1-x741.google.com ([2607:f8b0:4864:20::741]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kBV1x-0003xt-0W for pgsql-hackers@lists.postgresql.org; Fri, 28 Aug 2020 03:26:22 +0000 Received: by mail-qk1-x741.google.com with SMTP id b14so8205087qkn.4 for ; Thu, 27 Aug 2020 20:26:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=+BlebsWoYDn+AozcY27MfCdH2TjyzAkW/K4xqgS6Kvo=; b=x3/jVZtn/MxeC6bK04+xjQbp87SvLJsmjhOGtpgbhNNuVF/wTf9SOj/hSUWL0ebMuG SnFHEKu0CHD6e5s7kNYr5PkJYHFtEd69HS9CuzK1XZW/vLxp5pSf+SoIZnjliMo98ioL qh8MJUic1A8Jxk09XPm5sFg7Z4bb2IScYJDFmhoFogesbZFUR2t9em8ulXbYT/wZpIGj m0eDuGYtJ07TfKgFrSkMZ/QHoR0gb9mVZM49k40JUTye2uHVTBTvpptdwBxJ+eneHsNh 5RApQLH46U/hF4LTOQZ0qoKD0dMRaTNpeLAgvGLHdhTzuoa945818XDDzqdv2E7+Oxed jSFQ== 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:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=+BlebsWoYDn+AozcY27MfCdH2TjyzAkW/K4xqgS6Kvo=; b=GROTbgkhkp4PuwY2Jz/Jk4jdc+UDu+mMtzh/Ek8tKuLdQDcJ4KkHl9a2rO3JgycqSZ F0tmnwCR7HufLJ1hrkfYUxwVkEp6dbiB+NRJIhLdlUXSZPFIK+XbtXYi8xO8y/ePD6pd yErsUpO1rIrIoluFG+q2YIdwHZxsNtfVCLURHtx306lEr3T7v+S2FQk5hmjN2vw8fIpG hoi4l3MEEpux8sp/UsVdFjLTt1SgaatByBAeYGbEoj2KMvRWbrR43cuGtY9YLdioZe50 JNam2oANh1Xc4LfjNtQVtFz1RBFjdFRbuJZ/D7deaeQpEqggQFcNxrD4U5vzfSBaz0Ce VtPA== X-Gm-Message-State: AOAM532E8CJIwq28nVJTAINTjnQ71wfWwrAIw76p/Q7HJSw0Z/qB8QzJ vehab2AV0Bj+enbUXHHAJN3eIw== X-Google-Smtp-Source: ABdhPJxjJwxJ5BSGe+w2tsdi06V2U26NjF1BWIoJNwXNs3YYgNiGpauI7BZmQTLLCh+6slMISLJq0Q== X-Received: by 2002:a05:620a:1219:: with SMTP id u25mr7403639qkj.72.1598585179971; Thu, 27 Aug 2020 20:26:19 -0700 (PDT) Received: from perhan.alvh.no-ip.org ([190.95.19.47]) by smtp.gmail.com with ESMTPSA id i14sm3549374qtq.33.2020.08.27.20.26.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Aug 2020 20:26:19 -0700 (PDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id BCB502A03A1; Thu, 27 Aug 2020 23:26:17 -0400 (-04) Date: Thu, 27 Aug 2020 23:26:17 -0400 From: Alvaro Herrera To: Tatsuro Yamada Cc: Julien Rouhaud , Pavel Stehule , PostgreSQL Hackers , Tomas Vondra Subject: Re: list of extended statistics on psql Message-ID: <20200828032617.GA22893@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <6fc07377-c8c5-c762-2e2c-77059d8147af@nttcom.co.jp_1> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2020-Aug-28, Tatsuro Yamada wrote: > > IMO the per-type columns should show both the type being enabled as > > well as it being built. > > Hmm. I'm not sure how to get the status (enabled or disabled) of > extended stats. :( > Could you explain it more? pg_statistic_ext_data.stxdndistinct is not null if the stats have been built. (I'm not sure whether there's an easier way to determine this.) > * The suggested column order is like this: > =================== > Name | Schema | Table | Columns | Ndistinct | Dependencies | MCV > -----------+--------+-------+------------------+-----------+--------------+----- > stts_1 | public | t1 | a, b | f | t | f > stts_2 | public | t1 | a, b | t | t | f > stts_3 | public | t1 | a, b | t | t | t > stts_4 | public | t2 | b, c | t | t | t > =================== I suggest to do this Name | Schema | Definition | Ndistinct | Dependencies | MCV -----------+--------+--------------------------+-----------+--------------+----- stts_1 | public | (a, b) FROM t1 | f | t | f > I suppose that the current column order is sufficient if there is > no improvement of extended stats on PG14. Do you know any plan to > improve extended stats such as to allow it to cross multiple tables on PG14? I suggest that changing it in the future is going to be an uphill battle, so better get it right from the get go, without requiring a future restructure. > In addition, > Currently, I use this query to get Extended stats info from pg_statistic_ext. Maybe something like this would do SELECT stxnamespace::pg_catalog.regnamespace AS "Schema", stxname AS "Name", format('%s FROM %s', (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(attname),', ') FROM pg_catalog.unnest(stxkeys) s(attnum) JOIN pg_catalog.pg_attribute a ON (stxrelid = a.attrelid AND a.attnum = s.attnum AND NOT attisdropped)), stxrelid::regclass) AS "Definition", CASE WHEN stxdndistinct IS NOT NULL THEN 'built' WHEN 'd' = any(stxkind) THEN 'enabled, not built' END AS "n-distinct", CASE WHEN stxddependencies IS NOT NULL THEN 'built' WHEN 'f' = any(stxkind) THEN 'enabled, not built' END AS "functional dependencies", CASE WHEN stxdmcv IS NOT NULL THEN 'built' WHEN 'm' = any(stxkind) THEN 'enabled, not built' END AS mcv FROM pg_catalog.pg_statistic_ext es INNER JOIN pg_catalog.pg_class c ON stxrelid = c.oid LEFT JOIN pg_catalog.pg_statistic_ext_data esd ON es.oid = esd.stxoid ORDER BY 1, 2, 3; -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services