Re: Statistics Import and Export

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Corey Huinker <corey(dot)huinker(at)gmail(dot)com>
Cc: Jeff Davis <pgsql(at)j-davis(dot)com>, Nathan Bossart <nathandbossart(at)gmail(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Magnus Hagander <magnus(at)hagander(dot)net>, Stephen Frost <sfrost(at)snowman(dot)net>, Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>, Peter Smith <smithpb2250(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, alvherre(at)alvh(dot)no-ip(dot)org
Subject: Re: Statistics Import and Export
Date: 2025-01-17 14:20:12
Message-ID: CACJufxGreTY7qsCV8+Bkuv0p5SXGTScgh=D+Dq6=+_=XTp7FWg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

hi.

SELECT * FROM pg_catalog.pg_restore_relation_stats(
'relation', 'public.tenk1_hundred'::regclass,
'version', '180000'::integer,
'relpages', '11'::integer,
'reltuples', '10000'::real,
'relallvisible', '0'::integer
);
dump and execute the above query generated a warning
WARNING: missing lock for relation "tenk1_hundred" (OID 18431,
relkind i) @ TID (15,34)

in dumpRelationStats(Archive *fout, const RelStatsInfo *rsinfo)
{
getAttStatsExportQuery(query, fout, dobj->namespace->dobj.name,
dobj->name);
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
appendAttStatsImport(out, fout, res);
PQclear(res)
}
i think, getAttStatsExportQuery no need to join catalog pg_namespace.

for example, after getAttStatsExportQuery, query->data looks like:
SELECT c.oid::regclass AS relation,
s.attname,s.inherited,
current_setting('server_version_num') AS version,
s.null_frac,
s.avg_width,
s.n_distinct,
s.most_common_vals,
s.most_common_freqs,
s.histogram_bounds,
s.correlation,
s.most_common_elems,
s.most_common_elem_freqs,
s.elem_count_histogram,
s.range_length_histogram,
s.range_empty_frac,
s.range_bounds_histogram
FROM pg_stats s JOIN pg_namespace n ON n.nspname = s.schemaname JOIN pg_class c
ON c.relname = s.tablename AND c.relnamespace = n.oid
WHERE s.schemaname = 'public'
AND s.tablename = 'varchar_tbl'
ORDER BY s.attname, s.inherited
-----------------------
The SELECT column list doesn't mention/use any of the pg_namespace columns.

```WHERE s.schemaname = 'public' AND s.tablename = 'varchar_tbl'``
" s.schemaname" combined with "s.tablename" will make sure that the
output is unique, at most one row.

i did a minor refactor about validation dumpData, dumpSchema,
dumpStatistics option.
I think it's more intuitive. first we process ``*only``option then
process no* option

Attachment Content-Type Size
refactor_pg_dump_onlyoption.no-cfbot application/octet-stream 2.0 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Ryo Kanbayashi 2025-01-17 14:49:46 Re: ecpg command does not warn COPY ... FROM STDIN;
Previous Message Bruce Momjian 2025-01-17 14:16:08 Re: Re: proposal: schema variables