Content-Length: 627803 | pFad | http://github.com/postgrespro/postgres/commit/c0fc98bd73c614eb889cf25eb189f23ee93abee3

0C Use JsonMutators in jsonb_set() · postgrespro/postgres@c0fc98b · GitHub
Skip to content

Commit c0fc98b

Browse files
author
Nikita Glukhov
committed
Use JsonMutators in jsonb_set()
1 parent 5ea4a81 commit c0fc98b

File tree

4 files changed

+142
-433
lines changed

4 files changed

+142
-433
lines changed

contrib/jsonb_toaster/jsonb_toaster.c

Lines changed: 0 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,163 +2197,6 @@ isValueReplacable(JsonValue *oldval, JsonValue *newval)
21972197
}
21982198
}
21992199

2200-
static bool
2201-
jsonxSetPathInplace(JsonContainer *jc, int idx,
2202-
Datum *path_elems, bool *path_nulls,
2203-
int path_len, int level, JsonbValue *newval,
2204-
int op_type, JsonbParseState **st, JsonValue **res)
2205-
{
2206-
JsonbToastedContainerPointerData jbcptr;
2207-
2208-
if (!jsonb_inplace_updates)
2209-
return false;
2210-
2211-
if (level != path_len - 1 || /* FIXME */
2212-
(op_type & (JB_PATH_INSERT_AFTER | JB_PATH_INSERT_BEFORE)))
2213-
return false;
2214-
2215-
if (JsonContainerIsToasted(jc, &jbcptr) &&
2216-
(!jbcptr.tail_data || jbcptr.has_diff))
2217-
{
2218-
JsonFieldPtr ptr = {0};
2219-
JsonValue *old_val;
2220-
2221-
if (JsonContainerIsObject(jc))
2222-
old_val = JsonFindKeyPtrInObject(jc,
2223-
VARDATA_ANY(path_elems[level]),
2224-
VARSIZE_ANY_EXHDR(path_elems[level]),
2225-
NULL,
2226-
&ptr);
2227-
else
2228-
old_val = JsonGetArrayElementPtr(jc, idx, &ptr);
2229-
2230-
if (old_val && ptr.offset)
2231-
{
2232-
JsonxPointerDiff diff;
2233-
JsonValue *new_val = newval;
2234-
JsonValue new_val_buf;
2235-
2236-
ptr.offset += jbcptr.container_offset;
2237-
2238-
if (newval->type == jbvBinary &&
2239-
JsonContainerIsScalar(newval->val.binary.data))
2240-
new_val = JsonExtractScalar(newval->val.binary.data,
2241-
&new_val_buf);
2242-
2243-
if (jbcptr.tail_size > 0)
2244-
memcpy(&diff, jbcptr.tail_data, offsetof(JsonxPointerDiff, data));
2245-
else
2246-
diff.offset = ptr.offset;
2247-
2248-
if (ptr.offset == diff.offset &&
2249-
isValueReplacable(old_val, new_val))
2250-
{
2251-
JsonIteratorToken r;
2252-
JsonValue toast_diff_jv;
2253-
Datum toast_diff;
2254-
const void *val;
2255-
int len;
2256-
2257-
switch (new_val->type)
2258-
{
2259-
case jbvString:
2260-
val = new_val->val.string.val;
2261-
len = new_val->val.string.len;
2262-
break;
2263-
2264-
case jbvNumeric:
2265-
val = new_val->val.numeric;
2266-
len = VARSIZE_ANY(new_val->val.numeric);
2267-
break;
2268-
2269-
case jbvBinary:
2270-
Assert(new_val->val.binary.data->ops == &jsonbContainerOps);
2271-
val = JsonContainerDataPtr(new_val->val.binary.data);
2272-
len = new_val->val.binary.data->len;
2273-
break;
2274-
2275-
default:
2276-
break;
2277-
}
2278-
2279-
pfree(old_val);
2280-
2281-
toast_diff = PointerGetDatum(
2282-
jsonx_toast_make_pointer_diff(jbcptr.toasterid,
2283-
&jbcptr.ptr,
2284-
jbcptr.compressed_chunks,
2285-
diff.offset,
2286-
len, val));
2287-
2288-
JsonValueInitBinary(&toast_diff_jv,
2289-
jsonxzInitContainerFromDatum(jc, toast_diff));
2290-
2291-
r = *st && (*st)->contVal.type == jbvArray ? WJB_ELEM : WJB_VALUE;
2292-
2293-
*res = pushJsonbValueExt(st, r, &toast_diff_jv, false);
2294-
return true;
2295-
}
2296-
}
2297-
2298-
if (old_val)
2299-
pfree(old_val);
2300-
}
2301-
2302-
return false;
2303-
}
2304-
2305-
static Datum
2306-
jsonxSetPath(JsonContainer *js, Datum *path_elems,
2307-
bool *path_nulls, int path_len,
2308-
JsonValue *newval, int op_type)
2309-
{
2310-
#if 0
2311-
Datum res =
2312-
jsonxSetPathInplace(js, -1 path_elems, path_nulls, path_len, 0,
2313-
newval, op_type);
2314-
2315-
if (res != (Datum) 0)
2316-
return res;
2317-
#endif
2318-
2319-
return JsonSetPathGeneric(js, path_elems, path_nulls, path_len,
2320-
newval, op_type);
2321-
}
2322-
2323-
static JsonValue *
2324-
jsonxSetArrayElement(JsonContainer *jc, int idx,
2325-
Datum *path_elems, bool *path_nulls, int path_len,
2326-
JsonbParseState **st, int level,
2327-
JsonValue *newval, int op_type)
2328-
{
2329-
JsonValue *res;
2330-
2331-
if (jsonxSetPathInplace(jc, idx, path_elems,
2332-
path_nulls, path_len,
2333-
level, newval, op_type, st, &res))
2334-
return res;
2335-
2336-
return JsonSetArrayElementGeneric(jc, idx, path_elems, path_nulls, path_len,
2337-
st, level, newval, op_type);
2338-
}
2339-
2340-
static JsonValue *
2341-
jsonxSetObjectKey(JsonContainer *jc,
2342-
Datum *path_elems, bool *path_nulls, int path_len,
2343-
JsonbParseState **st, int level,
2344-
JsonValue *newval, int op_type)
2345-
{
2346-
JsonValue *res;
2347-
2348-
if (jsonxSetPathInplace(jc, -1, path_elems,
2349-
path_nulls, path_len,
2350-
level, newval, op_type, st, &res))
2351-
return res;
2352-
2353-
return JsonSetObjectKeyGeneric(jc, path_elems, path_nulls, path_len,
2354-
st, level, newval, op_type);
2355-
}
2356-
23572200
typedef struct JsonxMutatorRoot
23582201
{
23592202
JsonContainer *container;
@@ -2883,9 +2726,6 @@ jsonxzContainerOps =
28832726
jsonxzCopy,
28842727
jsonxzFree,
28852728
jsonxzEncode,
2886-
jsonxSetPath,
2887-
jsonxSetObjectKey,
2888-
jsonxSetArrayElement,
28892729
jsonxObjectMutatorInit,
28902730
jsonxArrayMutatorInit
28912731
};
@@ -2904,9 +2744,6 @@ jsonxContainerOps =
29042744
JsonCopyFlat,
29052745
NULL,
29062746
jsonxEncode,
2907-
jsonxSetPath,
2908-
jsonxSetObjectKey,
2909-
jsonxSetArrayElement,
29102747
jsonxObjectMutatorInit,
29112748
jsonxArrayMutatorInit
29122749
};

src/backend/utils/adt/jsonb_util.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,9 +2579,6 @@ jsonbContainerOps =
25792579
JsonCopyFlat,
25802580
NULL,
25812581
NULL,
2582-
JsonSetPathGeneric,
2583-
JsonSetObjectKeyGeneric,
2584-
JsonSetArrayElementGeneric,
25852582
JsonObjectMutatorInitGeneric,
25862583
JsonArrayMutatorInitGeneric
25872584
};
@@ -3175,9 +3172,6 @@ jsonbzContainerOps =
31753172
JsonCopyFlat, // FIXME
31763173
jsonbzFree,
31773174
NULL,
3178-
JsonSetPathGeneric,
3179-
JsonSetObjectKeyGeneric,
3180-
JsonSetArrayElementGeneric,
31813175
JsonObjectMutatorInitGeneric,
31823176
JsonArrayMutatorInitGeneric
31833177
};

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgrespro/postgres/commit/c0fc98bd73c614eb889cf25eb189f23ee93abee3

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy