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 1i33bV-0007K1-LP for pgsql-docs@arkaria.postgresql.org; Wed, 28 Aug 2019 19:27:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i33bU-0002iT-CJ for pgsql-docs@arkaria.postgresql.org; Wed, 28 Aug 2019 19:27:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i33bT-0002iM-WA for pgsql-docs@lists.postgresql.org; Wed, 28 Aug 2019 19:27:36 +0000 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i33bQ-0004PM-Tc for pgsql-docs@postgresql.org; Wed, 28 Aug 2019 19:27:35 +0000 Received: by mail-wr1-x435.google.com with SMTP id t16so946063wra.6 for ; Wed, 28 Aug 2019 12:27:32 -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:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ASH5DMsBtqarkTLmD4kR/rUhmtQ+FT5DUTTPQcPmCAc=; b=zB28qr7ruMQRNywSpnSFhwPpQCw2l/Fu2izPsnJB+VfuLfrEOjT4rySoNhKAgLjPWP 3cNfOsvf0ooR2oMKQbZvVi6X8YEBW3RsYxaQzplYuHrVA2GcYpO6+uHUt9ZGwYsSODIk C5vPdBVvACG7dY8v8aI8nwLVGAYzlL9ccswklIscE174pihCUPTPVfmMMjTXkLAhzMN5 jyT+3zMx5jYH5u9t2ptnL/Nnjt5TD+KEQaoXTmLMYvWnuEpIW74ktd0PpXuGuLi3iviz 6ycO5991pTqLAqrFcm97Rfb/t4hBFJk12hRbyqb6LFDrqflnvNMY5HAqk/BjBZFpXLTO xqmg== 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=ASH5DMsBtqarkTLmD4kR/rUhmtQ+FT5DUTTPQcPmCAc=; b=ipJF48oALTK30r4GktPKfwNUK5uNZjVyhnvKne1J9jaLuAruI5QGKhX46bIMKB58SG anqBSCMIONdR1yoy+uXwoYt8Dm/pE0pmzZxJLMUe3RCqJi3Bh0dkvMmlRBs9wIoM53ad qK5MWFQ0njfZuzcYDgdjW75LoPprOh3Xc3zJdBCL8blwny/dz/5WUZ58uroZO2CM6RqI zy0IGX9GNP5jBvpi5JPHReEo2McJLvzTNDYRY4+U3Z0LPrgVJpxt1vJOOi+itvzmsBzH 1uX6w+h/UD70UeonB47wWE2SK2chi3BjDWAJpXCpoprE0DpPK2lDYKhk1MbiVitTCHkc /SJg== X-Gm-Message-State: APjAAAVbtz0i9pT3eb8TvoBJbaXMuRFmENMc8Hgg2bplpzBaXdJTyjV9 gObZT4Swel/sxlpQbcIkx4uB9yuZjsCD2Q== X-Google-Smtp-Source: APXvYqziNFf7FM5BMAwO3QfKxn9x7rUx8iIxIcghyNA4FZT1wfcJGcJPsZ/l7DSKop1yst7qvdRj4Q== X-Received: by 2002:a5d:52cc:: with SMTP id r12mr6193276wrv.272.1567016743414; Wed, 28 Aug 2019 11:25:43 -0700 (PDT) Received: from localhost (host-46-23-60-67.maxtel.cz. [46.23.60.67]) by smtp.gmail.com with ESMTPSA id e13sm70742wmh.44.2019.08.28.11.25.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2019 11:25:42 -0700 (PDT) Date: Wed, 28 Aug 2019 20:25:41 +0200 From: Tomas Vondra To: Bruce Momjian Cc: PostgreSQL-documentation Subject: Re: Most-common value docs in PG 12 Message-ID: <20190828182541.zuexunho3hgb7vlw@development> References: <20190828162238.GA8360@momjian.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20190828162238.GA8360@momjian.us> User-Agent: NeoMutt/20180716-1444-295967-dirty List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, Aug 28, 2019 at 12:22:38PM -0400, Bruce Momjian wrote: >Our docs for most-common values in PG 12 has: > >--> CREATE STATISTICS stts3 (mcv) ON state, city FROM zipcodes; > > ANALYZE zipcodes; > > SELECT m.* FROM pg_statistic_ext join pg_statistic_ext_data on (oid = stxoid), > pg_mcv_list_items(stxdmcv) m WHERE stxname = 'stts3'; > > index | values | nulls | frequency | base_frequency > -------+------------------------+-------+-----------+---------------- >--> 0 | {Washington, DC} | {f,f} | 0.003467 | 2.7e-05 > 1 | {Apo, AE} | {f,f} | 0.003067 | 1.9e-05 > 2 | {Houston, TX} | {f,f} | 0.002167 | 0.000133 > 3 | {El Paso, TX} | {f,f} | 0.002 | 0.000113 > >It seems pg_mcv_list_items() reports the column names in the order they >appear in the table, not in the order they appear in the CREATE >STATISTICS statement. Same for psql \d: > > \d zipcodes > Table "public.zipcodes" > Column | Type | Collation | Nullable | Default > ---------+------+-----------+----------+--------- > city | text | | | > state | text | | | > zipcode | text | | | > Statistics objects: >--> "public"."stts3" (mcv) ON city, state FROM zipcodes > > >If this is so, why don't we show the CREATE STATISTICS example as >city/state, and not state/city? > Yes, we deduplicate the attributes and store them sorted by attnum. I'm not sure it makes sense to change the example to match this order, which is mostly an implementation detail, though. It might be better to point out the order may not exactly match CREATE STATISTICS, and point users to what e.g. "\d" shows (because that will show the order as stored in the system catalog). regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services