mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-06 15:24:56 +08:00
Use appendStringInfoString instead of appendBinaryStringInfo where possible
For the jsonpath output, we don't need to squeeze out every bit of performance, so instead use a more robust coding style. There are similar calls in jsonb.c, which we leave alone here since there is indeed a performance impact for bulk exports. Discussion: https://www.postgresql.org/message-id/flat/a0086cfc-ff0f-2827-20fe-52b591d2666c%40enterprisedb.com
This commit is contained in:
parent
faf3750657
commit
33a33f0ba4
@ -221,7 +221,7 @@ jsonPathToCstring(StringInfo out, JsonPath *in, int estimated_len)
|
|||||||
enlargeStringInfo(out, estimated_len);
|
enlargeStringInfo(out, estimated_len);
|
||||||
|
|
||||||
if (!(in->header & JSONPATH_LAX))
|
if (!(in->header & JSONPATH_LAX))
|
||||||
appendBinaryStringInfo(out, "strict ", 7);
|
appendStringInfoString(out, "strict ");
|
||||||
|
|
||||||
jspInit(&v, in);
|
jspInit(&v, in);
|
||||||
printJsonPathItem(out, &v, false, true);
|
printJsonPathItem(out, &v, false, true);
|
||||||
@ -542,9 +542,9 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
|
|||||||
break;
|
break;
|
||||||
case jpiBool:
|
case jpiBool:
|
||||||
if (jspGetBool(v))
|
if (jspGetBool(v))
|
||||||
appendBinaryStringInfo(buf, "true", 4);
|
appendStringInfoString(buf, "true");
|
||||||
else
|
else
|
||||||
appendBinaryStringInfo(buf, "false", 5);
|
appendStringInfoString(buf, "false");
|
||||||
break;
|
break;
|
||||||
case jpiAnd:
|
case jpiAnd:
|
||||||
case jpiOr:
|
case jpiOr:
|
||||||
@ -585,13 +585,13 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
|
|||||||
operationPriority(elem.type) <=
|
operationPriority(elem.type) <=
|
||||||
operationPriority(v->type));
|
operationPriority(v->type));
|
||||||
|
|
||||||
appendBinaryStringInfo(buf, " like_regex ", 12);
|
appendStringInfoString(buf, " like_regex ");
|
||||||
|
|
||||||
escape_json(buf, v->content.like_regex.pattern);
|
escape_json(buf, v->content.like_regex.pattern);
|
||||||
|
|
||||||
if (v->content.like_regex.flags)
|
if (v->content.like_regex.flags)
|
||||||
{
|
{
|
||||||
appendBinaryStringInfo(buf, " flag \"", 7);
|
appendStringInfoString(buf, " flag \"");
|
||||||
|
|
||||||
if (v->content.like_regex.flags & JSP_REGEX_ICASE)
|
if (v->content.like_regex.flags & JSP_REGEX_ICASE)
|
||||||
appendStringInfoChar(buf, 'i');
|
appendStringInfoChar(buf, 'i');
|
||||||
@ -623,13 +623,13 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
|
|||||||
appendStringInfoChar(buf, ')');
|
appendStringInfoChar(buf, ')');
|
||||||
break;
|
break;
|
||||||
case jpiFilter:
|
case jpiFilter:
|
||||||
appendBinaryStringInfo(buf, "?(", 2);
|
appendStringInfoString(buf, "?(");
|
||||||
jspGetArg(v, &elem);
|
jspGetArg(v, &elem);
|
||||||
printJsonPathItem(buf, &elem, false, false);
|
printJsonPathItem(buf, &elem, false, false);
|
||||||
appendStringInfoChar(buf, ')');
|
appendStringInfoChar(buf, ')');
|
||||||
break;
|
break;
|
||||||
case jpiNot:
|
case jpiNot:
|
||||||
appendBinaryStringInfo(buf, "!(", 2);
|
appendStringInfoString(buf, "!(");
|
||||||
jspGetArg(v, &elem);
|
jspGetArg(v, &elem);
|
||||||
printJsonPathItem(buf, &elem, false, false);
|
printJsonPathItem(buf, &elem, false, false);
|
||||||
appendStringInfoChar(buf, ')');
|
appendStringInfoChar(buf, ')');
|
||||||
@ -638,10 +638,10 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
|
|||||||
appendStringInfoChar(buf, '(');
|
appendStringInfoChar(buf, '(');
|
||||||
jspGetArg(v, &elem);
|
jspGetArg(v, &elem);
|
||||||
printJsonPathItem(buf, &elem, false, false);
|
printJsonPathItem(buf, &elem, false, false);
|
||||||
appendBinaryStringInfo(buf, ") is unknown", 12);
|
appendStringInfoString(buf, ") is unknown");
|
||||||
break;
|
break;
|
||||||
case jpiExists:
|
case jpiExists:
|
||||||
appendBinaryStringInfo(buf, "exists (", 8);
|
appendStringInfoString(buf, "exists (");
|
||||||
jspGetArg(v, &elem);
|
jspGetArg(v, &elem);
|
||||||
printJsonPathItem(buf, &elem, false, false);
|
printJsonPathItem(buf, &elem, false, false);
|
||||||
appendStringInfoChar(buf, ')');
|
appendStringInfoChar(buf, ')');
|
||||||
@ -655,10 +655,10 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
|
|||||||
appendStringInfoChar(buf, '$');
|
appendStringInfoChar(buf, '$');
|
||||||
break;
|
break;
|
||||||
case jpiLast:
|
case jpiLast:
|
||||||
appendBinaryStringInfo(buf, "last", 4);
|
appendStringInfoString(buf, "last");
|
||||||
break;
|
break;
|
||||||
case jpiAnyArray:
|
case jpiAnyArray:
|
||||||
appendBinaryStringInfo(buf, "[*]", 3);
|
appendStringInfoString(buf, "[*]");
|
||||||
break;
|
break;
|
||||||
case jpiAnyKey:
|
case jpiAnyKey:
|
||||||
if (inKey)
|
if (inKey)
|
||||||
@ -680,7 +680,7 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
|
|||||||
|
|
||||||
if (range)
|
if (range)
|
||||||
{
|
{
|
||||||
appendBinaryStringInfo(buf, " to ", 4);
|
appendStringInfoString(buf, " to ");
|
||||||
printJsonPathItem(buf, &to, false, false);
|
printJsonPathItem(buf, &to, false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -692,7 +692,7 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
|
|||||||
|
|
||||||
if (v->content.anybounds.first == 0 &&
|
if (v->content.anybounds.first == 0 &&
|
||||||
v->content.anybounds.last == PG_UINT32_MAX)
|
v->content.anybounds.last == PG_UINT32_MAX)
|
||||||
appendBinaryStringInfo(buf, "**", 2);
|
appendStringInfoString(buf, "**");
|
||||||
else if (v->content.anybounds.first == v->content.anybounds.last)
|
else if (v->content.anybounds.first == v->content.anybounds.last)
|
||||||
{
|
{
|
||||||
if (v->content.anybounds.first == PG_UINT32_MAX)
|
if (v->content.anybounds.first == PG_UINT32_MAX)
|
||||||
@ -713,25 +713,25 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
|
|||||||
v->content.anybounds.last);
|
v->content.anybounds.last);
|
||||||
break;
|
break;
|
||||||
case jpiType:
|
case jpiType:
|
||||||
appendBinaryStringInfo(buf, ".type()", 7);
|
appendStringInfoString(buf, ".type()");
|
||||||
break;
|
break;
|
||||||
case jpiSize:
|
case jpiSize:
|
||||||
appendBinaryStringInfo(buf, ".size()", 7);
|
appendStringInfoString(buf, ".size()");
|
||||||
break;
|
break;
|
||||||
case jpiAbs:
|
case jpiAbs:
|
||||||
appendBinaryStringInfo(buf, ".abs()", 6);
|
appendStringInfoString(buf, ".abs()");
|
||||||
break;
|
break;
|
||||||
case jpiFloor:
|
case jpiFloor:
|
||||||
appendBinaryStringInfo(buf, ".floor()", 8);
|
appendStringInfoString(buf, ".floor()");
|
||||||
break;
|
break;
|
||||||
case jpiCeiling:
|
case jpiCeiling:
|
||||||
appendBinaryStringInfo(buf, ".ceiling()", 10);
|
appendStringInfoString(buf, ".ceiling()");
|
||||||
break;
|
break;
|
||||||
case jpiDouble:
|
case jpiDouble:
|
||||||
appendBinaryStringInfo(buf, ".double()", 9);
|
appendStringInfoString(buf, ".double()");
|
||||||
break;
|
break;
|
||||||
case jpiDatetime:
|
case jpiDatetime:
|
||||||
appendBinaryStringInfo(buf, ".datetime(", 10);
|
appendStringInfoString(buf, ".datetime(");
|
||||||
if (v->content.arg)
|
if (v->content.arg)
|
||||||
{
|
{
|
||||||
jspGetArg(v, &elem);
|
jspGetArg(v, &elem);
|
||||||
@ -740,7 +740,7 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
|
|||||||
appendStringInfoChar(buf, ')');
|
appendStringInfoChar(buf, ')');
|
||||||
break;
|
break;
|
||||||
case jpiKeyValue:
|
case jpiKeyValue:
|
||||||
appendBinaryStringInfo(buf, ".keyvalue()", 11);
|
appendStringInfoString(buf, ".keyvalue()");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
elog(ERROR, "unrecognized jsonpath item type: %d", v->type);
|
elog(ERROR, "unrecognized jsonpath item type: %d", v->type);
|
||||||
|
Loading…
Reference in New Issue
Block a user