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

Commitc0fc98b

Browse files
author
Nikita Glukhov
committed
Use JsonMutators in jsonb_set()
1 parent5ea4a81 commitc0fc98b

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-
staticbool
2201-
jsonxSetPathInplace(JsonContainer*jc,intidx,
2202-
Datum*path_elems,bool*path_nulls,
2203-
intpath_len,intlevel,JsonbValue*newval,
2204-
intop_type,JsonbParseState**st,JsonValue**res)
2205-
{
2206-
JsonbToastedContainerPointerDatajbcptr;
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-
JsonFieldPtrptr= {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-
JsonxPointerDiffdiff;
2233-
JsonValue*new_val=newval;
2234-
JsonValuenew_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-
JsonIteratorTokenr;
2252-
JsonValuetoast_diff_jv;
2253-
Datumtoast_diff;
2254-
constvoid*val;
2255-
intlen;
2256-
2257-
switch (new_val->type)
2258-
{
2259-
casejbvString:
2260-
val=new_val->val.string.val;
2261-
len=new_val->val.string.len;
2262-
break;
2263-
2264-
casejbvNumeric:
2265-
val=new_val->val.numeric;
2266-
len=VARSIZE_ANY(new_val->val.numeric);
2267-
break;
2268-
2269-
casejbvBinary:
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-
staticDatum
2306-
jsonxSetPath(JsonContainer*js,Datum*path_elems,
2307-
bool*path_nulls,intpath_len,
2308-
JsonValue*newval,intop_type)
2309-
{
2310-
#if0
2311-
Datumres=
2312-
jsonxSetPathInplace(js,-1path_elems,path_nulls,path_len,0,
2313-
newval,op_type);
2314-
2315-
if (res!= (Datum)0)
2316-
returnres;
2317-
#endif
2318-
2319-
returnJsonSetPathGeneric(js,path_elems,path_nulls,path_len,
2320-
newval,op_type);
2321-
}
2322-
2323-
staticJsonValue*
2324-
jsonxSetArrayElement(JsonContainer*jc,intidx,
2325-
Datum*path_elems,bool*path_nulls,intpath_len,
2326-
JsonbParseState**st,intlevel,
2327-
JsonValue*newval,intop_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-
returnres;
2335-
2336-
returnJsonSetArrayElementGeneric(jc,idx,path_elems,path_nulls,path_len,
2337-
st,level,newval,op_type);
2338-
}
2339-
2340-
staticJsonValue*
2341-
jsonxSetObjectKey(JsonContainer*jc,
2342-
Datum*path_elems,bool*path_nulls,intpath_len,
2343-
JsonbParseState**st,intlevel,
2344-
JsonValue*newval,intop_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-
returnres;
2352-
2353-
returnJsonSetObjectKeyGeneric(jc,path_elems,path_nulls,path_len,
2354-
st,level,newval,op_type);
2355-
}
2356-
23572200
typedefstructJsonxMutatorRoot
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)

[8]ページ先頭

©2009-2025 Movatter.jp