Monday, 15 August 2011

postgresql - Do I have to create a surrogate key if I want to save space? -



postgresql - Do I have to create a surrogate key if I want to save space? -

let's have big table owners of cars so:

ownership owner | auto --------------- steven | audi bernahrd | vw dieter | vw eike | vw robert | audi ... 1 hundred 1000000 rows ...

if refactor this:

ownership owner | auto <-foreign key type.car_type --------------- steven | audi bernahrd | vw dieter | vw eike | vw robert | audi ... type car_type | --------------- audi vw

do win spacewise or speedwise or need create integer surrogate key on car_type that?

using 2 tables , string foreign key of course of study utilize more space using one. how much more depends on how many types of cars have.

you should utilize integer car_id:

using integer keys save space if important percentage of auto names repeat.

more if you'd need index car column, integer index much smaller string index.

also comparing integers faster comparing strings, searching auto should faster.

smaller table means bigger part if fit in cache, accessing should faster.

postgresql foreign-keys

No comments:

Post a Comment