Dynamic columns

Поиск
Список
Период
Сортировка
От Mohd Toha Taifor
Тема Dynamic columns
Дата
Msg-id 20020123035337.66997.qmail@web13807.mail.yahoo.com
обсуждение исходный текст
Список pgsql-admin
in term of performance, which is better?

i want to create dynamic columns for the same items:

-- items to be created

create table items (
id        integer
        primary key,
name        varchar(100)
);

-- categorization for items

create table categories (
id        integer
        primary key,
name        varchar(100)
);

create table item_category_map (
item_id        integer
        references items
        on delete cascade,
category_id    integer
        references categories
        on delete cascade,
primary key (item_id, category_id)
);

-- this is special table for dynamic columns generated
for specific
-- category so that items for this category will have
distinct
-- characteristics compared to other category

create table attributes (
id        integer
        primary key,
category_id    integer
        references categories
        on delete cascade,
name        varchar(100),
type        varchar(20)
        check (type in
        ('bool', 'long text', 'text', 'date', 'integer',
'float')),
);

-- this table stores value of column defined for
categories

create table values (
item_id        integer
        references items
        on delete cascade,
attribute_id    integer
        references attributes
        on delete cascade,
bool_value    char(1)
        check (bool_value in
          ('t', 'f')
        ),
long_value    varchar(4000),
text_value    varchar(200),
date_value    datetime,
int_value    integer,
float_value    numeric(30, 6)
);


table values will store dynamic column's value for
particular item. the problem would be because the
table create redundancies.

i could simply change definition so that the value, no
matter of what type, will be stored in varchar(4000),
but results in problem in application.

create table values (
item_id        integer
        references items
        on delete cascade,
attribute_id    integer
        references attributes
        on delete cascade,
value        varchar(4000)
);

the other way is to represent them in different table:

create table values_bool (
item        integer
        references items
        on delete cascade,
attribute_id    integer
        references attributes
        on delete cascade,
value        char(1)
        check (value in
          ('t', 'f')
        )
);

which also results in problem and annoyance to
application developer.

which one is better in term of performance?

or is there any better solution?

any references or document is highly appreciated

thank you


__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/

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

Предыдущее
От: "lonh SENG"
Дата:
Сообщение: Execute A String of Query
Следующее
От: Daniel Andersen
Дата:
Сообщение: Re: Execute A String of Query