Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sJEML-003VpE-SA for pgsql-admin@arkaria.postgresql.org; Mon, 17 Jun 2024 15:33:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sJEMI-000rqz-Rf for pgsql-admin@arkaria.postgresql.org; Mon, 17 Jun 2024 15:33:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sJEMI-000rqS-6I for pgsql-admin@lists.postgresql.org; Mon, 17 Jun 2024 15:33:27 +0000 Received: from qs51p00im-qukt01072701.me.com ([17.57.155.16]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sJEMG-0028gv-Ls for pgsql-admin@postgresql.org; Mon, 17 Jun 2024 15:33:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1718638403; bh=/nDw4NapPWKY2agLkijIfE19vckcah55TSmW8mmH71I=; h=Content-Type:Mime-Version:Subject:From:Date:Message-Id:To; b=i7YC1HikDRML9BsBaELcflZeRFt4ShUZP8VlLnAjard5kPBdjVq8czp8d2imhmJrN GdQrlNrIVm5+P/16KyJhg8x6ur59kLdbKCuvp8Pj4v5ghSAc0iV74+nvteXCXYmC2y ERRPkLl31d81p3Z3twyPYgu6lklFf2IxjahKatV4BIjUfhxhUBHaXA90v4AjTxn2vk l85lUiZNnjkzNpRaCcxVawY6QlmB3dyRnDVX6W+Fgs6wFl7wX9i79Bi3D03PAlwIvr LSJEtoo31y9zQ5ucpk5wiqNaaBS5CDf8C841a0GU2PqyRAhR7IuM2ULBUTv9gfxYV9 bmGi80VvYw79A== Received: from smtpclient.apple (qs51p00im-dlb-asmtp-mailmevip.me.com [17.57.155.28]) by qs51p00im-qukt01072701.me.com (Postfix) with ESMTPSA id D806315C01DF; Mon, 17 Jun 2024 15:33:21 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.8\)) Subject: Re: Custom ordering operator for type xid From: Rui DeSousa In-Reply-To: <3179495.1718636638@sss.pgh.pa.us> Date: Mon, 17 Jun 2024 11:33:17 -0400 Cc: Alexander Lipatov , pgsql-admin@postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <8A9CD524-7C29-4665-BCFB-10C4B8A8CD94@icloud.com> References: <2EA9BF93-EE2B-4B84-B21D-5EA86FA63913@mindbox.cloud> <3179495.1718636638@sss.pgh.pa.us> To: Tom Lane X-Mailer: Apple Mail (2.3696.120.41.1.8) X-Proofpoint-ORIG-GUID: JjfWBc0yPkqk6ky0mRE7q6ev3Z7o6QRb X-Proofpoint-GUID: JjfWBc0yPkqk6ky0mRE7q6ev3Z7o6QRb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-17_13,2024-06-17_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 adultscore=0 phishscore=0 bulkscore=0 mlxlogscore=924 clxscore=1011 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2406170121 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Jun 17, 2024, at 11:03 AM, Tom Lane wrote: >=20 > Alexander Lipatov writes: >> **Question**: Is it safe to create custom ordering operators for the = `xid` type and a default operator class with these operators? >=20 > 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.) >=20 > 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. >=20 > regards, tom lane >=20 >=20 Assuming they are using it for opportunist locking. I have use this = method before but not with a system column. i.e.=20 1. Application fetches the record with an xmin of 55, no need to = maintain an open transaction: select xmin, * from table where id =3D 8; = =20 2. Application edits record 3. Application saves record: update table set col1 =3D =E2=80=98x=E2=80=99= where id =3D 8 and xmin =3D 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.