I have a table for recording license usage. Each license usage needs to be associated with a user and a host machine. The table definition looks like this.
create table if not exists per_user_fact
(
per_user_fact_id int unsigned not null auto_increment,
time_of_day char(16) not null,
license_served_id smallint unsigned not null,
license_hours numeric(10,2) not null,
role_name varchar(64) null,
user varchar(128) not null,
host varchar(128) not null,
primary key (per_user_fact_id),
foreign key (license_served_id) references served_license(served_license_id),
foreign key (user, host) references user_host(username, hostname)
);
I want to normalize this table so that the user/host values, which are repetitive, are moved to a new table like this.
create table if not exists user_host
(
username varchar(64) not null,
hostname varchar(128) not null,
primary key (username, hostname)
);
For the user_host table, what kind of primary key should I pick up - natural or surrogate? I can think of the following governing factors.
- If the primary key is natural, that is a composite of user and host names, the parent table per_user_fact will not need additional joins to find out user and host names.
- If the primary key is natural, there will be waste of storage as the user and host names values will be duplicated in both the tables.
- If the primary key is surrogate, the additional join will be needed for the parent table to get the values for user and host names.
- If the primary key is surrogate, the indexing on the user_host table will be faster.
Please advise.