Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdbb9aed

Browse files
committed
Optimize get_jsonb_path_all avoiding an iterator
Instead of creating an iterator object at each step down the JSONBobject/array, we can just just examine its object/array flags, which isfaster. Also, use the recently introduced JsonbValueAsText instead ofopen-coding the same thing, for code simplicity.Author: Nikita GlukhovDiscussion:https://postgr.es/m/7c417f90-f95f-247e-ba63-d95e39c0ad14@postgrespro.ru
1 parentabb014a commitdbb9aed

File tree

1 file changed

+10
-23
lines changed

1 file changed

+10
-23
lines changed

‎src/backend/utils/adt/jsonfuncs.c

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,15 +1329,13 @@ get_jsonb_path_all(FunctionCallInfo fcinfo, bool as_text)
13291329
{
13301330
Jsonb*jb=PG_GETARG_JSONB_P(0);
13311331
ArrayType*path=PG_GETARG_ARRAYTYPE_P(1);
1332-
Jsonb*res;
13331332
Datum*pathtext;
13341333
bool*pathnulls;
13351334
intnpath;
13361335
inti;
13371336
boolhave_object= false,
13381337
have_array= false;
13391338
JsonbValue*jbvp=NULL;
1340-
JsonbValuetv;
13411339
JsonbContainer*container;
13421340

13431341
/*
@@ -1449,41 +1447,30 @@ get_jsonb_path_all(FunctionCallInfo fcinfo, bool as_text)
14491447

14501448
if (jbvp->type==jbvBinary)
14511449
{
1452-
JsonbIterator*it=JsonbIteratorInit((JsonbContainer*)jbvp->val.binary.data);
1453-
JsonbIteratorTokenr;
1454-
1455-
r=JsonbIteratorNext(&it,&tv, true);
1456-
container= (JsonbContainer*)jbvp->val.binary.data;
1457-
have_object=r==WJB_BEGIN_OBJECT;
1458-
have_array=r==WJB_BEGIN_ARRAY;
1450+
container=jbvp->val.binary.data;
1451+
have_object=JsonContainerIsObject(container);
1452+
have_array=JsonContainerIsArray(container);
1453+
Assert(!JsonContainerIsScalar(container));
14591454
}
14601455
else
14611456
{
1462-
have_object=jbvp->type==jbvObject;
1463-
have_array=jbvp->type==jbvArray;
1457+
Assert(IsAJsonbScalar(jbvp));
1458+
have_object= false;
1459+
have_array= false;
14641460
}
14651461
}
14661462

14671463
if (as_text)
14681464
{
1469-
/* special-case outputs for string and null values */
1470-
if (jbvp->type==jbvString)
1471-
PG_RETURN_TEXT_P(cstring_to_text_with_len(jbvp->val.string.val,
1472-
jbvp->val.string.len));
14731465
if (jbvp->type==jbvNull)
14741466
PG_RETURN_NULL();
1475-
}
1476-
1477-
res=JsonbValueToJsonb(jbvp);
14781467

1479-
if (as_text)
1480-
{
1481-
PG_RETURN_TEXT_P(cstring_to_text(JsonbToCString(NULL,
1482-
&res->root,
1483-
VARSIZE(res))));
1468+
PG_RETURN_TEXT_P(JsonbValueAsText(jbvp));
14841469
}
14851470
else
14861471
{
1472+
Jsonb*res=JsonbValueToJsonb(jbvp);
1473+
14871474
/* not text mode - just hand back the jsonb */
14881475
PG_RETURN_JSONB_P(res);
14891476
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp