Re: Efficiency question: VARCHAR with empty string vs NULL

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Efficiency question: VARCHAR with empty string vs NULL
Дата
Msg-id 13510.1022266454@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Efficiency question: VARCHAR with empty string vs NULL  (Doug Fields <dfields-pg-general@pexicom.com>)
Ответы Re: Efficiency question: VARCHAR with empty string  (Doug Fields <dfields-pg-general@pexicom.com>)
Список pgsql-general
Doug Fields <dfields-pg-general@pexicom.com> writes:
> Is there a performance difference with VARCHAR elements of value NULL and
> zero-length string?

These are not semantically equivalent (if you think they are, you've
been using Oracle too long).  You will almost certainly regret it
if you try recoding your app to make them equivalent.  An example:

regression=# select 'foo'::varchar || ''::varchar;
 ?column?
----------
 foo
(1 row)

regression=# select 'foo'::varchar || null::varchar;
 ?column?
----------

(1 row)


But to answer your question, NULLs might save a couple bytes if there
are multiple NULLs per row.  I think that replacing a single empty
varchar with a NULL would net out to no change (you lose the 4-byte
varchar length word, but have to store a null-values bitmap instead),
depending on alignment issues and how many columns there are in the
table.

            regards, tom lane

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

Предыдущее
От: Neil Conway
Дата:
Сообщение: Re: Altering existing table to be WITHOUT OIDs
Следующее
От: Neil Conway
Дата:
Сообщение: Re: Case Insensitive Data Type