I posted something similar a while back where I was thinking of going with a very generic structure where my program takes care of everything, it would be highly normalized, but create very complex queries. I decided to simplify it where I have a main object table with generic fields such as ID, parent ID, type etc... and each object type had it's own table with the first field always being the object ID.
When I query, I query both the main object table, and the proper table that matches that object's type. This is working out nicely so far.
Now, I was thinking, the only advantage this has is that I'm not constantly repeating the same generic fields for each object type, and if I add a new generic field later on I only have to edit one table. Other then that, querying is still a tad more complex, and I'm wondering if it will be slower in the future when there's tons of objects.
Would you suggest combining these into one table per object type?
Here is my current structure:
A typical object type table (each object type has it's own table with it's own fields)
Right now if I want to list all the users, or do a search, I do a SELECT from both the dataobject table with a join on dataobject_user using the oid and objectid fields.
Is this a decent setup (less fields per table, overall) or am I better off just repeating the main fields in each table so I'm not doing joins all the time?
When I query, I query both the main object table, and the proper table that matches that object's type. This is working out nicely so far.
Now, I was thinking, the only advantage this has is that I'm not constantly repeating the same generic fields for each object type, and if I add a new generic field later on I only have to edit one table. Other then that, querying is still a tad more complex, and I'm wondering if it will be slower in the future when there's tons of objects.
Would you suggest combining these into one table per object type?
Here is my current structure:
Code:
dataobject table (main table, everything "derives" from this)
CREATE TABLE `dataobject` (
`oid` bigint(20) unsigned NOT NULL auto_increment,
`opid` bigint(20) unsigned NOT NULL,
`otype` char(255) NOT NULL,
`oownerid` bigint(20) unsigned NOT NULL,
`oserverid` bigint(20) unsigned NOT NULL,
`oslaveserverid` bigint(20) unsigned NOT NULL,
UNIQUE KEY `oid` (`oid`),
KEY `opid` (`opid`,`oownerid`)
) ENGINE=MyISAM AUTO_INCREMENT=207 DEFAULT CHARSET=latin1 AUTO_INCREMENT=207 ;
A typical object type table (each object type has it's own table with it's own fields)
Code:
CREATE TABLE `dataobject_user` (
`objectid` bigint(20) NOT NULL,
`uname` varchar(255) default NULL,
`upass` varchar(255) default NULL,
`uhomedir` text NOT NULL,
`ushell` text NOT NULL,
PRIMARY KEY (`objectid`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
Right now if I want to list all the users, or do a search, I do a SELECT from both the dataobject table with a join on dataobject_user using the oid and objectid fields.
Is this a decent setup (less fields per table, overall) or am I better off just repeating the main fields in each table so I'm not doing joins all the time?