io7m / eigion

1 stars 0 forks source link

Switch varchar columns to text #9

Closed io7m closed 2 years ago

io7m commented 2 years ago

The Postgres manual states that varchar and text don't have any real performance difference, and having a hard limit on a varchar just means that's one extra exception the database might raise. We can enforce lengths in the Java type system more efficiently.

https://www.postgresql.org/docs/current/datatype-character.html

There is no performance difference among these three types, apart from increased storage space when using the blank-padded type, and a few extra CPU cycles to check the length when storing into a length-constrained column. While character(n) has performance advantages in some other database systems, there is no such advantage in PostgreSQL; in fact character(n) is usually the slowest of the three because of its additional storage costs. In most situations text or character varying should be used instead.

io7m commented 2 years ago

It seems this doesn't play nicely with jooq, which reports an error about being unable to create an index for a character large object type.

Switching to varchar(1000000) is better.