Suggest a Normalization technique in MySql -


following table structure

table 1:

create table page_visits (   domain varchar(50) not null,   campaign_id bigint default null,   subscriber_id bigint default null ); 

sample rows of above table.

+-----------+------------------+------------------+ | domain    | subscriber_id    | campaign_id      | +-----------+------------------+------------------+ | abcdef    | 5834234569635200 | 5814789314123456 | | abcdef    | 5834979786543520 | 5814789314123456 | | abcdef    | 1238003995770880 | 5814789314123456 | | abcdef    | 4567900658540544 | 5814789314123456 | | abcdef    | 8765906092156928 | 5814789314123456 | +--------+------------------+---------------------+ 

we have 100 million rows (approx) , size 100 gb (approx). want normalize table. instead of having "varchar" datatype domain , want use domain_id medium int in above table. because domain name repeating lot of times in table.

i keep domains in separate table following , domain name unique in following table.

table 2:

create table domains (   domain_id mediumint unsigned not null,   domain_name varchar(50) not null ); 

problem : every read , write request table 1 , need call table 2 domain_id domain name because i'm not storing domain_id in app. anyway optimize reduce size ??

table page_vits create statement :

create table `page_visits` (   `id` int(11) not null auto_increment,   `domain_id` int(11) default null,   `campaign_id` bigint(20) default null,   `subscriber_id` bigint(20) default null,   primary key (`id`),   key `domain_id_idx` (`domain_id`),   constraint `domain_id` foreign key (`domain_id`) references `domains` (`domain_id`) on delete no action on update no action ) engine=innodb default charset=latin1; 

now domain_id references domain table.

table domain create statement:

create table `domains` (   `domain_id` int(11) not null auto_increment,   `domain_name` varchar(50) not null,   primary key (`domain_id`) ) engine=innodb auto_increment=46 default charset=latin1; 

er diagram

enter image description here


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -