pg.ddx.io pgsql-committers@postgresql.org mailing list archive
help / color / mirror / Atom feedpgsql: Adjust string comparison in jsonpath
7+ messages / 4 participants
[nested] [flat]
Commits from this thread:
2019-08-12 de0dc0b758 251c8e39bc Fix string comparison in jsonpath
* pgsql: Adjust string comparison in jsonpath
@ 2019-08-11 20:10 Alexander Korotkov <akorotkov@postgresql.org>
0 siblings, 0 replies; 7+ messages in thread
From: Alexander Korotkov @ 2019-08-11 20:10 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Adjust string comparison in jsonpath
We have implemented jsonpath string comparison using default database locale.
However, standard requires us to compare Unicode codepoints. This commit
implements that, but for performance reasons we still use per-byte comparison
for "==" operator. Thus, for consistency other comparison operators do per-byte
comparison if Unicode codepoints appear to be equal.
In some edge cases, when same Unicode codepoints have different binary
representations in database encoding, we diverge standard to achieve better
performance of "==" operator. In future to implement strict standard
conformance, we can do normalization of input JSON strings.
Original patch was written by Nikita Glukhov, rewritten by me.
Reported-by: Markus Winand
Discussion: https://postgr.es/m/8B7FA3B4-328D-43D7-95A8-37B8891B8C78%40winand.at
Author: Nikita Glukhov, Alexander Korotkov
Backpatch-through: 12
Branch
------
REL_12_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/3218ff5c6aea5841ab547ecca26927716419fe4b
Modified Files
--------------
src/backend/utils/adt/jsonpath_exec.c | 72 +++++++++++-
src/test/regress/expected/jsonb_jsonpath.out | 163 +++++++++++++++++++++++++++
src/test/regress/sql/jsonb_jsonpath.sql | 16 +++
3 files changed, 248 insertions(+), 3 deletions(-)
^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Adjust string comparison in jsonpath
@ 2019-08-11 20:10 Alexander Korotkov <akorotkov@postgresql.org>
2019-08-11 21:03 ` Re: pgsql: Adjust string comparison in jsonpath Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
0 siblings, 1 reply; 7+ messages in thread
From: Alexander Korotkov @ 2019-08-11 20:10 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Adjust string comparison in jsonpath
We have implemented jsonpath string comparison using default database locale.
However, standard requires us to compare Unicode codepoints. This commit
implements that, but for performance reasons we still use per-byte comparison
for "==" operator. Thus, for consistency other comparison operators do per-byte
comparison if Unicode codepoints appear to be equal.
In some edge cases, when same Unicode codepoints have different binary
representations in database encoding, we diverge standard to achieve better
performance of "==" operator. In future to implement strict standard
conformance, we can do normalization of input JSON strings.
Original patch was written by Nikita Glukhov, rewritten by me.
Reported-by: Markus Winand
Discussion: https://postgr.es/m/8B7FA3B4-328D-43D7-95A8-37B8891B8C78%40winand.at
Author: Nikita Glukhov, Alexander Korotkov
Backpatch-through: 12
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/d54ceb9e176152f930e60709e07c636e8e5414f5
Modified Files
--------------
src/backend/utils/adt/jsonpath_exec.c | 72 +++++++++++-
src/test/regress/expected/jsonb_jsonpath.out | 163 +++++++++++++++++++++++++++
src/test/regress/sql/jsonb_jsonpath.sql | 16 +++
3 files changed, 248 insertions(+), 3 deletions(-)
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: pgsql: Adjust string comparison in jsonpath
2019-08-11 20:10 pgsql: Adjust string comparison in jsonpath Alexander Korotkov <akorotkov@postgresql.org>
@ 2019-08-11 21:03 ` Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
2019-08-11 22:24 ` Re: pgsql: Adjust string comparison in jsonpath Thomas Munro <thomas.munro@gmail.com>
0 siblings, 1 reply; 7+ messages in thread
From: Andrew Dunstan @ 2019-08-11 21:03 UTC (permalink / raw)
To: Alexander Korotkov <akorotkov@postgresql.org>; pgsql-committers@lists.postgresql.org
On 8/11/19 4:10 PM, Alexander Korotkov wrote:
> Adjust string comparison in jsonpath
>
> We have implemented jsonpath string comparison using default database locale.
> However, standard requires us to compare Unicode codepoints. This commit
> implements that, but for performance reasons we still use per-byte comparison
> for "==" operator. Thus, for consistency other comparison operators do per-byte
> comparison if Unicode codepoints appear to be equal.
>
> In some edge cases, when same Unicode codepoints have different binary
> representations in database encoding, we diverge standard to achieve better
> performance of "==" operator. In future to implement strict standard
> conformance, we can do normalization of input JSON strings.
>
This appears to have upset prion when testing on en_US.iso885915.
cheers
andrew
--
Andrew Dunstan https://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: pgsql: Adjust string comparison in jsonpath
2019-08-11 20:10 pgsql: Adjust string comparison in jsonpath Alexander Korotkov <akorotkov@postgresql.org>
2019-08-11 21:03 ` Re: pgsql: Adjust string comparison in jsonpath Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
@ 2019-08-11 22:24 ` Thomas Munro <thomas.munro@gmail.com>
2019-08-11 22:30 ` Re: pgsql: Adjust string comparison in jsonpath Alexander Korotkov <a.korotkov@postgrespro.ru>
0 siblings, 1 reply; 7+ messages in thread
From: Thomas Munro @ 2019-08-11 22:24 UTC (permalink / raw)
To: Andrew Dunstan <andrew.dunstan@2ndquadrant.com>; +Cc: Alexander Korotkov <akorotkov@postgresql.org>; pgsql-committers <pgsql-committers@lists.postgresql.org>
On Mon, Aug 12, 2019 at 9:04 AM Andrew Dunstan
<andrew.dunstan@2ndquadrant.com> wrote:
> On 8/11/19 4:10 PM, Alexander Korotkov wrote:
> > Adjust string comparison in jsonpath
> >
> > We have implemented jsonpath string comparison using default database locale.
> > However, standard requires us to compare Unicode codepoints. This commit
> > implements that, but for performance reasons we still use per-byte comparison
> > for "==" operator. Thus, for consistency other comparison operators do per-byte
> > comparison if Unicode codepoints appear to be equal.
> >
> > In some edge cases, when same Unicode codepoints have different binary
> > representations in database encoding, we diverge standard to achieve better
> > performance of "==" operator. In future to implement strict standard
> > conformance, we can do normalization of input JSON strings.
> >
>
>
> This appears to have upset prion when testing on en_US.iso885915.
Also lapwing's "InstallCheck-fr_FR" stage crashed on this commit, when
running JSON queries, on HEAD and REL_12_STABLE:
https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=lapwing&dt=2019-08-11%2021%3A02%3A32
https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=lapwing&dt=2019-08-11%2020%3A40%3A07
--
Thomas Munro
https://enterprisedb.com
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: pgsql: Adjust string comparison in jsonpath
2019-08-11 20:10 pgsql: Adjust string comparison in jsonpath Alexander Korotkov <akorotkov@postgresql.org>
2019-08-11 21:03 ` Re: pgsql: Adjust string comparison in jsonpath Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
2019-08-11 22:24 ` Re: pgsql: Adjust string comparison in jsonpath Thomas Munro <thomas.munro@gmail.com>
@ 2019-08-11 22:30 ` Alexander Korotkov <a.korotkov@postgrespro.ru>
2019-08-12 00:24 ` Re: pgsql: Adjust string comparison in jsonpath Thomas Munro <thomas.munro@gmail.com>
0 siblings, 1 reply; 7+ messages in thread
From: Alexander Korotkov @ 2019-08-11 22:30 UTC (permalink / raw)
To: Thomas Munro <thomas.munro@gmail.com>; +Cc: Andrew Dunstan <andrew.dunstan@2ndquadrant.com>; Alexander Korotkov <akorotkov@postgresql.org>; pgsql-committers <pgsql-committers@lists.postgresql.org>
On Mon, Aug 12, 2019 at 1:25 AM Thomas Munro <thomas.munro@gmail.com> wrote:
> On Mon, Aug 12, 2019 at 9:04 AM Andrew Dunstan
> <andrew.dunstan@2ndquadrant.com> wrote:
> > On 8/11/19 4:10 PM, Alexander Korotkov wrote:
> > > Adjust string comparison in jsonpath
> > >
> > > We have implemented jsonpath string comparison using default database locale.
> > > However, standard requires us to compare Unicode codepoints. This commit
> > > implements that, but for performance reasons we still use per-byte comparison
> > > for "==" operator. Thus, for consistency other comparison operators do per-byte
> > > comparison if Unicode codepoints appear to be equal.
> > >
> > > In some edge cases, when same Unicode codepoints have different binary
> > > representations in database encoding, we diverge standard to achieve better
> > > performance of "==" operator. In future to implement strict standard
> > > conformance, we can do normalization of input JSON strings.
> > >
> >
> >
> > This appears to have upset prion when testing on en_US.iso885915.
>
> Also lapwing's "InstallCheck-fr_FR" stage crashed on this commit, when
> running JSON queries, on HEAD and REL_12_STABLE:
>
> https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=lapwing&dt=2019-08-11%2021%3A02%3A32
> https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=lapwing&dt=2019-08-11%2020%3A40%3A07
Thank you for pointing! I hope I can investigate this shortly.
------
Alexander Korotkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: pgsql: Adjust string comparison in jsonpath
2019-08-11 20:10 pgsql: Adjust string comparison in jsonpath Alexander Korotkov <akorotkov@postgresql.org>
2019-08-11 21:03 ` Re: pgsql: Adjust string comparison in jsonpath Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
2019-08-11 22:24 ` Re: pgsql: Adjust string comparison in jsonpath Thomas Munro <thomas.munro@gmail.com>
2019-08-11 22:30 ` Re: pgsql: Adjust string comparison in jsonpath Alexander Korotkov <a.korotkov@postgrespro.ru>
@ 2019-08-12 00:24 ` Thomas Munro <thomas.munro@gmail.com>
2019-08-12 03:32 ` Re: pgsql: Adjust string comparison in jsonpath Alexander Korotkov <a.korotkov@postgrespro.ru>
0 siblings, 1 reply; 7+ messages in thread
From: Thomas Munro @ 2019-08-12 00:24 UTC (permalink / raw)
To: Alexander Korotkov <a.korotkov@postgrespro.ru>; +Cc: Andrew Dunstan <andrew.dunstan@2ndquadrant.com>; Alexander Korotkov <akorotkov@postgresql.org>; pgsql-committers <pgsql-committers@lists.postgresql.org>
On Mon, Aug 12, 2019 at 10:30 AM Alexander Korotkov
<a.korotkov@postgrespro.ru> wrote:
> > > This appears to have upset prion when testing on en_US.iso885915.
> >
> > Also lapwing's "InstallCheck-fr_FR" stage crashed on this commit, when
> > running JSON queries, on HEAD and REL_12_STABLE:
> Thank you for pointing! I hope I can investigate this shortly.
Hi Alexander,
I can reproduce this by running LANG="fr_FR.ISO8859-1" initdb, then
running installcheck (on some other OSes that might be called just
"fr_FR"). See this comment in mbutils.c:
* The functions return a palloc'd, null-terminated string if conversion
* is required. However, if no conversion is performed, the given source
* string pointer is returned as-is.
You call pfree() on the result of pg_server_to_any() without checking
if it just returned in the input pointer (for example, it does that if
you give it an empty string). That triggers an assertion failure
somewhere inside pfree(). The following fixes that for me, and is
based on code I found elsewhere in the tree.
inline patch 1: src/backend/utils/adt/jsonpath_exec.c (+0/-0 lines) download inline-1.patch
--- a/src/backend/utils/adt/jsonpath_exec.c
+++ b/src/backend/utils/adt/jsonpath_exec.c
@@ -2028,8 +2028,10 @@ compareStrings(const char *mbstr1, int mblen1,
cmp = binaryCompareStrings(utf8str1, strlen(utf8str1),
utf8str2, strlen(utf8str2));
- pfree(utf8str1);
- pfree(utf8str2);
+ if (mbstr1 != utf8str1)
+ pfree(utf8str1);
+ if (mbstr2 != utf8str2)
+ pfree(utf8str2);
With that fixed it no longer crashes, but then the regression test
fails due to differences in the output, which look like locale
ordering differences.
--
Thomas Munro
https://enterprisedb.com
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: pgsql: Adjust string comparison in jsonpath
2019-08-11 20:10 pgsql: Adjust string comparison in jsonpath Alexander Korotkov <akorotkov@postgresql.org>
2019-08-11 21:03 ` Re: pgsql: Adjust string comparison in jsonpath Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
2019-08-11 22:24 ` Re: pgsql: Adjust string comparison in jsonpath Thomas Munro <thomas.munro@gmail.com>
2019-08-11 22:30 ` Re: pgsql: Adjust string comparison in jsonpath Alexander Korotkov <a.korotkov@postgrespro.ru>
2019-08-12 00:24 ` Re: pgsql: Adjust string comparison in jsonpath Thomas Munro <thomas.munro@gmail.com>
@ 2019-08-12 03:32 ` Alexander Korotkov <a.korotkov@postgrespro.ru>
0 siblings, 0 replies; 7+ messages in thread
From: Alexander Korotkov @ 2019-08-12 03:32 UTC (permalink / raw)
To: Thomas Munro <thomas.munro@gmail.com>; +Cc: Andrew Dunstan <andrew.dunstan@2ndquadrant.com>; Alexander Korotkov <akorotkov@postgresql.org>; pgsql-committers <pgsql-committers@lists.postgresql.org>
пн, 12 авг. 2019 г., 3:25 Thomas Munro <thomas.munro@gmail.com>:
> On Mon, Aug 12, 2019 at 10:30 AM Alexander Korotkov
> <a.korotkov@postgrespro.ru> wrote:
> > > > This appears to have upset prion when testing on en_US.iso885915.
> > >
> > > Also lapwing's "InstallCheck-fr_FR" stage crashed on this commit, when
> > > running JSON queries, on HEAD and REL_12_STABLE:
>
> > Thank you for pointing! I hope I can investigate this shortly.
>
> Hi Alexander,
>
> I can reproduce this by running LANG="fr_FR.ISO8859-1" initdb, then
> running installcheck (on some other OSes that might be called just
> "fr_FR"). See this comment in mbutils.c:
>
> * The functions return a palloc'd, null-terminated string if conversion
> * is required. However, if no conversion is performed, the given source
> * string pointer is returned as-is.
>
> You call pfree() on the result of pg_server_to_any() without checking
> if it just returned in the input pointer (for example, it does that if
> you give it an empty string). That triggers an assertion failure
> somewhere inside pfree(). The following fixes that for me, and is
> based on code I found elsewhere in the tree.
>
> --- a/src/backend/utils/adt/jsonpath_exec.c
> +++ b/src/backend/utils/adt/jsonpath_exec.c
> @@ -2028,8 +2028,10 @@ compareStrings(const char *mbstr1, int mblen1,
> cmp = binaryCompareStrings(utf8str1, strlen(utf8str1),
>
> utf8str2, strlen(utf8str2));
>
> - pfree(utf8str1);
> - pfree(utf8str2);
> + if (mbstr1 != utf8str1)
> + pfree(utf8str1);
> + if (mbstr2 != utf8str2)
> + pfree(utf8str2);
>
> With that fixed it no longer crashes, but then the regression test
> fails due to differences in the output, which look like locale
> ordering differences.
>
Thank you for the diagnostics. Should be fixed by 251c8e39.
BTW, test failures appears to be caused not by locale differences, but by
using strlen() on non null-terminated original strings.
------
Alexander Korotkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
>
^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2019-08-12 03:32 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-08-11 20:10 pgsql: Adjust string comparison in jsonpath Alexander Korotkov <akorotkov@postgresql.org>
2019-08-11 20:10 pgsql: Adjust string comparison in jsonpath Alexander Korotkov <akorotkov@postgresql.org>
2019-08-11 21:03 ` Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
2019-08-11 22:24 ` Thomas Munro <thomas.munro@gmail.com>
2019-08-11 22:30 ` Alexander Korotkov <a.korotkov@postgrespro.ru>
2019-08-12 00:24 ` Thomas Munro <thomas.munro@gmail.com>
2019-08-12 03:32 ` Alexander Korotkov <a.korotkov@postgrespro.ru>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox