Skip site navigation (1) Skip section navigation (2)

changing mvstats output to be valid JSON

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: changing mvstats output to be valid JSON
Date: 2017-04-20 19:38:28
Message-ID: 20170420193828.k3fliiock5hdnehn@alvherre.pgsql (view raw, whole thread or download thread mbox)
Thread:
Lists: pgsql-hackers
Hi,

While writing the recent ext.stats docs, I became annoyed by the output
functions of the new types used by multivariate statistics: they are
almost JSON, but not quite.  Since they can become largish, I propose
that we make a point of ensuring the output of those types is valid
JSON, so that they can be processed by JSON tools, particularly by
jsonb_pretty().  Note that the internal bytea format does not change;
this is only for human consumption (or for external tools that want to
examine the values), not for the planner.  Also, the input function for
those types rejects input, so nothing needs to care about reading these
values; ANALYZE is the only valid source for them.

With the proposed attached patch, those columns look more convenient to
work with:

ialvherre=# select jsonb_pretty(stxndistinct::jsonb), jsonb_pretty( stxdependencies::jsonb) from pg_statistic_ext;
     jsonb_pretty     │        jsonb_pretty        
──────────────────────┼────────────────────────────
 {                   ↵│ {                         ↵
     "1, 2": 33178,  ↵│     "1 => 2": 1.000000,   ↵
     "1, 5": 33178,  ↵│     "1 => 5": 1.000000,   ↵
     "2, 5": 27435,  ↵│     "5 => 1": 0.422367,   ↵
     "1, 2, 5": 33178↵│     "5 => 2": 0.482567,   ↵
 }                    │     "1, 2 => 5": 1.000000,↵
                      │     "1, 5 => 2": 1.000000,↵
                      │     "2, 5 => 1": 0.807367 ↵
                      │ }

Changes:

* Removed the external [ ]; the whole string is now a single JSON object.
* Removed the bitmapset output artifact.  (I introduced that while
  simplifying the code, but I now think that was a mistake).
* The attribute list is the object key.
* In ndistinct, the value is now an integer rather than a floating point
  number.

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachment: mvstats-output.patch
Description: text/plain (2.4 KB)

Responses

pgsql-hackers by date

Next:From: Peter EisentrautDate: 2017-04-20 19:41:29
Subject: Re: some review comments on logical rep code
Previous:From: Peter EisentrautDate: 2017-04-20 19:36:14
Subject: Re: Interval for launching the table sync worker

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group