简体   繁体   中英

consitent vs peformance database design for db polymorphism with versioning

I need to create a database for 2 types of farmers (organizations and landlords) which have different columns that need to be stored and I also need to version their info.

One db design that I came up with is this: (the consistent one)

Farmers
Id
FType check(FType in ('organization', 'landlord'))
Unique(Id,Ftype)    

Organizations
Id
FType
Unique(Id, FType)
FK(Id, FType) Ref Farmers(Id, FType)

LandLords
Id
FType
Unique(Id, FType)
FK(Id, FType) Ref Farmers(Id, FType)

OrganisationVersions
Id
OrganisationId  ref Organizations(id)
--lots of stuff specific to organisation
Startdate
Endate -- if null than this is the current version

LandLordVersions
Id
LandLordId ref LandLords(id)
--lots of stuff specific to landlord
StartDate
EndDate

The second one not so consistent but much less tables is like this:

Farmers
Id
FType

Organizations
Id
FarmerId ref Farmers(Id)
--stuff
StartDate 
EndDate -- if null than this is the current version

LandLords
Id
FarmerId ref Farmers(Id)
--stuff
StartDate
EndDate

I don't see any especial difficulties with your second version. The first version has an FType column in the Organisations table and the Landlords table, which doesn't seem to be necessary as it will be the same for all rows.

Having multiple versions of each entry in the same table, with the latest end date as NULL for the current version also seems fine; you could create a view 'Current_Landlords' where only the current row is displayed; such a view would be updatable. Some indexes might be necessary to help it out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM