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.96) (envelope-from ) id 1wev9k-0058HG-0Q for pgsql-bugs@arkaria.postgresql.org; Wed, 01 Jul 2026 13:39:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wev9h-00Dv4K-0f for pgsql-bugs@arkaria.postgresql.org; Wed, 01 Jul 2026 13:39:09 +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.96) (envelope-from ) id 1wev9g-00Dv4C-2u for pgsql-bugs@lists.postgresql.org; Wed, 01 Jul 2026 13:39:08 +0000 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wev9e-00000001CY8-2Y17 for pgsql-bugs@lists.postgresql.org; Wed, 01 Jul 2026 13:39:08 +0000 Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-697cee2eb6dso623520a12.0 for ; Wed, 01 Jul 2026 06:39:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1782913145; cv=none; d=google.com; s=arc-20260327; b=A81+dpW+2dVtcbFu+NWWR2na1ixRNFxxnG0iuxTypnIoZ8r+yyBQQsKJBtgK+lSdEk KJ16oytpuP5vemEfpahTiaakmDIYeB/zzoZUoEDJ8hLQqec6cKFemb9lm7ijt4SBLHnv VKMuYv9pxlSF68qL3Ptrx89uxU7VMJIc2da0EiCUFvYsvsS6xsUK0Y0FYfJzINDLMhQv s07BMucjBF5c8TiaQ7mhIGukKXhFDrc850THxAVRDTDxncOx5+1UducLWFVGeNHG185/ Wk66P3puNeztmec3U6HyJOOScu+jgUB2QCwKRUyluAp2a6Np6eSrdDN/3bvkTRUffUN+ 9GmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=uPboQ5Teu0vjXX22oTKEWN5Q/6FoffiDdw/Xw8+0s7I=; fh=PKpp2EMaW91oKJWXIaePgxgoJ80iPVAvdYFZcP36kDE=; b=LXrMrDxECOCnPfPlmKEIhKFDSAA8rU2RP1fbPSdJTmD8a5jMex7LcdQ4sBDmVA0yQZ 6hGjQw0jwF86YHM4q0tzBqeYh5OmrVgiiSe1bpgSjPRBegN4DXgl7BiltbTfeys1OGIQ m8fPCRrRDQGlL8NE3Er0RwfhMvDc2OlMETcphHOjxI7wPXI42LAcVSDUYRMISNH54hqF acW2cLdOG7mKF56KLVxTRRnkRESZ7zLafOiHZrHeD673JgzHSfVw4IQWUrt22lG7NZ0m 3XmUigbEx13y6HG09Z6T63P71o3xFUZZV0ufh+YXQglbONWSp3alRDikAnJREvGwI0Yg FugA==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782913145; x=1783517945; darn=lists.postgresql.org; h=content-type:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:from:to:cc:subject:date:message-id:reply-to :content-type; bh=uPboQ5Teu0vjXX22oTKEWN5Q/6FoffiDdw/Xw8+0s7I=; b=n/KxNkbqy+mrGqxeg/qs36s87U9+NyCKSj5yqG1Wv5DG67YCGsSLQzSWWqqmg4h0lf 3y8pVpqakjJsoxA9Ug6EITz6LdzuAjXT+xJiZwAhYY5X5wpLr/1lBTV4YHA7sM47mqfm tWS4iFConff+YLv1hEsjrx+eYUaQyvAUJM3sS0uDOcs+bl9HYJPfogUiTEd1qbfDh74a jPRB9PdBJxkA6QE7r12OBXcygYk7D9lRr9zV+xAFeqgy4/Un0E4prdUtMwprqzVSwVnW 4N1k/A+bfpD7q6tnjZydGzZ92T5Us4ctk6LMdjPc0iS0D/0OMykXEt7S8rAKZjUr5RBO 1Icw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782913145; x=1783517945; h=content-type:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=uPboQ5Teu0vjXX22oTKEWN5Q/6FoffiDdw/Xw8+0s7I=; b=N0cV32cem4JIkcg0HX7jdJVGyAKgKPPO8HxR38ckfwA8z/yqcPV/n9ljrQ2wbP4Iio cQue2NqtjFufdK4LB4JI2uQLwbAEV159fj5il++PGfotg42sI4ayRV4SGviF66AErQ4N CpGeSwOPwfJ22ehkg3ilBAOYAcnuNWGtrrD81odB9jyRgLU1faOeFHuvBULDPTUJz7ed ue/Yxp/iLarSRagmrgA/BpssmPAVQzK2SLkcASuFKPHpyH0MiE78LTo7bn0jqWWY4p80 8UCiJ2oB09z4O4PHnyFYYipUWoHOcauu4YQDUZQA1bnAqzrYAwz3MQT9mO7lxrOSxygb bfBw== X-Forwarded-Encrypted: i=1; AHgh+RpDJRuU+pNp8EImx4LNEvuikRi1VFJtcgk+h5HLt4w7h4Z2Ekvq+BVrSP/r3vlfL5shTJhx9aR0DIgY@lists.postgresql.org X-Gm-Message-State: AOJu0YzPJqvCAvuHD1nCG+tyM3SVfeLc7G3DAM/a5ZkET8XN2X9StJrW 9WTDOjFVsnojpm+E8NPn3UtNY84AS0TqnZEQJCx7Gs6uIBjhVYYkx/pDBkwcdfj7if89eMi9tMb 157Jb6BPz7NYx/RKbSAW4GQyZ/ZV5pZ6v1ePD X-Gm-Gg: AfdE7cnYfCxdmLf+1dHAnuaNPyfYcyAa8r/w6ODV5n32Js0VuF9hARUt9+Q0TuhoGIS 4oUXDLhDenwgXzIyET+qdJbU9offeGDpL+sN4ujNiYOxAe0UON1AALjhI00Yqgfbzw3qsJ2Qjun Fp+MHADGZDfAEaMkXdLMVVPCJm9Zs17NS/pXi1QZgPZ6dU6BdU1VVSfm8oW9N7HVJ9EJ/3O+Sku Ks+dPnZc+CCfRhSmsKFWrdnjHHnHvfgTeQCFg9fsfe7zaGlIaceYmGwDDg1Ze43cGzFWNdm6ynQ 6OOtJfYKvz0wyefZheDsi702zNbGiA== X-Received: by 2002:a05:6402:1357:b0:698:415d:318b with SMTP id 4fb4d7f45d1cf-698a2c70b79mr247685a12.13.1782913144896; Wed, 01 Jul 2026 06:39:04 -0700 (PDT) MIME-Version: 1.0 References: <1703741.1782745481@sss.pgh.pa.us> <1717564.1782747310@sss.pgh.pa.us> <2231547.1782774522@sss.pgh.pa.us> In-Reply-To: <2231547.1782774522@sss.pgh.pa.us> From: Bill Kim Date: Wed, 1 Jul 2026 22:38:52 +0900 X-Gm-Features: AVVi8CewI01jrmLYj0w2Duvei083Z5jzOAVW6qzeg52T9ivvD9tb7sjii4XNvaU Message-ID: Subject: Re: BUG #19524: NaN handling in btree_gist's float4/float8 opclasses To: Tom Lane Cc: Daniel Gustafsson , pgsql-bugs@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000aac23a06558cd000" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000aac23a06558cd000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks. v2 applies cleanly on master and contrib/btree_gist regression passes here. Nothing to add. regards, Bill 2026=EB=85=84 6=EC=9B=94 30=EC=9D=BC (=ED=99=94) =EC=98=A4=EC=A0=84 8:08, T= om Lane =EB=8B=98=EC=9D=B4 =EC=9E=91=EC=84=B1: > I studied this and decided that it only partially fixes the problem. > Yes, we've got to fix the comparison functions, but we also have to > fix the penalty and distance functions. As things stand, the penalty > functions will probably return NaN for any input including a NaN, > which gistpenalty will clamp to zero, which we do not want because > it'll basically break all decisions about where to put things, > leading to a seriously inefficient index. (Maybe gistpenalty should > do something else with a NaN, but I'm hesitant to touch that right > now.) The penalty logic is also under the misapprehension that > multiplying everything by 0.49 keeps it from having to worry about > overflows; that won't fix things for infinities. The distance > functions will do the wrong things for NaN as well, probably breaking > any KNN search that happens across a NaN index entry. > > So I fixed all that, and then was dismayed to find that the new > penalty logic wasn't reached at all in the regression tests, per code > coverage testing. We don't compute any penalties during GiST index > build unless it's a multicolumn index, so most of the per-datatype > tests aren't reaching that. It didn't seem like adding more index > entries partway through the test would fit very well into the > structure of float[48].sql, so instead I added simple tests of > two-column float indexes to improve the coverage. Also, I thought > we should test this logic by adding NaN (and infinities for good > measure) to the initial data load, rather than creating a new small > table which would only exercise the logic very minimally. > > At the moment I'm leaning to back-patching this. We'd have to > release-note the need to reindex any btree_gist indexes containing > NaNs, but we've done similar things many times before. > > regards, tom lane > > --000000000000aac23a06558cd000 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks.=C2=A0
v2 applies cleanly on master and contrib= /btree_gist regression passes here.=C2=A0
Nothing to add.

= regards,
Bill

2026=EB=85=84 6=EC=9B=94 30=EC= =9D=BC (=ED=99=94) =EC=98=A4=EC=A0=84 8:08, Tom Lane <tgl@sss.pgh.pa.us>=EB=8B=98=EC=9D=B4 =EC=9E=91=EC= =84=B1:
I studie= d this and decided that it only partially fixes the problem.
Yes, we've got to fix the comparison functions, but we also have to
fix the penalty and distance functions.=C2=A0 As things stand, the penalty<= br> functions will probably return NaN for any input including a NaN,
which gistpenalty will clamp to zero, which we do not want because
it'll basically break all decisions about where to put things,
leading to a seriously inefficient index.=C2=A0 (Maybe gistpenalty should do something else with a NaN, but I'm hesitant to touch that right
now.)=C2=A0 The penalty logic is also under the misapprehension that
multiplying everything by 0.49 keeps it from having to worry about
overflows; that won't fix things for infinities.=C2=A0 The distance
functions will do the wrong things for NaN as well, probably breaking
any KNN search that happens across a NaN index entry.

So I fixed all that, and then was dismayed to find that the new
penalty logic wasn't reached at all in the regression tests, per code coverage testing.=C2=A0 We don't compute any penalties during GiST inde= x
build unless it's a multicolumn index, so most of the per-datatype
tests aren't reaching that.=C2=A0 It didn't seem like adding more i= ndex
entries partway through the test would fit very well into the
structure of float[48].sql, so instead I added simple tests of
two-column float indexes to improve the coverage.=C2=A0 Also, I thought
we should test this logic by adding NaN (and infinities for good
measure) to the initial data load, rather than creating a new small
table which would only exercise the logic very minimally.

At the moment I'm leaning to back-patching this.=C2=A0 We'd have to=
release-note the need to reindex any btree_gist indexes containing
NaNs, but we've done similar things many times before.

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 regards, tom lane

--000000000000aac23a06558cd000--