Professional Documents
Culture Documents
RichardBroersmaJr. ManganInc.SystemIntegrator
Fromadatamodelingperspective, whatisaTree?
AspecializedformofGraph(datastructure).
Fromadatamodelingperspective, whatisaGraph?
SimpleGraphIllustration
GraphAnalysisInPractice
OkaybutwhataboutTREES!
TreesInPractice:OrgChart
TreesInPractice:Assembly(BOM)
LogicEntityRelationshipDiagram
Barker's Notation/Style
ChenlikeStyle
GoodPracticeTreeDesign
LiberaladdCheckConstraintstoeliminate possiblesourcesoftreecorruption Decoupleentityandrelationshipinseparate tables. EliminatesEntity/RelationshipDenormalization Allowsmultipletreerelationshiptablestoexist torepresentdifferenttypesofrelationships
ConsiderationforTreeOperations
Modifyingtreestructureissignificantlymore intensivethanordinarytableInsert/Update/Deletes Operationstightlycoupledwithproblemdomain. Alloperationsshouldbedesignedandrolled togetherintoStoredProceduresasanapplication framework. Throughlytestallstoredprocedurestopreventtree structurecorruptionanomalies
PhysicalDesigns
NestedSetModel A.K.A.CelkoTree
First,asimpleTree
AdjacencyListModel
CREATETABLEOrgChart( empVARCHAR(10)NOTNULLPRIMARYKEY REFERENCESPersonnel(emp), bossVARCHAR(10)nullmeansroot REFERENCESPersonnel(emp), ...);
AdjacencyListModel
PerformswellwithInserts&Deletes. UsingSQL92,canonlyreturnatmostonelevel ofthetreeperstatement(untilPG8.4CTE)and canperformbadly. WithSQL03,WithRecursivemakesALMagood choice.
NestedSetModel
CREATETABLEOrgChart( lftINTEGERNOTNULL, rgtINTEGERNOTNULL, CONSTRAINTlftlessthanrgt CHECK(lft<rgt), empVARCHAR(10)NOTNULLPRIMARYKEY REFERENCESPersonnel(emp) ...);
lft 1 2 4 5 7 9
rgt 12 3 11 6 8 10
NestedSetModel
PerformsbadlywithnumerousInserts&Deletes. SelectsPerformverywell UsingSQL92,easilyreturnsalllevelsofthetree perstatement.(hardtolimittoimmediatelevels) NatureofNestedSetallowforeasyanalysisof treestructure ex.WHERElft>=4ANDrgt<=11
PathEnumerationModel
CREATETABLEOrgChart( pathVARCHARNOTNULL, empVARCHAR(10)NOTNULLPRIMARYKEY REFERENCESPersonnel(emp), CONSTRAINTvalidPath CHECK(pathLIKE'%'||emp), ...);
PathEnumerationModel
PerformswellnumerousInserts&Deletes. SelectsperformsverybuthastypicalLIKE'%.%' gotchas.(LTREEimprovesthiswithgistsupport) UsingSQL92,easilyreturnsalllevelsofthetree perstatementandcanlimittoimmediatelevels Analyzingtreestructureiscomplicated ex.WHEREempLIKE'AlbertChuck%'
References