Using varchar primary keys.

Поиск
Список
Период
Сортировка
От Tim Uckun
Тема Using varchar primary keys.
Дата
Msg-id CAGuHJrNUd-34fq0Ee-P6=-DDBa6T1ROthchsj6fuTbuwsGuVVA@mail.gmail.com
обсуждение исходный текст
Ответы Re: Using varchar primary keys.  (Modulok <modulok@gmail.com>)
Re: Using varchar primary keys.  (Gavan Schneider <pg-gts@snkmail.com>)
Список pgsql-general
Consider the following scenario.

I have a typical tagging structure. There is a table called tags, there is a table called taggings. The taggings table acts as a many to many join table between the taggers and the tags.

The tags table has two fields id and tag. id is a serial data type.

The taggings has a tag_id field along with the context, tagger_id etc.

I don't think there is even one query in this scenario which does not join the taggings table to the tags table so I am wondering if there is any advantage at all of having that id field in the tags table. Why shouldn't I just put the tag itself as the primary key?  The tags are quite short so if pg is smart about it I would guess they would take up less space than an integer in some cases.

I guess the same scenario happens in many of my lookup tables. I have all these tables with just two fields in them.  id field and then some varchar field.  Then every time I want to display that record I join with five other tables so I can look up all the associated lookup tables and display the text value to the user.

Given that you can still set foreign keys and cascade commands to adjust child records either way the tables would be properly normalized so I am wondering what I am gaining by using these serial ID fields.

Is this false economy?

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

Предыдущее
От: Juan Pablo Cook
Дата:
Сообщение: Re: Fwd: JDBC Array double precision [] error
Следующее
От: Pierre
Дата:
Сообщение: my-post-engine, let's make MySQL speak to PostgreSQL