Обсуждение: varchar(n) vs. varchar

Поиск
Список
Период
Сортировка

varchar(n) vs. varchar

От
"Daniel Serodio"
Дата:
I've found a thread discussing the use of "text" vs. "varchar"; what
I'd like to know if there's any performance difference between using
"varchar(n)" vs. "varchar", ie, should I constrain a "name" column to
an arbitrary length to improve performance, or will it actually degrade
performance because of the extra cycles used for checking the length?


Re: varchar(n) vs. varchar

От
Tom Lane
Дата:
"Daniel Serodio" <dserodio@gmail.com> writes:
> I've found a thread discussing the use of "text" vs. "varchar"; what
> I'd like to know if there's any performance difference between using
> "varchar(n)" vs. "varchar", ie, should I constrain a "name" column to
> an arbitrary length to improve performance, or will it actually degrade
> performance because of the extra cycles used for checking the length?

The latter.

The general rule of thumb is don't use varchar(n) (or even worse,
char(n)) unless you can point to a specific application requirement
for a maximum field width.  In particular, if you find yourself
picking a value for N out of the air, you're doing the wrong thing.

            regards, tom lane