UniversalTemporalDataLanguages CindyXinminChenandCarloZaniolo UniversityofCaliforniaatLosAngeles ComputerScienceDepartment Abstract.Temporalreasoningandtemporalquerylanguagespresentdicultresearchchallenges,whichareslowlyyieldingtothecombinedattackofmanyinvestigationsmotivated cchen@cs.ucla.eduzaniolo@cs.ucla.edu LosAngeles,CA90095 bythetheoreticalinterestandpracticalimportoftheproblem.inthispaper,wesubscribe anddatalog.inthispaper,weusedatalogasaframeworktodevelopanewlanguage totsql2insofaraspracticalrequirementsforaquerylanguageareconcerned,butweproposeasolutionthatovercomesitsshortcomings,particularlythelackofuniversalitywhereby constructsandsemanticscanbedirectlyappliedtoderivetemporalextensionsoflanguages, TemporalDataLanguage(TDL).Tosupportourclaimofuniversality,wearguethatTDL TSQL2temporalextensionscannotbeeasilyappliedtootherquerylanguages,suchasQBE suchasqbeandsql.finally,weevaluatealternativeapproachestotheimplementationof 1TDL,usingasthebasisforimplementationtheLDL++systemwithextendedaggregates developedatucla. querylanguagesbasedonlogicprograms.[sno95]introducedtsql2,whichisaconsensus Extensiveresearchhasfocusedontemporaldatabases[Tan93].[Cho93]addressedtemporal Introduction extensiontosql-92.tsql2usesabi-temporalconceptualdatamodel(bcdm)[jen94]. saythattsql2hasanimplicit-timedatamodel.becauseofimplicittime,thesemantics Withrespecttointerval-basedmodels,TSQL2presentstheadvantagethatitdoesnotrequire cannotbeexplicitlyreferredintheselectandwhereclausesofansqlquery:thus,we oftsql2queriesbecomediculttoformalize,andcomplexqueriesarehardtoexpress explicitcoalescingoftimeperiods[bss96].onedrawbackoftsql2isthattimecolumns universality:while[bcs96]proposedapossibleunicationbetweentsql2andtemporal andindeedrequiretheintroductionofspecialconstructs.thesecondproblemisitslackof logic,tsql2'sapproachisspecictosql,anddoesnotcontainthekernelofauniversal temporaldatamodelandquerylanguage,whichcanbeappliedto,say,qbeanddatalog. supportautomaticcoalescing,thusyieldingasimplersyntaxandclearersemantics.inpointbasedmodels,intervalsaretreatedasanabstractionofsetsofpoints.snapshot-equivalent Point-basedversusinterval-basedtemporaldatamodelswerediscussedin[Tom96]and [BBJ98].Point-baseddatamodelsaredirectlybasedonthesnapshotrepresentationand representationdependencyproblemofinterval-baseddatamodels. argumentrelationsaretreatedidenticallyinpoint-baseddatamodels,thusavoidingthe level.forconceptualschema,tdlbasicallysubscribestothepoint-basedapproachproposed Datalog.TDLdrawsacleardistinctionbetweenend-userview,conceptuallevel,andphysical (TDL),whichhasauniedsemanticsandservesasanaturalextensiontoSQL,QBEand Inthispaper,wepresentanewtemporalquerylanguage,theTemporalDataLanguage 123
by[tom97,tom98].ourmainnovelty,withrespecttothecitedworks,isasimpleand uniformapproachtoallen'sintervaloperatorsandothercomplextsql2constructs.we alsotaketherststeptowardanecientldl++implementationandtheapplicationof thesameextensionstosqlandqbe. canalsohandletransactiontime.toillustratesomeoftheissueswithtsql2,considerthe followingqueriesbasedonexamplesgivenin[ads97]. Becauseofspacelimitations,weonlydiscussvalidtimeinthispaper,althoughTDL andsampletsql2queriesareasfollows: 1.1TSQL2 Wehaveapatientdatabasewiththehistoryofprescriptionsgiventopatients.Theschema 1.Schemadenition CREATETABLEPrescription(NameCHAR(30), Example1DenethePrescriptionrelation ASVALIDSTATEDAY PhysicianCHAR(30),DrugCHAR(30),DosageCHAR(30), FrequencyINTERVALMINUTE) 2.Temporalselectionandjoin ThePrescriptionrelationisavalidtimerelation.Thevalidtimehasagranularityof oneday. Example2WhatdrugshavebeenprescribedwithProventil? WHEREP1.Drug=`Proventil`ANDP2.Drug<>`Proventil` FROMPrescriptionASP1,PrescriptionASP2 SELECTP1.Name,P2.Drug Thequeryreturnsthepatient'sname,thedrugandthemaximalperiodsduringwhich ANDP1.Name=P2.Name boththatdrugandproventilwereprescribedtothepatient. Undoubtedly,theexpressionofsimpleselectionandjoinsrepresentsthebestfeature oftsql2,insofarasthesequeriesremainthesameasinstandardsql.thisisaccomplishedbykeepingthetimedimensionimplicit,asillustratedbythefactthatthe valid-timecolumnisnotevenmentionedinthepreviousquery.therefore,bydefault, snapshotmustbeaddedtoproduceanormalrelationinsteadofavalid-timeone; whileaddingthekeywordsnapshotrepresentsasimplemodication,otherchanges structsmustthenbeusedtodeviatefromthisbehavior.forinstance,thekeyword atsql2queryonavalid-timerelationreturnsavalid-timerelation.additionalcon- discussednextarenotsosimple. 124
3.VALIDclause TheVALIDclauseisusedtooverridethedefaulttimestampoftheresultingtupleofa query. VALIDINTERSECT(VALID(Prescription),PERIOD`[1996]`DAY) SELECTDrug Example3WhatdrugswereMelanieprescribedduring1996? FROMPrescription WHEREName=`Melanie` duringwhichmelanietookthedrugs.therewillbetuplesreturnedifsomedrugs Thequeryreturnsdrugs,ifany,prescribedtoMelaniein1996andthemaximalperiods wereprescribedin1996,butratherthanthewholedrughistorybeingshown,onlythe 4.RestructuringandAllen'sintervaloperators historyforthe1996periodwillbereturned.theneedforthisspecialconstructvalid AnobviousrequirementofalltemporallanguagesistosupportAllen'sintervaloperators iscreatedbythefactthattimeintsql2iskeptimplicit. Temporallanguagesthatarebasedontemporalintervals[LM97]relyontheseoperators suchasoverlaps,precedes,contains,equals,meets,andintersects[all83]. toexpresstemporaljoins.inthiskindoflanguages,thequeryofexample2wouldbe expressedbythecondition'p1overlapsp2'.noexplicituseofoverlapsisneededin point-basedsemanticssinceintervaloverlappingtantamountstoequalitybetweensome oftheirpoints[tom96,bbj98].tsql2followsthepoint-basedsemantics,butassumes thattheequalitybetweentimepointsholdsimplicitly(ratherthanaskingtheuserto explicitlystateitinthequery).tsql2,however,mustprovideexplicitconstructsfor theremainingallen'soperators.forinstance: Example4FindthepatientswhohavebeenprescribedProventil,providedthatallsuch prescriptionperiodsarein1996. WHEREP.Drug=`Proventil` FROMPrescription(Name,Drug)ASP SELECTSNAPSHOTName neverbeforeorafter1996. Thequeryreturnsthepatient'snameifthepatienttookProventilduring1996and ANDCONTAINS(PERIOD`[1996]`DAY,VALID(P)) ofvalid(p)andcontainsinthewhereclauseisimplicitlydeterminedbythisrestructuring.sayforinstancethatthefromclausebecomes:prescription(name,drug, performtemporalprojectionwithcoalescingontheselectedrelations.themeaning Physician)ASP;thenthequerywillreturnthemaximalperiodswhereProventilwas prescribedbythesamephysician.apatient,whowasprescribedproventilinmarch TSQL2's\special"constructcalledrestructuring.Thefunctionofthisconstructisto ConsiderPrescription(Name,Drug)ASPintheFROMclause.Thisillustratesanother 125
againinhislifebya,evenifhewasprescribedproventilbyotherphysicians.however 1996byphysicianA,wouldsatisfythequeryaslongashewasneverprescribedProventil 5.Partitioning withprescription(name,drug)asp,theprescriptionsbydierentphysiciansofthe Thisisyetanother\special"newconstructintroducedbyTSQL2.Syntacticallyitcan samedrugtothesamepersonarecoalescedtogether. beexpressedbyappendingtheperiodconstructtoarestructuredprojectioninthe FROMclause.Semantically,partitioningdealswiththefactthatTSQL2'stemporal whotookproventilinoctober1988andmarch1996doesnotqualify insofaras elementsaresetsofperiods,notsingleperiods.thusinthepreviousqueryapatient requiresthatalltheperiodsmustbecontainedin1996.thekeywordperiodtransforms atuplewhichisvalidinnperiodstontupleseachvalidinoneofthoseperiods. CONTAINS(PERIOD`[1996]`DAY,VALID(P)) Example5FindthepatientswhohavebeenprescribedProventilforoneotmore(continuous)periodswithin1996. WHEREP.Drug=`Proventil` FROMPrescription(Name,Drug)(PERIOD)ASP SELECTSNAPSHOTName ThequeryreturnsnamesofpatientswhotookProventilforsomecontinuousperiod thatbeganandendedin1996.forinstance,apatientwhotookproventilinmarch ANDCONTAINS(PERIOD`[1996]`DAY,VALID(P)) ofexample4.apatientwhowascontinuouslyonproventilfrommarch1996tillapril 1996,andthenagaininOctober1997,satisesthisquery,butnotthepreviousquery 1997doesnotsatisfythisquery.Hereisanotherexampleofpartitioning. FROMPrescription(Name,Drug)(PERIOD)ASP months? SELECTSNAPSHOTName Example6WhohasbeenonProventilforaperiodofmorethansixconsecutive WHERECAST(VALID(P)ASINTERVALMONTH) Thequeryreturnsthepatient'snameifthepatienthastakenProventilformore thansixconsecutivemonths.partitioningallowstheintermediaterelationtohave >INTERVAL`6`MONTH value-equivalenttuplestimestampedwithdierentmaximalperiods(thusviolatingthe temporaldatabases.insection3thetemporaldatalanguage(tdl)isintroducedasan Thispaperisorganizedasfollows:Section2introducesanewapproachofquerying BCDMdatamodel). extensionofldl++[zan88,nt89];theprevioussixtsql2examplesarethenreexpressed intdl.then,section4discussesthesemanticsanduniversalityfortdl,andsection5 proposesvariousimplementationapproachesfortdl.section6concludesthepaper. 126
Thepreviousexamplesprovideasimpliedsampleofthemanyandcomplexqueriesthat occurintheframeworkoftemporaldatabases.tsql2'seaseofspecifyingprojectionsand 2 ANewApproach joins(example2)representsaverydesirablefeature,butthemanyadditionalconstructs neededtosupportotherkindsofqueries(e.g.,thoseinvolvingallen'sintervaloperators otherthanoverlaps Examples3{6)representanimportantdrawbackofthelanguage. structsdevelopedinoneframeworktotheothers.forinstance,sincetheexperienceofsql, works.manyrelationallanguageframeworksproposedinthepast,suchassql,qbe,quel anddatalog,allsharedacommonlogic-basedsemanticsthatallownaturaltranslationofcon- TheshortcomingsofTSQL2becomeobviousifoneconsidersdierentsyntacticframe- QBEandQUELhaswelldemonstratedthatsetaggregatesshouldbeincludedasprimitive inaquerylanguage,oneofthersttasksundertakenbythedesignersofldlwasextendingdatalogwithsetaggregates[zao93].conversely,theexperiencegainedwithrecursive forsql[fmm96].tsql2oersnohopeforsuchcross-fertilizationbecauseitsnewtem- introduction,wehavereferredtotheselimitationsaslackofuniversality.moreover,the queriesindataloghasrecentlyresultedintheintroductionofnewrecursivequeryconstructs poralconstructs,(restructuring,partitioning,etc.)aretotallyidiosyncratictosql.inthe TSQL2approachisparticularlycripplingfortheDataloglanguageanditselegantformal wheretimeremainsimplicitratherthanbeingapartofthequeryprogram. theprogram.itishardtoseehowdatalogsemanticscanbesalvagedinaquerylanguage semantics,wherebythemeaningofaprogramisconstructedfromthesymbolsappearingin sentexplicittime,weadoptapoint-basedrepresentationattheconceptuallevel.asshown in[tom97,tom98],thisrepresentationoerstheimportantadvantagethatselect-projectjoinqueriesareexpressedinaverynaturalway,withoutrequiringthe(implicit-or-explicit) Therefore,ourapproachtotemporalextensionswillbebasedonexplicittime.Torepre- coalescingdemandedbyinterval-basedtemporallanguages. thetuplesinthetemporalrelationcontainanadditionalcolumn,saythelastcolumn,where (time)pointatwhichthedatabasefactisvalid. asingletime-granuleisstored;and(iii)eachtemporalrelationcontainsonetupleforeach Ourpoint-basedtemporalmodelassumes:(i)atimegranularityisused,e.g.,days;(ii) Thesimplestkindoftemporalfactwecanconsiderisatemporalpropositionalpredicate validtimehasgranularityofoneday,andisrepresentedbytermsdate(year,month,day), i.e.,apredicatewhoseonlycolumnisthetemporalcolumn.forinstance,assumingthatour InDatalog,ratherthanusingtuplesindatabaserelations,wewillusedatabasefacts. 366facts:year_1996(date(1996,1,1)). thepropositionaltemporalpredicateyear1996couldberepresentedbythefollowingsetsof year_1996(date(1996,1,2)). Wewillusethispoint-basedrepresentationattheconceptuallevel i.e.,todenethe year_1996(date(1996,12,31)).... syntaxandsemanticsofthetemporaldatalanguage(tdl),whichissimple,expressive, anduniversal. succincttemporalrepresentations.aninterval-basedrepresentation,andanevent-based Intermsofimplementation,eciencyconsiderationsdemandthatweworkwithmore 127
representationconstitutetwonaturalcandidatesforthetasks;thesewillbestudiedinsection 5.Therefore,ourproposaltakesfulladvantageofthethreelevelDBarchitectureproposed byansi/sparc,withaninternalrepresentation,aconceptualone,andanexternalone. Ourmainadvance(w.r.t.Toman'sapproach)isthatTDLusesaggregatestocaptureandexpressnaturallyallnewcomplextemporalconstructsusedbyTSQL2,includingrestructuring, partitioning,andallen'stemporaloperators[all83]. OurapproachisdierentfromToman's[Tom97,Tom98]approachinseveralrespects. 1.Explicitvalidtime 2.Point-basedrepresentation Insummary,thedeningfeaturesofournewapproachare: 3.Noadditionalconstruct(otherthannewtemporalaggregates) 4.Ecientimplementationbymappingpoint-baseddatamodelintoequivalentinternal languagesalreadycontainaggregateconstructs,andtheycaneasilyaccommodatenewag- TDLextendsDatalogbyaddinganexplicittemporalelement.Oneofthebasictemporal datatypessupportedintdlisdate:time-pointwithgranularityofdays,whichisbasically TemporalDataLanguage(TDL) Theuniversalityofourapproachfollowsdirectlyfromthethirdpointabove.Allexisting representations. standards. 3gregateswithintheirexistingsyntax,e.g.,user-denedaggregatesarepartofthenewSQL3 thesameassql-92'sdatetime[dd93].intdl,dateisacomplextermwhichconsists rulesofthegregoriancalendar. ofthreeintegers \YEAR",\MONTH"and\DAY",whosevaluesareconstrainedbythe 1.Schemadeclaration WenowexpressthepreviousTSQL2examplesinTDL: Example7DenethePrescriptionrelation(sameasExample1) database(fprescript(name:string;physician:string;drug:string; TherstveeldsinthedatabaseschemaarethesameasthoseinTSQL2.Anexplicit Day:DATE)g): Dosagemg:integer;FrequencyMinute:integer; 2.Temporalselectionandjoin temporalelement,\day",whichhasatypeofdate,isaddedandrepresentsthevalid Example8WhatdrugshavebeenprescribedwithProventil(sameasExample2)? timeofthedatabasefact.weusethegranularityofonedayinthesamplequeries. 128
query2(name;drug;day) prescript(name;;`proventil`;;;day); Thisqueryreturnsthepatient'sname,thedrugandthedatewhenboththatdrug Drug=`Proventil`: prescript(name;;drug;;;day); andproventilwereprescribedtothepatient.intdl,temporaljoinisperformedby specifyingthesameargumentnameforthetemporalelements(\day"inthiscase)in thejoiningpredicatesofthequery.thesymbol`='denotesinequality. 3.Validclause Thus,inTDL,temporalselectionandprojectionaretrivial.Temporaljoinisdoneby explicitlyspecifyingthatthetwojoiningrelationshavethesametemporalelement. Example9WhatdrugswereMelanieprescribedduring1996(sameasExample3)? query3(drug;day) year1996(day); Thequeryreturnsdrugs,ifany,prescribedtoMelaniein1996.Ontheotherhand,if Name=`Melanie`: prescript(name;;drug;;;day); boththeconditionsandthetargettime. willberemovedfromtherule.therefore,tdl'sexplicittimemakesiteasytocontrol wewantthecompletehistoryofmelanie'sdrugprescription,thegoalyear1996(day) 4.RestructuringandAllen'stemporaloperators Example10FindthepatientswhohavebeenprescribedProventil,wherealltheprescriptionintervalsarewithintheyear1996(sameasExample4). query4(name;contains<(day1;day2)>) year1996(day1); Herecontains<>isanLDL++aggregatethatbehavesasabooleanoperator:it prescript(name;;drug;;;day2); returnsazero-aritytuple()foreachpairofsetsofvaluest1andt2ifthesetoft1 Drug=`Proventil`: UnlikeTSQL2whichneedstouserestructuringtoperformcoalescingonselectedrelations,TDLusesexplicittimeandaggregatestoidentifythecolumnsonwhichthetime pointsaregroupedintomaximalperiods. tocontains,theotherallen'soperatorssupportedintdlviaaggregatesinclude precedes,equals,meets;thereisnooverlapsandintersectsaggregatesincethese TDLusesuser-denedaggregatestoimplementAllen'stemporaloperators.Inaddition areautomaticallysupportedbythepoint-basedsemantics.thuswehavethefollowing: Theaggregatecontains<(Day1,Day2)>issatisedifeveryDay2dateisalsoaDay1 date. forwhichthesubsetrelationshipissatised,whileothervaluesofnameforwhichthe relationisnotsatisedaresimplydropped. containsthesetoft2.thusweobtainasetoftuples(name;())foreachvalueofname 129
Theaggregateprecedes<(Day1,Day2)>issatisedifalltheDay1datesprecede Theaggregateequals<(Day1,Day2)>issatisedwhenboththeconditions theday2dates i.e.,ifthemaxoftheformersetofdatesprecedestheleastof contains<(day1,day2)>andcontains<(day2,day1)>aresatised. thelattersetofdates. Theaggregatemeets<(Day1,Day2)>issatisedwhenthelastDay1datecoincides Inreality,theseoperatorssupportageneralizationofAllen'soriginallogicbecausethey leastofthelatersetofdates. withtherstday2date,i.e,themaxoftheformersetofdatesisthesameasthe 5.Partitioning applytosetsofperiodsratherthantoasingleperiod.intsql2,partitioningisused totranslateasetofperiodsintoindividualperiodsthatcanbeoperatedonseparately. query5(name;id;contains<(day1;day2)>) Example11FindthepatientswhohavebeenprescribedProventilforoneormore periodsin1996(sameasexample5). year1996(day1); prsprd(name;drug;(id;day2)); Theaggregateperiod<Day>transformsasetofdatesintoaperiodbyassigningeach prsprd(name;drug;period<day>) prescript(name;;drug;;;day): Drug=`Proventil`: dateanid,whichisanintegerdenotingwhetherthisdatebelongstotherst,second, IDbelongtothesamesegment.Theuseoftheaggregateperiodperformspartitioning whileretainsthepoint-basedsemanticsofthetdldatamodel. :::;nthcontinuoussegmentinthesequence.allthedatesassociatedwiththesame Example12WhohasbeenonProventilforaperiodofmorethansixconsecutive months(sameasexample6)? months(name;drug;id;lengthmonths<day>) query6(name) months(name;drug;id;months); Drug=`Proventil`;Months>6: Thequeryreturnsthepatient'snameifthepatienthastakenProventilformorethansix consecutivemonths.thisqueryusestheprsprddenedinthepreviousexample.the aggregatelengthmonths<day>rstformsthedatesintoaset,thencountsthenumber prsprd(name;drug;(id;day)): returnthecountintermsofdaysandyears,respectively,assumingeachyearhas365 ofdatesintheset,andreturnsthecountintermsofmonthsassumingeachmonthhas Inthelastthreeexamples,wehaveconstructedsnapshotrelationswhereweareonly 30days.Similaraggregatesincludelengthdays<Day>andlengthyears<Day>which interestedinnamesdisregardingtheirhistory.butifwewantedtondthepatient's 130
nameandthedaysinthoseperiodsthatsatisfythequery,wewouldrewritequery6 asfollows: query7(name;day) months(name;drug;id;months); Finally,ifwewantedtheentireprescriptionhistoryofthepatientssatisfyingthepreviousquery,thenwewouldwrite: prsprd(name;drug;(id;day)): Drug=`Proventil`;Months>6; query8(name;day) months(name;drug;id;months); Drug=`Proventil`;Months>6; thatexplicittimewithaggregatesprovidegreatexibilityandpowerinexpressing SincesimilarconsiderationsapplytothequeriesofExamples10and11,weconclude prescript(name;;;;;day): 4 SemanticsandUniversality temporalqueries. Fromthepreviousexamples,weconcludethatTDLisanaturalextensiontoDatalog.No additionallanguageconstructisneededotherthanaggregates,aconstructthatisalready foundindeductivedatabaselanguages.theoperationsinvolvingtimeperiodsa.k.a.setsof thatinfactthenewtemporalaggregatesarebasedonthetraditionalsqlaggregates.thus timeinstants,aredonevianewtemporalaggregates.afterwetakeasecondlook,wesee contains<(x,y)>simplydenotesthatthesetofy-valuesisasubsetofthesetofx-values. IntermsoftraditionalSQLaggregates,thiscanbeexpressedas: precedes<(x,y)>andmeets<(x,y)>cansimplybecomputedbycomparingtheextrema wheresxdenotesthesetofx-valuesandsydenotesthesetofy-values.likewise, count(sy)=count(sx\sy) inthetwosets.thereforetheaggregatesusedtodeneallen'stemporaloperatorsinour modelcanbereducedtothefamiliar,vanillaavored,aggregatesinsql.thenewlynamed aggregatesareneverthelessimportantbecauseoftheirsignicancetotheuser,andbecause theyenablemoreecientimplementations.thus,theyprovidesignicantpracticaladvantagesbeyondthoseoeredbytsql/tp[tom97].ingeneral,thetdlapproachoerstwo SinceaggregatesinDataloghaveastandarddeclarativelogic-basedsemantics[WZ98] signicantbenets: Alldatabasequerylanguages,suchasSQLandQBE,haveaggregateconstructs.Thus, theselanguages. (i.e.,least-modelandleast-x-pointbased)tdlinheritselegantformalsemanticsof Therefore,TDLachievesformalsemanticsanduniversalityinasimplefashion. tosupporttemporalextensionsalongthelinesillustratedbytdl,noadditionallanguageconstructneedtobeintroducedotherthansomenewaggregates. 131
5Inthissection,wewilldiscussvariousimplementationsofTDL.Wewillfocusonthemappings betweenthepoint-basedrelationandtheinterval-basedandevent-basedrelations.weassume ImplementingTDL thatallthefactsstoredinthedatabasehaveanascendingorderintermsoftheirtemporal elements.currently,tdlonlysupportsthegregoriancalendar,furtherworkisneededto supportothercalendarsanduserdenedcalendars. 5.1Interval-basedimplementation associatedwiththepoint-baseddatamodel.ininterval-basedrelations,alltuplesaretimestampedwithantwotimeinstants:oneindicatesthestart-pointandtheotherend-pointof Ininterval-basedimplementation,thedatabaseschemainExample1isimplementedas Usinganinterval-basedrelationtoimplementTDLsolvesthespaceandeciencyproblems theinterval. follows:database(fprescript(name:string;physician:string;drug:string; Usingtheaggregateperioddescribedintheprevioussection,wecanmapaqueryona Interval:(DATE;DATE))g): Dosagemg:integer;FrequencyMinute:integer; point-basedviewtoitsinterval-basedimplementation. basedrelationandpisaninterval-basedrelation. 1.Maptimepointsintointervals Thefollowingrulesshowhowthemappingisperformed.Intheexamples,qisapoint- aux11(x1;;xn;id;minday<day>;maxday<day>) p(x1;;xn;int(startday;endday)) aux11(x1;;xn;id;startday;endday): Thepredicateaux12rstconstructsaperiodfromallthedatesintherelationq.The aux12(x1;;xn;period<day>) aux12(x1;;xn;(id;day)): predicateaux11calculatestheminimumandmaximumofallthedateswhichbelong toasamesegmentoftheperiod,i.e.,attachedwiththesameid.thepairofminimal q(x1;;xn;day): andmaximaldatesthenserveasthestartandendpointsofanintervalinthenal respectively. Theytakeinputasasetofdatesandndtheminimalandmaximaldatesoftheset, TheaggregatesmindayandmaxdayareyettwomoretemporalaggregatesinTDL. interval-basedrelationp. Thenewaggregateinstantisdenedtomapaqueryfromitsinterval-basedimplementationbacktothepoint-basedrelation. 132
2.Maptimeintervalsintopoints Theaggregateinstanttakesanintervalasinput,andreturnsallthedateswithinthattime interval.forexample, q(x1;;xn;instant<interval>) p(x1;;xn;interval): returnsq(date(1996,1,1)). q(instant<int(date(1996;1;1);date(1996;1;31))> p(int(date(1996;1;1);date(1996;1;31))): q(date(1996,1,2)). 5.2Event-basedimplementation q(date(1996,1,31)).... Anevent-basedimplementationoersalladvantagesofinterval-basedimplementationsand anevent-basedrelation,alltuplesareattachedwithanevent-typespecicationandasingle itisclosertothesemanticsofthepoint-baseddatamodelbecauseofitseventnature.in anddel,whichstandforinsertionanddeletion,respectively.atuplewiththesamenontemporalvaluemayappeartwiceinadatabase,i.e.,oneforinsertionofthefactandonefor deletionofthefact.ifnodeletiontupleisinthedatabase,thenthefactisassumedtohold trueuntiladefaulttimeassignedbythesystem.anupdateofadatabasefactisperformed asamodicationofthetimespeciedinitsolddeletiontuplefollowedbyinsertingapairof insertionanddeletiontupleswithnewvaluesintothedatabase.alltuplesarestoredinthe databaseaccordingtotheascendingorderoftheirtimestamps. Inevent-basedimplementation,thedatabaseschemainExample1isdenedas: database(fprescript(name:string;physician:string;drug:string; timeinstant.theevent-typespecieswhichtypeofeventthetuplerepresents,namely,ins Theaggregatesmindayandmaxdayareusedtomapaqueryinapoint-baseddata Event:string;Day:DATE)g): Dosagemg:integer;FrequencyMinute:integer; tomapaqueryfromitsevent-basedimplementationbacktothepoint-baseddatamodel. modeltoitsevent-basedimplementationandtheaggregatespairupandinstantareused Thefollowingexamplesshowhowthemappingsareperformed.Intheexamples,qisa point-basedrelationandrisanevent-basedrelation. 1.Maptimepointsintoevents r(x1;;xn;event;maxday<day>) r(x1;;xn;event;minday<day>) q(x1;;xn;day);event=`ins`: Theinsertiontimeofdatabasefactistheminimaldateofthesetofdatesintherelation qandthedeletiontimeofadatabasefactisthemaximaldate. q(x1;;xn;day);event=`del`: 133
2.Mapeventsintotimepoints aux21(x1;;xn;pairup<(event;day)>) q(x1;;xn;instant<int(startday;endday)>) aux21(x1;;xn;(startday;endday)): here.itpairsupthetwotupleswhichrepresenttheinsertionanddeletionofadatabase Anintervalisrstconstructedwiththeinsertionanddeletiontimeofthedatabasefact speciedasitsstartandendpointsviaaux21.anewaggregatepairupisintroduced r(x1;;xn;event;day): fact.theaggregatetakestheeventtypesanddatesasinputandreturnspairsofdates, i.e.,theinsertiondateandthedeletiondatewhichcanalsobetreatedasthestartand endofaninterval.theaggregateinstantsisthenusedtoextractallthedateswithin theinterval.ifnodeletiontupleofafactexists,thentheassumed\untilchanged", tationandhasacloserrelationshipwithcompositeeventspecicationlanguagesandprovides Theevent-basedimplementationretainstheadvantagesoftheinterval-basedimplemen- i.e.,untilthedefaultvalue. 6anopportunitytocombineactiveruleswithtemporaldatabases[MZ97]. WehaveshownthatTDLisanaturaltemporalextensionofDatalog.Thesameapproachis alsoapplicabletosqlandqbe.weusedapoint-baseddatamodelattheconceptuallevel Conclusion andtookthepoint-basedreasoningapproachbeyondthatoftsql/tp[tom97,tom98]by usingaggregatestoexpressqueriesreasoningontimeperiods. universalapproachtosolvetheproblemofextendingconventionaldatabasequerylanguages, suchassql,qbeanddatalog,toexpresstemporalqueries. TDLhasthesamestandarddeclarativelogic-basedsemanticsasDatalogandprovidesa event-based.bothoftheimplementationapproachesovercomethespaceineciencyproblem thepoint-baseddatamodelmaycause. WehaveshowedtwodierentimplementationapproachesofTDL,i.e.,interval-basedand Acknowledgements supportforbi-temporalreasoningwillbediscussedinfuturepapers. Duetolackofspace,weonlyshowedTDLwithvalidtimesupportedinthepaper.TDL's References RezaSadriandtherefereesfortheirhelpfulcomments. TheauthorswouldliketothankHaixunWangforhishelpwithtemporalaggregates,and [BCS96]M.H.Bohlen,J.Chomicki,R.T.SnodgrassandD.Toman.QueryingTSQL2 [All83]J.F.Allen.Maintainingknowledgeabouttemporalintervals.InCommunicationsof DatabaseTechnology,pages325-341,1996 DatabaseswithTemporalLogic.InProceedingsofthe5thConferenceonExtended theacm,vol.26,no.11,pages832-843,1983 134
[BSS96]M.H.Bohlen,R.T.SnodgrassandM.D.Soo.CoalescinginTemporalDatabases. [BBJ98]M.H.Bohlen,R.BusattoandC.S.Jensen.Point-VersusInterval-basedTemporal InProceedingsofthe22ndInternationalConferenceonVeryLargeDatabases,pages 180-191,1996 [Cho93]J.Chomicki.TemporalDatabases.InProceedingsofthe12thACMSymposiumon DataModels.InProceedingsofthe14thInternationalConferenceonDataEngineering, [DD93]C.J.DateandH.Darwen.AGuidetotheSQLStandard,thirdedition,Addison- pages192-200,1998 PrinciplesofDatabaseSystems,pages1-16,1993 [Jen94]C.S.Jensen,etal.AConsensusGlossaryofTemporalDatabaseConcepts.InSIG- [FMM96]S.J.Finkelstein,N.Mattos,I.S.MumickandH.Pirahesh.ExpressingRecursive QueriesinSQL.ISO/IECJTC1/SC21/WG3DBL:MCIRep.X3H2-96-075,1996 Wesley,1993 [LM97]N.A.LorentzosandY.G.Mitsopoulos.SQLExtensionforIntervalData.InIEEE [MZ97]I.MotakisandC.Zaniolo.TemporalAggregationinActiveDatabaseRules.InSIG- MODRecord,Vol.23,No.1,pages52-64,1994 TransactionsonKnowledgeandDataEngineering,Vol.9,No.3,pages480-499,1997 [Sno95]R.T.Snodgrass,etal.TheTSQL2TemporalQueryLanguage,Kluwer,1995 [NT89]S.NaqviandS.Tsur.ALogicalLanguageForDataAndKnowledgeBases,Computer SciencePress,1989 MODRecord,Vol.26,No.2,pages440-451,1997 [Tan93]A.Tansel,etal.TemporalDatabases:theory,designandimplementation,Benjamin/Cumming,1993 [Tom96]D.Toman.Pointvs.Interval-basedQueryLanguagesforTemporalDatabases.In [Tom97]D.Toman.APoint-BasedTemporalExtensionofSQL.InProceedingsofthe6th Proceedingsofthe15thACMSIGACT-SIGMOD-SIGARTSymposiumonPrinciples ofdatabasesystems,pages,58-67,1996 [Tom98]D.Toman.Point-BasedTemporalExtensionsofSQLandtheirEcientImplementation.ToappearinProceedingsofDagstuhlWorkshoponTemporalDatabases,1998 1997 InternationalConferenceonDeductiveandObject-OrientedDatabases,pages103-121, [WZ98]H.WangandC.Zaniolo.User-DenedAggregatesforLogicalDataLanguages.submittedtoDDLP'98,1998 [Zan88]C.Zaniolo.DesignandImplementationofaLogicBasedLanguageforDataIntensive [ZAO93]C.Zaniolo,N.ArniandK.Ong.NegationandAggregatesinRecursiveRules:the Applications.InProceedingsoftheInternationalConferenceonLogicProgramming, andobject-orienteddatabases,pages204-221,1993 LDL++Approach.InProceedingsofthe3rdInternationalConferenceonDeductive 1988 [ADS97]C.Zaniolo,S.Ceri,C.Faloutsos,R.Snodgrass,andR.Zicari,AdvancedDatabase Systems,MorganKaufmann,1997 135