@@ -2786,12 +2786,44 @@ jsonb_toaster_validate(Oid typeoid, char storage, char compression,
2786
2786
return ok ;
2787
2787
}
2788
2788
2789
+ static Datum
2790
+ jsonb_toaster_default_toast (Relation rel ,Oid toasterid ,char cmethod ,
2791
+ Datum new_val ,Json * new_js ,
2792
+ int max_inline_size ,int options )
2793
+ {
2794
+
2795
+ Datum compressed_val = (Datum )0 ;
2796
+
2797
+ if (VARATT_IS_CUSTOM (new_val ))
2798
+ {
2799
+ /* Convert custom-TOASTed jsonb to plain jsonb */
2800
+ JsonbValue jbv ;
2801
+
2802
+ JsonValueInitBinary (& jbv ,JsonRoot (new_js ));
2803
+
2804
+ new_val = PointerGetDatum (JsonEncode (& jbv ,JsonbEncode ,NULL ));
2805
+ }
2806
+
2807
+ if (!VARATT_IS_COMPRESSED (new_val ))
2808
+ {
2809
+ compressed_val = toast_compress_datum (new_val ,cmethod );
2810
+
2811
+ if (compressed_val == (Datum )0 )
2812
+ compressed_val = new_val ;
2813
+ }
2814
+
2815
+ if (VARSIZE_ANY (compressed_val ) <=max_inline_size )
2816
+ return compressed_val ;
2817
+
2818
+ return jsonx_toast_save_datum_ext (rel ,toasterid ,compressed_val ,
2819
+ NULL ,options ,NULL , false);
2820
+ }
2821
+
2789
2822
static struct varlena *
2790
2823
jsonb_toaster_toast (Relation rel ,Oid toasterid ,
2791
2824
Datum new_val ,Datum old_val ,
2792
2825
int max_inline_size ,int options )
2793
2826
{
2794
-
2795
2827
Json * new_js ;
2796
2828
Datum res ;
2797
2829
char cmethod = TOAST_PGLZ_COMPRESSION ;
@@ -2803,17 +2835,10 @@ jsonb_toaster_toast(Relation rel, Oid toasterid,
2803
2835
res = jsonb_toaster_save (rel ,toasterid ,new_js ,max_inline_size ,cmethod );
2804
2836
2805
2837
if (res == (Datum )0 )
2806
- {
2807
- Datum compressed_val = (Datum )0 ;
2808
-
2809
- if (!VARATT_IS_COMPRESSED (new_val ))
2810
- compressed_val = toast_compress_datum (new_val ,cmethod );
2811
-
2812
- if (compressed_val == (Datum )0 )
2813
- compressed_val = new_val ;
2814
-
2815
- res = jsonx_toast_save_datum_ext (rel ,toasterid ,compressed_val ,NULL ,options ,NULL , false);
2816
- }
2838
+ /* Fallback to default TOAST */
2839
+ res = jsonb_toaster_default_toast (rel ,toasterid ,cmethod ,
2840
+ new_val ,new_js ,
2841
+ max_inline_size ,options );
2817
2842
2818
2843
res = res == (Datum )0 ?new_val :res ;
2819
2844