Skip to content
Snippets Groups Projects
Select Git revision
  • benchmark-tools
  • postgres-lambda
  • master default
  • REL9_4_25
  • REL9_5_20
  • REL9_6_16
  • REL_10_11
  • REL_11_6
  • REL_12_1
  • REL_12_0
  • REL_12_RC1
  • REL_12_BETA4
  • REL9_4_24
  • REL9_5_19
  • REL9_6_15
  • REL_10_10
  • REL_11_5
  • REL_12_BETA3
  • REL9_4_23
  • REL9_5_18
  • REL9_6_14
  • REL_10_9
  • REL_11_4
23 results

jsonb.c

Blame
    • Tom Lane's avatar
      def4c28c
      Change JSONB's on-disk format for improved performance. · def4c28c
      Tom Lane authored
      The original design used an array of offsets into the variable-length
      portion of a JSONB container.  However, such an array is basically
      uncompressible by simple compression techniques such as TOAST's LZ
      compressor.  That's bad enough, but because the offset array is at the
      front, it tended to trigger the give-up-after-1KB heuristic in the TOAST
      code, so that the entire JSONB object was stored uncompressed; which was
      the root cause of bug #11109 from Larry White.
      
      To fix without losing the ability to extract a random array element in O(1)
      time, change this scheme so that most of the JEntry array elements hold
      lengths rather than offsets.  With data that's compressible at all, there
      tend to be fewer distinct element lengths, so that there is scope for
      compression of the JEntry array.  Every N'th entry is still an offset.
      To determine the length or offset of any specific element, we might have
      to examine up to N preceding JEntrys, but that's still O(1) so far as the
      total container size is concerned.  Testing shows that this cost is
      negligible compared to other costs of accessing a JSONB field, and that
      the method does largely fix the incompressible-data problem.
      
      While at it, rearrange the order of elements in a JSONB object so that
      it's "all the keys, then all the values" not alternating keys and values.
      This doesn't really make much difference right at the moment, but it will
      allow providing a fast path for extracting individual object fields from
      large JSONB values stored EXTERNAL (ie, uncompressed), analogously to the
      existing optimization for substring extraction from large EXTERNAL text
      values.
      
      Bump catversion to denote the incompatibility in on-disk format.
      We will need to fix pg_upgrade to disallow upgrading jsonb data stored
      with 9.4 betas 1 and 2.
      
      Heikki Linnakangas and Tom Lane
      def4c28c
      History
      Change JSONB's on-disk format for improved performance.
      Tom Lane authored
      The original design used an array of offsets into the variable-length
      portion of a JSONB container.  However, such an array is basically
      uncompressible by simple compression techniques such as TOAST's LZ
      compressor.  That's bad enough, but because the offset array is at the
      front, it tended to trigger the give-up-after-1KB heuristic in the TOAST
      code, so that the entire JSONB object was stored uncompressed; which was
      the root cause of bug #11109 from Larry White.
      
      To fix without losing the ability to extract a random array element in O(1)
      time, change this scheme so that most of the JEntry array elements hold
      lengths rather than offsets.  With data that's compressible at all, there
      tend to be fewer distinct element lengths, so that there is scope for
      compression of the JEntry array.  Every N'th entry is still an offset.
      To determine the length or offset of any specific element, we might have
      to examine up to N preceding JEntrys, but that's still O(1) so far as the
      total container size is concerned.  Testing shows that this cost is
      negligible compared to other costs of accessing a JSONB field, and that
      the method does largely fix the incompressible-data problem.
      
      While at it, rearrange the order of elements in a JSONB object so that
      it's "all the keys, then all the values" not alternating keys and values.
      This doesn't really make much difference right at the moment, but it will
      allow providing a fast path for extracting individual object fields from
      large JSONB values stored EXTERNAL (ie, uncompressed), analogously to the
      existing optimization for substring extraction from large EXTERNAL text
      values.
      
      Bump catversion to denote the incompatibility in on-disk format.
      We will need to fix pg_upgrade to disallow upgrading jsonb data stored
      with 9.4 betas 1 and 2.
      
      Heikki Linnakangas and Tom Lane