Re: Custom ordering operator for type xid

From: Alexander Lipatov <lipatov(at)mindbox(dot)cloud>
To: Rui DeSousa <rui(dot)desousa(at)icloud(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-admin(at)postgresql(dot)org
Subject: Re: Custom ordering operator for type xid
Date: 2024-06-17 15:40:38
Message-ID: E0FDD879-BB8A-44DC-A06E-02296A95B485@mindbox.cloud
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Yes exactly. And in Postgres they use xmin as an analogue of SQL Server rowversion/timestamp ([docs](https://www.npgsql.org/efcore/modeling/concurrency.html?tabs=data-annotations))

Ok, I think I'll wait for their response and won't do anything questionable on the part of Postgres itself. Thank you!

> 17 июня 2024 г., в 18:33, Rui DeSousa <rui(dot)desousa(at)icloud(dot)com> написал(а):
>
>
>
>> On Jun 17, 2024, at 11:03 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>>
>> Alexander Lipatov <lipatov(at)mindbox(dot)cloud> writes:
>>> **Question**: Is it safe to create custom ordering operators for the `xid` type and a default operator class with these operators?
>>
>> I wouldn't do it, mainly because the semantics of what you've written
>> have nothing to do with the actual behavior of xids. (The real
>> comparison behavior is "circular", which can't be modeled as a total
>> order, which is why there's not a built-in opclass already.)
>>
>> What is that ORM doing with XIDs anyway, and is there a good reason
>> not to run away screaming from such an ill-thought-out product?
>> I don't believe for a minute that this is going to be the only
>> semantic issue you'll run into with an ORM that thinks it knows
>> how XIDs behave despite a clear lack of even the most minimal
>> investigation into the question.
>>
>> regards, tom lane
>>
>>
>
>
> Assuming they are using it for opportunist locking. I have use this method before but not with a system column.
>
> i.e.
>
> 1. Application fetches the record with an xmin of 55, no need to maintain an open transaction: select xmin, * from table where id = 8;
> 2. Application edits record
> 3. Application saves record: update table set col1 = ‘x’ where id = 8 and xmin = 55;
> 4. If the record was updated by another session then xmin would be different, the save would fail by updating zero records, and user would have to reedit the record.
>
> Not a fan of ORMs myself but I think opportunist locking has its place.
>

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Phani Prathyush Somayajula 2024-06-18 10:38:10 Postgres RDS DB Parameters ::INSTANCE CLASS : db.m6id.2xlarge
Previous Message Rui DeSousa 2024-06-17 15:33:17 Re: Custom ordering operator for type xid