@@ -177,7 +177,7 @@ static JsonbValue *fillCompressedJsonbValue(CompressedJsonb *cjb,
177
177
uint32 offset , JsonValue * result );
178
178
static JsonbContainerHeader * jsonxzDecompress (JsonContainer * jc );
179
179
static bool JsonContainerIsToasted (JsonContainer * jc ,
180
- JsonbToastedContainerPointer * jbcptr );
180
+ JsonbToastedContainerPointerData * jbcptr );
181
181
static bool JsonValueContainsToasted (const JsonValue * jv );
182
182
183
183
static bool jsonb_toast_fields = true; /* GUC */
@@ -187,12 +187,12 @@ static JsonContainerOps jsonxContainerOps;
187
187
static JsonContainerOps jsonxzContainerOps ;
188
188
189
189
static struct varlena *
190
- jsonxMakeToastPointer (struct varatt_external * ptr )
190
+ jsonxMakeToastPointer (JsonbToastedContainerPointerData * ptr )
191
191
{
192
192
struct varlena * toast_ptr = palloc (TOAST_POINTER_SIZE );
193
193
194
194
SET_VARTAG_EXTERNAL (toast_ptr , VARTAG_ONDISK );
195
- memcpy (VARDATA_EXTERNAL (toast_ptr ), ptr , sizeof (* ptr ));
195
+ memcpy (VARDATA_EXTERNAL (toast_ptr ), & ptr -> ptr , sizeof (ptr -> ptr ));
196
196
197
197
return toast_ptr ;
198
198
}
@@ -501,11 +501,14 @@ jsonxFillValue(const JsonbContainerHeader *container, int index,
501
501
else if (JBE_ISCONTAINER_PTR (entry ))
502
502
{
503
503
JsonbToastedContainerPointer * jbcptr = (JsonbToastedContainerPointer * )(base_addr + INTALIGN (offset ));
504
- struct varlena * toast_ptr = jsonxMakeToastPointer (& jbcptr -> ptr );
504
+ JsonbToastedContainerPointerData jbcptr_data ;
505
+ struct varlena * toast_ptr ;
505
506
bool is_jsonx = (jbcptr -> header & JBC_TOBJECT_TOASTED ) != 0 ;
506
507
JsonContainerData * cont =
507
508
JsonContainerAlloc (is_jsonx ? & jsonxzContainerOps : & jsonbzContainerOps );
508
509
510
+ jbcptr_data .ptr = jbcptr -> ptr ;
511
+ toast_ptr = jsonxMakeToastPointer (& jbcptr_data );
509
512
jsonxzInitWithHeader (cont , PointerGetDatum (toast_ptr ), & jbcptr -> header );
510
513
JsonValueInitBinary (result , cont );
511
514
@@ -1010,19 +1013,21 @@ estimateJsonbValueSize(const JsonbValue *jbv)
1010
1013
}
1011
1014
1012
1015
static void
1013
- jsonxInitToastedContainerPointer (JsonbToastedContainerPointer * jbcptr ,
1014
- JsonContainer * jc ,
1015
- struct varatt_external * toast_ptr )
1016
+ jsonxInitToastedContainerPointer (JsonbToastedContainerPointerData * jbcptr ,
1017
+ varatt_external * toast_ptr ,
1018
+ uint32 container_offset )
1016
1019
{
1020
+ /*
1017
1021
jbcptr->header =
1018
1022
(JsonContainerIsArray(jc) ? JBC_TARRAY : JBC_TOBJECT) |
1019
1023
(jc->ops == &jsonxzContainerOps ? JBC_TOBJECT_TOASTED : 0) |
1020
- JsonContainerSize (jc );
1024
+ JsonContainerSize(jc);*/
1021
1025
jbcptr -> ptr = * toast_ptr ;
1026
+ jbcptr -> container_offset = container_offset ;
1022
1027
}
1023
1028
1024
1029
static bool
1025
- JsonContainerIsToasted (JsonContainer * jc , JsonbToastedContainerPointer * jbcptr )
1030
+ JsonContainerIsToasted (JsonContainer * jc , JsonbToastedContainerPointerData * jbcptr )
1026
1031
{
1027
1032
if (jc -> ops == & jsonbzContainerOps ||
1028
1033
jc -> ops == & jsonxzContainerOps )
@@ -1034,8 +1039,9 @@ JsonContainerIsToasted(JsonContainer *jc, JsonbToastedContainerPointer *jbcptr)
1034
1039
cjb -> offset == offsetof(JsonbDatum , root ))
1035
1040
{
1036
1041
if (jbcptr )
1037
- jsonxInitToastedContainerPointer (jbcptr , jc , & fetch_iter -> toast_pointer );
1038
-
1042
+ jsonxInitToastedContainerPointer (jbcptr ,
1043
+ & fetch_iter -> toast_pointer ,
1044
+ cjb -> offset );
1039
1045
return true;
1040
1046
}
1041
1047
}
@@ -1397,12 +1403,12 @@ convertJsonbBinary(StringInfo buffer, JEntry *pheader, const JsonbValue *val,
1397
1403
1398
1404
if (jsonb_toast_fields )
1399
1405
{
1400
- JsonbToastedContainerPointer jbcptr ;
1406
+ JsonbToastedContainerPointerData jbcptr ;
1401
1407
1402
1408
if (JsonContainerIsToasted (jc , & jbcptr ))
1403
1409
{
1404
1410
padBufferToInt (buffer );
1405
- appendToBuffer (buffer , (void * ) & jbcptr , sizeof (jbcptr ));
1411
+ appendToBuffer (buffer , (void * ) & jbcptr . ptr , sizeof (jbcptr . ptr ));
1406
1412
* pheader = JENTRY_ISCONTAINER_PTR | (buffer -> len - base_offset );
1407
1413
return ;
1408
1414
}
@@ -1851,6 +1857,28 @@ jsonxContainerOps =
1851
1857
jsonxEncode
1852
1858
};
1853
1859
1860
+ static JsonContainer *
1861
+ jsonxzInitContainerFromDatum (JsonContainer * jc , Datum toasted_val )
1862
+ {
1863
+ JsonContainerData * tjc ;
1864
+ JsonbContainerHeader header ;
1865
+ bool is_jsonx ;
1866
+
1867
+ Assert (VARATT_IS_EXTERNAL_ONDISK (toasted_val ));
1868
+
1869
+ is_jsonx = jc -> ops == & jsonxContainerOps || jc -> ops == & jsonxzContainerOps ;
1870
+
1871
+ header =
1872
+ (JsonContainerIsArray (jc ) ? JBC_TARRAY : JBC_TOBJECT ) |
1873
+ (is_jsonx ? JBC_TOBJECT_TOASTED : 0 ) |
1874
+ JsonContainerSize (jc );
1875
+
1876
+ tjc = JsonContainerAlloc (is_jsonx ? & jsonxzContainerOps : & jsonbzContainerOps ); /* FIXME optimize */
1877
+ jsonxzInitWithHeader (tjc , toasted_val , & header );
1878
+
1879
+ return tjc ;
1880
+ }
1881
+
1854
1882
static bool
1855
1883
jsonb_toaster_save_object (Relation rel , JsonContainer * root ,
1856
1884
/* XXX bool uniquified, */ Size max_size , char cmethod ,
@@ -1959,10 +1987,7 @@ jsonb_toaster_save_object(Relation rel, JsonContainer *root,
1959
1987
Datum compressed_val ;
1960
1988
Datum toasted_val ;
1961
1989
JsonContainer * jc ;
1962
- JsonContainerData * tjc ;
1963
1990
JsonbContainerHeader * jbc ;
1964
- JsonbContainerHdr header ;
1965
- bool is_jsonx ;
1966
1991
1967
1992
for (i = 0 ; i < nkeys ; i ++ )
1968
1993
{
@@ -2011,20 +2036,7 @@ jsonb_toaster_save_object(Relation rel, JsonContainer *root,
2011
2036
if (DatumGetPointer (compressed_val ))
2012
2037
pfree (DatumGetPointer (compressed_val ));
2013
2038
2014
- Assert (VARATT_IS_EXTERNAL_ONDISK (toasted_val ));
2015
-
2016
- is_jsonx = jc -> ops == & jsonxContainerOps || jc -> ops == & jsonxzContainerOps ;
2017
-
2018
- header =
2019
- (JsonContainerIsArray (jc ) ? JBC_TARRAY : JBC_TOBJECT ) |
2020
- (is_jsonx ? JBC_TOBJECT_TOASTED : 0 ) |
2021
- JsonContainerSize (jc );
2022
-
2023
- tjc = JsonContainerAlloc (is_jsonx ? & jsonxzContainerOps : & jsonbzContainerOps ); /* FIXME optimize */
2024
- jsonxzInitWithHeader (tjc , toasted_val , & header );
2025
-
2026
- pairs [max_key_idx ].value .val .binary .data = tjc ;
2027
-
2039
+ pairs [max_key_idx ].value .val .binary .data = jsonxzInitContainerFromDatum (jc , toasted_val );
2028
2040
sizes [max_key_idx ] = sizeof (JsonbToastedContainerPointer );
2029
2041
total_size += INTALIGN (sizes [max_key_idx ] + 3 );
2030
2042
}
@@ -2220,11 +2232,11 @@ jsonb_toaster_copy(Relation rel, JsonContainer *jc, char cmethod)
2220
2232
static void
2221
2233
jsonb_toaster_delete_container (Relation rel , JsonContainer * jc )
2222
2234
{
2223
- JsonbToastedContainerPointer jbcptr ;
2235
+ JsonbToastedContainerPointerData jbcptr ;
2224
2236
2225
2237
if (JsonContainerIsToasted (jc , & jbcptr ))
2226
2238
{
2227
- struct varlena * ptr = jsonxMakeToastPointer (& jbcptr . ptr );
2239
+ struct varlena * ptr = jsonxMakeToastPointer (& jbcptr );
2228
2240
2229
2241
toast_delete_datum (PointerGetDatum (ptr ), false);
2230
2242
pfree (ptr );
@@ -2265,8 +2277,8 @@ jsonb_toaster_delete_recursive(Relation rel, JsonContainer *jc, bool delete_self
2265
2277
static bool
2266
2278
jsonb_toaster_cmp_recursive (Relation rel , JsonContainer * old_jc , JsonContainer * new_jc , char cmethod )
2267
2279
{
2268
- JsonbToastedContainerPointer new_jbcptr ;
2269
- JsonbToastedContainerPointer old_jbcptr ;
2280
+ JsonbToastedContainerPointerData new_jbcptr ;
2281
+ JsonbToastedContainerPointerData old_jbcptr ;
2270
2282
JsonIterator * old_it ;
2271
2283
JsonIterator * new_it ;
2272
2284
JsonValue old_jbv ;
@@ -2312,7 +2324,7 @@ jsonb_toaster_cmp_recursive(Relation rel, JsonContainer *old_jc, JsonContainer *
2312
2324
if (JsonContainerIsToasted (newjc , & new_jbcptr ))
2313
2325
{
2314
2326
if (!JsonContainerIsToasted (oldjc , & old_jbcptr ) ||
2315
- memcmp (& new_jbcptr , & old_jbcptr , sizeof (new_jbcptr )))
2327
+ memcmp (& new_jbcptr . ptr , & old_jbcptr . ptr , sizeof (new_jbcptr . ptr )))
2316
2328
{
2317
2329
changed |= jsonb_toaster_replace_toasted (rel , & new_jbv , (jsonbIterator * ) new_it , offset , cmethod );
2318
2330
jsonb_toaster_delete_recursive (rel , oldjc , true);
@@ -2379,8 +2391,8 @@ jsonb_toaster_cmp_recursive(Relation rel, JsonContainer *old_jc, JsonContainer *
2379
2391
static Datum
2380
2392
jsonb_toaster_cmp (Relation rel , JsonContainer * new_jc , JsonContainer * old_jc , char cmethod )
2381
2393
{
2382
- JsonbToastedContainerPointer new_jbcptr ;
2383
- JsonbToastedContainerPointer old_jbcptr ;
2394
+ JsonbToastedContainerPointerData new_jbcptr ;
2395
+ JsonbToastedContainerPointerData old_jbcptr ;
2384
2396
Datum res ;
2385
2397
void * jb ;
2386
2398
JsonbContainerHeader * new_jbc ;
@@ -2389,7 +2401,7 @@ jsonb_toaster_cmp(Relation rel, JsonContainer *new_jc, JsonContainer *old_jc, ch
2389
2401
if (JsonContainerIsToasted (new_jc , & new_jbcptr ))
2390
2402
{
2391
2403
if (JsonContainerIsToasted (old_jc , & old_jbcptr ) &&
2392
- !memcmp (& new_jbcptr , & old_jbcptr , sizeof (new_jbcptr )))
2404
+ !memcmp (& new_jbcptr . ptr , & old_jbcptr . ptr , sizeof (new_jbcptr . ptr )))
2393
2405
return (Datum ) 0 ;
2394
2406
2395
2407
res = jsonb_toaster_copy (rel , new_jc , cmethod );
0 commit comments