From: | "Shinoda, Noriyoshi (SXD Japan FSIP)" <noriyoshi(dot)shinoda(at)hpe(dot)com> |
---|---|
To: | Jeff Davis <pgsql(at)j-davis(dot)com>, jian he <jian(dot)universality(at)gmail(dot)com>, Corey Huinker <corey(dot)huinker(at)gmail(dot)com> |
Cc: | Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Nathan Bossart <nathandbossart(at)gmail(dot)com>, 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>, Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com>, "alvherre(at)alvh(dot)no-ip(dot)org" <alvherre(at)alvh(dot)no-ip(dot)org> |
Subject: | RE: Statistics Import and Export |
Date: | 2024-10-12 13:02:55 |
Message-ID: | DM4PR84MB17345E2DFF28A5557B7CBC3CEE7A2@DM4PR84MB1734.NAMPRD84.PROD.OUTLOOK.COM |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi,
Thank you for developing this great feature. I have tested the committed feature.
The manual for the pg_set_relation_stats function says the following:
"The value of relpages must be greater than or equal to 0"
However, this function seems to accept -1 for the relpages parameter. Below is an example of execution:
---
postgres=> CREATE TABLE data1(c1 INT PRIMARY KEY, c2 VARCHAR(10));
CREATE TABLE
postgres=> SELECT pg_set_relation_stats('data1', relpages=>-1);
pg_set_relation_stats
-----------------------
t
(1 row)
postgres=> SELECT relname, relpages FROM pg_class WHERE relname='data1';
relname | relpages
---------+----------
data1 | -1
(1 row)
---
The attached patch modifies the pg_set_relation_stats function to work as described in the manual.
Regards,
Noriyoshi Shinoda
-----Original Message-----
From: Jeff Davis <pgsql(at)j-davis(dot)com>
Sent: Saturday, October 12, 2024 8:11 AM
To: jian he <jian(dot)universality(at)gmail(dot)com>; Corey Huinker <corey(dot)huinker(at)gmail(dot)com>
Cc: Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>; Bruce Momjian <bruce(at)momjian(dot)us>; Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>; Nathan Bossart <nathandbossart(at)gmail(dot)com>; 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>; Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com>; alvherre(at)alvh(dot)no-ip(dot)org
Subject: Re: Statistics Import and Export
On Mon, 2024-09-23 at 08:57 +0800, jian he wrote:
> newtup = heap_modify_tuple_by_cols(ctup, tupdesc, ncols, replaces,
> nulls);
>
> you just directly declared "bool nulls[3] = {false, false, false};"
Those must be false (not NULL), because in pg_class those are non-NULL attributes. They must be set to something whenever we update.
> if any of (RELPAGES_ARG, RELTUPLES_ARG, RELALLVISIBLE_ARG) is null,
> should you set that null[position] to true?
If the corresponding SQL argument is NULL, we leave the existing value unchanged, we don't set it to NULL.
> otherwise, i am confused with the variable nulls.
>
> Looking at other usage of heap_modify_tuple_by_cols, "ncols" cannot be
> dynamic, it should be a fixed value?
> The current implementation works, because the (bool[3] nulls) is
> always false, never changed.
> if nulls becomes {false, false, true} then "ncols" must be 3, cannot
> be 2.
heap_modify_tuple_by_cols() uses ncols to specify the length of the values/isnull arrays. The "replaces" is an array of attribute numbers to replace (in contrast to plain heap_modify_tuple(), which uses an array of booleans).
We are going to replace a maximum of 3 attributes, so the arrays have a maximum size of 3. Predeclaring the arrays to be 3 elements is just fine even if we only use the first 1-2 elements -- it avoids a needless heap allocation/free.
Regards,
Jeff Davis
Attachment | Content-Type | Size |
---|---|---|
relpages_stat_update_v1.diff | application/octet-stream | 633 bytes |
From | Date | Subject | |
---|---|---|---|
Next Message | Alexander Korotkov | 2024-10-12 14:25:45 | Re: POC, WIP: OR-clause support for indexes |
Previous Message | Nitin Motiani | 2024-10-12 12:35:06 | Re: Inval reliability, especially for inplace updates |