Re: CHAR vs NVARCHAR vs TEXT performance

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: CHAR vs NVARCHAR vs TEXT performance
Дата
Msg-id 30249.1556559837@sss.pgh.pa.us
обсуждение исходный текст
Ответ на CHAR vs NVARCHAR vs TEXT performance  (Rob <postgresql@mintsoft.net>)
Список pgsql-hackers
Rob <postgresql@mintsoft.net> writes:
> Basically, if a table exists with a PK which is CHAR(n) and a query is
> sent with VARCHAR or CHAR then it uses an Index Scan. If the query is
> sent with TEXT as the type then postgresql casts the column to TEXT
> (rather than the value to CHAR) and it does a Seq Scan.

Yeah, this is an artifact of the fact that text is considered a
"preferred type" so it wins out in the parser's choice of which
type to promote to.  See

https://www.postgresql.org/docs/current/typeconv-oper.html

> I guess the root question is: is TEXT supposed to be identical to 
> VARCHAR in all scenarios?

It's not for this purpose, because varchar isn't a preferred type.

FWIW, my recommendation for this sort of thing is almost always
to not use CHAR(n).  The use-case for that datatype pretty much
disappeared with the last IBM Model 029 card punch.

            regards, tom lane



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Race conditions with checkpointer and shutdown
Следующее
От: Ashwin Agrawal
Дата:
Сообщение: Re: Race conditions with checkpointer and shutdown