GNU social JP
  • FAQ
  • Login
GNU social JPは日本のGNU socialサーバーです。
Usage/ToS/admin/test/Pleroma FE
  • Public

    • Public
    • Network
    • Groups
    • Featured
    • Popular
    • People

Conversation

Notices

  1. Embed this notice
    Ayo (ayo@lonely.town)'s status on Sunday, 22-Dec-2024 17:35:36 JST Ayo Ayo

    I often struggle to disable the micro-optimization-addicted part of my brain when designing SQL schemas.

    VNDB has a table with 4 enum columns, each supporting 5-6 possible values. Postgres encodes enums as 4 bytes, so those 4 columns occupy 16 bytes on disk. But the same information would comfortably fit in just 2 bytes!

    Of course, I could merge the columns into a single smallint with some fancy bit twiddling, but that comes at the cost of awkward queries and complicating the codebase. The benefits aren't worth it either: space savings will likely be insignificant if you factor in other columns and row overhead, and it's unlikely to make much of a difference in terms of performance.

    BUT STILL THAT INFORMATION COULD BE 8 TIMES SMALLER! :blobcatreeeeeee:

    In conversation about 5 months ago from lonely.town permalink
    • Haelwenn /элвэн/ :triskell: and gidi like this.
    • Embed this notice
      Haelwenn /элвэн/ :triskell: (lanodan@queer.hacktivis.me)'s status on Sunday, 22-Dec-2024 18:31:25 JST Haelwenn /элвэн/ :triskell: Haelwenn /элвэн/ :triskell:
      in reply to
      • Wolf480pl
      @ayo @wolf480pl And I guess they screwed up the varint size for encoding the length of the string? (should be encoding for 254 bytes with 1 byte, then 65533 with 2 bytes, …).
      In conversation about 5 months ago permalink
    • Embed this notice
      Ayo (ayo@lonely.town)'s status on Sunday, 22-Dec-2024 18:31:26 JST Ayo Ayo
      in reply to
      • Wolf480pl

      @wolf480pl Yup, it's essentially a varchar(n) with automatic padding.

      In conversation about 5 months ago permalink
    • Embed this notice
      Wolf480pl (wolf480pl@mstdn.io)'s status on Sunday, 22-Dec-2024 18:31:27 JST Wolf480pl Wolf480pl
      in reply to

      @ayo (inb4 it's toast)

      In conversation about 5 months ago permalink
    • Embed this notice
      Wolf480pl (wolf480pl@mstdn.io)'s status on Sunday, 22-Dec-2024 18:31:27 JST Wolf480pl Wolf480pl
      in reply to

      @ayo
      > The storage requirement for a short string (up to 126 bytes) is 1 byte plus the actual string,

      :(

      In conversation about 5 months ago permalink
    • Embed this notice
      Wolf480pl (wolf480pl@mstdn.io)'s status on Sunday, 22-Dec-2024 18:31:28 JST Wolf480pl Wolf480pl
      in reply to

      @ayo how long is char(1)?

      In conversation about 5 months ago permalink
    • Embed this notice
      Wolf480pl (wolf480pl@mstdn.io)'s status on Sunday, 22-Dec-2024 18:31:29 JST Wolf480pl Wolf480pl
      in reply to

      @ayo omg it's using 4 WHOLE BYTES for an Enum? That's crazy...

      what if you made a separate table with enum values and 1-byte PK, and replaced the enum columns with 1-byte foreign keys?

      In conversation about 5 months ago permalink
    • Embed this notice
      Ayo (ayo@lonely.town)'s status on Sunday, 22-Dec-2024 18:31:29 JST Ayo Ayo
      in reply to
      • Wolf480pl

      @wolf480pl I know, right?

      Sadly the only 1-byte type in core Postgres is a boolean, which is... not quite suitable. Using the FK approach with smallints still halves the storage requirements, but meh.

      I'm almost considering hacking in support for 1-byte enums into Postgres. Even have an idea on how to do that within its current enum framework, but I doubt there's much enthusiasm among postgres devs to add the complexity unless I can motivate it with some strong use cases and benchmarks.

      In conversation about 5 months ago permalink

Feeds

  • Activity Streams
  • RSS 2.0
  • Atom
  • Help
  • About
  • FAQ
  • TOS
  • Privacy
  • Source
  • Version
  • Contact

GNU social JP is a social network, courtesy of GNU social JP管理人. It runs on GNU social, version 2.0.2-dev, available under the GNU Affero General Public License.

Creative Commons Attribution 3.0 All GNU social JP content and data are available under the Creative Commons Attribution 3.0 license.