php - Object and Object meta schema design -
am working on project save many types of objects database. these include: articles, polls, writers .. etc. of unknown me @ design time trying build generic table schema enable me save type of item database.
my design
table object
objectid int title varchar body text type int #will represent id of type of object inserting
having circumstances or requirements might need additional data, decided go call "object metadata" follows:
table object_metadata
metaid int metakey varchar metaintkey int #representing integer value of metakey calculated using algorithm speed queries metavalue varchar(1000)
i doing work in php , mysql btw.
a couple of things came mind when doing design regarding performance of database on long run:
1) saving int, boolean, small text, big text metavalue effecient?
2) on long run metadata table going grow quite quickly. maintainance nightmare? how mysql going to handle this?
3) in php when fetching objects, have loop each object fetch metadata, or load metadata once using lazy loading or load single metakey once requested via __get magic method. when fetching list of 50 objects, @ least 50 select statements executed when using of methods suggested. there better more efficient way of doing this?
any thoughts or comments on design welcome.
i'd suggest re-architecting solution. pattern called "entity-attribute-value" (eav), , commonly seen anti-pattern. instead, define metadata attributes in columns (of same table, or if needed). use proper data types well.
i'd suggest giving bill karwin's book sql antipatterns read. has great insights give hand here specifically. can feel of this presentation...
Comments
Post a Comment