Uploaded image for project: 'Apache HAWQ'
  1. Apache HAWQ
  2. HAWQ-944

Numutils.c: pg_ltoa and pg_itoa functions allocate unnecessary amount of bytes

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 2.2.0.0-incubating
    • Core
    • None

    Description

      The current implementations of pg_ltoa and pg_itoa allocate a 33 byte char array and set the input pointer to that array. This is far too many bytes than needed to translate an int16 or int32 to a string

      int32 -> 10 bytes maximum + 1 sign bit + '\0' = 12 bytes
      int16 -> 5 bytes maximum + 1 sign bit + '\0' = 7 bytes

      When HAWQ/Greenplum forked from Postgres the two functions simply delegated to sprintf so an optimization was introduced that involved the 33 byte solution. Postgres itself implemented these functions in commit https://github.com/postgres/postgres/commit/4fc115b2e981f8c63165ca86a23215380a3fda66 that require a 12 byte maximum char pointer.

      This is a minor improvement that can be made to the HAWQ codebase and it's relatively little effort to do so.

      Attachments

        Issue Links

          Activity

            People

              kavinderd Kavinder Dhaliwal
              kavinderd Kavinder Dhaliwal
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: