| From: | Nathan Bossart <nathandbossart(at)gmail(dot)com> | 
|---|---|
| To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> | 
| Cc: | Michael Paquier <michael(at)paquier(dot)xyz>, pgsql-hackers(at)postgresql(dot)org | 
| Subject: | Re: pg_sequence_last_value() for unlogged sequences on standbys | 
| Date: | 2024-05-07 18:40:51 | 
| Message-ID: | 20240507184051.GA2600328@nathanxps13 | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-hackers | 
On Tue, May 07, 2024 at 01:44:16PM -0400, Tom Lane wrote:
> Nathan Bossart <nathandbossart(at)gmail(dot)com> writes:
>> 	char relpersist = seqrel->rd_rel->relpersistence;
> 
>> 	if (relpersist == RELPERSISTENCE_PERMANENT ||
>> 		(relpersist == RELPERSISTENCE_UNLOGGED && !RecoveryInProgress()) ||
>> 		!RELATION_IS_OTHER_TEMP(seqrel))
>> 	{
>> 		...
>> 	}
> 
> Should be AND'ing not OR'ing the !TEMP condition, no?  Also I liked
> your other formulation of the persistence check better.
Yes, that's a silly mistake on my part. I changed it to
	if ((RelationIsPermanent(seqrel) || !RecoveryInProgress()) &&
		!RELATION_IS_OTHER_TEMP(seqrel))
	{
		...
	}
in the attached v2.
>> I personally think that would be fine to back-patch since pg_sequences
>> already filters it out anyway.
> 
> +1 to include that, as it offers a defense if someone invokes this
> function directly.  In HEAD we could then rip out the test in the
> view.
I apologize for belaboring this point, but I don't see how we would be
comfortable removing that check unless we are okay with other sessions'
temporary sequences appearing in the view, albeit with a NULL last_value.
This check lives in the WHERE clause today, so if we remove it, we'd no
longer exclude those sequences.  Michael and you seem united on this, so I
have a sinking feeling that I'm missing something terribly obvious.
> BTW, I think you also need something like
> 
> -	int64		result;
> +	int64		result = 0;
> 
> Your compiler may not complain about result being possibly
> uninitialized, but IME others will.
Good call.
-- 
Nathan Bossart
Amazon Web Services: https://aws.amazon.com
| Attachment | Content-Type | Size | 
|---|---|---|
| v2-0001-Fix-pg_sequence_last_value-for-non-permanent-sequ.patch | text/x-diff | 2.7 KB | 
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Noah Misch | 2024-05-07 18:53:10 | Re: Weird test mixup | 
| Previous Message | Andres Freund | 2024-05-07 18:29:05 | Re: Use pgstat_kind_infos to read fixed shared stats structs |