@@ -2662,7 +2662,6 @@ jsonb_toaster_save_object(Relation rel, Oid toasterid, JsonContainer *root,
2662
2662
if (!jsonb_toast_fields )
2663
2663
goto exit ;
2664
2664
2665
-
2666
2665
Datum value_to_toast ;
2667
2666
bool compress_chunks ;
2668
2667
@@ -3142,6 +3141,54 @@ jsonb_toaster_validate(Oid typeoid, char storage, char compression,
3142
3141
return ok ;
3143
3142
}
3144
3143
3144
+ static Datum
3145
+ jsonb_toaster_toast2 (Relation rel , Oid toasterid , Datum val , Datum compressed_val ,
3146
+ int max_inline_size , int options )
3147
+ {
3148
+ Datum toasted_val ;
3149
+ bool compress_chunks = jsonb_compress_chunks ;
3150
+
3151
+ if (jsonb_direct_toast && VARSIZE_ANY (compressed_val ) / 1900 * 1 + TOAST_POINTER_SIZE + 16 < max_inline_size )
3152
+ {
3153
+ struct varlena * chunks = NULL ;
3154
+
3155
+ toasted_val = jsonx_toast_save_datum_ext (rel , toasterid , val , NULL , 0 , & chunks , compress_chunks );
3156
+
3157
+ if (!chunks )
3158
+ ;
3159
+ else if (VARSIZE_ANY (chunks ) <= max_inline_size )
3160
+ {
3161
+ pfree (DatumGetPointer (toasted_val ));
3162
+ toasted_val = PointerGetDatum (chunks );
3163
+ }
3164
+ else
3165
+ {
3166
+ if (jsonb_compress_chunk_tids )
3167
+ {
3168
+ struct varlena * compressed_chunks = jsonx_toast_compress_tids (chunks , max_inline_size );
3169
+
3170
+ if (compressed_chunks )
3171
+ {
3172
+ if (VARSIZE_ANY (compressed_chunks ) <= max_inline_size )
3173
+ {
3174
+ pfree (DatumGetPointer (toasted_val ));
3175
+ toasted_val = PointerGetDatum (compressed_chunks );
3176
+ }
3177
+ else
3178
+ pfree (compressed_chunks );
3179
+ }
3180
+ }
3181
+
3182
+ pfree (chunks );
3183
+ }
3184
+ }
3185
+ else
3186
+ toasted_val = jsonx_toast_save_datum_ext (rel , toasterid , val ,
3187
+ NULL , options , NULL , compress_chunks );
3188
+
3189
+ return toasted_val ;
3190
+ }
3191
+
3145
3192
static Datum
3146
3193
jsonb_toaster_default_toast (Relation rel , Oid toasterid , char cmethod ,
3147
3194
Datum new_val , Json * new_js ,
@@ -3171,6 +3218,9 @@ jsonb_toaster_default_toast(Relation rel, Oid toasterid, char cmethod,
3171
3218
if (VARSIZE_ANY (compressed_val ) <= max_inline_size )
3172
3219
return compressed_val ;
3173
3220
3221
+ return jsonb_toaster_toast2 (rel , toasterid , new_val , compressed_val ,
3222
+ max_inline_size , options );
3223
+
3174
3224
return jsonx_toast_save_datum_ext (rel , toasterid , compressed_val ,
3175
3225
NULL , options , NULL , false);
3176
3226
}
0 commit comments