Re: Varchar vs foreign key vs enumerator - table and index size - Mailing list pgsql-performance

From Vitalii Tymchyshyn
Subject Re: Varchar vs foreign key vs enumerator - table and index size
Date
Msg-id CABWW-d28Y9HiLAvnj5BDm-yeMXr61aWv3HiUQtKj1_V-+DoYnA@mail.gmail.com
Whole thread Raw
In response to Varchar vs foreign key vs enumerator - table and index size  (Łukasz Walkowski <lukasz.walkowski@homplex.pl>)
Responses Re: Varchar vs foreign key vs enumerator - table and index size
List pgsql-performance



2013/8/31 Łukasz Walkowski <lukasz.walkowski@homplex.pl>

3. And this part is most interesting for me. Columns browser, eventsource, eventtype, devicetype, operatingsystem contain a small pool of strings - for example for devicetype this is set to Computer, Mobile, Tablet or Unknown. Browser is set to normalized browser name. In every case I can store those data using one of 3 different methods:


Well, there are some more options:
a) Store int keys and do mapping in the application (e.g. with java enums). This can save you a join, that is especially useful if you are going to do paged output with limit/offset scenario. Optimizer sometimes produce suboptimal plans for join in offset/limit queries.
b) Store small varchar values as keys (up to "char" type if you really want to save space) and do user display mapping in application. It's different from (a) since it's harder to mess with the mapping and values are still more or less readable with simple select. But it can be less efficient than (a).
c) Do mixed approach with mapping table, loaded on start into application memory. This would be an optimization in case you get into optimizer troubles.

Best regards, Vitalii Tymchyshyn

pgsql-performance by date:

Previous
From: Craig James
Date:
Subject: Re: Varchar vs foreign key vs enumerator - table and index size
Next
From: Scott Marlowe
Date:
Subject: Re: How clustering for scale out works in PostgreSQL