@@ -189,6 +189,7 @@ static JsonbValue *fillCompressedJsonbValue(CompressedJsonb *cjb,
189
189
int index , char * base_addr ,
190
190
uint32 offset , JsonValue * result );
191
191
static JsonbContainerHeader * jsonxzDecompress (JsonContainer * jc );
192
+ static void jsonxzDecompressTo (CompressedJsonb * cjb , Size offset );
192
193
static bool JsonContainerIsToasted (JsonContainer * jc ,
193
194
JsonbToastedContainerPointerData * jbcptr );
194
195
static bool JsonContainerIsCompressed (JsonContainer * jc ,
@@ -747,7 +748,7 @@ JsonxIteratorInit(JsonContainer *cont, const JsonbContainerHeader *container,
747
748
748
749
/* decompress container header */
749
750
if (cjb )
750
- PG_DETOAST_ITERATE (cjb -> iter , cjb -> iter -> buf -> buf + cjb -> offset + offsetof(JsonbDatum , root . children ));
751
+ jsonxzDecompressTo (cjb , cjb -> offset + offsetof(JsonbContainerHeader , children ));
751
752
752
753
type = container -> header & JBC_TMASK ;
753
754
@@ -792,7 +793,7 @@ JsonxIteratorInit(JsonContainer *cont, const JsonbContainerHeader *container,
792
793
}
793
794
794
795
if (it -> dataProper && cjb )
795
- PG_DETOAST_ITERATE (cjb -> iter , it -> dataProper );
796
+ jsonxzDecompressTo (cjb , cjb -> offset + ( it -> dataProper - ( char * ) container ) );
796
797
797
798
return (JsonIterator * ) it ;
798
799
}
@@ -1616,14 +1617,26 @@ jsonxzInitContainer(JsonContainerData *jc, CompressedJsonb *cjb,
1616
1617
jsonxInitContainerFromHeader (jc , header );
1617
1618
}
1618
1619
1620
+ static void
1621
+ jsonxzDecompressAll (CompressedJsonb * cjb )
1622
+ {
1623
+ PG_DETOAST_ITERATE (cjb -> iter , cjb -> iter -> buf -> capacity );
1624
+ }
1625
+
1626
+ static void
1627
+ jsonxzDecompressTo (CompressedJsonb * cjb , Size offset )
1628
+ {
1629
+ PG_DETOAST_ITERATE (cjb -> iter , cjb -> iter -> buf -> buf + offset );
1630
+ }
1631
+
1619
1632
static JsonbContainerHeader *
1620
1633
jsonxzDecompress (JsonContainer * jc )
1621
1634
{
1622
1635
CompressedJsonb * cjb = jsonbzGetCompressedJsonb (jc );
1623
1636
JsonbDatum * jb = (JsonbDatum * ) cjb -> iter -> buf -> buf ;
1624
1637
JsonbContainerHeader * container = (JsonbContainerHeader * )((char * ) jb + cjb -> offset );
1625
1638
1626
- PG_DETOAST_ITERATE (cjb -> iter , cjb -> iter -> buf -> buf + cjb -> offset + jc -> len );
1639
+ jsonxzDecompressTo (cjb , cjb -> offset + jc -> len );
1627
1640
1628
1641
return container ;
1629
1642
}
@@ -1658,15 +1671,13 @@ fillCompressedJsonbValue(CompressedJsonb *cjb, const JsonbContainerHeader *conta
1658
1671
1659
1672
len -= INTALIGN (offset ) - offset ;
1660
1673
1661
- PG_DETOAST_ITERATE (cjb -> iter , cjb -> iter -> buf -> buf + cjb2 .offset +
1662
- offsetof(JsonbContainerHeader , children ));
1663
-
1674
+ jsonxzDecompressTo (cjb , cjb2 .offset + offsetof(JsonbContainerHeader , children ));
1664
1675
jsonxzInitContainer (cont , & cjb2 , NULL , len );
1665
1676
JsonValueInitBinary (result , cont );
1666
1677
}
1667
1678
else
1668
1679
{
1669
- PG_DETOAST_ITERATE (cjb -> iter , cjb -> iter -> buf -> buf + base_offset + offset + len );
1680
+ jsonxzDecompressTo (cjb , base_offset + offset + len );
1670
1681
jsonxFillValue (container , index , base_addr , offset , result );
1671
1682
}
1672
1683
@@ -1702,7 +1713,7 @@ findValueInCompressedJsonbObject(CompressedJsonb *cjb, const char *keystr, int k
1702
1713
key .val .string .val = keystr ;
1703
1714
key .val .string .len = keylen ;
1704
1715
1705
- PG_DETOAST_ITERATE (cjb -> iter , cjb -> iter -> buf -> buf + base_offset );
1716
+ jsonxzDecompressTo (cjb , base_offset );
1706
1717
1707
1718
/* Binary search on object/pair keys *only* */
1708
1719
while (stopLow < stopHigh )
@@ -1717,7 +1728,7 @@ findValueInCompressedJsonbObject(CompressedJsonb *cjb, const char *keystr, int k
1717
1728
offset = getJsonbOffset (container , stopMiddle );
1718
1729
len = getJsonbLength (container , stopMiddle );
1719
1730
1720
- PG_DETOAST_ITERATE (cjb -> iter , cjb -> iter -> buf -> buf + base_offset + offset + len );
1731
+ jsonxzDecompressTo (cjb , base_offset + offset + len );
1721
1732
1722
1733
difference = lengthCompareJsonbString (base_addr + offset , len ,
1723
1734
key .val .string .val ,
@@ -1767,7 +1778,7 @@ jsonxzFindKeyInObject(JsonContainer *jc, const char *key, int len, JsonValue *re
1767
1778
1768
1779
CompressedDatumDecompress (cjb -> datum , cjb -> offset + offsetof(JsonbContainerHeader , header ));
1769
1780
#else
1770
- PG_DETOAST_ITERATE (cjb -> iter , cjb -> iter -> buf -> buf + cjb -> offset + offsetof(JsonbContainerHeader , header ));
1781
+ jsonxzDecompressTo (cjb , cjb -> offset + offsetof(JsonbContainerHeader , children ));
1771
1782
#endif
1772
1783
1773
1784
return findValueInCompressedJsonbObject (cjb , key , len , res );
@@ -1789,11 +1800,11 @@ JsonbzArrayIteratorInit(JsonbzArrayIterator *it, CompressedJsonb *cjb)
1789
1800
JsonbDatum * jb = (JsonbDatum * ) cjb -> iter -> buf -> buf ;
1790
1801
const JsonbContainerHeader * jbc = (const JsonbContainerHeader * )((char * ) jb + cjb -> offset );
1791
1802
1792
- PG_DETOAST_ITERATE (cjb -> iter , ( const char * ) & jbc -> children );
1803
+ jsonxzDecompressTo (cjb , cjb -> offset + (( char * ) & jbc -> children - ( char * ) jbc ) );
1793
1804
1794
1805
it -> count = (cjb -> header & JBC_CMASK );
1795
1806
1796
- PG_DETOAST_ITERATE (cjb -> iter , ( const char * ) & jbc -> children [it -> count ]);
1807
+ jsonxzDecompressTo (cjb , cjb -> offset + (( char * ) & jbc -> children [it -> count ] - ( char * ) jbc ) );
1797
1808
1798
1809
it -> cjb = cjb ;
1799
1810
it -> container = jbc ;
@@ -1871,7 +1882,7 @@ jsonxzIteratorInit(JsonContainer *jc)
1871
1882
JsonbContainerHeader * jbc = (JsonbContainerHeader * )((char * ) jb + cjb -> offset );
1872
1883
1873
1884
if (!jsonb_partial_decompression )
1874
- PG_DETOAST_ITERATE (cjb -> iter , cjb -> iter -> buf -> capacity );
1885
+ jsonxzDecompressAll (cjb );
1875
1886
1876
1887
return JsonxIteratorInit (jc , jbc , cjb );
1877
1888
}
@@ -1880,15 +1891,17 @@ static void
1880
1891
jsonxzInitFromDetoastIterator (JsonContainerData * jc , DetoastIterator iter , JsonbContainerHdr * header )
1881
1892
{
1882
1893
CompressedJsonb * cjb = palloc (sizeof (* cjb ));
1894
+ int len = VARSIZE_ANY_EXHDR (iter -> buf -> buf );
1895
+
1883
1896
cjb -> iter = iter ;
1884
1897
cjb -> offset = offsetof(JsonbDatum , root );
1885
1898
1886
1899
if (!jsonb_partial_decompression )
1887
- PG_DETOAST_ITERATE ( iter , iter -> buf -> capacity );
1900
+ jsonxzDecompressAll ( cjb );
1888
1901
else if (!header )
1889
- PG_DETOAST_ITERATE ( iter , Min (iter -> buf -> buf + offsetof(JsonbDatum , root .children ), iter -> buf -> capacity ));
1902
+ jsonxzDecompressTo ( cjb , Min (offsetof(JsonbDatum , root .children ), iter -> buf -> capacity - iter -> buf -> buf ));
1890
1903
1891
- jsonxzInitContainer (jc , cjb , header , VARSIZE_ANY_EXHDR ( iter -> buf -> buf )); // cd->total_len - VARHDRSZ
1904
+ jsonxzInitContainer (jc , cjb , header , len );
1892
1905
}
1893
1906
1894
1907
static void
0 commit comments