diff --git a/doc/internals.ps b/doc/internals.ps new file mode 100644 index 0000000000000000000000000000000000000000..1cdf6ae28ac012b4884322d97d17db2386e265c5 --- /dev/null +++ b/doc/internals.ps @@ -0,0 +1,13986 @@ +%!PS-Adobe-2.0 +%%Creator: dvipsk 5.58f Copyright 1986, 1994 Radical Eye Software +%%Title: diplarb.dvi +%%Pages: 117 +%%PageOrder: Ascend +%%BoundingBox: 0 0 596 842 +%%DocumentFonts: Times-Roman Courier Times-Bold Times-Italic +%%DocumentPaperSizes: A4 +%%EndComments +%DVIPSCommandLine: dvips diplarb.dvi +%DVIPSParameters: dpi=360, comments removed +%DVIPSSource: TeX output 1998.11.29:1121 +%%BeginProcSet: tex.pro +/TeXDict 250 dict def TeXDict begin /N{def}def /B{bind def}N /S{exch}N +/X{S N}B /TR{translate}N /isls false N /vsize 11 72 mul N /hsize 8.5 72 +mul N /landplus90{false}def /@rigin{isls{[0 landplus90{1 -1}{-1 1} +ifelse 0 0 0]concat}if 72 Resolution div 72 VResolution div neg scale +isls{landplus90{VResolution 72 div vsize mul 0 exch}{Resolution -72 div +hsize mul 0}ifelse TR}if Resolution VResolution vsize -72 div 1 add mul +TR[matrix currentmatrix{dup dup round sub abs 0.00001 lt{round}if} +forall round exch round exch]setmatrix}N /@landscape{/isls true N}B +/@manualfeed{statusdict /manualfeed true put}B /@copies{/#copies X}B +/FMat[1 0 0 -1 0 0]N /FBB[0 0 0 0]N /nn 0 N /IE 0 N /ctr 0 N /df-tail{ +/nn 8 dict N nn begin /FontType 3 N /FontMatrix fntrx N /FontBBox FBB N +string /base X array /BitMaps X /BuildChar{CharBuilder}N /Encoding IE N +end dup{/foo setfont}2 array copy cvx N load 0 nn put /ctr 0 N[}B /df{ +/sf 1 N /fntrx FMat N df-tail}B /dfs{div /sf X /fntrx[sf 0 0 sf neg 0 0] +N df-tail}B /E{pop nn dup definefont setfont}B /ch-width{ch-data dup +length 5 sub get}B /ch-height{ch-data dup length 4 sub get}B /ch-xoff{ +128 ch-data dup length 3 sub get sub}B /ch-yoff{ch-data dup length 2 sub +get 127 sub}B /ch-dx{ch-data dup length 1 sub get}B /ch-image{ch-data +dup type /stringtype ne{ctr get /ctr ctr 1 add N}if}B /id 0 N /rw 0 N +/rc 0 N /gp 0 N /cp 0 N /G 0 N /sf 0 N /CharBuilder{save 3 1 roll S dup +/base get 2 index get S /BitMaps get S get /ch-data X pop /ctr 0 N ch-dx +0 ch-xoff ch-yoff ch-height sub ch-xoff ch-width add ch-yoff +setcachedevice ch-width ch-height true[1 0 0 -1 -.1 ch-xoff sub ch-yoff +.1 sub]{ch-image}imagemask restore}B /D{/cc X dup type /stringtype ne{]} +if nn /base get cc ctr put nn /BitMaps get S ctr S sf 1 ne{dup dup +length 1 sub dup 2 index S get sf div put}if put /ctr ctr 1 add N}B /I{ +cc 1 add D}B /bop{userdict /bop-hook known{bop-hook}if /SI save N @rigin +0 0 moveto /V matrix currentmatrix dup 1 get dup mul exch 0 get dup mul +add .99 lt{/QV}{/RV}ifelse load def pop pop}N /eop{SI restore userdict +/eop-hook known{eop-hook}if showpage}N /@start{userdict /start-hook +known{start-hook}if pop /VResolution X /Resolution X 1000 div /DVImag X +/IE 256 array N 0 1 255{IE S 1 string dup 0 3 index put cvn put}for +65781.76 div /vsize X 65781.76 div /hsize X}N /p{show}N /RMat[1 0 0 -1 0 +0]N /BDot 260 string N /rulex 0 N /ruley 0 N /v{/ruley X /rulex X V}B /V +{}B /RV statusdict begin /product where{pop product dup length 7 ge{0 7 +getinterval dup(Display)eq exch 0 4 getinterval(NeXT)eq or}{pop false} +ifelse}{false}ifelse end{{gsave TR -.1 .1 TR 1 1 scale rulex ruley false +RMat{BDot}imagemask grestore}}{{gsave TR -.1 .1 TR rulex ruley scale 1 1 +false RMat{BDot}imagemask grestore}}ifelse B /QV{gsave newpath transform +round exch round exch itransform moveto rulex 0 rlineto 0 ruley neg +rlineto rulex neg 0 rlineto fill grestore}B /a{moveto}B /delta 0 N /tail +{dup /delta X 0 rmoveto}B /M{S p delta add tail}B /b{S p tail}B /c{-4 M} +B /d{-3 M}B /e{-2 M}B /f{-1 M}B /g{0 M}B /h{1 M}B /i{2 M}B /j{3 M}B /k{ +4 M}B /w{0 rmoveto}B /l{p -4 w}B /m{p -3 w}B /n{p -2 w}B /o{p -1 w}B /q{ +p 1 w}B /r{p 2 w}B /s{p 3 w}B /t{p 4 w}B /x{0 S rmoveto}B /y{3 2 roll p +a}B /bos{/SS save N}B /eos{SS restore}B end +%%EndProcSet +%%BeginFont: Times-Roman +% @@psencodingfile@{ +% author = "S. Rahtz, P. MacKay, Alan Jeffrey, B. Horn, K. Berry", +% version = "0.6", +% date = "22 June 1996", +% filename = "8r.enc", +% email = "kb@@mail.tug.org", +% address = "135 Center Hill Rd. // Plymouth, MA 02360", +% codetable = "ISO/ASCII", +% checksum = "119 662 4424", +% docstring = "Encoding for TrueType or Type 1 fonts to be used with TeX." +% @} +% +% Idea is to have all the characters normally included in Type 1 fonts +% available for typesetting. This is effectively the characters in Adobe +% Standard Encoding + ISO Latin 1 + extra characters from Lucida. +% +% Character code assignments were made as follows: +% +% (1) the Windows ANSI characters are almost all in their Windows ANSI +% positions, because some Windows users cannot easily reencode the +% fonts, and it makes no difference on other systems. The only Windows +% ANSI characters not available are those that make no sense for +% typesetting -- rubout (127 decimal), nobreakspace (160), softhyphen +% (173). quotesingle and grave are moved just because it's such an +% irritation not having them in TeX positions. +% +% (2) Remaining characters are assigned arbitrarily to the lower part +% of the range, avoiding 0, 10 and 13 in case we meet dumb software. +% +% (3) Y&Y Lucida Bright includes some extra text characters; in the +% hopes that other PostScript fonts, perhaps created for public +% consumption, will include them, they are included starting at 0x12. +% +% (4) Remaining positions left undefined are for use in (hopefully) +% upward-compatible revisions, if someday more characters are generally +% available. +% +% (5) hyphen appears twice for compatibility with both ASCII and Windows. +% +/TeXBase1Encoding [ +% 0x00 (encoded characters from Adobe Standard not in Windows 3.1) + /.notdef /dotaccent /fi /fl + /fraction /hungarumlaut /Lslash /lslash + /ogonek /ring /.notdef + /breve /minus /.notdef +% These are the only two remaining unencoded characters, so may as +% well include them. + /Zcaron /zcaron +% 0x10 + /caron /dotlessi +% (unusual TeX characters available in, e.g., Lucida Bright) + /dotlessj /ff /ffi /ffl + /.notdef /.notdef /.notdef /.notdef + /.notdef /.notdef /.notdef /.notdef + % very contentious; it's so painful not having quoteleft and quoteright + % at 96 and 145 that we move the things normally found there down to here. + /grave /quotesingle +% 0x20 (ASCII begins) + /space /exclam /quotedbl /numbersign + /dollar /percent /ampersand /quoteright + /parenleft /parenright /asterisk /plus /comma /hyphen /period /slash +% 0x30 + /zero /one /two /three /four /five /six /seven + /eight /nine /colon /semicolon /less /equal /greater /question +% 0x40 + /at /A /B /C /D /E /F /G /H /I /J /K /L /M /N /O +% 0x50 + /P /Q /R /S /T /U /V /W + /X /Y /Z /bracketleft /backslash /bracketright /asciicircum /underscore +% 0x60 + /quoteleft /a /b /c /d /e /f /g /h /i /j /k /l /m /n /o +% 0x70 + /p /q /r /s /t /u /v /w + /x /y /z /braceleft /bar /braceright /asciitilde + /.notdef % rubout; ASCII ends +% 0x80 + /.notdef /.notdef /quotesinglbase /florin + /quotedblbase /ellipsis /dagger /daggerdbl + /circumflex /perthousand /Scaron /guilsinglleft + /OE /.notdef /.notdef /.notdef +% 0x90 + /.notdef /.notdef /.notdef /quotedblleft + /quotedblright /bullet /endash /emdash + /tilde /trademark /scaron /guilsinglright + /oe /.notdef /.notdef /Ydieresis +% 0xA0 + /.notdef % nobreakspace + /exclamdown /cent /sterling + /currency /yen /brokenbar /section + /dieresis /copyright /ordfeminine /guillemotleft + /logicalnot + /hyphen % Y&Y (also at 45); Windows' softhyphen + /registered + /macron +% 0xD0 + /degree /plusminus /twosuperior /threesuperior + /acute /mu /paragraph /periodcentered + /cedilla /onesuperior /ordmasculine /guillemotright + /onequarter /onehalf /threequarters /questiondown +% 0xC0 + /Agrave /Aacute /Acircumflex /Atilde /Adieresis /Aring /AE /Ccedilla + /Egrave /Eacute /Ecircumflex /Edieresis + /Igrave /Iacute /Icircumflex /Idieresis +% 0xD0 + /Eth /Ntilde /Ograve /Oacute + /Ocircumflex /Otilde /Odieresis /multiply + /Oslash /Ugrave /Uacute /Ucircumflex + /Udieresis /Yacute /Thorn /germandbls +% 0xE0 + /agrave /aacute /acircumflex /atilde + /adieresis /aring /ae /ccedilla + /egrave /eacute /ecircumflex /edieresis + /igrave /iacute /icircumflex /idieresis +% 0xF0 + /eth /ntilde /ograve /oacute + /ocircumflex /otilde /odieresis /divide + /oslash /ugrave /uacute /ucircumflex + /udieresis /yacute /thorn /ydieresis +] def +%%EndFont +%%BeginProcSet: texps.pro +TeXDict begin /rf{findfont dup length 1 add dict begin{1 index /FID ne 2 +index /UniqueID ne and{def}{pop pop}ifelse}forall[1 index 0 6 -1 roll +exec 0 exch 5 -1 roll VResolution Resolution div mul neg 0 0]/Metrics +exch def dict begin Encoding{exch dup type /integertype ne{pop pop 1 sub +dup 0 le{pop}{[}ifelse}{FontMatrix 0 get div Metrics 0 get div def} +ifelse}forall Metrics /Metrics currentdict end def[2 index currentdict +end definefont 3 -1 roll makefont /setfont load]cvx def}def +/ObliqueSlant{dup sin S cos div neg}B /SlantFont{4 index mul add}def +/ExtendFont{3 -1 roll mul exch}def /ReEncodeFont{/Encoding exch def}def +end +%%EndProcSet +%%BeginProcSet: special.pro +TeXDict begin /SDict 200 dict N SDict begin /@SpecialDefaults{/hs 612 N +/vs 792 N /ho 0 N /vo 0 N /hsc 1 N /vsc 1 N /ang 0 N /CLIP 0 N /rwiSeen +false N /rhiSeen false N /letter{}N /note{}N /a4{}N /legal{}N}B +/@scaleunit 100 N /@hscale{@scaleunit div /hsc X}B /@vscale{@scaleunit +div /vsc X}B /@hsize{/hs X /CLIP 1 N}B /@vsize{/vs X /CLIP 1 N}B /@clip{ +/CLIP 2 N}B /@hoffset{/ho X}B /@voffset{/vo X}B /@angle{/ang X}B /@rwi{ +10 div /rwi X /rwiSeen true N}B /@rhi{10 div /rhi X /rhiSeen true N}B +/@llx{/llx X}B /@lly{/lly X}B /@urx{/urx X}B /@ury{/ury X}B /magscale +true def end /@MacSetUp{userdict /md known{userdict /md get type +/dicttype eq{userdict begin md length 10 add md maxlength ge{/md md dup +length 20 add dict copy def}if end md begin /letter{}N /note{}N /legal{} +N /od{txpose 1 0 mtx defaultmatrix dtransform S atan/pa X newpath +clippath mark{transform{itransform moveto}}{transform{itransform lineto} +}{6 -2 roll transform 6 -2 roll transform 6 -2 roll transform{ +itransform 6 2 roll itransform 6 2 roll itransform 6 2 roll curveto}}{{ +closepath}}pathforall newpath counttomark array astore /gc xdf pop ct 39 +0 put 10 fz 0 fs 2 F/|______Courier fnt invertflag{PaintBlack}if}N +/txpose{pxs pys scale ppr aload pop por{noflips{pop S neg S TR pop 1 -1 +scale}if xflip yflip and{pop S neg S TR 180 rotate 1 -1 scale ppr 3 get +ppr 1 get neg sub neg ppr 2 get ppr 0 get neg sub neg TR}if xflip yflip +not and{pop S neg S TR pop 180 rotate ppr 3 get ppr 1 get neg sub neg 0 +TR}if yflip xflip not and{ppr 1 get neg ppr 0 get neg TR}if}{noflips{TR +pop pop 270 rotate 1 -1 scale}if xflip yflip and{TR pop pop 90 rotate 1 +-1 scale ppr 3 get ppr 1 get neg sub neg ppr 2 get ppr 0 get neg sub neg +TR}if xflip yflip not and{TR pop pop 90 rotate ppr 3 get ppr 1 get neg +sub neg 0 TR}if yflip xflip not and{TR pop pop 270 rotate ppr 2 get ppr +0 get neg sub neg 0 S TR}if}ifelse scaleby96{ppr aload pop 4 -1 roll add +2 div 3 1 roll add 2 div 2 copy TR .96 dup scale neg S neg S TR}if}N /cp +{pop pop showpage pm restore}N end}if}if}N /normalscale{Resolution 72 +div VResolution 72 div neg scale magscale{DVImag dup scale}if 0 setgray} +N /psfts{S 65781.76 div N}N /startTexFig{/psf$SavedState save N userdict +maxlength dict begin /magscale true def normalscale currentpoint TR +/psf$ury psfts /psf$urx psfts /psf$lly psfts /psf$llx psfts /psf$y psfts +/psf$x psfts currentpoint /psf$cy X /psf$cx X /psf$sx psf$x psf$urx +psf$llx sub div N /psf$sy psf$y psf$ury psf$lly sub div N psf$sx psf$sy +scale psf$cx psf$sx div psf$llx sub psf$cy psf$sy div psf$ury sub TR +/showpage{}N /erasepage{}N /copypage{}N /p 3 def @MacSetUp}N /doclip{ +psf$llx psf$lly psf$urx psf$ury currentpoint 6 2 roll newpath 4 copy 4 2 +roll moveto 6 -1 roll S lineto S lineto S lineto closepath clip newpath +moveto}N /endTexFig{end psf$SavedState restore}N /@beginspecial{SDict +begin /SpecialSave save N gsave normalscale currentpoint TR +@SpecialDefaults count /ocount X /dcount countdictstack N}N /@setspecial +{CLIP 1 eq{newpath 0 0 moveto hs 0 rlineto 0 vs rlineto hs neg 0 rlineto +closepath clip}if ho vo TR hsc vsc scale ang rotate rwiSeen{rwi urx llx +sub div rhiSeen{rhi ury lly sub div}{dup}ifelse scale llx neg lly neg TR +}{rhiSeen{rhi ury lly sub div dup scale llx neg lly neg TR}if}ifelse +CLIP 2 eq{newpath llx lly moveto urx lly lineto urx ury lineto llx ury +lineto closepath clip}if /showpage{}N /erasepage{}N /copypage{}N newpath +}N /@endspecial{count ocount sub{pop}repeat countdictstack dcount sub{ +end}repeat grestore SpecialSave restore end}N /@defspecial{SDict begin} +N /@fedspecial{end}B /li{lineto}B /rl{rlineto}B /rc{rcurveto}B /np{ +/SaveX currentpoint /SaveY X N 1 setlinecap newpath}N /st{stroke SaveX +SaveY moveto}N /fil{fill SaveX SaveY moveto}N /ellipse{/endangle X +/startangle X /yrad X /xrad X /savematrix matrix currentmatrix N TR xrad +yrad scale 0 0 1 startangle endangle arc savematrix setmatrix}N end +%%EndProcSet +TeXDict begin 39158280 55380996 1000 360 360 (diplarb.dvi) +@start /Fa 1 106 df<0C0E0C00000000305898983030606464683007127D910D>105 +D E /Fb 4 96 df<70000000000EF8000000001FF8000000001FF8000000001FF8000000 +001FF8000000001FF8000000001FF8000000001FF8000000001FF8000000001FF8000000 +001FF8000000001FF8000000001FF8000000001FF8000000001FF8000000001FF8000000 +001FF8000000001FF8000000001FF8000000001FF8000000001FF8000000001FF8000000 +001FF8000000001FF8000000001FF8000000001FF8000000001FF8000000001FF8000000 +001FF8000000001FF8000000001FF8000000001FF8000000001FF8000000001FF8000000 +001FF8000000001FF8000000001FF8000000001FF8000000001FF8000000001FF8000000 +001FF8000000001FF8000000001FF8000000001FF8000000001FF8000000001FF8000000 +001FF8000000001FF8000000001FF8000000001FFC000000003F7C000000003E7C000000 +003E7E000000007E3E000000007C3F00000000FC1F00000000F81F80000001F80FC00000 +03F00FE0000007F007F000000FE003F800001FC001FE00007F8000FF8001FF00007FF00F +FE00003FFFFFFC00000FFFFFF0000007FFFFE0000000FFFF000000001FF8000030467D7F +37>91 D<00001FF800000000FFFF00000007FFFFE000000FFFFFF000003FFFFFFC00007F +F00FFE0000FF8001FF0001FE00007F8003F800001FC007F000000FE00FE0000007F00FC0 +000003F01F80000001F81F00000000F83F00000000FC3E000000007C7E000000007E7C00 +0000003E7C000000003EFC000000003FF8000000001FF8000000001FF8000000001FF800 +0000001FF8000000001FF8000000001FF8000000001FF8000000001FF8000000001FF800 +0000001FF8000000001FF8000000001FF8000000001FF8000000001FF8000000001FF800 +0000001FF8000000001FF8000000001FF8000000001FF8000000001FF8000000001FF800 +0000001FF8000000001FF8000000001FF8000000001FF8000000001FF8000000001FF800 +0000001FF8000000001FF8000000001FF8000000001FF8000000001FF8000000001FF800 +0000001FF8000000001FF8000000001FF8000000001FF8000000001FF8000000001FF800 +0000001FF8000000001FF8000000001FF8000000001FF8000000001FF8000000001FF800 +0000001FF8000000001FF8000000001FF8000000001F70000000000E30467D7F37>I<00 +0001C00000000003C00000000007E00000000007E00000000007E0000000000FF0000000 +000FF0000000000FF0000000001FF8000000001FF8000000001FF8000000003FFC000000 +003E7C000000003E7C000000007E7E000000007C3E000000007C3E00000000FC3F000000 +00F81F00000000F81F00000001F81F80000001F00F80000001F00F80000003F00FC00000 +03E007C0000003E007C0000007E007E0000007C003E0000007C003E000000FC003F00000 +0F8001F000000F8001F000001F8001F800001F0000F800001F0000F800003F0000FC0000 +3E00007C00003E00007C00007E00007E00007C00003E00007C00003E0000FC00003F0000 +F800001F0000F800001F0001F800001F8001F000000F8001F000000F8003F000000FC003 +E0000007C003E0000007C007E0000007E007C0000003E007C0000003E00FC0000003F00F +80000001F00F80000001F01F80000001F81F00000000F81F00000000F83F00000000FC3E +000000007C3E000000007C7E000000007E7C000000003E7C000000003EFC000000003FF8 +000000001FF8000000001FF8000000001F70000000000E30467D7F37>94 +D<70000000000EF8000000001FF8000000001FF8000000001FFC000000003F7C00000000 +3E7C000000003E7E000000007E3E000000007C3E000000007C3F00000000FC1F00000000 +F81F00000000F81F80000001F80F80000001F00F80000001F00FC0000003F007C0000003 +E007C0000003E007E0000007E003E0000007C003E0000007C003F000000FC001F000000F +8001F000000F8001F800001F8000F800001F0000F800001F0000FC00003F00007C00003E +00007C00003E00007E00007E00003E00007C00003E00007C00003F0000FC00001F0000F8 +00001F0000F800001F8001F800000F8001F000000F8001F000000FC003F0000007C003E0 +000007C003E0000007E007E0000003E007C0000003E007C0000003F00FC0000001F00F80 +000001F00F80000001F81F80000000F81F00000000F81F00000000FC3F000000007C3E00 +0000007C3E000000007E7E000000003E7C000000003E7C000000003FFC000000001FF800 +0000001FF8000000001FF8000000000FF0000000000FF0000000000FF00000000007E000 +00000007E00000000007E00000000003C00000000001C0000030467D7F37>I +E /Fc 1 49 df<060F0F0F1E1E1C3C38383870706060E0C04008127E920B>48 +D E /Fd 1 49 df<081C1C3838383070706060C0C0060D7E8D0B>48 +D E /Fe 1 50 df49 D E /Ff 27 120 +df<60F0F06004047C830C>58 D<60F0F07010101020204040040B7C830C>I<0000300000 +007000000078000000F8000001F8000001F800000378000003780000067800000E780000 +0C780000187C0000183C0000303C0000603C0000603C0000FFFC0000FFFC0001803C0003 +003C0003003E0006001E000E001E007F80FFC0FF81FFC01A197E981E>65 +D<07FFFE0007FFFF8000F007C000F003C000F001E000F001E001E001C001E003C001E007 +8001E00F0003C03E0003FFF80003C01E0003C00F00078007800780078007800780078007 +800F000F000F000F000F003E000F007C00FFFFF000FFFFC0001B187E971E>I<000FE040 +003FF8C000F81DC001E00780078007800F0003801E0003801C0003003C00030078000300 +78000000F0000000F0000000F0000000F0000000F0000000E0000C00E0000C00F0001800 +F000180070003000780060003C00C0001F0380000FFF000003F800001A1A7D981D>I<07 +FFFE0007FFFF8000F003E000F000F000F0007000F0007801E0007801E0003801E0003801 +E0003803C0007803C0007803C0007803C00078078000F0078000F0078001E0078001C00F +0003C00F0007800F000E000F007C00FFFFF000FFFFC0001D187E9721>I<07FFFFE007FF +FFE000F001E000F000C000F000C000F000C001E000C001E030C001E030C001E0700003C0 +600003FFE00003FFE00003C0E0000780C1800780C1800780C300078003000F0006000F00 +06000F001E000F007C00FFFFFC00FFFFF8001B187E971D>I<03FFC003FF800078000078 +0000780000780000F00000F00000F00000F00001E00001E00001E00001E00003C00003C0 +0003C00003C0000780000780000780000780007FF000FFF00012187E9712>73 +D<07FF8007FF8000F00000F00000F00000F00001E00001E00001E00001E00003C00003C0 +0003C00003C00007800C07800C07800C0780180F00180F00380F00700F01F0FFFFE0FFFF +E016187E971B>76 D<07FC0003FC07FC0007FC00FC000FC000DE000FC000DE001BC000DE +0033C0019E003780019E006780019E00C780018F00C780030F018F00030F030F00030F03 +0F00030F060F00060F0C1E0006078C1E000607981E000607B01E000C07B03C000C07E03C +000C07C03C001C03C03C00FF8383FF80FF8303FF8026187E9726>I<07F801FF07FC01FF +00FC003800FE003000DE003000CF0030018F006001878060018780600183C0600303E0C0 +0301E0C00301F0C00300F0C00600F9800600798006007D8006003D800C003F000C001F00 +0C000F001C000F00FF800600FF80060020187E9720>I<07FFFC0007FFFF0000F0078000 +F003C000F001C000F001C001E003C001E003C001E003C001E0078003C00F0003C01E0003 +FFF80003C00000078000000780000007800000078000000F0000000F0000000F0000000F +000000FFE00000FFE000001A187E9719>80 D<07FFF80007FFFE0000F00F0000F0078000 +F0038000F003C001E0078001E0078001E0070001E00E0003C0380003FFE00003C0700003 +C0380007803C0007803C0007803C0007803C000F0078000F0078000F0078600F007860FF +E078C0FFE0388000000F001B197E971E>82 D<001F84007FCC01E0FC0380380300380700 +380700380F00300F00000F800007F00007FE0003FF8000FFC0001FC00003E00001E00000 +E03000E06001C06001C0700380700300FC0E00CFFC0083F000161A7D9818>I<1FFFFFC0 +1FFFFFC03C0F03C0300F0180700F0180600F0180601E0180C01E0180C01E0180001E0000 +003C0000003C0000003C0000003C00000078000000780000007800000078000000F00000 +00F0000000F0000000F000003FFF00003FFF00001A187E9718>II<03FF87FC03FF87FC003C +03C0003E0300001E0600001F0E00000F1C00000FB800000FF0000007E0000007C0000003 +C0000003E0000007E000000DF0000018F0000030F0000060F80000C0780001807C000300 +3C000F003E00FFC0FFC0FFC1FFC01E187E9721>88 D<07980C781878303870386070E070 +E070E070C0E1C0E3C0E3C1E663E43C38100F7D8E16>97 D<03E00E301878307870706000 +E000E000E000C000C000C010603060E01F800D0F7D8E12>99 D<03E00E30181830187030 +E070FFC0E000E000E000E000E010603030E01F800D0F7D8E13>101 +D<018003C003800380000000000000000000001C0027004700C700C7000E000E001C001C +001C4038C038C0398039001E000A187E970E>105 D<001C001C003C0018000000000000 +0000000001E0033006380C380C38007000700070007000E000E000E000E001C001C001C0 +01C06380F380F700E60078000E1F7F9710>I<1F801F8007000700070007000E000E000E +000E0E1C371C4F1C8F1D063A003F003BC038E070E170E370E370E6E064603810187D9715 +>I<3C1F00666380478180C781C0C701C00E03800E03800E03800E07001C07081C07181C +0E181C0E303806601803C0150F7E8E19>110 D<3C7C66C7478FC70FC7060E000E000E00 +0E001C001C001C001C0038001800100F7E8E12>114 D<03E00C300878187818701F001F +E00FF003F06030F030F030E06060C03F000D0F7D8E13>I<1E0183002303878063038380 +C7038380C7038380070703000E0703000E0703000E0703001C0E06001C0E06001C0E0400 +0C0E08000617180003E1E000190F7E8E1D>119 D E /Fg 4 62 df<03000F00FF00F700 +07000700070007000700070007000700070007000700070007000700070007000700FFF0 +FFF00C177D9614>49 D<0F803FE070F06078F83CF83CF83C703C003C00380078007000E0 +01C0038003000600080C100C201C7FF8FFF8FFF80E177E9614>I<0F801FE038F0707078 +78787878783078007000E001C00F8000E000700038003C703CF83CF83CF838707870F03F +E00F800E187E9614>I61 D E /Fh 133[27 +30 30 43 30 33 20 23 27 1[33 30 33 50 17 33 1[17 33 30 +20 27 33 27 33 30 9[60 43 43 40 33 43 47 37 47 43 56 +40 2[23 47 47 37 40 43 43 1[43 8[30 30 30 30 30 30 30 +30 2[15 20 15 2[20 20 37[33 2[{ TeXBase1Encoding ReEncodeFont }58 +60.000002 /Times-Bold rf /Fi 133[32 36 36 52 36 40 24 +28 32 1[40 36 40 60 20 2[20 40 36 24 32 40 32 40 36 9[72 +1[52 48 40 52 56 44 56 1[68 48 2[28 56 56 44 48 52 52 +1[52 8[36 36 36 36 36 36 36 36 1[20 18 1[18 4[24 39[{ + TeXBase1Encoding ReEncodeFont }53 71.999969 /Times-Bold +rf /Fj 139[34 1[46 1[57 7[57 2[46 3[52 29[75 15[52 52 +52 49[{ TeXBase1Encoding ReEncodeFont }10 103.700026 +/Times-Bold rf /Fk 43 123 df<07FFFFC00FFFFFC01FFFFFC0383060006070C000C0 +60C000C060C0000060C00000E1C00000C1C00001C1C00001C1C00001C1C0000381C00003 +81C0000781E0000701E0000F01E0000F01F0000E00F0000C00E0001A157F941C>25 +D<007FFF8001FFFF8003FFFF800783C0000F01C0001E01E0003C01E0003C01E0007801E0 +007801E0007801E000F003C000F003C000F003C000F0078000F0070000700F0000700E00 +00301800001870000007C0000019157E941C>27 D<78FCFCFCFC7806067C850E>58 +D<78FCFCFEFE7A0202020404040810204007107C850E>I<0000000C0000003C000000F0 +000003C000000F0000003C000000F0000003C000000F0000003C000000F0000003C00000 +0F0000003C000000F0000000F00000003C0000000F00000003C0000000F00000003C0000 +000F00000003C0000000F00000003C0000000F00000003C0000000F00000003C0000000C +1E1E7C9A27>I62 D<000001C000000001C0 +00000003C000000003C000000007C00000000FC00000000FC00000001FC00000001FE000 +000037E000000033E000000063E0000000C3E0000000C3E000000183E000000183E00000 +0303E000000703E000000603E000000C03E000000C03F000001801F000001801F000003F +FFF000007FFFF000006001F00000C001F00000C001F000018001F000038001F000030001 +F000070001F8001F0001F800FFE01FFF80FFC01FFF8021237EA225>65 +D<00FFFFFC0000FFFFFF000007C00FC00007C003C0000F8003E0000F8001E0000F8001F0 +000F8001F0001F0001E0001F0003E0001F0003E0001F0007C0003E000780003E001F0000 +3E003E00003E00F800007FFFF000007C003C00007C001E00007C001F0000F8000F0000F8 +000F0000F8000F8000F8000F8001F0000F0001F0001F0001F0001F0001F0003E0003E000 +7C0003E0007C0003E001F80007E007E000FFFFFFC000FFFFFE000024227FA126>I<0000 +7F00C00003FFC180000FC0E380001F003380007C001F8000F0000F0001E0000F0003C000 +0F000780000F000F800006000F000006001F000006003E000006003E00000C007C000000 +007C000000007C00000000F800000000F800000000F800000000F800000000F800000000 +F000000000F000003000F000003000F000006000F800006000F80000C000780000C00078 +000180003C000300001E000600000F001C000007C070000003FFE00000007F0000002224 +7DA224>I<00FFFFFC0000FFFFFF800007C00FC00007C003E0000F8001F0000F8000F000 +0F800078000F800078001F000078001F00007C001F00007C001F00007C003E00007C003E +00007C003E00007C003E00007C007C000078007C0000F8007C0000F8007C0000F800F800 +01F000F80001F000F80001E000F80003E001F00003C001F000078001F0000F8001F0000F +0003E0001E0003E0007C0003E000F00007E007E000FFFFFF8000FFFFFC000026227FA129 +>I<00FFFFFFF000FFFFFFF00007C001F00007C000F0000F800070000F800070000F8000 +60000F800060001F000060001F006060001F006060001F006060003E00C000003E00C000 +003E03C000003FFFC000007FFF8000007C038000007C038000007C03800000F803000000 +F80300C000F80300C000F800018001F000018001F000030001F000030001F000070003E0 +00060003E0000E0003E0003C0007E000FC00FFFFFFFC00FFFFFFF80024227FA125>I<00 +FFFFFFE000FFFFFFE00007C003E00007C001E0000F8000E0000F8000E0000F8000C0000F +8000C0001F0000C0001F0000C0001F00C0C0001F00C0C0003E018000003E018000003E03 +8000003E078000007FFF0000007FFF0000007C070000007C07000000F806000000F80600 +0000F806000000F806000001F000000001F000000001F000000001F000000003E0000000 +03E000000003E000000007E0000000FFFF800000FFFF00000023227EA120>I<007FFE00 +FFFE0007C00007C0000F80000F80000F80000F80001F00001F00001F00001F00003E0000 +3E00003E00003E00007C00007C00007C00007C0000F80000F80000F80000F80001F00001 +F00001F00001F00003E00003E00003E00007E0007FFE00FFFE0017227FA116>73 +D<00FFFF0000FFFF000007C0000007C000000F8000000F8000000F8000000F8000001F00 +00001F0000001F0000001F0000003E0000003E0000003E0000003E0000007C0000007C00 +00007C0000007C000000F8000000F8000C00F8000C00F8001801F0001801F0001801F000 +3001F0003003E0007003E000E003E003E007E00FE0FFFFFFC0FFFFFFC01E227FA122>76 +D<00FFE00003FF8000FFE00003FF800007E00007F0000007E0000DF000000DE0000FE000 +000DE0001BE000000DE0001BE000000DE00033E0000019E00067C0000019E00067C00000 +18F000C7C0000018F000C7C0000030F0018F80000030F0030F80000030F0030F80000030 +F0060F80000060F0061F00000060F00C1F00000060F0181F0000006078181F000000C078 +303E000000C078303E000000C078603E000000C078C03E0000018078C07C000001807980 +7C0000018079807C000001807B007C000003007E00F8000003003E00F8000003003C00F8 +00000F803C01F80000FFF0383FFF8000FFF0303FFF800031227EA130>I<007FE001FFC0 +00FFE003FFC00007F0003C000007F0003800000DF0003000000DF8003000000CF8003000 +000CFC00300000187C00600000187C00600000183E00600000183E00600000303F00C000 +00301F00C00000301F80C00000300F80C00000600F81800000600FC18000006007C18000 +006007E1800000C003E3000000C003E3000000C001F3000000C001F30000018001FE0000 +018000FE0000018000FE00000180007E00000300007C00000300007C00000300003C0000 +0F80003C00007FF000180000FFF0001800002A227FA128>I<00007F00000003C1E00000 +0E007000003C0038000078001C0000E0001E0001E0000E0003C0000F000780000F000F00 +000F000F00000F801E00000F803E00000F803E00000F807C00000F807C00000F807C0000 +0F80F800001F00F800001F00F800001F00F800001E00F800003E00F000003E00F000007C +00F000007C00F00000F800F00000F000F80001F000780003E000780003C0003800078000 +3C000E00001E001C00000F007800000381E0000000FF00000021247DA226>I<00FFFFFC +0000FFFFFF000007C00F800007C003C0000F8003E0000F8001E0000F8001E0000F8001E0 +001F0003E0001F0003E0001F0003E0001F0003C0003E0007C0003E000780003E000F0000 +3E001E00007C00F800007FFFE000007C000000007C00000000F800000000F800000000F8 +00000000F800000001F000000001F000000001F000000001F000000003E000000003E000 +000003E000000007E0000000FFFE000000FFFE00000023227FA120>I<00FFFFF00000FF +FFFC000007C03F000007C00F80000F8007C0000F8003C0000F8003C0000F8003C0001F00 +07C0001F0007C0001F0007C0001F000F80003E000F00003E001E00003E007800003E01E0 +00007FFF0000007C03C000007C01E000007C00F00000F800F80000F800F80000F800F800 +00F800F80001F001F00001F001F00001F001F00001F001F00003E003E00003E003E06003 +E003E06007E001E0C0FFFE01E0C0FFFE00F1800000003E0023237EA126>82 +D<0001F8180007FE30001E0770003C01F0007801F000F000E000E000E001E000E001E000 +E003E000C003E000C003E0000003E0000003F0000003FF000001FFE00001FFF80000FFFC +00007FFE00000FFE000000FE0000003F0000001F0000001F0000001F0030001E0030001E +0030001E0030001C0070003C0078003800780070007C00E000EF03C000C3FF800080FE00 +001D247DA21F>I<1FFFFFFF1FFFFFFF1F01F01F3C01F0073803E0073003E0077003E006 +6003E0066007C006C007C006C007C006C007C006000F8000000F8000000F8000000F8000 +001F0000001F0000001F0000001F0000003E0000003E0000003E0000003E0000007C0000 +007C0000007C0000007C000000F8000000F8000000F8000001F80000FFFFE000FFFFE000 +20227EA11D>I<3FFF00FFE07FFF01FFE003E0001E0003E0001C0007C000180007C00018 +0007C000180007C00018000F800030000F800030000F800030000F800030001F00006000 +1F000060001F000060001F000060003E0000C0003E0000C0003E0000C0003E0000C0007C +000180007C000180007C000180007C000180007800030000F80003000078000600007800 +06000078000C000078001800003C003000001E00E000000F03C0000007FF00000001FC00 +000023237EA122>I<007FFE0FFF007FFE0FFF0007F003F00003E001C00003F003800003 +F007000001F00E000001F80C000000F818000000FC30000000FC600000007CC00000007F +800000007F800000003F000000003F000000001F000000001F800000003F800000006F80 +000000CFC00000018FC000000387C000000707E000000E03E000000C03F000001803F000 +003001F000006001F80000C001F80001C000F80007C001FC00FFF00FFFC0FFF00FFFC028 +227FA129>88 D<007C6001C6F00303F00601E00E01E01C01E03C01E03803C07803C07803 +C07803C0F00780F00780F00784F00786F00F0C700F0C701F083037181867100F81E01715 +7E941A>97 D<01E0003FC0003FC00003C00003C0000780000780000780000780000F0000 +0F00000F00000F00001E00001E7C001EC6001F03003E03803C03C03C03C03C03C07803C0 +7803C07803C07803C0F00780F00780F00780F00F00F00E00701E00701C00303800186000 +0F800012237EA215>I<003F0000E1800381C00703C00E07C01C07C03C03803C00007800 +00780000780000F00000F00000F00000F000007000407000C03001803807001C1C0007F0 +0012157E9416>I<00000F0001FE0001FE00001E00001E00003C00003C00003C00003C00 +00780000780000780000780000F0007CF001C6F00303F00601E00E01E01C01E03C01E038 +03C07803C07803C07803C0F00780F00780F00784F00786F00F0C700F0C701F0830371818 +67100F81E018237EA21A>I<007E000383000701800E01801C0180380180780300700600 +FFF800F00000F00000E00000E00000E00000E00000E00080E00180700300300E00183800 +0FE00011157D9417>I<007000F800F800F000E000000000000000000000000000000000 +0F00118021C061C0C3C0C3C0C3C0078007800F000F000F001E001E101E183C303C303C60 +384018C00F000D227FA111>105 D<0078000FF0000FF00000F00000F00001E00001E000 +01E00001E00003C00003C00003C00003C00007800007807807818C07821C0F043C0F087C +0F107C0F20381EC0001F00001FF0001E3C003C1E003C1E003C0F083C0F0C781E18781E18 +781E10780E30F006206003C016237EA21A>107 D<00F00FE01FE001E001E003C003C003 +C003C007800780078007800F000F000F000F001E001E001E001E003C003C003C003C0078 +007800788078C0F180F180F180730073001C000C237EA20F>I<1E03F000338C380063D8 +1C0063E01E00C3E01E00C3C01E00C3C01E0007803C0007803C0007803C0007803C000F00 +78000F0078000F00F0400F00F0601E00F0C01E01E0C01E01E1801E00E1003C00E2001800 +3C001B157F941E>110 D<003F0000E1C00380E00700700E00701C00783C00783C007878 +0078780078780078F000F0F000F0F000E0F001E07001C0700380300700380E001C3C0007 +E00015157E9418>I<03C0F80006718C000C7E06000C7C07001878078018780780187807 +8000F0078000F0078000F0078000F0078001E00F0001E00F0001E00F0001E01E0003C01C +0003C03C0003E0380003E0700007B0C000078F000007800000078000000F0000000F0000 +000F0000000F0000001E0000001E000000FFE00000FFE00000191F819419>I<007C1001 +C6700303F00601E00E01E01C01E03C01E03803C07803C07803C07803C0F00780F00780F0 +0780F00780F00F00700F00701F00303F00187E000F9E00001E00001E00003C00003C0000 +3C00003C0000780000780007FF8007FF80141F7E9416>I<1F078033984063F0E063E1E0 +C3C3E0C3C3E0C3C1C00780000780000780000780000F00000F00000F00000F00001E0000 +1E00001E00001E00003C000018000013157F9416>I<007E0000C3000181800303800707 +8007078007020007E00007FC0007FE0003FF0001FF80001F80300780780780F80700F807 +00F00600600C003038000FE00011157E9417>I<00E001E001E001E001E003C003C003C0 +03C00780FFFCFFFC07800F000F000F000F001E001E001E001E003C003C003C083C0C7818 +78107830386038C00F000E1F7F9E12>I<0F807019C0F031E0F861E078C1E038C1E038C3 +C03803C0300780300780300780300F00600F00600F00400F00C00F00800F01800F010007 +0200038C0001F00015157F9418>118 D<0F80180E19C03C1E31E03C1F61E0780FC1E078 +07C1E07807C3C0780703C0F0060780F0060780F0060780F0060F01E00C0F01E00C0F01E0 +0C0F01E0180F01E0180F01E0100F03E0200702E060038470C000F81F0020157F9424>I< +03E0F00C3318183E1C303E3C203C7C603C7C603C3800780000780000780000780000F000 +00F00000F00830F00C79E018F9E018F9E030F360606230C03C1F0016157E941C>I<0F80 +0C19C01E31E01E61E03CC1E03CC1E03CC3C03C03C0780780780780780780780F00F00F00 +F00F00F00F00F00F01E00F01E00F01E00703E0030FC001F3C00003C00003C00007803C07 +007C0F007C0E00781C0060380030E0001F8000171F7F9418>I<00E03003F03007F86007 +FFC00C01800C0300000600000C0000180000300000600000C0000180000300400600600C +00C01803C03FFF8071FF0060FE00C0780014157E9417>I E /Fl +14 94 df<00200040008001800300060006000E000C001C001800380038003800700070 +0070007000F000F000F000F000F000F000F000F000F000F000F000F000F000F000700070 +007000700038003800380018001C000C000E0006000600030001800080004000200B327C +A413>40 D<800040002000300018000C000C000E0006000700030003800380038001C001 +C001C001C001E001E001E001E001E001E001E001E001E001E001E001E001E001E001C001 +C001C001C00380038003800300070006000E000C000C00180030002000400080000B327D +A413>I<0001800000018000000180000001800000018000000180000001800000018000 +0001800000018000000180000001800000018000000180000001800000018000FFFFFFFF +FFFFFFFF0001800000018000000180000001800000018000000180000001800000018000 +000180000001800000018000000180000001800000018000000180000001800020227D9C +27>43 D<01F800070E000E07001C03803C03C03801C07801E07801E07801E07801E0F801 +F0F801F0F801F0F801F0F801F0F801F0F801F0F801F0F801F0F801F0F801F0F801F0F801 +F0F801F07801E07801E07801E07801E03C03C03C03C01C03800E0700070E0001F8001422 +7EA019>48 D<00C001C007C0FFC0FBC003C003C003C003C003C003C003C003C003C003C0 +03C003C003C003C003C003C003C003C003C003C003C003C003C003C003C003C0FFFFFFFF +10217CA019>I<03F8000FFE001C1F803007C06003C06003E0F801E0FC01F0FC01F0FC01 +F07801F03001F00001E00003E00003E00007C0000780000F00000E00001C000038000070 +0000E0000180000300300600300400300800701000603FFFE07FFFE0FFFFE0FFFFE01421 +7EA019>I<01F8000FFE001E0F803807C03803C07C03E07C03E07C03E03C03E01803E000 +03C0000780000780000E00001C0003F800000E000007800003C00003E00001E00001F000 +01F03001F07801F0FC01F0FC01F0FC01E0F803E06003C03007801C0F000FFE0003F80014 +227EA019>I<000180000380000380000780000F80001F80001780003780006780004780 +00C7800187800107800307800607800407800C0780180780300780200780600780C00780 +FFFFFCFFFFFC00078000078000078000078000078000078000078000FFFC00FFFC16217F +A019>I<1000401E03801FFF001FFE001FFC001FF0001800001800001800001800001800 +0018000018F8001B0E001C07001803801003C00001E00001E00001F00001F00001F07001 +F0F801F0F801F0F801F0F801E0C001E06003C07003C03807801C1F000FFC0003F0001422 +7EA019>I<003E0000FF8003C1C00780E00F01E01E03E01C03E03C01C03C000078000078 +0000780000F8F800F90E00FA0300FC0380FC01C0FC01E0F801E0F801F0F801F0F801F0F8 +01F0F801F07801F07801F07801E03801E03C01E01C03C01E03800F0F0003FE0001F80014 +227EA019>I<78FCFCFCFC7800000000000000000078FCFCFCFC7806157C940E>58 +D61 D91 D93 D +E /Fm 165[30 1[36 47 36 36 30 28 33 36 28 36 36 44 30 +2[17 36 36 28 30 36 33 1[36 8[25 25 25 25 25 25 25 25 +1[14 12 1[12 4[17 39[{ .167 SlantFont TeXBase1Encoding ReEncodeFont }34 +50.000002 /Times-Roman rf /Fn 105[25 27[22 25 25 36 25 +28 17 19 22 28 28 25 28 41 14 28 1[14 28 25 17 22 28 +22 28 25 10[36 36 33 28 36 39 30 39 36 47 33 39 25 19 +39 39 30 33 36 36 1[36 6[17 25 25 25 25 25 25 25 25 25 +25 14 12 1[12 2[17 17 17 36[28 2[{ TeXBase1Encoding ReEncodeFont }65 +50.000002 /Times-Bold rf /Fo 22 111 df0 +D2 D<00C00000E00000C00000C00040C080E0C1C0F8C7C07CCF801EDE00 +03F00000C00003F0001EDE007CCF80F8C7C0E0C1C040C08000C00000C00000E00000C000 +12157D9619>I[<00038000000FE000000FE000000FE000000FE000000FE0000003800000 +0000000000000000000000000000000000000000000000FFFFFFFEFFFFFFFE0000000000 +0000000000000000000000000000000000000000038000000FE000000FE000000FE00000 +0FE000000FE00000038000>31 28 125 153 38 I<03F0000FFC001FFE003FFF007FFF80 +7FFF80FFFFC0FFFFC0FFFFC0FFFFC0FFFFC0FFFFC0FFFFC0FFFFC07FFF807FFF803FFF00 +1FFE000FFC0003F00012147D9519>15 D<001FFFFC00FFFFFC01E00000078000000E0000 +001C0000003800000030000000700000006000000060000000E0000000C0000000C00000 +00C0000000C0000000C0000000C0000000E0000000600000006000000070000000300000 +00380000001C0000000E0000000780000001E0000000FFFFFC001FFFFC00000000000000 +000000000000000000000000000000000000000000000000007FFFFFFC7FFFFFFC1E287C +9F27>18 D<0000000C0000003C000000F0000003C000000F0000003C000000F0000003C0 +00000F0000003C000000F0000003C000000F0000003C000000F0000000F00000003C0000 +000F00000003C0000000F00000003C0000000F00000003C0000000F00000003C0000000F +00000003C0000000F00000003C0000000C00000000000000000000000000000000000000 +00000000000000000000000000FFFFFFFCFFFFFFFC1E287C9F27>20 +DI<000000600000000000300000 +0000003000000000001800000000001800000000000C0000000000060000000000030000 +FFFFFFFF8000FFFFFFFFE000000000007000000000001C00000000000F800000000003E0 +000000000780000000001E00000000003800000000006000FFFFFFFFC000FFFFFFFF8000 +0000000300000000000600000000000C0000000000180000000000180000000000300000 +0000003000000000006000002B1C7D9932>41 D<001FFF00FFFF01E0000780000E00001C +0000380000300000700000600000600000E00000C00000C00000FFFFFFFFFFFFC00000C0 +0000E000006000006000007000003000003800001C00000E000007800001E00000FFFF00 +1FFF181E7C9A21>50 D<00000300000300000700000600000E00000C00001C0000180000 +380000300000700000600000E00000C00001C0000180000380000300000700000600000E +00000C00001C0000180000180000380000300000700000600000E00000C00001C0000180 +000380000300000700000600000E00000C00001C00001800003800003000007000006000 +00E00000C00000C00000183079A300>54 D56 DII91 D<007F800003FFF0000F807C001C000E00380007007000038060000180E00001 +C0C00000C0C00000C0C00000C0C00000C0C00000C0C00000C0C00000C0C00000C0C00000 +C0C00000C0C00000C0C00000C0C00000C0C00000C0C00000C0C00000C0C00000C0C00000 +C0C00000C0C00000C0C00000C0C00000C0C00000C01A1F7D9D21>I<000C0000000C0000 +001E0000001E0000003F00000033000000330000007380000061800000E1C00000C0C000 +01C0E000018060000180600003807000030030000700380006001800060018000E001C00 +0C000C001C000E00180006003800070030000300300003007000038060000180E00001C0 +C00000C0C00000C01A1F7D9D21>94 DI<0007C0003E0000780000F00001E00001E00001E00001E00001E00001E00001E000 +01E00001E00001E00001E00001E00001E00001E00001E00001E00001E00003C000078000 +1F0000F800001F000007800003C00001E00001E00001E00001E00001E00001E00001E000 +01E00001E00001E00001E00001E00001E00001E00001E00001E00001E00000F000007800 +003E000007C012317DA419>102 DI106 D110 D E /Fp 133[19 +22 22 33 22 25 14 19 19 25 25 25 25 36 14 22 14 14 25 +25 14 22 25 22 25 25 9[41 30 36 28 25 30 36 30 36 33 +41 28 33 1[17 36 36 30 30 36 33 30 30 3[34 3[25 6[25 +25 1[14 12 17 12 2[17 17 17 36[25 2[{ TeXBase1Encoding ReEncodeFont }60 +50.000002 /Times-Italic rf /Fq 134[62 1[89 1[69 41 48 +55 1[69 62 69 103 34 2[34 69 62 41 55 1[55 69 62 10[89 +89 1[69 1[96 76 3[83 5[76 2[89 83 89 25[41 39[{ + TeXBase1Encoding ReEncodeFont }30 124.400017 /Times-Bold +rf /Fr 119[30 10[30 30 30 30 30 30 30 30 30 30 30 30 +30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 1[30 +1[30 30 30 1[30 30 30 30 30 30 30 30 30 30 30 30 30 30 +30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 +30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 +30 30 30 30 30 30 30 33[{ TeXBase1Encoding ReEncodeFont }91 +50.000002 /Courier rf /Fs 134[30 2[30 1[17 23 20 2[30 +30 47 17 2[17 1[30 20 27 2[30 27 11[43 1[33 2[33 43 43 +53 1[43 3[43 2[43 2[43 7[30 30 5[30 30 2[15 1[15 44[{ + TeXBase1Encoding ReEncodeFont }31 60.000002 /Times-Roman +rf /Ft 87[17 19[22 25[22 25 25 36 25 25 14 19 17 25 25 +25 25 39 14 25 14 14 25 25 17 22 25 22 25 22 3[17 1[17 +1[36 36 47 36 36 30 28 33 36 28 36 36 44 30 36 19 17 +36 36 28 30 36 33 33 36 1[22 1[28 1[14 14 25 25 25 25 +25 25 25 25 25 25 14 12 17 12 28 25 17 17 17 2[25 2[17 +29[28 28 2[{ TeXBase1Encoding ReEncodeFont }82 50.000002 +/Times-Roman rf /Fu 139[24 33 29 1[43 43 43 67 24 2[24 +43 43 29 38 1[38 1[38 13[48 1[62 48 1[62 1[53 2[29 3[53 +3[62 65[{ TeXBase1Encoding ReEncodeFont }23 86.399998 +/Times-Roman rf /Fv 139[20 1[24 1[36 36 1[56 20 2[20 +3[32 2[36 32 28[52 68[{ TeXBase1Encoding ReEncodeFont }11 +71.999969 /Times-Roman rf end +%%EndProlog +%%BeginSetup +%%Feature: *Resolution 360dpi +TeXDict begin +%%PaperSize: A4 + +%%EndSetup +%%Page: 1 1 +1 0 bop 907 899 a Fv(Diplomarbeit)221 1151 y Fu(Enhancement)22 +b(of)f(the)h(ANSI)f(SQL)g(Implementation)h(of)888 1260 +y(PostgreSQL)629 1492 y Ft(ausgef)t(\250)-21 b(uhrt)12 +b(am)g(Institut)g(f)t(\250)-21 b(ur)11 b(Informationssysteme)761 +1552 y(der)h(T)m(echnischen)h(Uni)o(v)o(ersit)s(\250)-20 +b(at)11 b(W)n(ien)860 1612 y(unter)h(der)g(Anleitung)f(v)o(on)726 +1771 y Fs(O.Uni)o(v)l(.Prof.Dr)m(.)17 b(Geor)o(g)d(Gottlob)1061 +1831 y Ft(und)762 1891 y Fs(Uni)o(v)l(.Ass.)k(Mag.)g(Katrin)c(Se)o(yr) +671 1950 y Ft(als)f(v)o(erantwortlicher)d(Uni)o(v)o(ersit)s(\250)-20 +b(atsassistentin)1041 2110 y(durch)859 2269 y Fr(Stefan)29 +b(Simkovics)814 2329 y(Paul)h(Petersgasse)e(36)799 2389 +y(A)i(-)g(2384)f(Breitenfurt)244 2749 y Fs(No)o(v)o(ember)14 +b(29,)g(1998)p 244 2766 475 2 v 414 2819 a Ft(Datum)p +1431 2730 567 2 v 1594 2800 a(Unterschrift)p eop +%%Page: 2 2 +2 1 bop eop +%%Page: 3 3 +3 2 bop 198 633 a Fq(Abstract)198 892 y Ft(PostgreSQL)14 +b(is)i(an)f Fp(object-r)n(elational)f Ft(database)h(management)g +(system)g(that)g(runs)f(on)h(almost)g(an)o(y)198 951 +y(UNIX)g(based)i(operating)e(system)h(and)g(is)g(distrib)o(uted)f(as)h +(C-source)g(code.)26 b(It)15 b(is)h(neither)f Fp(fr)n(ee)o(war)n(e)198 +1011 y Ft(nor)f Fp(public)h(domain)f Ft(software.)23 +b(It)14 b(is)h(copyrighted)e(by)i(the)g(Uni)o(v)o(ersity)f(of)h +(California)f(b)o(ut)g(may)h(be)198 1071 y(used,)e(modi\002ed)e(and)i +(distrib)o(uted)e(as)i(long)f(as)g(the)h(licensing)f(terms)g(of)f(the)i +(copyright)d(are)i(accepted.)273 1131 y(As)g(the)f(name)g(already)h +(suggests,)h(PostgreSQL)e(uses)h(an)g(e)o(xtended)f(subset)h(of)f(the)h +(SQL92)f(stan-)198 1191 y(dard)17 b(as)i(the)f(query)f(language.)32 +b(At)18 b(the)g(time)f(of)h(writing)f(this)h(document)f(the)h(actual)g +(v)o(ersion)g(of)198 1250 y(PostgreSQL)11 b(was)h(v6.3.2.)k(In)11 +b(this)h(v)o(ersion)g(the)f(implemented)g(part)g(of)g(SQL)h(did)f(not)h +(support)f(some)198 1310 y(important)e(features)g(included)h(in)g(the)g +(SQL92)g(standard.)k(T)l(wo)c(of)g(the)g(not)f(supported)h(features)f +(were:)273 1410 y Fo(\017)25 b Ft(the)12 b Fp(having)g(clause)273 +1509 y Fo(\017)25 b Ft(the)12 b(support)g(of)g(the)g(set)h(theoretic)f +(operations)g Fp(intersect)g Ft(and)g Fp(e)o(xcept)198 +1609 y Ft(It)e(was)g(the)h(author')m(s)f(task)g(to)g(add)h(the)f +(support)g(for)g(the)g(two)f(missing)i(features)f(to)g(the)h(e)o +(xisting)f(source)198 1669 y(code.)22 b(Before)14 b(the)g +(implementation)g(could)g(be)g(started)h(an)f(intensi)o(v)o(e)h(study)f +(of)g(the)g Fp(r)n(ele)o(vant)i(parts)198 1729 y(of)d(the)g(SQL92)f +(standar)n(d)h Ft(and)g(the)g(implementation)f(of)g(the)h +Fp(e)o(xisting)g(featur)n(es)h Ft(of)f(PostgreSQL)f(had)198 +1788 y(been)h(necessary)m(.)19 b(This)13 b(document)g(will)g(not)g +(present)g(only)f(the)h(results)h(of)e(the)h(implementation)f(b)o(ut) +198 1848 y(also)h(the)h(kno)o(wledge)e(collected)h(while)g(studying)g +(the)g(SQL)g(language)h(and)f(the)g(source)g(code)g(of)g(the)198 +1908 y(already)f(e)o(xisting)h(features.)273 1968 y(Chapter)i(1)h +(presents)h(an)f(o)o(v)o(ervie)o(w)f(on)h(the)g(SQL92)g(standard.)26 +b(It)16 b(gi)o(v)o(es)g(a)g(description)g(of)f(the)198 +2027 y Fp(r)n(elational)k(data)f(model)h Ft(and)g(the)g(theoretical)g +(\(mathematical\))e(background)i(of)f(SQL.)i(Ne)o(xt)f(the)198 +2087 y(SQL)13 b(language)g(itself)f(is)h(described.)18 +b(The)13 b(most)g(important)e(SQL)i(statements)h(are)e(presented)h(and) +g(a)198 2147 y(lot)d(of)g(e)o(xamples)h(are)f(included)h(for)e(better)h +(understanding.)15 b(The)c(information)d(gi)o(v)o(en)j(in)f(this)g +(chapter)198 2207 y(has)j(mainly)f(been)g(taken)g(form)f(the)i(books)f +([D)n(A)-6 b(TE96)q(],)12 b([D)n(A)-6 b(TE94)q(])12 b(and)g([ULL88)q +(].)273 2267 y(Chapter)18 b(2)g(gi)o(v)o(es)g(a)h(description)e(on)h +(ho)o(w)g(to)g(use)h(PostgreSQL.)f(First)g(it)g(is)g(sho)o(wn)g(ho)o(w) +g(the)198 2326 y Fp(bac)o(kend)e Ft(\(serv)o(er\))g(can)h(be)g(started) +g(and)f(ho)o(w)h(a)g(connection)f(from)g(a)h(client)f(to)h(the)f(serv)o +(er)h(can)g(be)198 2386 y(established.)f(Ne)o(xt)c(some)g(basic)h +(database)f(management)g(tasks)h(like)e(creating)g(a)h(database,)i +(creating)198 2446 y(a)g(table)f(etc.)19 b(are)14 b(described.)19 +b(Finally)12 b(some)i(of)f(PostgreSQL)-5 b(')m(s)14 b(special)g +(features)f(like)g Fp(user)h(de\002ned)198 2506 y(functions)p +Ft(,)d Fp(user)h(de\002ned)f(types)p Ft(,)h(the)f Fp(rule)g(system)h +Ft(etc.)j(are)c(presented)g(and)g(illustrated)f(using)h(a)g(lot)g(of) +198 2565 y(e)o(xamples.)16 b(The)d(information)d(gi)o(v)o(en)i(in)g +(chapter)g(2)g(has)g(mainly)g(been)g(taken)f(from)g(the)h(PostgreSQL) +198 2625 y(documentation)17 b(\(see)i([LOCK98)o(]\),)h(the)e +(PostgreSQL)f(manual)h(pages)h(and)f(was)g(v)o(eri\002ed)f(by)h(the)198 +2685 y(author)12 b(throughout)f(v)o(arious)h(e)o(xamples)h(which)f(ha)o +(v)o(e)g(also)h(been)g(included.)273 2745 y(Chapter)h(3)g(concentrates) +h(on)f(the)h(internal)e(structure)h(of)g(the)h(PostgreSQL)f +Fp(bac)o(kend)p Ft(.)21 b(First)14 b(the)198 2804 y(stages)19 +b(that)g(a)g(query)f(has)h(to)f(pass)h(in)g(order)f(to)g(retrie)o(v)o +(e)g(a)h(result)f(are)g(described)h(using)f(a)h(lot)g(of)198 +2864 y(\002gures)h(to)f(illustrate)g(the)h(in)n(v)o(olv)o(ed)g(data)g +(structures.)38 b(The)20 b(information)e(gi)o(v)o(en)i(in)f(that)h +(part)g(of)198 2924 y(chapter)e(3)h(has)g(been)g(collected)g(while)f +(intensi)o(v)o(ely)h(studying)f(the)h(source)f(code)h(of)f(the)h(rele)o +(v)o(ant)198 2984 y(parts)13 b(of)g(PostgreSQL.)g(This)h(intensi)o(v)o +(e)f(and)g(detailed)g(e)o(xamination)g(of)f(the)h(source)h(code)f(had)g +(been)198 3044 y(necessary)h(to)f(be)g(able)g(to)g(add)g(the)g(missing) +h(functionality)m(.)i(The)e(kno)o(wledge)f(gathered)f(during)g(that)198 +3103 y(period)h(of)h(time)f(has)i(been)f(summarized)f(here)h(in)g +(order)f(to)g(make)h(it)f(easier)i(for)e(programmers)f(who)198 +3163 y(are)g(ne)o(w)g(to)h(PostgreSQL)f(to)g(\002nd)g(their)g(way)g +(in.)273 3223 y(The)f(follo)o(wing)f(sections)i(co)o(v)o(er)f(the)g +(author')m(s)g(ideas)h(for)e(the)h(implementation)f(of)h(the)g(two)f +(miss-)198 3283 y(ing)i(SQL)h(features)f(mentioned)g(abo)o(v)o(e)g(and) +h(a)f(description)g(of)g(the)g(implementation)g(itself.)273 +3342 y(Section)e(3.7)h(deals)h(with)e(the)h(implementation)e(of)i(the)g +Fp(having)f(logic)p Ft(.)15 b(As)c(mentioned)f(earlier)g(the)198 +3402 y Fp(having)15 b(logic)f Ft(is)i(one)f(of)f(the)h(two)g(missing)g +(SQL92)g(features)g(that)g(the)g(author)f(had)i(to)e(implement.)1086 +3552 y(3)p eop +%%Page: 4 4 +4 3 bop 270 60 a Ft(4)270 234 y(The)13 b(\002rst)g(parts)g(of)f(the)h +(chapter)f(describe)h(ho)o(w)g Fp(aggr)n(e)n(gate)f(functions)g +Ft(are)h(realized)g(in)f(PostgreSQL)270 294 y(and)e(after)e(that)i(a)f +(description)g(of)g(the)h(enhancements)g(applied)f(to)g(the)h(code)f +(of)h(the)f Fp(planner/optimizer)270 354 y Ft(and)14 +b(the)f Fp(e)o(xecutor)i Ft(in)e(order)g(to)g(realize)h(the)g(ne)o(w)f +(functionality)f(is)i(gi)o(v)o(en.)20 b(The)14 b(functions)f(and)h +(data)270 413 y(structures)e(used)h(and)f(added)h(to)f(the)g(source)h +(code)f(are)g(also)h(handled)f(here.)345 473 y(Section)19 +b(3.8)i(deals)g(with)e(the)i(implementation)e(of)g(the)h +Fp(intersect)h Ft(and)f Fp(e)o(xcept)g Ft(functionality)270 +533 y(which)d(was)h(the)f(second)h(missing)f(SQL92)g(feature)g(that)g +(had)h(to)f(be)g(added)h(by)f(the)g(author)m(.)31 b(First)270 +593 y(a)13 b(theoretical)f(description)g(of)g(the)h(basic)g(idea)g(is)g +(gi)o(v)o(en.)j(The)d Fp(intersect)g Ft(and)g Fp(e)o(xcept)g +Ft(logic)f(is)h(imple-)270 653 y(mented)i(using)f(a)i +Fp(query)f(r)n(e)o(write)h Ft(technique)f(\(i.e.)23 b(a)15 +b(query)g(in)n(v)o(olving)f(an)h Fp(intersect)g Ft(and/or)f +Fp(e)o(xcept)270 712 y Ft(operation)h(is)h Fp(r)n(e)o(written)h +Ft(to)f(a)g(semantically)g(equi)o(v)o(alent)f(form)g(that)g(does)i(not) +e(use)h(these)h Fp(set)f(oper)o(-)270 772 y(ations)e +Ft(an)o(y)h(more\).)21 b(After)14 b(presenting)g(the)g(basic)h(idea)g +(the)f(changes)h(made)g(to)f(the)h Fp(parser)g Ft(and)f(the)270 +832 y Fp(r)n(e)o(write)g(system)f Ft(are)f(described)h(and)f(the)g +(added)h(functions)f(and)g(data)g(structures)h(are)f(presented.)p +eop +%%Page: 5 5 +5 4 bop 198 633 a Fq(Contents)198 943 y Fn(1)50 b(SQL)1600 +b(9)273 1003 y Ft(1.1)52 b(The)13 b(Relational)f(Data)h(Model)27 +b(.)e(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h +(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(10)387 1063 y(1.1.1)61 +b(F)o(ormal)11 b(Notion)h(of)g(the)g(Relational)h(Data)f(Model)47 +b(.)25 b(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 +b(10)547 1123 y(Domains)12 b(vs.)k(Data)d(T)l(ypes)35 +b(.)25 b(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.) +h(.)f(.)h(.)f(.)g(.)h(.)44 b(11)273 1184 y(1.2)52 b(Operations)12 +b(in)h(the)f(Relational)g(Data)h(Model)22 b(.)k(.)f(.)g(.)h(.)f(.)g(.)h +(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(11)387 +1244 y(1.2.1)61 b(Relational)12 b(Algebra)33 b(.)25 b(.)g(.)h(.)f(.)g +(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.) +f(.)g(.)h(.)44 b(11)387 1304 y(1.2.2)61 b(Relational)12 +b(Calculus)20 b(.)25 b(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g +(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 +b(14)547 1364 y(T)n(uple)12 b(Relational)g(Calculus)43 +b(.)25 b(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.) +f(.)h(.)f(.)g(.)h(.)44 b(14)387 1425 y(1.2.3)61 b(Relational)12 +b(Algebra)g(vs.)k(Relational)c(Calculus)43 b(.)26 b(.)f(.)g(.)h(.)f(.)g +(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(14)273 1485 y(1.3)52 +b(The)13 b(SQL)g(Language)28 b(.)e(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h +(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.) +g(.)h(.)44 b(14)387 1545 y(1.3.1)61 b(Select)27 b(.)e(.)h(.)f(.)h(.)f +(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.) +g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(15)547 1605 +y(Simple)11 b(Selects)42 b(.)25 b(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h +(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.) +44 b(15)547 1665 y(Joins)j(.)25 b(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h +(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.) +f(.)h(.)f(.)g(.)h(.)44 b(16)547 1726 y(Aggre)o(gate)12 +b(Operators)32 b(.)25 b(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h +(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(17)547 +1786 y(Aggre)o(gation)11 b(by)h(Groups)k(.)26 b(.)f(.)g(.)h(.)f(.)h(.)f +(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 +b(17)547 1846 y(Ha)o(ving)c(.)26 b(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f +(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.) +h(.)f(.)g(.)h(.)44 b(19)547 1906 y(Subqueries)39 b(.)26 +b(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h +(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(19)547 +1967 y(Union,)12 b(Intersect,)h(Except)39 b(.)25 b(.)g(.)h(.)f(.)h(.)f +(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 +b(20)387 2027 y(1.3.2)61 b(Data)12 b(De\002nition)27 +b(.)e(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f +(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(21)547 +2087 y(Create)12 b(T)l(able)48 b(.)25 b(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h +(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.) +g(.)h(.)44 b(21)547 2147 y(Data)12 b(T)l(ypes)h(in)g(SQL)29 +b(.)c(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h +(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(21)547 2208 y(Create)12 +b(Inde)o(x)44 b(.)25 b(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g +(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 +b(22)547 2268 y(Create)12 b(V)m(ie)o(w)j(.)26 b(.)f(.)g(.)h(.)f(.)g(.)h +(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.) +f(.)h(.)f(.)g(.)h(.)44 b(22)547 2328 y(Drop)12 b(T)l(able,)h(Drop)f +(Inde)o(x,)g(Drop)g(V)m(ie)o(w)27 b(.)e(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f +(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(23)387 2388 y(1.3.3)61 +b(Data)12 b(Manipulation)36 b(.)25 b(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.) +g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 +b(23)547 2449 y(Insert)12 b(Into)17 b(.)25 b(.)h(.)f(.)g(.)h(.)f(.)g(.) +h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h +(.)f(.)h(.)f(.)g(.)h(.)44 b(23)547 2509 y(Update)e(.)26 +b(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f +(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 +b(24)547 2569 y(Delete)19 b(.)25 b(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h +(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.) +f(.)h(.)f(.)g(.)h(.)44 b(24)387 2629 y(1.3.4)61 b(System)12 +b(Catalogs)40 b(.)26 b(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f +(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 +b(24)387 2690 y(1.3.5)61 b(Embedded)12 b(SQL)17 b(.)25 +b(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g +(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(24)198 2800 +y Fn(2)50 b(P)o(ostgr)o(eSQL)12 b(fr)o(om)h(the)f(User')n(s)h(P)o(oint) +f(of)g(V)n(iew)778 b(26)273 2860 y Ft(2.1)52 b(A)13 b(Short)e(History)h +(of)g(PostgreSQL)k(.)26 b(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h +(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(26)273 +2920 y(2.2)52 b(An)13 b(Ov)o(ervie)o(w)e(on)i(the)f(Features)g(of)g +(PostgreSQL)49 b(.)26 b(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f +(.)g(.)h(.)44 b(26)273 2981 y(2.3)52 b(Where)12 b(to)h(Get)f +(PostgreSQL)46 b(.)25 b(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g +(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 +b(27)547 3041 y(Copyright)11 b(of)h(PostgreSQL)48 b(.)25 +b(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h +(.)f(.)g(.)h(.)44 b(27)547 3101 y(Support)11 b(for)g(PostgreSQL)39 +b(.)25 b(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.) +h(.)f(.)h(.)f(.)g(.)h(.)44 b(27)273 3161 y(2.4)52 b(Ho)o(w)12 +b(to)h(use)f(PostgreSQL)i(.)25 b(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.) +f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 +b(28)387 3222 y(2.4.1)61 b(Starting)11 b(The)i(Postmaster)44 +b(.)25 b(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.) +h(.)f(.)h(.)f(.)g(.)h(.)44 b(28)387 3282 y(2.4.2)61 b(Creating)12 +b(a)g(Ne)o(w)h(Database)k(.)25 b(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.) +h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(28)387 +3342 y(2.4.3)61 b(Connecting)12 b(T)l(o)h(a)f(Database)38 +b(.)25 b(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.) +f(.)h(.)f(.)g(.)h(.)44 b(29)387 3402 y(2.4.4)61 b(De\002ning)11 +b(and)i(Populating)e(T)l(ables)45 b(.)26 b(.)f(.)g(.)h(.)f(.)g(.)h(.)f +(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(29)1086 +3552 y(5)p eop +%%Page: 6 6 +6 5 bop 270 60 a Ft(6)1515 b Fm(CONTENTS)459 234 y Ft(2.4.5)61 +b(Retrie)o(ving)11 b(Data)i(From)e(The)i(Database)27 +b(.)e(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 +b(30)345 294 y(2.5)52 b(Some)12 b(of)g(PostgreSQL)-5 +b(')m(s)13 b(Special)f(Features)g(in)g(Detail)41 b(.)25 +b(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 +b(31)459 354 y(2.5.1)61 b(Inheritance)36 b(.)26 b(.)f(.)g(.)h(.)f(.)g +(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.) +h(.)f(.)h(.)f(.)g(.)h(.)44 b(31)459 413 y(2.5.2)61 b(User)12 +b(De\002ned)g(Functions)g(.)26 b(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.) +g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 +b(33)619 473 y(Query)12 b(Language)g(\(SQL\))g(Functions)28 +b(.)d(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h +(.)44 b(33)619 533 y(Programming)10 b(Language)j(Functions)18 +b(.)25 b(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.) +h(.)44 b(35)459 593 y(2.5.3)61 b(User)12 b(De\002ned)g(T)l(ypes)18 +b(.)25 b(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.) +h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(36)459 653 y(2.5.4)61 +b(Extending)12 b(Operators)34 b(.)25 b(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g +(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 +b(39)459 712 y(2.5.5)61 b(Extending)12 b(Aggre)o(gates)42 +b(.)26 b(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.) +g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(40)459 772 y(2.5.6)61 +b(T)n(riggers)19 b(.)26 b(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h +(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.) +g(.)h(.)44 b(43)459 832 y(2.5.7)61 b(Serv)o(er)11 b(Programming)g +(Interface)g(\(SPI\))23 b(.)i(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h +(.)f(.)h(.)f(.)g(.)h(.)44 b(46)459 892 y(2.5.8)61 b(Rules)13 +b(in)f(PostgreSQL)27 b(.)e(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g +(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 +b(49)270 1001 y Fn(3)50 b(P)o(ostgr)o(eSQL)12 b(fr)o(om)h(the)f(Pr)o +(ogrammer')n(s)i(P)o(oint)e(of)g(V)n(iew)602 b(51)345 +1061 y Ft(3.1)52 b(The)13 b(W)l(ay)g(of)f(a)g(Query)j(.)26 +b(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h +(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(51)345 +1121 y(3.2)52 b(Ho)o(w)12 b(Connections)h(are)f(Established)48 +b(.)25 b(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.) +f(.)h(.)f(.)g(.)h(.)44 b(52)345 1181 y(3.3)52 b(The)13 +b(P)o(arser)f(Stage)47 b(.)25 b(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h +(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.) +g(.)h(.)44 b(52)459 1240 y(3.3.1)61 b(P)o(arser)25 b(.)g(.)h(.)f(.)h(.) +f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f +(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(53)459 +1300 y(3.3.2)61 b(T)n(ransformation)11 b(Process)i(.)26 +b(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h +(.)f(.)h(.)f(.)g(.)h(.)44 b(54)345 1360 y(3.4)52 b(The)13 +b(PostgreSQL)f(Rule)h(System)45 b(.)26 b(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.) +h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 +b(58)459 1420 y(3.4.1)61 b(The)13 b(Re)o(write)f(System)42 +b(.)25 b(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.) +f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(58)619 1479 y(T)m(echniques)12 +b(T)l(o)h(Implement)e(V)m(ie)o(ws)19 b(.)26 b(.)f(.)g(.)h(.)f(.)g(.)h +(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(58)345 +1539 y(3.5)52 b(Planner/Optimizer)14 b(.)25 b(.)h(.)f(.)g(.)h(.)f(.)g +(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.) +h(.)f(.)h(.)f(.)g(.)h(.)44 b(59)459 1599 y(3.5.1)61 b(Generating)11 +b(Possible)i(Plans)40 b(.)25 b(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f +(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(59)459 +1659 y(3.5.2)61 b(Data)12 b(Structure)f(of)h(the)h(Plan)42 +b(.)25 b(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.) +f(.)h(.)f(.)g(.)h(.)44 b(59)345 1719 y(3.6)52 b(Ex)o(ecutor)18 +b(.)25 b(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.) +f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g +(.)h(.)44 b(60)345 1778 y(3.7)52 b(The)13 b(Realization)g(of)e(the)i +(Ha)o(ving)f(Clause)45 b(.)25 b(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h +(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(62)459 1838 y(3.7.1)61 +b(Ho)o(w)12 b(Aggre)o(gate)g(Functions)g(are)g(Implemented)23 +b(.)j(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 +b(62)619 1898 y(The)13 b(P)o(arser)f(Stage)36 b(.)26 +b(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h +(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(62)619 1958 y(The)13 +b(Re)o(write)f(System)42 b(.)25 b(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h +(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 +b(63)619 2017 y(Planner/Optimizer)d(.)25 b(.)g(.)h(.)f(.)g(.)h(.)f(.)h +(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.) +44 b(63)619 2077 y(Ex)o(ecutor)h(.)25 b(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f +(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.) +h(.)f(.)g(.)h(.)44 b(65)459 2137 y(3.7.2)61 b(Ho)o(w)12 +b(the)g(Ha)o(ving)g(Clause)h(is)g(Implemented)25 b(.)g(.)g(.)h(.)f(.)g +(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(66)619 2197 +y(The)13 b(P)o(arser)f(Stage)36 b(.)26 b(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.) +h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h +(.)44 b(66)619 2257 y(The)13 b(Re)o(write)f(System)42 +b(.)25 b(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.) +f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(68)619 2316 y(Planner/Optimizer)d +(.)25 b(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h +(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(80)619 2376 y(Ex)o(ecutor)h(.) +25 b(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.) +g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 +b(87)345 2436 y(3.8)52 b(The)13 b(Realization)g(of)e(Union,)i +(Intersect)f(and)g(Except)43 b(.)25 b(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h +(.)f(.)h(.)f(.)g(.)h(.)44 b(89)459 2496 y(3.8.1)61 b(Ho)o(w)12 +b(Unions)g(ha)o(v)o(e)h(been)f(Realized)h(Until)f(V)-6 +b(ersion)13 b(6.3.2)42 b(.)25 b(.)h(.)f(.)h(.)f(.)g(.)h(.)44 +b(91)619 2555 y(The)13 b(P)o(arser)f(Stage)36 b(.)26 +b(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h +(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(91)619 2615 y(The)13 +b(Re)o(write)f(System)42 b(.)25 b(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h +(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 +b(92)619 2675 y(Planner/Optimizer)d(.)25 b(.)g(.)h(.)f(.)g(.)h(.)f(.)h +(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.) +44 b(92)619 2735 y(Ex)o(ecutor)h(.)25 b(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f +(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.) +h(.)f(.)g(.)h(.)44 b(93)459 2795 y(3.8.2)61 b(Ho)o(w)12 +b(Intersect,)g(Except)h(and)f(Union)g(W)l(ork)g(T)l(ogether)34 +b(.)26 b(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(93)619 +2854 y(Set)12 b(Operations)g(as)h(Propositional)e(Logic)i(F)o(ormulas)i +(.)25 b(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(95)459 +2914 y(3.8.3)61 b(Implementing)11 b(Intersect)h(and)g(Except)h(Using)f +(the)h(Union)f(Capabilities)k(.)26 b(.)44 b(95)619 2974 +y(P)o(arser)25 b(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.) +f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g +(.)h(.)44 b(98)619 3034 y(T)n(ransformations)h(.)26 b(.)f(.)g(.)h(.)f +(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.) +h(.)f(.)g(.)h(.)19 b(105)619 3093 y(The)13 b(Re)o(write)f(System)42 +b(.)25 b(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.) +f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)19 b(106)p eop +%%Page: 7 7 +7 6 bop 198 633 a Fq(List)32 b(of)f(Figur)n(es)273 892 +y Ft(1.1)52 b(The)13 b(suppliers)g(and)f(parts)g(database)36 +b(.)25 b(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.) +h(.)f(.)h(.)f(.)g(.)h(.)44 b(10)273 1001 y(3.1)52 b(Ho)o(w)12 +b(a)h(connection)f(is)h(established)42 b(.)25 b(.)g(.)h(.)f(.)h(.)f(.)g +(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 +b(52)273 1061 y(3.2)52 b Fp(T)-5 b(ar)n(getList)12 b +Ft(and)h Fp(F)m(r)n(omList)g Ft(for)e(query)h(of)g(e)o(xample)h(3.1)35 +b(.)25 b(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 +b(54)273 1121 y(3.3)52 b Fp(Wher)n(eClause)14 b Ft(for)e(query)g(of)g +(e)o(xample)g(3.1)23 b(.)i(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f +(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(55)273 1181 y(3.4)52 +b(T)n(ransformed)12 b Fp(T)-5 b(ar)n(getList)12 b Ft(and)h +Fp(F)m(r)n(omList)g Ft(for)e(query)h(of)g(e)o(xample)h(3.1)28 +b(.)e(.)f(.)h(.)f(.)g(.)h(.)44 b(56)273 1240 y(3.5)52 +b(T)n(ransformed)12 b Fp(wher)n(e)i(clause)e Ft(for)g(query)g(of)g(e)o +(xample)g(3.1)23 b(.)j(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 +b(57)273 1300 y(3.6)52 b Fp(Plan)13 b Ft(for)e(query)h(of)g(e)o(xample) +h(3.1)45 b(.)26 b(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g +(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(61)273 1360 +y(3.7)52 b Fp(Querytr)n(ee)14 b Ft(b)o(uilt)e(up)g(for)f(the)i(query)f +(of)g(e)o(xample)g(3.2)38 b(.)25 b(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f +(.)h(.)f(.)g(.)h(.)44 b(63)273 1420 y(3.8)52 b Fp(Plantr)n(ee)13 +b Ft(for)f(the)g(query)g(of)g(e)o(xample)h(3.2)46 b(.)25 +b(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g +(.)h(.)44 b(64)273 1479 y(3.9)52 b(Data)13 b(structure)f(handed)g(back) +g(by)h(the)f Fp(parser)49 b Ft(.)25 b(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h +(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)44 b(92)273 1539 y(3.10)27 +b Fp(Plan)13 b Ft(for)e(a)i(union)f(query)44 b(.)25 b(.)h(.)f(.)g(.)h +(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.) +f(.)h(.)f(.)g(.)h(.)44 b(93)273 1599 y(3.11)27 b Fp(Oper)o(ator)13 +b(tr)n(ee)g Ft(for)f Fl(\()p Fk(A)g Fo([)f Fk(B)r Fl(\))p +Fo(n)p Fl(\()p Fk(C)k Fo(\\)d Fk(D)q Fl(\))29 b Ft(.)d(.)f(.)h(.)f(.)g +(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)19 +b(101)273 1659 y(3.12)27 b(Data)13 b(structure)f(handed)g(back)g(by)h +Fr(SelectStmt)e Ft(rule)48 b(.)26 b(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f +(.)g(.)h(.)19 b(102)273 1719 y(3.13)27 b(Data)13 b(structure)f(of)f +Fl(\()p Fk(A)h Fo([)g Fk(B)r Fl(\))p Fo(n)p Fk(C)k Ft(after)11 +b(transformation)g(to)h(DNF)50 b(.)25 b(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.) +19 b(107)273 1778 y(3.14)27 b(Data)13 b(structure)f(of)f +Fk(A)h Fo(\\)f Fk(C)16 b Ft(after)c(query)f(re)o(writing)40 +b(.)26 b(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)g(.)h(.)f(.)h(.)f(.)g(.)h(.)19 +b(109)1086 3552 y(7)p eop +%%Page: 8 8 +8 7 bop eop +%%Page: 9 9 +9 8 bop 198 661 a Fj(Chapter)26 b(1)198 964 y Fq(SQL)198 +1276 y Ft(SQL)10 b(has)h(become)f(one)g(of)g(the)g(most)g(popular)f +(relational)g(query)h(languages)g(all)g(o)o(v)o(er)h(the)f(world.)k +(The)198 1336 y(name)i(\224SQL\224)g(is)g(an)g(abbre)o(viation)f(for)g +Fp(Structur)n(ed)h(Query)g(Language)p Ft(.)25 b(In)15 +b(1974)h(Donald)f(Cham-)198 1395 y(berlin)f(and)g(others)g(de\002ned)h +(the)f(language)g(SEQUEL)h Fp(\(Structur)n(ed)g(English)g(Query)g +(Language\))d Ft(at)198 1455 y(IBM)f(Research.)16 b(This)11 +b(language)f(was)h(\002rst)f(implemented)f(in)i(an)f(IBM)h(prototype)e +(called)i(SEQUEL-)198 1515 y(XRM)h(in)e(1974-75.)15 b(In)10 +b(1976-77)g(a)i(re)o(vised)e(v)o(ersion)h(of)g(SEQUEL)g(called)g +(SEQUEL/2)g(was)g(de\002ned)198 1575 y(and)h(the)h(name)f(was)g +(changed)h(to)f(SQL)h(subsequently)m(.)273 1688 y(A)j(ne)o(w)f +(prototype)g(called)h(System)g(R)g(was)g(de)o(v)o(eloped)g(by)f(IBM)h +(in)g(1977.)26 b(System)16 b(R)g(imple-)198 1748 y(mented)f(a)h(lar)o +(ge)f(subset)h(of)f(SEQUEL/2)h(\(no)o(w)f(SQL\))g(and)h(a)f(number)g +(of)g(changes)h(were)g(made)f(to)198 1808 y(SQL)i(during)e(the)h +(project.)28 b(System)16 b(R)h(was)f(installed)g(in)h(a)f(number)g(of)g +(user)g(sites,)j(both)d(internal)198 1867 y(IBM)d(sites)h(and)f(also)g +(some)h(selected)f(customer)g(sites.)19 b(Thanks)13 b(to)g(the)g +(success)i(and)e(acceptance)h(of)198 1927 y(System)d(R)g(at)g(those)g +(user)h(sites)f(IBM)g(started)g(to)g(de)o(v)o(elop)g(commercial)f +(products)h(that)g(implemented)198 1987 y(the)h(SQL)h(language)f(based) +h(on)f(the)h(System)f(R)g(technology)m(.)273 2100 y(Ov)o(er)g(the)g(ne) +o(xt)g(years)h(IBM)f(and)h(also)f(a)h(number)e(of)h(other)g(v)o(endors) +g(announced)g(SQL)g(products)198 2160 y(such)18 b(as)h(SQL/DS)e +(\(IBM\),)h(DB2)g(\(IBM\))f(ORA)n(CLE)i(\(Oracle)e(Corp.\))32 +b(DG/SQL)18 b(\(Data)f(General)198 2220 y(Corp.\))e(SYB)n(ASE)e +(\(Sybase)f(Inc.\).)273 2333 y(SQL)i(is)h(also)g(an)g(of)o(\002cial)e +(standard)h(no)o(w)m(.)22 b(In)14 b(1982)g(the)h(American)f(National)g +(Standards)g(Insti-)198 2392 y(tute)g(\(ANSI\))e(chartered)h(its)h +(Database)h(Committee)e(X3H2)g(to)h(de)o(v)o(elop)g(a)g(proposal)f(for) +g(a)h(standard)198 2452 y(relational)9 b(language.)16 +b(This)10 b(proposal)g(was)h(rati\002ed)e(in)h(1986)g(and)g(consisted)h +(essentially)g(of)f(the)g(IBM)198 2512 y(dialect)j(of)f(SQL.)i(In)e +(1987)g(this)h(ANSI)f(standard)h(was)g(also)g(accepted)g(as)h(an)f +(international)e(standard)198 2572 y(by)h(the)g(International)f(Or)o +(ganization)g(for)g(Standardization)g(\(ISO\).)f(This)j(original)e +(standard)h(v)o(ersion)198 2632 y(of)k(SQL)g(is)h(often)f(referred)f +(to,)i(informally)m(,)f(as)h(\224SQL/86\224.)27 b(In)16 +b(1989)g(the)h(original)e(standard)h(was)198 2691 y(e)o(xtended)c(and)f +(this)h(ne)o(w)f(standard)g(is)h(often,)g(again)f(informally)m(,)f +(referred)h(to)g(as)h(\224SQL/89\224.)k(Also)11 b(in)198 +2751 y(1989,)i(a)f(related)g(standard)g(called)h Fp(Database)f +(Language)f(Embedded)i(SQL)f Ft(was)g(de)o(v)o(eloped.)273 +2864 y(The)22 b(ISO)f(and)h(ANSI)f(committees)g(ha)o(v)o(e)i(been)f +(working)e(for)h(man)o(y)h(years)g(on)f(the)h(de\002ni-)198 +2924 y(tion)g(of)g(a)h(greatly)f(e)o(xpanded)h(v)o(ersion)g(of)f(the)h +(original)e(standard,)26 b(referred)21 b(to)h(informally)g(as)198 +2984 y(\224SQL2\224)17 b(or)f(\224SQL/92\224.)27 b(This)18 +b(v)o(ersion)e(became)g(a)h(rati\002ed)f(standard)g(-)g +(\224International)f(Standard)198 3044 y(ISO/IEC)d(9075:1992)o(,)f +Fp(Database)f(Language)e(SQL)p Ft(\224)h(-)h(in)g(late)g(1992.)k +(\224SQL/92\224)c(is)g(the)g(v)o(ersion)g(nor)o(-)198 +3103 y(mally)h(meant)g(when)g(people)h(refer)e(to)h(\224the)h(SQL)f +(standard\224.)16 b(A)11 b(detailed)g(description)g(of)g +(\224SQL/92\224)198 3163 y(is)18 b(gi)o(v)o(en)f(in)h([D)n(A)-6 +b(TE96)q(].)31 b(At)18 b(the)f(time)h(of)f(writing)g(this)g(document)h +(a)g(ne)o(w)f(standard)h(informally)198 3223 y(referred)11 +b(to)i(as)g(\224SQL3\224)g(is)g(under)f(de)o(v)o(elopment.)17 +b(It)12 b(is)h(planned)f(to)h(make)f(SQL)h(a)g(turing-complete)198 +3283 y(language,)e(i.e.)h(all)f(computable)f(queries)g(\(e.g.)16 +b(recursi)o(v)o(e)10 b(queries\))g(will)h(be)f(possible.)16 +b(This)11 b(is)g(a)g(v)o(ery)198 3342 y(comple)o(x)h(task)h(and)g +(therefore)e(the)h(completion)g(of)g(the)h(ne)o(w)f(standard)g(can)h +(not)f(be)h(e)o(xpected)g(before)198 3402 y(1999.)1086 +3552 y(9)p eop +%%Page: 10 10 +10 9 bop 270 60 a Ft(10)1351 b Fm(CHAPTER)14 b(1.)28 +b(SQL)270 234 y Fi(1.1)71 b(The)18 b(Relational)f(Data)g(Model)270 +346 y Ft(As)10 b(mentioned)f(before,)h(SQL)g(is)g(a)g(relational)e +(language.)15 b(That)10 b(means)g(it)g(is)g(based)g(on)f(the)h +(\224relational)270 405 y(data)j(model\224)f(\002rst)g(published)h(by)f +(E.F)l(.)i(Codd)e(in)h(1970.)j(W)l(e)d(will)f(gi)o(v)o(e)h(a)f(formal)g +(description)g(of)g(the)270 465 y(relational)h(model)h(in)f(section)h +(1.1.1)h Fp(F)-5 b(ormal)14 b(Notion)g(of)g(the)f(Relational)h(Data)g +(Model)g Ft(b)o(ut)f(\002rst)h(we)270 525 y(want)e(to)g(ha)o(v)o(e)h(a) +f(look)g(at)h(it)f(from)f(a)i(more)f(intuiti)o(v)o(e)f(point)h(of)g +(vie)o(w)m(.)345 585 y(A)19 b Fp(r)n(elational)g(database)g +Ft(is)h(a)f(database)h(that)f(is)h(percei)o(v)o(ed)f(by)g(its)g(users)h +(as)g(a)f Fp(collection)g(of)270 645 y(tables)13 b Ft(\(and)f(nothing)g +(else)i(b)o(ut)e(tables\).)17 b(A)c(table)g(consists)h(of)e(ro)o(ws)h +(and)f(columns)h(where)g(each)g(ro)o(w)270 704 y(represents)g(a)g +(record)f(and)h(each)g(column)f(represents)h(an)g(attrib)o(ute)f(of)g +(the)h(records)f(contained)h(in)f(the)270 764 y(table.)k(Figure)11 +b(1.1)i(sho)o(ws)g(an)f(e)o(xample)h(of)f(a)g(database)h(consisting)g +(of)f(three)g(tables:)345 864 y Fo(\017)25 b Ft(SUPPLIER)16 +b(is)h(a)f(table)h(storing)e(the)i(number)f(\(SNO\),)f(the)i(name)f +(\(SN)n(AME\))g(and)h(the)f(city)395 924 y(\(CITY\))11 +b(of)h(a)h(supplier)m(.)345 1024 y Fo(\017)25 b Ft(P)-5 +b(AR)m(T)10 b(is)g(a)g(table)g(storing)f(the)h(number)f(\(PNO\))g(the)g +(name)h(\(PN)n(AME\))g(and)f(the)h(price)g(\(PRICE\))395 +1084 y(of)h(a)i(part.)345 1184 y Fo(\017)25 b Ft(SELLS)12 +b(stores)g(information)e(about)h(which)h(part)f(\(PNO\))g(is)h(sold)f +(by)h(which)f(supplier)h(\(SNO\).)395 1243 y(It)f(serv)o(es)j(in)e(a)g +(sense)i(to)e(connect)g(the)h(other)e(two)h(tables)h(together)m(.)360 +1391 y Fr(SUPPLIER)88 b(SNO)30 b(|)60 b(SNAME)f(|)h(CITY)178 +b(SELLS)90 b(SNO)29 b(|)h(PNO)659 1451 y(-----+---------+--------)326 +b(-----+-----)718 1511 y(1)60 b(|)g(Smith)f(|)30 b(London)417 +b(1)60 b(|)g(1)718 1571 y(2)g(|)g(Jones)f(|)30 b(Paris)447 +b(1)60 b(|)g(2)718 1631 y(3)g(|)g(Adams)f(|)30 b(Vienna)417 +b(2)60 b(|)g(4)718 1690 y(4)g(|)g(Blake)f(|)30 b(Rome)477 +b(3)60 b(|)g(1)1764 1750 y(3)g(|)g(3)1764 1810 y(4)g(|)g(2)360 +1870 y(PART)208 b(PNO)30 b(|)60 b(PNAME)f(|)h(PRICE)417 +b(4)60 b(|)g(3)659 1929 y(-----+---------+---------)355 +b(4)60 b(|)g(4)718 1989 y(1)g(|)g(Screw)f(|)89 b(10)718 +2049 y(2)60 b(|)g(Nut)119 b(|)g(8)718 2109 y(3)60 b(|)g(Bolt)89 +b(|)g(15)718 2169 y(4)60 b(|)g(Cam)119 b(|)89 b(25)729 +2328 y Ft(Figure)12 b(1.1:)j(The)e(suppliers)g(and)f(parts)g(database) +270 2448 y(The)h(tables)f(P)-5 b(AR)m(T)13 b(and)f(SUPPLIER)f(may)h(be) +g(re)o(garded)g(as)g Fp(entities)g Ft(and)g(SELLS)h(may)f(be)g(re)o +(garded)270 2507 y(as)h(a)g Fp(r)n(elationship)f Ft(between)g(a)h +(particular)e(part)h(and)h(a)f(particular)f(supplier)m(.)345 +2567 y(As)k(we)g(will)f(see)h(later)n(,)g(SQL)g(operates)g(on)f(tables) +h(like)f(the)h(ones)g(just)g(de\002ned)f(b)o(ut)g(before)g(that)270 +2627 y(we)f(will)e(study)i(the)f(theory)g(of)g(the)g(relational)g +(model.)270 2770 y Fh(1.1.1)59 b(F)o(ormal)13 b(Notion)i(of)f(the)h +(Relational)e(Data)i(Model)270 2864 y Ft(The)22 b(mathematical)f +(concept)g(underlying)f(the)h(relational)g(model)g(is)g(the)h +(set-theoretic)e Fp(r)n(elation)270 2924 y Ft(which)d(is)h(a)g(subset)g +(of)g(the)f(Cartesian)h(product)f(of)g(a)h(list)f(of)g(domains.)32 +b(This)18 b(set-theoretic)f Fp(r)n(ela-)270 2983 y(tion)i +Ft(gi)o(v)o(es)g(the)g(model)g(its)g(name)g(\(do)g(not)g(confuse)g(it)g +(with)g(the)g(relationship)f(from)g(the)h Fp(Entity-)270 +3043 y(Relationship)14 b(model)p Ft(\).)20 b(F)o(ormally)13 +b(a)h(domain)g(is)g(simply)g(a)g(set)g(of)g(v)o(alues.)21 +b(F)o(or)13 b(e)o(xample)h(the)g(set)h(of)270 3103 y(inte)o(gers)d(is)g +(a)g(domain.)j(Also)c(the)h(set)g(of)f(character)h(strings)f(of)g +(length)h(20)f(and)h(the)f(real)h(numbers)f(are)270 3163 +y(e)o(xamples)i(of)f(domains.)270 3283 y Fn(De\002nition)f(1.1)25 +b Ft(The)65 b Fp(Cartesian)g Ft(product)e(of)h(domains)h +Fk(D)1580 3290 y Fg(1)1602 3283 y Fk(;)8 b(D)1665 3290 +y Fg(2)1688 3283 y Fk(;)g(:)g(:)g(:)h(;)f(D)1840 3290 +y Ff(k)1929 3283 y Ft(written)270 3342 y Fk(D)311 3349 +y Fg(1)345 3342 y Fo(\002)i Fk(D)435 3349 y Fg(2)469 +3342 y Fo(\002)h Fk(:)d(:)g(:)j Fo(\002)g Fk(D)679 3349 +y Ff(k)757 3342 y Ft(is)54 b(the)g(set)g(of)f(all)h Fk(k)r +Ft(-tuples)e Fl(\()p Fk(v)1526 3349 y Fg(1)1549 3342 +y Fk(;)8 b(v)1595 3349 y Fg(2)1618 3342 y Fk(;)g(:)g(:)g(:)g(;)g(v)1752 +3349 y Ff(k)1777 3342 y Fl(\))54 b Ft(such)g(that)270 +3402 y Fk(v)294 3409 y Fg(1)330 3402 y Fo(2)14 b Fk(D)418 +3409 y Fg(1)441 3402 y Fk(;)8 b(v)487 3409 y Fg(2)523 +3402 y Fo(2)14 b Fk(D)611 3409 y Fg(2)634 3402 y Fk(;)8 +b(:)g(:)g(:)h(;)f(v)769 3409 y Ff(k)807 3402 y Fo(2)14 +b Fk(D)895 3409 y Ff(k)920 3402 y Ft(.)p eop +%%Page: 11 11 +11 10 bop 198 60 a Fm(1.2.)29 b(OPERA)-6 b(TIONS)12 b(IN)g(THE)i(RELA) +-6 b(TION)n(AL)14 b(D)n(A)-6 b(T)h(A)14 b(MODEL)521 b +Ft(11)198 234 y(F)o(or)16 b(e)o(xample,)h(when)f(we)g(ha)o(v)o(e)g +Fk(k)22 b Fl(=)f(2)p Ft(,)c Fk(D)989 241 y Fg(1)1032 +234 y Fl(=)j Fo(f)p Fl(0)p Fk(;)8 b Fl(1)p Fo(g)16 b +Ft(and)g Fk(D)1358 241 y Fg(2)1401 234 y Fl(=)21 b Fo(f)p +Fk(a;)8 b(b;)g(c)p Fo(g)p Ft(,)17 b(then)f Fk(D)1796 +241 y Fg(1)1833 234 y Fo(\002)d Fk(D)1926 241 y Fg(2)1965 +234 y Ft(is)198 294 y Fo(f)p Fl(\(0)p Fk(;)8 b(a)p Fl(\))p +Fk(;)g Fl(\(0)p Fk(;)g(b)p Fl(\))p Fk(;)g Fl(\(0)p Fk(;)g(c)p +Fl(\))p Fk(;)g Fl(\(1)p Fk(;)g(a)q Fl(\))p Fk(;)g Fl(\()q(1)p +Fk(;)g(b)p Fl(\))p Fk(;)h Fl(\(1)p Fk(;)f(c)p Fl(\))p +Fo(g)p Ft(.)198 420 y Fn(De\002nition)j(1.2)25 b Ft(A)13 +b(Relation)g(is)h(an)o(y)g(subset)f(of)g(the)h(Cartesian)f(product)g +(of)f(one)i(or)f(more)f(domains:)198 480 y Fk(R)i Fo(\022)e +Fk(D)342 487 y Fg(1)376 480 y Fo(\002)f Fk(D)467 487 +y Fg(2)500 480 y Fo(\002)g Fk(:)d(:)g(:)j Fo(\002)g Fk(D)710 +487 y Ff(k)198 584 y Ft(F)o(or)g(e)o(xample)h Fo(f)p +Fl(\(0)p Fk(;)c(a)p Fl(\))p Fk(;)g Fl(\(0)p Fk(;)g(b)p +Fl(\))p Fk(;)g Fl(\(1)p Fk(;)g(a)p Fl(\))p Fo(g)15 b +Ft(is)d(a)g(relation,)f(it)g(is)h(in)g(fact)f(a)g(subset)i(of)e +Fk(D)1635 591 y Fg(1)1666 584 y Fo(\002)d Fk(D)1754 591 +y Fg(2)1788 584 y Ft(mentioned)198 644 y(abo)o(v)o(e.)15 +b(The)10 b(members)g(of)f(a)h(relation)e(are)i(called)f(tuples.)15 +b(Each)10 b(relation)f(of)g(some)h(Cartesian)g(product)198 +703 y Fk(D)239 710 y Fg(1)273 703 y Fo(\002)g Fk(D)363 +710 y Fg(2)397 703 y Fo(\002)h Fk(:)d(:)g(:)j Fo(\002)g +Fk(D)607 710 y Ff(k)644 703 y Ft(is)i(said)g(to)f(ha)o(v)o(e)g(arity)g +Fk(k)i Ft(and)f(is)f(therefore)f(a)i(set)g(of)f Fk(k)r +Ft(-tuples.)273 764 y(A)j(relation)f(can)h(be)f(vie)o(wed)h(as)g(a)g +(table)g(\(as)g(we)g(already)f(did,)i(remember)d(\002gure)i(1.1)g +Fp(The)f(sup-)198 824 y(pliers)j(and)g(parts)h(database)p +Ft(\))f(where)g(e)o(v)o(ery)g(tuple)g(is)g(represented)g(by)g(a)h(ro)o +(w)e(and)i(e)o(v)o(ery)f(column)198 884 y(corresponds)c(to)h(one)f +(component)g(of)g(a)h(tuple.)19 b(Gi)o(ving)13 b(names)h(\(called)f +(attrib)o(utes\))f(to)i(the)f(columns)198 944 y(leads)g(to)f(the)g +(de\002nition)g(of)g(a)g Fp(r)n(elation)h(sc)o(heme)p +Ft(.)198 1070 y Fn(De\002nition)e(1.3)25 b Ft(A)12 b +Fp(r)n(elation)g(sc)o(heme)h Fk(R)g Ft(is)f(a)g(\002nite)g(set)g(of)g +(attrib)o(utes)g Fo(f)p Fk(A)1507 1077 y Fg(1)1529 1070 +y Fk(;)c(A)1588 1077 y Fg(2)1611 1070 y Fk(;)g(:)g(:)g(:)h(;)f(A)1759 +1077 y Ff(k)1784 1070 y Fo(g)p Ft(.)15 b(There)e(is)198 +1130 y(a)h(domain)g Fk(D)439 1137 y Ff(i)470 1130 y Ft(for)g(each)g +(attrib)o(ute)g Fk(A)865 1137 y Ff(i)882 1130 y Fk(;)8 +b Fl(1)17 b Fo(\024)g Fk(i)g Fo(\024)g Fk(k)f Ft(where)e(the)g(v)o +(alues)h(of)f(the)g(attrib)o(utes)f(are)i(taken)198 1189 +y(from.)g(W)l(e)d(often)g(write)g(a)h(relation)e(scheme)i(as)g +Fk(R)p Fl(\()p Fk(A)1139 1196 y Fg(1)1162 1189 y Fk(;)8 +b(A)1221 1196 y Fg(2)1244 1189 y Fk(;)g(:)g(:)g(:)h(;)f(A)1392 +1196 y Ff(k)1417 1189 y Fl(\))p Ft(.)198 1293 y Fn(Note:)21 +b Ft(A)15 b Fp(r)n(elation)g(sc)o(heme)i Ft(is)e(just)h(a)f(kind)g(of)g +(template)g(whereas)h(a)g Fp(r)n(elation)f Ft(is)h(an)f(instance)h(of)f +(a)198 1353 y Fp(r)n(elation)h(sc)o(heme)p Ft(.)26 b(The)17 +b Fp(r)n(elation)e Ft(consists)i(of)e(tuples)h(\(and)f(can)h(therefore) +e(be)i(vie)o(wed)f(as)i(a)f(table\))198 1413 y(not)c(so)h(the)f +Fp(r)n(elation)h(sc)o(heme)p Ft(.)198 1552 y Fn(Domains)g(vs.)j(Data)c +(T)l(ypes)198 1647 y Ft(W)l(e)j(often)g(talked)f(about)h +Fp(domains)g Ft(in)g(the)g(last)g(section.)25 b(Recall)15 +b(that)g(a)g(domain)g(is,)h(formally)m(,)f(just)198 1707 +y(a)f(set)g(of)f(v)o(alues)h(\(e.g.,)h(the)e(set)h(of)g(inte)o(gers)f +(or)g(the)h(real)f(numbers\).)19 b(In)13 b(terms)h(of)f(database)h +(systems)198 1767 y(we)f(often)f(talk)g(of)g Fp(data)h(types)g +Ft(instead)g(of)f(domains.)k(When)d(we)g(de\002ne)f(a)h(table)g(we)f +(ha)o(v)o(e)h(to)g(make)f(a)198 1827 y(decision)j(about)f(which)g +(attrib)o(utes)g(to)g(include.)22 b(Additionally)14 b(we)g(ha)o(v)o(e)h +(to)g(decide)f(which)g(kind)h(of)198 1886 y(data)f(is)f(going)g(to)h +(be)f(stored)h(as)g(attrib)o(ute)e(v)o(alues.)20 b(F)o(or)13 +b(e)o(xample)g(the)h(v)o(alues)f(of)h(SN)n(AME)g(from)e(the)198 +1946 y(table)g(SUPPLIER)f(will)g(be)h(character)f(strings,)h(whereas)g +(SNO)f(will)h(store)f(inte)o(gers.)16 b(W)l(e)c(de\002ne)f(this)198 +2006 y(by)f(assigning)f(a)h Fp(data)g(type)f Ft(to)h(each)g(attrib)o +(ute.)k(The)c(type)f(of)h(SN)n(AME)g(will)f(be)h(V)-7 +b(ARCHAR\(20\))9 b(\(this)198 2066 y(is)14 b(the)f(SQL)h(type)f(for)g +(character)g(strings)g(of)h(length)f Fo(\024)g Ft(20\),)h(the)f(type)h +(of)f(SNO)g(will)g(be)g(INTEGER.)198 2125 y(W)n(ith)i(the)h(assignment) +g(of)f(a)g Fp(data)h(type)f Ft(we)h(also)g(ha)o(v)o(e)g(selected)g(a)g +(domain)f(for)f(an)i(attrib)o(ute.)25 b(The)198 2185 +y(domain)12 b(of)g(SN)n(AME)i(is)f(the)f(set)h(of)f(all)h(character)f +(strings)h(of)f(length)g Fo(\024)h Ft(20,)g(the)f(domain)g(of)g(SNO)h +(is)198 2245 y(the)f(set)h(of)f(all)g(inte)o(ger)g(numbers.)198 +2419 y Fi(1.2)71 b(Operations)17 b(in)h(the)f(Relational)g(Data)g +(Model)198 2533 y Ft(In)11 b(section)h(1.1.1)g(we)g(de\002ned)f(the)g +(mathematical)g(notion)g(of)g(the)h(relational)f(model.)k(No)o(w)c(we)h +(kno)o(w)198 2592 y(ho)o(w)j(the)g(data)h(can)g(be)f(stored)g(using)h +(a)f(relational)g(data)g(model)g(b)o(ut)h(we)f(do)h(not)f(kno)o(w)g +(what)g(to)g(do)198 2652 y(with)g(all)f(these)i(tables)f(to)g(retrie)o +(v)o(e)f(something)g(from)g(the)h(database)g(yet.)24 +b(F)o(or)14 b(e)o(xample)h(somebody)198 2712 y(could)i(ask)g(for)f(the) +h(names)g(of)g(all)g(suppliers)g(that)g(sell)g(the)g(part)f('Scre)o +(w'.)28 b(Therefore)17 b(two)f(rather)198 2772 y(dif)o(ferent)11 +b(kinds)h(of)g(notations)g(for)g(e)o(xpressing)g(operations)g(on)h +(relations)f(ha)o(v)o(e)g(been)h(de\002ned:)273 2875 +y Fo(\017)25 b Ft(The)14 b Fp(Relational)f(Algebr)o(a)g +Ft(which)h(is)f(an)h(algebraic)f(notation,)g(where)h(queries)f(are)g(e) +o(xpressed)323 2934 y(by)f(applying)g(specialized)g(operators)g(to)g +(the)h(relations.)273 3039 y Fo(\017)25 b Ft(The)13 b +Fp(Relational)f(Calculus)h Ft(which)f(is)h(a)g(logical)g(notation,)f +(where)h(queries)f(are)h(e)o(xpressed)g(by)323 3098 y(formulating)d +(some)j(logical)f(restrictions)g(that)g(the)g(tuples)h(in)f(the)g +(answer)h(must)f(satisfy)m(.)198 3247 y Fh(1.2.1)59 b(Relational)14 +b(Algebra)198 3342 y Ft(The)20 b Fp(Relational)f(Algebr)o(a)h +Ft(was)f(introduced)g(by)g(E.)i(F)l(.)e(Codd)h(in)f(1972.)37 +b(It)19 b(consists)h(of)f(a)h(set)g(of)198 3402 y(operations)12 +b(on)g(relations:)p eop +%%Page: 12 12 +12 11 bop 270 60 a Ft(12)1351 b Fm(CHAPTER)14 b(1.)28 +b(SQL)345 234 y Fo(\017)d Ft(SELECT)17 b(\()p Fk(\033)r +Ft(\):)j(e)o(xtracts)c Fp(tuples)g Ft(from)e(a)i(relation)e(that)i +(satisfy)f(a)h(gi)o(v)o(en)f(restriction.)24 b(Let)16 +b Fk(R)395 294 y Ft(be)f(a)h(table)g(that)f(contains)h(an)g(attrib)o +(ute)e Fk(A)p Ft(.)27 b Fk(\033)1227 301 y Ff(A)p Fg(=)p +Ff(a)1312 294 y Fl(\()p Fk(R)p Fl(\))21 b(=)e Fo(f)p +Fk(t)h Fo(2)g Fk(R)g Fo(j)g Fk(t)p Fl(\()p Fk(A)p Fl(\))h(=)f +Fk(a)p Fo(g)c Ft(where)f Fk(t)395 354 y Ft(denotes)d(a)h(tuple)f(of)g +Fk(R)g Ft(and)h Fk(t)p Fl(\()p Fk(A)p Fl(\))g Ft(denotes)g(the)f(v)o +(alue)g(of)g(attrib)o(ute)g Fk(A)h Ft(of)f(tuple)g Fk(t)p +Ft(.)345 471 y Fo(\017)25 b Ft(PR)n(OJECT)17 b(\()p Fk(\031)r +Ft(\):)22 b(e)o(xtracts)16 b(speci\002ed)g Fp(attrib)o(utes)g +Ft(\(columns\))f(from)g(a)h(relation.)26 b(Let)17 b Fk(R)f +Ft(be)g(a)395 530 y(relation)10 b(that)h(contains)g(an)g(attrib)o(ute)f +Fk(X)t Ft(.)16 b Fk(\031)1156 537 y Ff(X)1194 530 y Fl(\()p +Fk(R)p Fl(\))f(=)f Fo(f)p Fk(t)p Fl(\()p Fk(X)t Fl(\))g +Fo(j)g Fk(t)g Fo(2)g Fk(R)p Fo(g)p Ft(,)e(where)f Fk(t)p +Fl(\()p Fk(X)t Fl(\))h Ft(denotes)395 590 y(the)g(v)o(alue)g(of)g +(attrib)o(ute)f Fk(X)17 b Ft(of)12 b(tuple)g Fk(t)p Ft(.)345 +707 y Fo(\017)25 b Ft(PR)n(ODUCT)12 b(\()p Fo(\002)p +Ft(\):)i(b)o(uilds)f(the)f(Cartesian)g(product)g(of)f(two)h(relations.) +j(Let)e Fk(R)g Ft(be)f(a)g(table)g(with)395 767 y(arity)i +Fk(k)527 774 y Fg(1)564 767 y Ft(and)h(let)g Fk(S)i Ft(be)e(a)g(table)g +(with)f(arity)g Fk(k)1210 774 y Fg(2)1233 767 y Ft(.)23 +b Fk(R)13 b Fo(\002)g Fk(S)k Ft(is)e(the)g(set)g(of)g(all)g +Fl(\()p Fk(k)1780 774 y Fg(1)1815 767 y Fl(+)e Fk(k)1893 +774 y Fg(2)1915 767 y Fl(\))p Ft(-tuples)395 827 y(whose)h(\002rst)f +Fk(k)653 834 y Fg(1)690 827 y Ft(components)g(form)g(a)h(tuple)g(in)g +Fk(R)g Ft(and)g(whose)g(last)g Fk(k)1646 834 y Fg(2)1682 +827 y Ft(components)g(form)f(a)395 887 y(tuple)f(in)g +Fk(S)s Ft(.)345 1004 y Fo(\017)25 b Ft(UNION)13 b(\()p +Fo([)p Ft(\):)18 b(b)o(uilds)c(the)g(set-theoretic)f(union)h(of)g(two)f +(tables.)21 b(Gi)o(v)o(en)14 b(the)g(tables)g Fk(R)h +Ft(and)f Fk(S)395 1063 y Ft(\(both)e(must)g(ha)o(v)o(e)h(the)g(same)g +(arity\),)g(the)f(union)h Fk(R)e Fo([)h Fk(S)j Ft(is)e(the)g(set)g(of)g +(tuples)g(that)f(are)h(in)f Fk(R)i Ft(or)395 1123 y Fk(S)g +Ft(or)e(both.)345 1240 y Fo(\017)25 b Ft(INTERSECT)12 +b(\()p Fo(\\)p Ft(\):)h(b)o(uilds)e(the)f(set-theoretic)g(intersection) +g(of)g(two)g(tables.)16 b(Gi)o(v)o(en)10 b(the)h(tables)395 +1300 y Fk(R)j Ft(and)f Fk(S)s Ft(,)i Fk(R)d Fo([)g Fk(S)17 +b Ft(is)d(the)g(set)g(of)f(tuples)h(that)g(are)g(in)f +Fk(R)h Ft(and)g(in)g Fk(S)s Ft(.)20 b(W)l(e)14 b(again)f(require)g +(that)h Fk(R)395 1360 y Ft(and)e Fk(S)j Ft(ha)o(v)o(e)e(the)f(same)h +(arity)m(.)345 1477 y Fo(\017)25 b Ft(DIFFERENCE)14 b(\()p +Fo(\000)g Ft(or)f Fo(n)p Ft(\):)18 b(b)o(uilds)c(the)g(set)h(dif)o +(ference)d(of)i(two)f(tables.)21 b(Let)15 b Fk(R)f Ft(and)g +Fk(S)i Ft(again)395 1536 y(be)c(two)g(tables)g(with)g(the)h(same)g +(arity)m(.)h Fk(R)e Fo(\000)f Fk(S)j Ft(is)f(the)f(set)h(of)f(tuples)h +(in)f Fk(R)h Ft(b)o(ut)f(not)g(in)g Fk(S)s Ft(.)345 1653 +y Fo(\017)25 b Ft(JOIN)d(\()p Fe(1)p Ft(\):)36 b(connects)23 +b(two)g(tables)g(by)g(their)f(common)g(attrib)o(utes.)47 +b(Let)24 b Fk(R)f Ft(be)g(a)g(table)395 1713 y(with)18 +b(the)g(attrib)o(utes)g Fk(A;)8 b(B)22 b Ft(and)c Fk(C)k +Ft(and)c(let)h Fk(S)i Ft(a)e(table)f(with)g(the)h(attrib)o(utes)f +Fk(C)q(;)8 b(D)19 b Ft(and)g Fk(E)s Ft(.)395 1773 y(There)k(is)g(one)g +(attrib)o(ute)f(common)g(to)h(both)f(relations,)k(the)d(attrib)o(ute)f +Fk(C)t Ft(.)47 b Fk(R)33 b Fe(1)g Fk(S)j Fl(=)395 1833 +y Fk(\031)423 1840 y Ff(R:A;R:B)r(;R:C;S:D)q(;S:E)826 +1833 y Fl(\()p Fk(\033)873 1840 y Ff(R:C)r Fg(=)p Ff(S:C)1047 +1833 y Fl(\()p Fk(R)15 b Fo(\002)e Fk(S)s Fl(\)\))p Ft(.)27 +b(What)16 b(are)g(we)g(doing)f(here?)27 b(W)l(e)16 b(\002rst)f(cal-)395 +1893 y(culate)g(the)h(Cartesian)f(product)g Fk(R)f Fo(\002)f +Fk(S)s Ft(.)24 b(Then)16 b(we)g(select)g(those)g(tuples)f(whose)h(v)o +(alues)g(for)395 1952 y(the)c(common)g(attrib)o(ute)g +Fk(C)k Ft(are)d(equal)f(\()p Fk(\033)1124 1959 y Ff(R:C)r +Fg(=)p Ff(S:C)1297 1952 y Ft(\).)17 b(No)o(w)12 b(we)h(got)f(a)h(table) +g(that)f(contains)h(the)395 2012 y(attrib)o(ute)e Fk(C)16 +b Ft(two)11 b(times)i(and)f(we)h(correct)e(this)i(by)f(projecting)f +(out)i(the)f(duplicate)g(column.)395 2153 y Fn(Example)g(1.1)25 +b Ft(Let')m(s)11 b(ha)o(v)o(e)g(a)g(look)f(at)g(the)g(tables)h(that)f +(are)h(produced)e(by)i(e)o(v)o(aluating)e(the)h(steps)395 +2213 y(necessary)j(for)e(a)i(join.)395 2273 y(Let)f(the)h(follo)o(wing) +e(two)g(tables)i(be)f(gi)o(v)o(en:)664 2410 y Fr(R)89 +b(A)30 b(|)g(B)f(|)h(C)179 b(S)90 b(C)30 b(|)f(D)h(|)g(E)753 +2470 y(---+---+---)238 b(---+---+---)783 2529 y(1)30 +b(|)g(2)f(|)h(3)299 b(3)30 b(|)f(a)h(|)g(b)783 2589 y(4)g(|)g(5)f(|)h +(6)299 b(6)30 b(|)f(c)h(|)g(d)783 2649 y(7)g(|)g(8)f(|)h(9)395 +2786 y Ft(First)11 b(we)i(calculate)f(the)h(Cartesian)f(product)g +Fk(R)f Fo(\002)g Fk(S)k Ft(and)d(get:)604 2923 y Fr(R)30 +b(x)f(S)90 b(A)30 b(|)f(B)h(|)g(R.C)g(|)f(S.C)h(|)g(D)f(|)h(E)813 +2983 y(---+---+-----+-----+---+---)843 3042 y(1)g(|)f(2)h(|)60 +b(3)g(|)f(3)h(|)30 b(a)f(|)h(b)843 3102 y(1)g(|)f(2)h(|)60 +b(3)g(|)f(6)h(|)30 b(c)f(|)h(d)843 3162 y(4)g(|)f(5)h(|)60 +b(6)g(|)f(3)h(|)30 b(a)f(|)h(b)843 3222 y(4)g(|)f(5)h(|)60 +b(6)g(|)f(6)h(|)30 b(c)f(|)h(d)843 3281 y(7)g(|)f(8)h(|)60 +b(9)g(|)f(3)h(|)30 b(a)f(|)h(b)843 3341 y(7)g(|)f(8)h(|)60 +b(9)g(|)f(6)h(|)30 b(c)f(|)h(d)p eop +%%Page: 13 13 +13 12 bop 198 60 a Fm(1.2.)29 b(OPERA)-6 b(TIONS)12 b(IN)g(THE)i(RELA) +-6 b(TION)n(AL)14 b(D)n(A)-6 b(T)h(A)14 b(MODEL)521 b +Ft(13)323 234 y(After)11 b(the)h(selection)h Fk(\033)731 +241 y Ff(R:C)r Fg(=)p Ff(S:C)905 234 y Fl(\()p Fk(R)e +Fo(\002)g Fk(S)s Fl(\))h Ft(we)h(get:)771 347 y Fr(A)30 +b(|)f(B)h(|)g(R.C)g(|)f(S.C)h(|)g(D)f(|)h(E)741 407 y +(---+---+-----+-----+---+---)771 467 y(1)g(|)f(2)h(|)60 +b(3)g(|)f(3)h(|)30 b(a)f(|)h(b)771 526 y(4)g(|)f(5)h(|)60 +b(6)g(|)f(6)h(|)30 b(c)f(|)h(d)323 639 y Ft(T)l(o)16 +b(remo)o(v)o(e)g(the)f(duplicate)h(column)f Fk(S:C)k +Ft(we)d(project)f(it)h(out)f(by)h(the)g(follo)o(wing)e(operation:)323 +699 y Fk(\031)351 706 y Ff(R:A;R:B)r(;R:C;S:D)q(;S:E)754 +699 y Fl(\()p Fk(\033)801 706 y Ff(R:C)r Fg(=)p Ff(S:C)975 +699 y Fl(\()p Fk(R)e Fo(\002)f Fk(S)s Fl(\)\))h Ft(and)h(get:)890 +812 y Fr(A)30 b(|)g(B)g(|)g(C)f(|)h(D)g(|)g(E)861 872 +y(---+---+---+---+---)890 931 y(1)g(|)g(2)g(|)g(3)f(|)h(a)g(|)g(b)890 +991 y(4)g(|)g(5)g(|)g(6)f(|)h(c)g(|)g(d)273 1104 y Fo(\017)25 +b Ft(DIVIDE)11 b(\()p Fo(\004)p Ft(\):)k(Let)d Fk(R)g +Ft(be)g(a)g(table)g(with)f(the)h(attrib)o(utes)f Fk(A;)d(B)r(;)g(C)16 +b Ft(and)c Fk(D)i Ft(and)d(let)h Fk(S)i Ft(be)e(a)g(table)323 +1164 y(with)i(the)h(attrib)o(utes)f Fk(C)k Ft(and)d Fk(D)q +Ft(.)24 b(Then)16 b(we)f(de\002ne)g(the)f(di)o(vision)h(as:)21 +b Fk(R)13 b Fo(\004)g Fk(S)21 b Fl(=)e Fo(f)p Fk(t)f +Fo(j)g(8)p Fk(t)1926 1171 y Ff(s)1965 1164 y Fo(2)323 +1224 y Fk(S)c Fo(9)p Fk(t)414 1231 y Ff(r)450 1224 y +Fo(2)g Fk(R)e Ft(such)g(that)g Fk(t)755 1231 y Ff(r)777 +1224 y Fl(\()p Fk(A;)c(B)r Fl(\))15 b(=)f Fk(t)21 b Fo(^)h +Fk(t)1094 1231 y Ff(r)1116 1224 y Fl(\()p Fk(C)q(;)8 +b(D)q Fl(\))15 b(=)e Fk(t)1340 1231 y Ff(s)1362 1224 +y Fo(g)f Ft(where)f Fk(t)1550 1231 y Ff(r)1572 1224 y +Fl(\()p Fk(x;)d(y)r Fl(\))14 b Ft(denotes)e(a)g(tuple)323 +1283 y(of)i(table)g Fk(R)h Ft(that)g(consists)g(only)f(of)g(the)h +(components)f Fk(x)i Ft(and)e Fk(y)r Ft(.)23 b(Note)14 +b(that)h(the)f(tuple)h Fk(t)f Ft(only)323 1343 y(consists)f(of)f(the)g +(components)g Fk(A)h Ft(and)f Fk(B)j Ft(of)d(relation)g +Fk(R)p Ft(.)323 1459 y Fn(Example)g(1.2)25 b Ft(Gi)o(v)o(en)13 +b(the)f(follo)o(wing)f(tables)621 1571 y Fr(R)90 b(A)30 +b(|)g(B)f(|)h(C)g(|)g(D)239 b(S)89 b(C)30 b(|)g(D)711 +1631 y(---+---+---+---)297 b(---+---)741 1691 y(a)30 +b(|)g(b)f(|)h(c)g(|)g(d)358 b(c)30 b(|)g(d)741 1751 y(a)g(|)g(b)f(|)h +(e)g(|)g(f)358 b(e)30 b(|)g(f)741 1811 y(b)g(|)g(c)f(|)h(e)g(|)g(f)741 +1870 y(e)g(|)g(d)f(|)h(c)g(|)g(d)741 1930 y(e)g(|)g(d)f(|)h(e)g(|)g(f) +741 1990 y(a)g(|)g(b)f(|)h(d)g(|)g(e)323 2103 y Fk(R)11 +b Fo(\004)h Fk(S)i Ft(is)f(deri)o(v)o(ed)f(as)1070 2216 +y Fr(A)30 b(|)f(B)1040 2275 y(---+---)1070 2335 y(a)h(|)f(b)1070 +2395 y(e)h(|)f(d)198 2508 y Ft(F)o(or)12 b(a)g(more)g(detailed)g +(description)g(and)g(de\002nition)g(of)g(the)g(relational)g(algebra)g +(refer)f(to)h([ULL88])h(or)198 2568 y([D)n(A)-6 b(TE94)q(].)198 +2683 y Fn(Example)13 b(1.3)25 b Ft(Recall)12 b(that)g(we)h(formulated)e +(all)h(those)g(relational)g(operators)f(to)h(be)h(able)f(to)g(retrie)o +(v)o(e)198 2743 y(data)i(from)e(the)i(database.)20 b(Let')m(s)14 +b(return)f(to)g(our)g(e)o(xample)h(of)f(section)h(1.2)g(where)f +(someone)h(wanted)198 2803 y(to)d(kno)o(w)f(the)h(names)g(of)g(all)g +(suppliers)f(that)h(sell)g(the)g(part)g('Scre)o(w'.)i(This)f(question)f +(can)g(be)g(answered)198 2862 y(using)h(relational)g(algebra)g(by)g +(the)h(follo)o(wing)e(operation:)222 2965 y Fk(\031)250 +2972 y Ff(S)r(U)t(P)5 b(P)g(LI)s(E)r(R:S)r(N)t(AM)t(E)657 +2965 y Fl(\()p Fk(\033)704 2972 y Ff(P)g(ART)s(:P)g(N)t(AM)t(E)r +Fg(=)1033 2963 y Fd(0)1047 2972 y Ff(S)r(cr)q(ew)1159 +2963 y Fd(0)1176 2965 y Fl(\()p Fk(S)s(U)g(P)i(P)g(LI)t(E)s(R)13 +b Fe(1)h Fk(S)s(E)s(LLS)h Fe(1)f Fk(P)7 b(ART)g Fl(\)\))198 +3068 y Ft(W)l(e)14 b(call)g(such)g(an)g(operation)g(a)g(query)m(.)20 +b(If)13 b(we)h(e)o(v)o(aluate)f(the)h(abo)o(v)o(e)h(query)e(against)h +(the)g(tables)g(form)198 3128 y(\002gure)e(1.1)g Fp(The)h(suppliers)f +(and)g(parts)h(database)g Ft(we)f(will)g(obtain)g(the)g(follo)o(wing)f +(result:)1065 3222 y Fr(SNAME)1035 3282 y(-------)1065 +3342 y(Smith)1065 3402 y(Adams)p eop +%%Page: 14 14 +14 13 bop 270 60 a Ft(14)1351 b Fm(CHAPTER)14 b(1.)28 +b(SQL)270 234 y Fh(1.2.2)59 b(Relational)14 b(Calculus)270 +332 y Ft(The)20 b(relational)f(calculus)g(is)h(based)g(on)f(the)g +(\002rst)g(order)g(logic.)37 b(There)19 b(are)h(two)e(v)o(ariants)h(of) +g(the)270 391 y(relational)12 b(calculus:)345 498 y Fo(\017)25 +b Ft(The)13 b Fp(Domain)g(Relational)f(Calculus)i Ft(\(DRC\),)f(where)g +(v)o(ariables)f(stand)i(for)e(components)h(\(at-)395 +557 y(trib)o(utes\))e(of)h(the)g(tuples.)345 666 y Fo(\017)25 +b Ft(The)12 b Fp(T)m(uple)h(Relational)f(Calculus)g Ft(\(TRC\),)h +(where)f(v)o(ariables)g(stand)h(for)f(tuples.)270 772 +y(W)l(e)j(want)g(to)g(discuss)h(the)f(tuple)g(relational)f(calculus)h +(only)g(because)h(it)f(is)g(the)g(one)g(underlying)f(the)270 +832 y(most)c(relational)g(languages.)16 b(F)o(or)10 b(a)g(detailed)g +(discussion)h(on)g(DRC)g(\(and)f(also)h(TRC\))g(see)g([D)n(A)-6 +b(TE94])270 891 y(or)12 b([ULL88].)270 1036 y Fn(T)-5 +b(uple)12 b(Relational)g(Calculus)270 1133 y Ft(The)h(queries)f(used)h +(in)f(TRC)i(are)e(of)g(the)g(follo)o(wing)f(form:)1019 +1247 y Fo(f)p Fk(x)p Fl(\()p Fk(A)p Fl(\))k Fo(j)f Fk(F)7 +b Fl(\()p Fk(x)p Fl(\))p Fo(g)270 1361 y Ft(where)k Fk(x)h +Ft(is)g(a)f(tuple)g(v)o(ariable)g Fk(A)h Ft(is)g(a)f(set)h(of)f(attrib) +o(utes)g(and)g Fk(F)19 b Ft(is)11 b(a)h(formula.)i(The)e(resulting)f +(relation)270 1421 y(consists)i(of)f(all)g(tuples)h Fk(t)p +Fl(\()p Fk(A)p Fl(\))g Ft(that)g(satisfy)f Fk(F)7 b Fl(\()p +Fk(t)p Fl(\))p Ft(.)270 1554 y Fn(Example)13 b(1.4)25 +b Ft(If)9 b(we)h(want)g(to)g(answer)g(the)g(question)g(from)f(e)o +(xample)h(1.3)g(using)g(TRC)h(we)f(formulate)270 1613 +y(the)i(follo)o(wing)f(query:)370 1725 y Fo(f)p Fk(x)p +Fl(\()p Fk(S)s(N)5 b(AM)g(E)s Fl(\))51 b Fo(j)f Fk(x)14 +b Fo(2)g Fk(S)s(U)5 b(P)i(P)g(LI)t(E)s(R)12 b Fo(^)785 +1785 y(9)p Fk(y)k Fo(2)e Fk(S)s(E)s(LLS)g Fo(9)p Fk(z)h +Fo(2)f Fk(P)7 b(ART)58 b Fl(\()p Fk(y)r Fl(\()p Fk(S)s(N)5 +b(O)q Fl(\))15 b(=)f Fk(x)p Fl(\()p Fk(S)s(N)5 b(O)q +Fl(\))14 b Fo(^)1413 1845 y Fk(z)r Fl(\()p Fk(P)7 b(N)e(O)q +Fl(\))16 b(=)d Fk(y)r Fl(\()p Fk(P)7 b(N)e(O)q Fl(\))15 +b Fo(^)1413 1904 y Fk(z)r Fl(\()p Fk(P)7 b(N)e(AM)g(E)s +Fl(\))16 b(=)1745 1886 y Fc(0)1773 1904 y Fk(S)s(cr)q(ew)1912 +1886 y Fc(0)1926 1904 y Fl(\))p Fo(g)270 2016 y Ft(Ev)o(aluating)f(the) +h(query)f(against)h(the)f(tables)h(from)e(\002gure)h(1.1)h +Fp(The)g(suppliers)g(and)f(parts)h(database)270 2075 +y Ft(again)c(leads)h(to)f(the)g(same)h(result)f(as)h(in)g(e)o(xample)f +(1.3.)270 2230 y Fh(1.2.3)59 b(Relational)14 b(Algebra)f(vs.)19 +b(Relational)13 b(Calculus)270 2327 y Ft(The)j(relational)g(algebra)f +(and)h(the)g(relational)f(calculus)i(ha)o(v)o(e)f(the)g(same)g +Fp(e)o(xpr)n(essive)i(power)e Ft(i.e.)h(all)270 2387 +y(queries)g(that)f(can)i(be)e(formulated)g(using)h(relational)f +(algebra)h(can)g(also)g(be)g(formulated)e(using)i(the)270 +2447 y(relational)9 b(calculus)h(and)g(vice)g(v)o(ersa.)16 +b(This)10 b(was)g(\002rst)g(pro)o(v)o(ed)g(by)g(E.)h(F)l(.)f(Codd)g(in) +g(1972.)k(This)d(proof)e(is)270 2507 y(based)k(on)g(an)f(algorithm)g +(-\224Codd')m(s)g(reduction)g(algorithm\224-)f(by)h(which)h(an)f +(arbitrary)g(e)o(xpression)h(of)270 2567 y(the)g(relational)f(calculus) +h(can)g(be)g(reduced)f(to)h(a)g(semantically)f(equi)o(v)o(alent)g(e)o +(xpression)i(of)e(relational)270 2626 y(algebra.)j(F)o(or)d(a)h(more)f +(detailed)g(discussion)h(on)f(that)g(refer)g(to)g([D)n(A)-6 +b(TE94)q(])12 b(and)g([ULL88].)345 2688 y(It)i(is)h(sometimes)g(said)g +(that)f(languages)h(based)g(on)g(the)f(relational)g(calculus)h(are)g +(\224higher)f(le)o(v)o(el\224)270 2748 y(or)e(\224more)g(declarati)o(v) +o(e\224)h(than)f(languages)h(based)g(on)f(relational)g(algebra)g +(because)h(the)g(algebra)f(\(par)o(-)270 2808 y(tially\))i(speci\002es) +h(the)g(order)f(of)g(operations)h(while)f(the)h(calculus)g(lea)o(v)o +(es)h(it)e(to)h(a)g(compiler)f(or)g(inter)o(-)270 2868 +y(preter)e(to)g(determine)f(the)i(most)f(ef)o(\002cient)g(order)f(of)h +(e)o(v)o(aluation.)270 3048 y Fi(1.3)71 b(The)18 b(SQL)f(Language)270 +3163 y Ft(As)11 b(most)f(modern)g(relational)f(languages)i(SQL)f(is)h +(based)g(on)f(the)g(tuple)g(relational)g(calculus.)15 +b(As)c(a)g(re-)270 3223 y(sult)i(e)o(v)o(ery)f(query)g(that)h(can)g(be) +f(formulated)g(using)g(the)h(tuple)f(relational)g(calculus)h(\(or)f +(equi)o(v)o(alently)m(,)270 3283 y(relational)g(algebra\))h(can)g(also) +h(be)f(formulated)f(using)i(SQL.)g(There)f(are,)h(ho)o(we)o(v)o(er)n(,) +f(capabilities)g(be-)270 3342 y(yond)h(the)f(scope)i(of)e(relational)h +(algebra)f(or)h(calculus.)20 b(Here)14 b(is)g(a)h(list)e(of)h(some)g +(additional)f(features)270 3402 y(pro)o(vided)f(by)g(SQL)h(that)f(are)g +(not)g(part)g(of)g(relational)g(algebra)g(or)g(calculus:)p +eop +%%Page: 15 15 +15 14 bop 198 60 a Fm(1.3.)29 b(THE)13 b(SQL)f(LANGU)n(A)n(GE)1160 +b Ft(15)273 234 y Fo(\017)25 b Ft(Commands)12 b(for)f(insertion,)i +(deletion)f(or)g(modi\002cation)f(of)h(data.)273 333 +y Fo(\017)25 b Ft(Arithmetic)12 b(capability:)17 b(In)c(SQL)h(it)g(is)f +(possible)h(to)g(in)n(v)o(olv)o(e)f(arithmetic)g(operations)g(as)h +(well)323 393 y(as)g(comparisons,)h(e.g.)22 b Fk(A)c(<)f(B)e +Fl(+)d(3)p Ft(.)21 b(Note)15 b(that)f Fl(+)g Ft(or)g(other)f +(arithmetic)h(operators)f(appear)323 453 y(neither)e(in)i(relational)e +(algebra)h(nor)g(in)g(relational)g(calculus.)273 552 +y Fo(\017)25 b Ft(Assignment)14 b(and)g(Print)g(Commands:)19 +b(It)14 b(is)g(possible)h(to)f(print)g(a)g(relation)g(constructed)g(by) +g(a)323 612 y(query)d(and)i(to)f(assign)h(a)g(computed)e(relation)h(to) +g(a)h(relation)f(name.)273 711 y Fo(\017)25 b Ft(Aggre)o(gate)15 +b(Functions:)22 b(Operations)16 b(such)g(as)h Fp(aver)o(age)p +Ft(,)g Fp(sum)p Ft(,)h Fp(max)p Ft(,)f(.)7 b(.)g(.)g(can)19 +b(be)d(applied)g(to)323 771 y(columns)c(of)g(a)g(relation)g(to)g +(obtain)g(a)h(single)f(quantity)m(.)198 913 y Fh(1.3.1)59 +b(Select)198 1006 y Ft(The)17 b(most)f(often)g(used)h(command)f(in)g +(SQL)h(is)f(the)h(SELECT)h(statement)e(that)g(is)h(used)g(to)f(retrie)o +(v)o(e)198 1066 y(data.)g(The)d(syntax)f(is:)288 1165 +y Fr(SELECT)29 b([ALL|DISTINCT])497 1225 y({)h(*)f(|)h()f([AS)h +(])e([,)i(...)676 1285 y([,)g()f([AS)g +(]]]})288 1344 y(FROM)g()f([t_alias_1])437 +1404 y([,)i(...)f([,)h()e([t_alias_n]]])288 +1464 y([WHERE)h(condition])288 1524 y([GROUP)g(BY)h() +587 1583 y([,...)f([,)h(]])d([HAVING)j(condition]])288 +1643 y([{UNION)f(|)h(INTERSECT)e(|)i(EXCEPT})f(SELECT)h(...])288 +1703 y([ORDER)f(BY)h()e([ASC|DESC])587 +1763 y([,)h(...)h([,)f()g([ASC|DESC]]]];)198 +1861 y Ft(No)o(w)15 b(we)g(will)g(illustrate)g(the)g(comple)o(x)g +(syntax)g(of)g(the)g(SELECT)i(statement)f(with)f(v)o(arious)f(e)o(xam-) +198 1921 y(ples.)28 b(The)17 b(tables)g(used)f(for)g(the)g(e)o(xamples) +h(are)f(de\002ned)g(in)g(\002gure)g(1.1)h Fp(The)f(suppliers)g(and)h +(parts)198 1981 y(database)p Ft(.)198 2113 y Fn(Simple)12 +b(Selects)198 2207 y(Example)h(1.5)25 b Ft(Here)12 b(are)g(some)h +(simple)f(e)o(xamples)h(using)f(a)h(SELECT)h(statement:)198 +2326 y(T)l(o)23 b(retrie)o(v)o(e)f(all)h(tuples)g(from)f(table)g(P)-5 +b(AR)m(T)24 b(where)f(the)f(attrib)o(ute)g(PRICE)h(is)g(greater)g(than) +f(10)198 2386 y(we)13 b(formulate)e(the)h(follo)o(wing)f(query)288 +2485 y Fr(SELECT)29 b(*)288 2545 y(FROM)g(PART)288 2604 +y(WHERE)g(PRICE)g(>)h(10;)198 2703 y Ft(and)12 b(get)h(the)f(table:)766 +2802 y Fr(PNO)29 b(|)60 b(PNAME)f(|)h(PRICE)736 2862 +y(-----+---------+--------)796 2921 y(3)f(|)h(Bolt)89 +b(|)h(15)796 2981 y(4)59 b(|)h(Cam)119 b(|)90 b(25)198 +3080 y Ft(Using)12 b(\224)p Fo(\003)p Ft(\224)g(in)g(the)g(SELECT)i +(statement)e(will)g(deli)o(v)o(er)f(all)h(attrib)o(utes)g(from)f(the)h +(table.)j(If)d(we)g(want)f(to)198 3140 y(retrie)o(v)o(e)h(only)g(the)g +(attrib)o(utes)g(PN)n(AME)h(and)f(PRICE)h(from)e(table)h(P)-5 +b(AR)m(T)14 b(we)e(use)h(the)f(statement:)288 3238 y +Fr(SELECT)29 b(PNAME,)g(PRICE)288 3298 y(FROM)g(PART)288 +3358 y(WHERE)g(PRICE)g(>)h(10;)p eop +%%Page: 16 16 +16 15 bop 270 60 a Ft(16)1351 b Fm(CHAPTER)14 b(1.)28 +b(SQL)270 234 y Ft(In)12 b(this)g(case)i(the)e(result)g(is:)928 +339 y Fr(PNAME)59 b(|)g(PRICE)898 399 y(--------+--------)928 +459 y(Bolt)89 b(|)g(15)928 519 y(Cam)119 b(|)89 b(25)270 +622 y Ft(Note)12 b(that)f(the)h(SQL)g(SELECT)i(corresponds)e(to)f(the)h +(\224projection\224)f(in)h(relational)f(algebra)h(not)f(to)h(the)270 +682 y(\224selection\224)h(\(see)f(section)h(1.2.1)g Fp(Relational)f +(Algebr)o(a)p Ft(\).)270 802 y(The)26 b(quali\002cations)g(in)g(the)f +(WHERE)i(clause)g(can)f(also)g(be)g(logically)f(connected)h(using)g +(the)270 862 y(ke)o(ywords)11 b(OR,)i(AND)g(and)f(NO)n(T)n(:)360 +967 y Fr(SELECT)29 b(PNAME,)g(PRICE)360 1027 y(FROM)g(PART)360 +1086 y(WHERE)g(PNAME)g(=)h('Bolt')f(AND)539 1146 y(\(PRICE)g(=)h(0)g +(OR)f(PRICE)h(<)g(15\);)270 1250 y Ft(will)12 b(lead)g(to)h(the)f +(result:)928 1355 y Fr(PNAME)59 b(|)g(PRICE)898 1415 +y(--------+--------)928 1475 y(Bolt)89 b(|)g(15)270 1578 +y Ft(Arithmetic)10 b(operations)g(may)h(be)g(used)g(in)g(the)f +Fp(selectlist)i Ft(and)e(in)h(the)g(WHERE)h(clause.)k(F)o(or)10 +b(e)o(xample)270 1638 y(if)k(we)h(want)f(to)g(kno)o(w)h(ho)o(w)f(much)g +(it)g(would)g(cost)h(if)f(we)h(take)f(two)g(pieces)h(of)f(a)h(part)f +(we)h(could)g(use)270 1698 y(the)d(follo)o(wing)f(query:)360 +1803 y Fr(SELECT)29 b(PNAME,)g(PRICE)g(*)h(2)g(AS)g(DOUBLE)360 +1863 y(FROM)f(PART)360 1923 y(WHERE)g(PRICE)g(*)h(2)g(<)g(50;)270 +2027 y Ft(and)12 b(we)h(get:)928 2132 y Fr(PNAME)59 b(|)g(DOUBLE)898 +2191 y(--------+---------)928 2251 y(Screw)g(|)119 b(20)928 +2311 y(Nut)g(|)g(16)928 2371 y(Bolt)89 b(|)119 b(30)270 +2475 y Ft(Note)14 b(that)f(the)h(word)e(DOUBLE)j(after)e(the)g(ke)o +(yword)g(AS)g(is)h(the)g(ne)o(w)f(title)g(of)g(the)h(second)g(column.) +270 2534 y(This)i(technique)f(can)h(be)g(used)g(for)e(e)o(v)o(ery)h +(element)h(of)f(the)g Fp(selectlist)h Ft(to)g(assign)g(a)f(ne)o(w)h +(title)f(to)g(the)270 2594 y(resulting)i(column.)32 b(This)19 +b(ne)o(w)f(title)f(is)i(often)e(referred)g(to)g(as)i(alias.)33 +b(The)18 b(alias)h(cannot)f(be)g(used)270 2654 y(throughout)11 +b(the)h(rest)h(of)f(the)g(query)m(.)270 2794 y Fn(J)o(oins)270 +2890 y(Example)h(1.6)25 b Ft(The)13 b(follo)o(wing)e(e)o(xample)h(sho)o +(ws)h(ho)o(w)f Fp(joins)g Ft(are)g(realized)h(in)f(SQL:)270 +3010 y(T)l(o)23 b(join)g(the)g(three)g(tables)g(SUPPLIER,)g(P)-5 +b(AR)m(T)24 b(and)f(SELLS)h(o)o(v)o(er)f(their)f(common)h(attrib)o +(utes)270 3070 y(we)13 b(formulate)e(the)h(follo)o(wing)f(statement:) +360 3175 y Fr(SELECT)29 b(S.SNAME,)g(P.PNAME)360 3235 +y(FROM)g(SUPPLIER)g(S,)h(PART)f(P,)h(SELLS)f(SE)360 3294 +y(WHERE)g(S.SNO)g(=)h(SE.SNO)f(AND)539 3354 y(P.PNO)g(=)h(SE.PNO;)p +eop +%%Page: 17 17 +17 16 bop 198 60 a Fm(1.3.)29 b(THE)13 b(SQL)f(LANGU)n(A)n(GE)1160 +b Ft(17)198 234 y(and)12 b(get)h(the)f(follo)o(wing)f(table)h(as)h(a)g +(result:)885 330 y Fr(SNAME)30 b(|)g(PNAME)856 390 y(-------+-------) +885 450 y(Smith)g(|)g(Screw)885 510 y(Smith)g(|)g(Nut)885 +570 y(Jones)g(|)g(Cam)885 629 y(Adams)g(|)g(Screw)885 +689 y(Adams)g(|)g(Bolt)885 749 y(Blake)g(|)g(Nut)885 +809 y(Blake)g(|)g(Bolt)885 868 y(Blake)g(|)g(Cam)198 +965 y Ft(In)11 b(the)h(FR)n(OM)g(clause)g(we)g(introduced)f(an)h(alias) +g(name)g(for)f(e)o(v)o(ery)g(relation)g(because)i(there)e(are)h(com-) +198 1025 y(mon)j(named)g(attrib)o(utes)f(\(SNO)g(and)h(PNO\))g(among)f +(the)h(relations.)24 b(No)o(w)14 b(we)h(can)h(distinguish)e(be-)198 +1084 y(tween)g(the)h(common)f(named)g(attrib)o(utes)g(by)g(simply)g +(pre\002xing)g(the)g(attrib)o(ute)g(name)g(with)g(the)h(alias)198 +1144 y(name)f(follo)o(wed)e(by)i(a)g(dot.)20 b(The)14 +b(join)g(is)g(calculated)g(in)f(the)h(same)g(way)g(as)g(sho)o(wn)g(in)f +(e)o(xample)h(1.1.)198 1204 y(First)d(the)g(Cartesian)h(product)e +Fk(S)s(U)5 b(P)i(P)g(LI)t(E)s(R)g Fo(\002)g Fk(P)g(ART)14 +b Fo(\002)7 b Fk(S)s(E)s(LLS)12 b Ft(is)g(deri)o(v)o(ed.)j(No)o(w)c +(only)g(those)198 1264 y(tuples)i(satisfying)h(the)f(conditions)g(gi)o +(v)o(en)g(in)g(the)h(WHERE)g(clause)g(are)f(selected)h(\(i.e.)g(the)g +(common)198 1323 y(named)g(attrib)o(utes)f(ha)o(v)o(e)h(to)g(be)g +(equal\).)20 b(Finally)13 b(we)h(project)f(out)g(all)h(columns)g(b)o +(ut)f(S.SN)n(AME)i(and)198 1383 y(P)-6 b(.PN)n(AME.)198 +1515 y Fn(Aggr)o(egate)12 b(Operators)198 1608 y Ft(SQL)k(pro)o(vides)f +(aggre)o(gate)g(operators)g(\(e.g.)25 b(A)-7 b(V)o(G,)16 +b(COUNT)l(,)h(SUM,)f(MIN,)g(MAX\))f(that)g(take)g(the)198 +1668 y(name)d(of)f(an)h(attrib)o(ute)f(as)i(an)f(ar)o(gument.)j(The)d +(v)o(alue)g(of)f(the)h(aggre)o(gate)g(operator)f(is)h(calculated)g(o)o +(v)o(er)198 1728 y(all)i(v)o(alues)g(of)g(the)g(speci\002ed)g(attrib)o +(ute)f(\(column\))g(of)g(the)h(whole)g(table.)21 b(If)13 +b(groups)h(are)g(speci\002ed)g(in)198 1788 y(the)e(query)g(the)h +(calculation)f(is)g(done)h(only)f(o)o(v)o(er)g(the)g(v)o(alues)h(of)f +(a)g(group)g(\(see)h(ne)o(xt)f(section\).)198 1905 y +Fn(Example)h(1.7)25 b Ft(If)15 b(we)h(want)f(to)g(kno)o(w)h(the)f(a)o +(v)o(erage)h(cost)h(of)e(all)g(parts)h(in)g(table)f(P)-5 +b(AR)m(T)17 b(we)f(use)g(the)198 1965 y(follo)o(wing)11 +b(query:)288 2061 y Fr(SELECT)29 b(AVG\(PRICE\))g(AS)g(AVG_PRICE)288 +2121 y(FROM)g(PART;)198 2217 y Ft(The)13 b(result)f(is:)945 +2313 y Fr(AVG_PRICE)915 2373 y(-----------)1005 2433 +y(14.5)198 2529 y Ft(If)g(we)g(want)g(to)g(kno)o(w)g(ho)o(w)g(man)o(y)g +(parts)h(are)f(stored)g(in)g(table)h(P)-5 b(AR)m(T)13 +b(we)f(use)h(the)g(statement:)288 2626 y Fr(SELECT)29 +b(COUNT\(PNO\))288 2685 y(FROM)g(PART;)198 2782 y Ft(and)12 +b(get:)1005 2878 y Fr(COUNT)975 2938 y(-------)1065 2998 +y(4)198 3130 y Fn(Aggr)o(egation)f(by)h(Gr)o(oups)198 +3223 y Ft(SQL)18 b(allo)o(ws)f(to)h(partition)f(the)g(tuples)h(of)f(a)h +(table)g(into)f(groups.)31 b(Then)19 b(the)e(aggre)o(gate)h(operators) +198 3283 y(described)12 b(abo)o(v)o(e)i(can)e(be)h(applied)f(to)g(the)h +(groups)f(\(i.e.)k(the)d(v)o(alue)f(of)g(the)h(aggre)o(gate)f(operator) +f(is)i(no)198 3342 y(longer)f(calculated)g(o)o(v)o(er)h(all)f(the)h(v)o +(alues)f(of)g(the)g(speci\002ed)h(column)f(b)o(ut)g(o)o(v)o(er)h(all)f +(v)o(alues)h(of)f(a)g(group.)198 3402 y(Thus)h(the)f(aggre)o(gate)g +(operator)g(is)h(e)o(v)o(aluated)e(indi)o(vidually)g(for)h(e)o(v)o(ery) +g(group.\))p eop +%%Page: 18 18 +18 17 bop 270 60 a Ft(18)1351 b Fm(CHAPTER)14 b(1.)28 +b(SQL)270 294 y Ft(The)21 b(partitioning)e(of)h(the)g(tuples)h(into)f +(groups)g(is)h(done)f(by)g(using)h(the)f(ke)o(ywords)g(GR)n(OUP)12 +b(BY)270 354 y(follo)o(wed)g(by)h(a)g(list)g(of)g(attrib)o(utes)f(that) +h(de\002ne)g(the)g(groups.)18 b(If)12 b(we)h(ha)o(v)o(e)h +Fr(GROUP)29 b(BY)h Fk(A)1875 361 y Fg(1)1897 354 y Fk(;)8 +b(:)g(:)g(:)h(;)f(A)2045 361 y Ff(k)270 413 y Ft(we)k(partition)f(the)h +(relation)f(into)h(groups,)g(such)g(that)g(two)f(tuples)i(are)e(in)h +(the)g(same)h(group)e(if)g(and)h(only)270 473 y(if)g(the)o(y)g(agree)h +(on)f(all)g(the)h(attrib)o(utes)e Fk(A)962 480 y Fg(1)985 +473 y Fk(;)d(:)g(:)g(:)h(;)f(A)1133 480 y Ff(k)1158 473 +y Ft(.)270 600 y Fn(Example)13 b(1.8)25 b Ft(If)11 b(we)h(want)g(to)g +(kno)o(w)g(ho)o(w)f(man)o(y)h(parts)g(are)g(sold)h(by)f(e)o(v)o(ery)f +(supplier)h(we)g(formulate)270 660 y(the)g(query:)360 +764 y Fr(SELECT)29 b(S.SNO,)g(S.SNAME,)g(COUNT\(SE.PNO\))360 +824 y(FROM)g(SUPPLIER)g(S,)h(SELLS)f(SE)360 883 y(WHERE)g(S.SNO)g(=)h +(SE.SNO)360 943 y(GROUP)f(BY)h(S.SNO,)f(S.SNAME;)270 +1046 y Ft(and)12 b(get:)898 1151 y Fr(SNO)29 b(|)h(SNAME)f(|)h(COUNT) +868 1210 y(-----+-------+-------)928 1270 y(1)59 b(|)30 +b(Smith)f(|)90 b(2)928 1330 y(2)59 b(|)30 b(Jones)f(|)90 +b(1)928 1390 y(3)59 b(|)30 b(Adams)f(|)90 b(2)928 1450 +y(4)59 b(|)30 b(Blake)f(|)90 b(3)270 1553 y Ft(No)o(w)12 +b(let')m(s)h(ha)o(v)o(e)f(a)h(look)f(of)g(what)g(is)h(happening)f +(here:)270 1612 y(First)g(the)g(join)g(of)g(the)g(tables)h(SUPPLIER)f +(and)h(SELLS)g(is)f(deri)o(v)o(ed:)808 1717 y Fr(S.SNO)29 +b(|)h(S.SNAME)f(|)h(SE.PNO)778 1777 y(-------+---------+--------)868 +1836 y(1)89 b(|)60 b(Smith)f(|)90 b(1)868 1896 y(1)f(|)60 +b(Smith)f(|)90 b(2)868 1956 y(2)f(|)60 b(Jones)f(|)90 +b(4)868 2016 y(3)f(|)60 b(Adams)f(|)90 b(1)868 2075 y(3)f(|)60 +b(Adams)f(|)90 b(3)868 2135 y(4)f(|)60 b(Blake)f(|)90 +b(2)868 2195 y(4)f(|)60 b(Blake)f(|)90 b(3)868 2255 y(4)f(|)60 +b(Blake)f(|)90 b(4)270 2358 y Ft(Ne)o(xt)16 b(we)g(partition)f(the)h +(tuples)g(into)f(groups)h(by)g(putting)f(all)h(tuples)g(together)f +(that)h(agree)g(on)f(both)270 2418 y(attrib)o(utes)d(S.SNO)g(and)g +(S.SN)n(AME:)808 2522 y Fr(S.SNO)29 b(|)h(S.SNAME)f(|)h(SE.PNO)778 +2582 y(-------+---------+--------)868 2642 y(1)89 b(|)60 +b(Smith)f(|)90 b(1)1286 2701 y(|)g(2)778 2761 y +(--------------------------)868 2821 y(2)f(|)60 b(Jones)f(|)90 +b(4)778 2881 y(--------------------------)868 2940 y(3)f(|)60 +b(Adams)f(|)90 b(1)1286 3000 y(|)g(3)778 3060 y +(--------------------------)868 3120 y(4)f(|)60 b(Blake)f(|)90 +b(2)1286 3180 y(|)g(3)1286 3239 y(|)g(4)270 3342 y Ft(In)13 +b(our)f(e)o(xample)i(we)f(got)g(four)f(groups)h(and)g(no)o(w)g(we)g +(can)g(apply)g(the)g(aggre)o(gate)g(operator)f(COUNT)270 +3402 y(to)g(e)o(v)o(ery)g(group)g(leading)g(to)g(the)h(total)f(result)g +(of)g(the)g(query)g(gi)o(v)o(en)g(abo)o(v)o(e.)p eop +%%Page: 19 19 +19 18 bop 198 60 a Fm(1.3.)29 b(THE)13 b(SQL)f(LANGU)n(A)n(GE)1160 +b Ft(19)198 234 y(Note)11 b(that)f(for)g(the)h(result)g(of)f(a)h(query) +f(using)h(GR)n(OUP)g(BY)g(and)g(aggre)o(gate)f(operators)g(to)h(make)f +(sense)198 294 y(the)16 b(attrib)o(utes)f(grouped)h(by)f(must)h(also)h +(appear)e(in)h(the)g Fp(selectlist)p Ft(.)27 b(All)16 +b(further)e(attrib)o(utes)i(not)f(ap-)198 354 y(pearing)d(in)g(the)g +(GR)n(OUP)g(BY)h(clause)g(can)f(only)g(be)h(selected)f(by)h(using)f(an) +g(aggre)o(gate)g(function.)j(On)198 413 y(the)f(other)f(hand)g(you)g +(can)h(not)f(use)h(aggre)o(gate)g(functions)f(on)g(attrib)o(utes)g +(appearing)g(in)h(the)f(GR)n(OUP)198 473 y(BY)g(clause.)198 +606 y Fn(Ha)o(ving)198 699 y Ft(The)18 b(HA)-7 b(VING)17 +b(clause)i(works)e(much)g(like)g(the)g(WHERE)i(clause)f(and)g(is)g +(used)g(to)f(consider)g(only)198 759 y(those)h(groups)g(satisfying)f +(the)h(quali\002cation)f(gi)o(v)o(en)h(in)g(the)f(HA)-7 +b(VING)18 b(clause.)33 b(The)18 b(e)o(xpressions)198 +818 y(allo)o(wed)13 b(in)h(the)g(HA)-7 b(VING)13 b(clause)i(must)e(in)n +(v)o(olv)o(e)h(aggre)o(gate)f(functions.)20 b(Ev)o(ery)14 +b(e)o(xpression)g(using)198 878 y(only)h(plain)h(attrib)o(utes)f +(belongs)h(to)g(the)g(WHERE)h(clause.)27 b(On)15 b(the)h(other)f(hand)h +(e)o(v)o(ery)g(e)o(xpression)198 938 y(in)n(v)o(olving)11 +b(an)i(aggre)o(gate)f(function)f(must)i(be)f(put)g(to)h(the)f(HA)-7 +b(VING)12 b(clause.)198 1056 y Fn(Example)h(1.9)25 b +Ft(If)11 b(we)h(want)f(only)h(those)g(suppliers)g(selling)g(more)f +(than)h(one)g(part)f(we)h(use)h(the)f(query:)288 1155 +y Fr(SELECT)29 b(S.SNO,)g(S.SNAME,)g(COUNT\(SE.PNO\))288 +1214 y(FROM)g(SUPPLIER)g(S,)h(SELLS)f(SE)288 1274 y(WHERE)g(S.SNO)g(=)h +(SE.SNO)288 1334 y(GROUP)f(BY)h(S.SNO,)f(S.SNAME)288 +1394 y(HAVING)g(COUNT\(SE.PNO\))f(>)i(1;)198 1492 y Ft(and)12 +b(get:)826 1590 y Fr(SNO)29 b(|)h(SNAME)f(|)h(COUNT)796 +1650 y(-----+-------+-------)856 1709 y(1)59 b(|)30 b(Smith)f(|)90 +b(2)856 1769 y(3)59 b(|)30 b(Adams)f(|)90 b(2)856 1829 +y(4)59 b(|)30 b(Blake)f(|)90 b(3)198 1961 y Fn(Subqueries)198 +2055 y Ft(In)11 b(the)g(WHERE)i(and)e(HA)-7 b(VING)12 +b(clauses)g(the)f(use)h(of)f(subqueries)h(\(subselects\))f(is)h(allo)o +(wed)f(in)g(e)o(v)o(ery)198 2114 y(place)k(where)g(a)g(v)o(alue)g(is)g +(e)o(xpected.)24 b(In)14 b(this)h(case)h(the)f(v)o(alue)g(must)g(be)g +(deri)o(v)o(ed)f(by)h(e)o(v)o(aluating)f(the)198 2174 +y(subquery)e(\002rst.)j(The)e(usage)g(of)f(subqueries)h(e)o(xtends)g +(the)f(e)o(xpressi)o(v)o(e)h(po)o(wer)f(of)g(SQL.)198 +2293 y Fn(Example)h(1.10)25 b Ft(If)17 b(we)h(want)g(to)f(kno)o(w)h +(all)g(parts)g(ha)o(ving)g(a)g(greater)f(price)h(than)g(the)g(part)f +(named)198 2352 y('Scre)o(w')11 b(we)h(use)h(the)g(query:)288 +2450 y Fr(SELECT)29 b(*)288 2510 y(FROM)g(PART)288 2570 +y(WHERE)g(PRICE)g(>)h(\(SELECT)f(PRICE)h(FROM)f(PART)736 +2630 y(WHERE)g(PNAME='Screw'\);)198 2728 y Ft(The)13 +b(result)f(is:)766 2826 y Fr(PNO)29 b(|)60 b(PNAME)f(|)h(PRICE)736 +2886 y(-----+---------+--------)796 2945 y(3)f(|)h(Bolt)89 +b(|)h(15)796 3005 y(4)59 b(|)h(Cam)119 b(|)90 b(25)198 +3103 y Ft(When)15 b(we)g(look)g(at)g(the)g(abo)o(v)o(e)h(query)e(we)h +(can)h(see)f(the)g(ke)o(yword)f(SELECT)j(two)d(times.)24 +b(The)15 b(\002rst)198 3163 y(one)h(at)g(the)f(be)o(ginning)h(of)f(the) +h(query)f(-)h(we)g(will)f(refer)g(to)h(it)f(as)i(outer)e(SELECT)i(-)f +(and)g(the)f(one)h(in)198 3223 y(the)h(WHERE)h(clause)g(which)f(be)o +(gins)h(a)f(nested)h(query)e(-)h(we)g(will)g(refer)f(to)h(it)g(as)h +(inner)f(SELECT)l(.)198 3283 y(F)o(or)d(e)o(v)o(ery)g(tuple)g(of)g(the) +g(outer)g(SELECT)i(the)e(inner)g(SELECT)i(has)f(to)f(be)h(e)o(v)o +(aluated.)21 b(After)13 b(e)o(v)o(ery)198 3342 y(e)o(v)o(aluation)f(we) +i(kno)o(w)f(the)g(price)g(of)g(the)g(tuple)g(named)h('Scre)o(w')d(and)j +(we)f(can)h(check)f(if)g(the)h(price)f(of)198 3402 y(the)f(actual)h +(tuple)f(is)g(greater)m(.)p eop +%%Page: 20 20 +20 19 bop 270 60 a Ft(20)1351 b Fm(CHAPTER)14 b(1.)28 +b(SQL)270 294 y Ft(If)19 b(we)i(want)f(to)g(kno)o(w)f(all)i(suppliers)f +(that)g(do)g(not)g(sell)g(an)o(y)h(part)f(\(e.g.)39 b(to)20 +b(be)h(able)f(to)g(remo)o(v)o(e)270 354 y(these)13 b(suppliers)f(from)f +(the)i(database\))f(we)h(use:)360 471 y Fr(SELECT)29 +b(*)360 531 y(FROM)g(SUPPLIER)g(S)360 590 y(WHERE)g(NOT)h(EXISTS)659 +650 y(\(SELECT)f(*)g(FROM)h(SELLS)f(SE)688 710 y(WHERE)h(SE.SNO)f(=)h +(S.SNO\);)270 823 y Ft(In)19 b(our)h(e)o(xample)g(the)g(result)f(will)h +(be)g(empty)f(because)i(e)o(v)o(ery)e(supplier)h(sells)g(at)g(least)g +(one)g(part.)270 883 y(Note)15 b(that)g(we)g(use)h(S.SNO)e(from)g(the)h +(outer)g(SELECT)i(within)d(the)h(WHERE)h(clause)g(of)f(the)g(inner)270 +942 y(SELECT)l(.)d(As)f(described)f(abo)o(v)o(e)g(the)g(subquery)g(is)g +(e)o(v)o(aluated)f(for)g(e)o(v)o(ery)h(tuple)g(from)e(the)i(outer)g +(query)270 1002 y(i.e.)16 b(the)d(v)o(alue)f(for)f(S.SNO)i(is)f(always) +g(taken)g(from)f(the)h(actual)h(tuple)f(of)g(the)g(outer)g(SELECT)l(.) +270 1159 y Fn(Union,)g(Intersect,)h(Except)270 1261 y +Ft(These)19 b(operations)e(calculate)h(the)g(union,)i(intersect)d(and)h +(set)h(theoretic)e(dif)o(ference)g(of)g(the)h(tuples)270 +1320 y(deri)o(v)o(ed)12 b(by)g(two)g(subqueries:)270 +1466 y Fn(Example)h(1.11)25 b Ft(The)13 b(follo)o(wing)e(query)g(is)i +(an)g(e)o(xample)f(for)g(UNION:)360 1583 y Fr(SELECT)29 +b(S.SNO,)g(S.SNAME,)g(S.CITY)360 1643 y(FROM)g(SUPPLIER)g(S)360 +1703 y(WHERE)g(S.SNAME)g(=)h('Jones')360 1763 y(UNION)360 +1822 y(SELECT)f(S.SNO,)g(S.SNAME,)g(S.CITY)360 1882 y(FROM)g(SUPPLIER)g +(S)360 1942 y(WHERE)g(S.SNAME)g(=)h('Adams';)270 2055 +y Ft(gi)o(v)o(es)13 b(the)f(result:)898 2172 y Fr(SNO)29 +b(|)h(SNAME)f(|)60 b(CITY)868 2232 y(-----+-------+--------)928 +2292 y(2)f(|)30 b(Jones)f(|)h(Paris)928 2351 y(3)59 b(|)30 +b(Adams)f(|)h(Vienna)270 2464 y Ft(Here)12 b(an)h(e)o(xample)f(for)g +(INTERSECT)n(:)360 2581 y Fr(SELECT)29 b(S.SNO,)g(S.SNAME,)g(S.CITY)360 +2641 y(FROM)g(SUPPLIER)g(S)360 2701 y(WHERE)g(S.SNO)g(>)h(1)360 +2761 y(INTERSECT)360 2820 y(SELECT)f(S.SNO,)g(S.SNAME,)g(S.CITY)360 +2880 y(FROM)g(SUPPLIER)g(S)360 2940 y(WHERE)g(S.SNO)g(>)h(2;)270 +3053 y Ft(gi)o(v)o(es)13 b(the)f(result:)898 3170 y Fr(SNO)29 +b(|)h(SNAME)f(|)60 b(CITY)868 3230 y(-----+-------+--------)928 +3289 y(2)f(|)30 b(Jones)f(|)h(Paris)270 3402 y Ft(The)13 +b(only)f(tuple)g(returned)f(by)i(both)f(parts)g(of)g(the)g(query)g(is)h +(the)f(one)h(ha)o(ving)f Fk(S)s(N)5 b(O)15 b Fl(=)e(2)p +Ft(.)p eop +%%Page: 21 21 +21 20 bop 198 60 a Fm(1.3.)29 b(THE)13 b(SQL)f(LANGU)n(A)n(GE)1160 +b Ft(21)198 234 y(Finally)12 b(an)g(e)o(xample)h(for)e(EXCEPT)n(:)288 +342 y Fr(SELECT)29 b(S.SNO,)g(S.SNAME,)g(S.CITY)288 402 +y(FROM)g(SUPPLIER)g(S)288 461 y(WHERE)g(S.SNO)g(>)h(1)288 +521 y(EXCEPT)288 581 y(SELECT)f(S.SNO,)g(S.SNAME,)g(S.CITY)288 +641 y(FROM)g(SUPPLIER)g(S)288 700 y(WHERE)g(S.SNO)g(>)h(3;)198 +806 y Ft(gi)o(v)o(es)13 b(the)f(result:)826 914 y Fr(SNO)29 +b(|)h(SNAME)f(|)60 b(CITY)796 974 y(-----+-------+--------)856 +1033 y(2)f(|)30 b(Jones)f(|)h(Paris)856 1093 y(3)59 b(|)30 +b(Adams)f(|)h(Vienna)198 1247 y Fh(1.3.2)59 b(Data)15 +b(De\002nition)198 1344 y Ft(There)e(is)f(a)h(set)g(of)f(commands)g +(used)h(for)e(data)i(de\002nition)e(included)h(in)g(the)h(SQL)f +(language.)198 1488 y Fn(Cr)o(eate)g(T)-5 b(able)198 +1585 y Ft(The)12 b(most)g(fundamental)e(command)h(for)g(data)h +(de\002nition)e(is)i(the)g(one)f(that)g(creates)h(a)g(ne)o(w)f +(relation)g(\(a)198 1645 y(ne)o(w)h(table\).)k(The)c(syntax)h(of)f(the) +g(CREA)-6 b(TE)15 b(T)-5 b(ABLE)14 b(command)e(is:)288 +1752 y Fr(CREATE)29 b(TABLE)g()676 1812 y +(\()f()706 1872 y([,)i +()e()706 1932 y([,)i(...]]\);)198 +2063 y Fn(Example)13 b(1.12)25 b Ft(T)l(o)13 b(create)g(the)g(tables)h +(de\002ned)e(in)h(\002gure)g(1.1)g(the)g(follo)o(wing)f(SQL)h +(statements)g(are)198 2123 y(used:)288 2231 y Fr(CREATE)29 +b(TABLE)g(SUPPLIER)676 2290 y(\(SNO)89 b(INTEGER,)706 +2350 y(SNAME)29 b(VARCHAR\(20\),)706 2410 y(CITY)59 b(VARCHAR\(20\)\);) +288 2530 y(CREATE)29 b(TABLE)g(PART)676 2589 y(\(PNO)89 +b(INTEGER,)706 2649 y(PNAME)29 b(VARCHAR\(20\),)706 2709 +y(PRICE)g(DECIMAL\(4)g(,)h(2\)\);)288 2828 y(CREATE)f(TABLE)g(SELLS)676 +2888 y(\(SNO)h(INTEGER,)706 2948 y(PNO)g(INTEGER\);)198 +3092 y Fn(Data)12 b(T)l(ypes)h(in)f(SQL)198 3189 y Ft(The)h(follo)o +(wing)e(is)i(a)f(list)g(of)g(some)h(data)f(types)h(that)f(are)h +(supported)e(by)i(SQL:)273 3295 y Fo(\017)25 b Ft(INTEGER:)13 +b(signed)f(fullword)e(binary)i(inte)o(ger)g(\(31)g(bits)g(precision\).) +273 3402 y Fo(\017)25 b Ft(SMALLINT)n(:)12 b(signed)h(halfword)d +(binary)i(inte)o(ger)g(\(15)g(bits)g(precision\).)p eop +%%Page: 22 22 +22 21 bop 270 60 a Ft(22)1354 b Fm(CHAPTER)14 b(1.)25 +b(SQL)345 234 y Fo(\017)g Ft(DECIMAL)19 b(\()p Fk(p)p +Fl([)p Fk(;)8 b(q)r Fl(])p Ft(\):)27 b(signed)19 b(packed)f(decimal)h +(number)f(of)g Fk(p)h Ft(digits)f(precision)h(with)f(as-)395 +294 y(sumed)13 b Fk(q)j Ft(of)e(them)f(right)g(to)h(the)g(decimal)f +(point.)20 b Fl(\(15)d Fo(\025)f Fk(p)g Fo(\025)h Fk(q)h +Fo(\025)e Fl(0\))p Ft(.)21 b(If)13 b Fk(q)j Ft(is)e(omitted)f(it)h(is) +395 354 y(assumed)f(to)f(be)g(0.)345 448 y Fo(\017)25 +b Ft(FLO)n(A)-6 b(T)n(:)13 b(signed)f(double)o(word)f(\003oating)g +(point)h(number)m(.)345 543 y Fo(\017)25 b Ft(CHAR\()p +Fk(n)p Ft(\):)14 b(\002x)o(ed)f(length)f(character)g(string)f(of)h +(length)g Fk(n)p Ft(.)345 638 y Fo(\017)25 b Ft(V)-7 +b(ARCHAR\()p Fk(n)p Ft(\):)15 b(v)o(arying)c(length)h(character)g +(string)g(of)g(maximum)f(length)h Fk(n)p Ft(.)270 768 +y Fn(Cr)o(eate)g(Index)270 862 y Ft(Indices)i(are)g(used)h(to)f(speed)h +(up)f(access)i(to)e(a)g(relation.)21 b(If)14 b(a)g(relation)g +Fk(R)g Ft(has)h(an)f(inde)o(x)h(on)f(attrib)o(ute)270 +921 y Fk(A)j Ft(then)f(we)h(can)f(retrie)o(v)o(e)g(all)g(tuples)h +Fk(t)g Ft(ha)o(ving)f Fk(t)p Fl(\()p Fk(A)p Fl(\))22 +b(=)f Fk(a)c Ft(in)f(time)h(roughly)e(proportional)g(to)h(the)270 +981 y(number)c(of)g(such)g(tuples)h Fk(t)f Ft(rather)g(than)g(in)g +(time)g(proportional)f(to)h(the)h(size)f(of)g Fk(R)p +Ft(.)345 1041 y(T)l(o)h(create)f(an)g(inde)o(x)h(in)f(SQL)h(the)f(CREA) +-6 b(TE)14 b(INDEX)f(command)f(is)g(used.)17 b(The)c(syntax)f(is:)360 +1131 y Fr(CREATE)29 b(INDEX)g()360 1190 y(ON)g +()g(\()h()d(\);)270 1303 +y Fn(Example)13 b(1.13)25 b Ft(T)l(o)12 b(create)g(an)f(inde)o(x)h +(named)g(I)f(on)h(attrib)o(ute)f(SN)n(AME)h(of)f(relation)g(SUPPLIER)h +(we)270 1362 y(use)h(the)f(follo)o(wing)f(statement:)360 +1452 y Fr(CREATE)29 b(INDEX)g(I)360 1512 y(ON)g(SUPPLIER)g(\(SNAME\);) +270 1602 y Ft(The)11 b(created)f(inde)o(x)h(is)g(maintained)f +(automatically)m(,)g(i.e.)i(whene)o(v)o(er)e(a)g(ne)o(w)h(tuple)f(is)h +(inserted)f(into)g(the)270 1661 y(relation)k(SUPPLIER)g(the)h(inde)o(x) +f(I)h(is)g(adapted.)22 b(Note)15 b(that)f(the)h(only)f(changes)h(a)g +(user)g(can)f(percept)270 1721 y(when)e(an)h(inde)o(x)f(is)h(present)f +(are)g(an)h(increased)g(speed.)270 1852 y Fn(Cr)o(eate)f(V)n(iew)270 +1945 y Ft(A)i(vie)o(w)f(may)h(be)g(re)o(garded)f(as)h(a)g +Fp(virtual)g(table)p Ft(,)g(i.e.)h(a)f(table)f(that)h(does)g(not)g +Fp(physically)f Ft(e)o(xist)i(in)e(the)270 2005 y(database)i(b)o(ut)f +(looks)g(to)g(the)g(user)g(as)h(if)e(it)h(did.)21 b(By)14 +b(contrast,)h(when)f(we)g(talk)g(of)g(a)g Fp(base)h(table)e +Ft(there)270 2064 y(is)f(really)g(a)g(physically)f(stored)h +(counterpart)e(of)i(each)g(ro)o(w)f(of)h(the)f(table)h(some)o(where)g +(in)f(the)h(physical)270 2124 y(storage.)345 2184 y(V)m(ie)o(ws)h(do)g +(not)g(ha)o(v)o(e)h(their)f(o)o(wn,)h(physically)e(separate,)j +(distinguishable)e(stored)g(data.)19 b(Instead,)270 2244 +y(the)d(system)g(stores)g(the)f Fp(de\002nition)g Ft(of)h(the)f(vie)o +(w)h(\(i.e.)g(the)g(rules)f(about)h(ho)o(w)f(to)g(access)i(physically) +270 2304 y(stored)c Fp(base)g(tables)h Ft(in)e(order)h(to)g +(materialize)f(the)h(vie)o(w\))g(some)o(where)f(in)h(the)g +Fp(system)h(catalogs)f Ft(\(see)270 2363 y(section)19 +b(1.3.4)h Fp(System)g(Catalogs)p Ft(\).)36 b(F)o(or)18 +b(a)i(discussion)g(on)f(dif)o(ferent)e(techniques)j(to)f(implement)270 +2423 y(vie)o(ws)12 b(refer)g(to)g(section)h(3.4.1)g Fp(T)-5 +b(ec)o(hniques)13 b(T)-5 b(o)12 b(Implement)g(V)l(ie)o(ws)p +Ft(.)345 2483 y(In)g(SQL)g(the)h(CREA)-6 b(TE)14 b(VIEW)f(command)f(is) +g(used)h(to)f(de\002ne)g(a)h(vie)o(w)m(.)i(The)e(syntax)g(is:)360 +2573 y Fr(CREATE)29 b(VIEW)g()360 2632 y(AS)g() +270 2722 y Ft(where)10 b Fk(<)p Fr(select)p 624 2722 +15 2 v 17 w(stmt)p Fk(>)40 b Ft(is)11 b(a)g(v)o(alid)g(select)g +(statement)f(as)i(de\002ned)e(in)h(section)g(1.3.1.)16 +b(Note)10 b(that)270 2782 y(the)15 b Fk(<)p Fr(select)p +568 2782 V 17 w(stmt)p Fk(>)44 b Ft(is)15 b(not)g(e)o(x)o(ecuted)g +(when)g(the)g(vie)o(w)f(is)h(created.)23 b(It)15 b(is)g(just)g(stored)f +(in)h(the)270 2842 y Fp(system)e(catalogs)f Ft(and)g(is)h(e)o(x)o +(ecuted)g(whene)o(v)o(er)f(a)h(query)f(against)g(the)g(vie)o(w)g(is)h +(made.)270 2954 y Fn(Example)g(1.14)25 b Ft(Let)16 b(the)g(follo)o +(wing)f(vie)o(w)h(de\002nition)f(be)h(gi)o(v)o(en)g(\(we)g(use)g(the)g +(tables)h(from)e(\002gure)270 3014 y(1.1)e Fp(The)f(suppliers)h(and)f +(parts)h(database)f Ft(again\):)360 3103 y Fr(CREATE)29 +b(VIEW)g(London_Suppliers)449 3163 y(AS)h(SELECT)f(S.SNAME,)g(P.PNAME) +539 3223 y(FROM)g(SUPPLIER)g(S,)h(PART)g(P,)f(SELLS)h(SE)539 +3283 y(WHERE)f(S.SNO)h(=)f(SE.SNO)h(AND)718 3342 y(P.PNO)g(=)f(SE.PNO)h +(AND)718 3402 y(S.CITY)g(=)f('London';)p eop +%%Page: 23 23 +23 22 bop 198 60 a Fm(1.3.)26 b(THE)13 b(SQL)f(LANGU)n(A)n(GE)1163 +b Ft(23)198 234 y(No)o(w)10 b(we)g(can)g(use)g(this)g +Fp(virtual)g(r)n(elation)f Fr(London)p 1100 234 15 2 +v 18 w(Suppliers)g Ft(as)h(if)f(it)h(were)g(another)f(base)h(table:)288 +338 y Fr(SELECT)29 b(*)288 397 y(FROM)g(London_Suppliers)288 +457 y(WHERE)g(P.PNAME)g(=)h('Screw';)198 560 y Ft(will)12 +b(return)f(the)i(follo)o(wing)e(table:)885 663 y Fr(SNAME)30 +b(|)g(PNAME)856 723 y(-------+-------)885 783 y(Smith)g(|)g(Screw)198 +885 y Ft(T)l(o)17 b(calculate)h(this)f(result)g(the)g(database)g +(system)h(has)f(to)g(do)g(a)g Fp(hidden)g Ft(access)h(to)f(the)g(base)h +(tables)198 945 y(SUPPLIER,)e(SELLS)g(and)g(P)-5 b(AR)m(T)16 +b(\002rst.)25 b(It)15 b(does)h(so)g(by)f(e)o(x)o(ecuting)h(the)f(query) +g(gi)o(v)o(en)h(in)f(the)g(vie)o(w)198 1005 y(de\002nition)h(against)g +(those)h(base)h(tables.)28 b(After)16 b(that)h(the)f(additional)g +(quali\002cations)h(\(gi)o(v)o(en)f(in)g(the)198 1065 +y(query)c(against)g(the)h(vie)o(w\))e(can)i(be)f(applied)g(to)h(obtain) +f(the)g(resulting)g(table.)198 1202 y Fn(Dr)o(op)g(T)-5 +b(able,)13 b(Dr)o(op)g(Index,)f(Dr)o(op)h(V)n(iew)198 +1298 y Ft(T)l(o)g(destroy)e(a)h(table)h(\(including)e(all)h(tuples)g +(stored)g(in)g(that)g(table\))g(the)g(DR)n(OP)g(T)-5 +b(ABLE)14 b(command)e(is)198 1357 y(used:)288 1461 y +Fr(DROP)29 b(TABLE)g(;)198 1586 y Fn(Example)13 +b(1.15)25 b Ft(T)l(o)13 b(destroy)e(the)h(SUPPLIER)h(table)f(use)h(the) +f(follo)o(wing)f(statement:)288 1690 y Fr(DROP)29 b(TABLE)g(SUPPLIER;) +198 1792 y Ft(The)13 b(DR)n(OP)f(INDEX)h(command)f(is)g(used)h(to)f +(destroy)g(an)g(inde)o(x:)288 1896 y Fr(DROP)29 b(INDEX)g +(;)198 1998 y Ft(Finally)12 b(to)g(destroy)f(a)i(gi)o(v)o +(en)f(vie)o(w)g(use)h(the)f(command)g(DR)n(OP)h(VIEW)n(:)288 +2102 y Fr(DROP)29 b(VIEW)h(;)198 2250 y Fh(1.3.3)59 +b(Data)15 b(Manipulation)198 2345 y Fn(Insert)e(Into)198 +2440 y Ft(Once)h(a)h(table)f(is)h(created)f(\(see)g(section)h(1.3.2\),) +g(it)f(can)h(be)f(\002lled)g(with)g(tuples)g(using)g(the)h(command)198 +2500 y(INSER)m(T)e(INT)o(O.)g(The)g(syntax)f(is:)288 +2603 y Fr(INSERT)29 b(INTO)g()g(\()1065 +2663 y([,)g()g([,...]]\))288 2723 y(VALUES)g +(\()527 2783 y([,)g()g([,)h(...]]\);)198 +2908 y Fn(Example)13 b(1.16)25 b Ft(T)l(o)14 b(insert)g(the)h(\002rst)f +(tuple)f(into)h(the)h(relation)e(SUPPLIER)h(of)g(\002gure)g(1.1)g +Fp(The)g(sup-)198 2968 y(pliers)e(and)h(parts)f(database)h +Ft(we)f(use)h(the)g(follo)o(wing)d(statement:)288 3071 +y Fr(INSERT)29 b(INTO)g(SUPPLIER)g(\(SNO,)h(SNAME,)f(CITY\))288 +3131 y(VALUES)g(\(1,)g('Smith',)g('London'\);)198 3234 +y Ft(T)l(o)13 b(insert)f(the)g(\002rst)g(tuple)g(into)g(the)h(relation) +e(SELLS)i(we)g(use:)288 3337 y Fr(INSERT)29 b(INTO)g(SELLS)h(\(SNO,)f +(PNO\))288 3397 y(VALUES)g(\(1,)g(1\);)p eop +%%Page: 24 24 +24 23 bop 270 60 a Ft(24)1351 b Fm(CHAPTER)14 b(1.)28 +b(SQL)270 234 y Fn(Update)270 330 y Ft(T)l(o)17 b(change)f(one)h(or)f +(more)g(attrib)o(ute)f(v)o(alues)i(of)f(tuples)g(in)h(a)f(relation)g +(the)g(UPD)n(A)-6 b(TE)18 b(command)e(is)270 389 y(used.)g(The)d +(syntax)g(is:)360 493 y Fr(UPDATE)29 b()360 +553 y(SET)g()f(=)i()479 613 +y([,)g(...)f([,)h()e(=)i(]])360 +672 y(WHERE)f(;)270 798 y Fn(Example)13 b(1.17)25 +b Ft(T)l(o)15 b(change)g(the)f(v)o(alue)h(of)f(attrib)o(ute)g(PRICE)h +(of)f(the)g(part)h('Scre)o(w')e(in)h(the)h(relation)270 +858 y(P)-5 b(AR)m(T)13 b(we)g(use:)360 962 y Fr(UPDATE)29 +b(PART)360 1022 y(SET)g(PRICE)h(=)f(15)360 1081 y(WHERE)g(PNAME)g(=)h +('Screw';)270 1184 y Ft(The)13 b(ne)o(w)f(v)o(alue)g(of)g(attrib)o(ute) +g(PRICE)g(of)g(the)h(tuple)f(whose)g(name)h(is)f('Scre)o(w')f(is)i(no)o +(w)f(15.)270 1323 y Fn(Delete)270 1418 y Ft(T)l(o)h(delete)f(a)g(tuple) +g(from)f(a)h(particular)f(table)h(use)h(the)f(command)g(DELETE)i(FR)n +(OM.)f(The)g(syntax)f(is:)360 1522 y Fr(DELETE)29 b(FROM)g +()360 1582 y(WHERE)g(;)270 1708 +y Fn(Example)13 b(1.18)25 b Ft(T)l(o)13 b(delete)g(the)g(supplier)f +(called)h('Smith')e(of)i(the)f(table)h(SUPPLIER)g(the)g(follo)o(wing) +270 1767 y(statement)f(is)h(used:)360 1871 y Fr(DELETE)29 +b(FROM)g(SUPPLIER)360 1931 y(WHERE)g(SNAME)g(=)h('Smith';)270 +2079 y Fh(1.3.4)59 b(System)15 b(Catalogs)270 2175 y +Ft(In)10 b(e)o(v)o(ery)g(SQL)g(database)h(system)f Fp(system)h +(catalogs)f Ft(are)g(used)g(to)g(keep)g(track)g(of)g(which)g(tables,)h +(vie)o(ws)270 2235 y(inde)o(x)o(es)16 b(etc.)24 b(are)15 +b(de\002ned)g(in)g(the)g(database.)24 b(These)17 b(system)e(catalogs)h +(can)f(be)g(queried)g(as)g(if)g(the)o(y)270 2294 y(were)g(normal)g +(relations.)23 b(F)o(or)15 b(e)o(xample)h(there)e(is)i(one)f(catalog)g +(used)h(for)e(the)i(de\002nition)e(of)h(vie)o(ws.)270 +2354 y(This)h(catalog)f(stores)h(the)f(query)g(from)f(the)h(vie)o(w)g +(de\002nition.)23 b(Whene)o(v)o(er)16 b(a)f(query)g(against)g(a)g(vie)o +(w)270 2414 y(is)f(made,)h(the)e(system)i(\002rst)e(gets)h(the)g +Fp(vie)o(w-de\002nition-query)f Ft(out)h(of)f(the)h(catalog)g(and)f +(materializes)270 2474 y(the)e(vie)o(w)g(before)g(proceeding)g(with)g +(the)g(user)g(query)g(\(see)h(section)f(3.4.1)h Fp(T)-5 +b(ec)o(hniques)12 b(T)-5 b(o)12 b(Implement)270 2533 +y(V)l(ie)o(ws)k Ft(for)e(a)h(more)f(detailed)g(description\).)21 +b(F)o(or)14 b(more)g(information)f(about)i Fp(system)g(catalogs)f +Ft(refer)270 2593 y(to)e([D)n(A)-6 b(TE96)q(].)270 2742 +y Fh(1.3.5)59 b(Embedded)15 b(SQL)270 2837 y Ft(In)h(this)h(section)g +(we)g(will)g(sketch)f(ho)o(w)h(SQL)g(can)g(be)g(embedded)f(into)h(a)g +(host)g(language)f(\(e.g.)i(C\).)270 2897 y(There)13 +b(are)f(two)g(main)g(reasons)g(why)g(we)h(want)f(to)g(use)h(SQL)f(from) +g(a)g(host)h(language:)345 3000 y Fo(\017)25 b Ft(There)13 +b(are)g(queries)f(that)h(cannot)g(be)g(formulated)e(using)i(pure)g(SQL) +g(\(i.e.)18 b(recursi)o(v)o(e)12 b(queries\).)395 3059 +y(T)l(o)f(be)g(able)g(to)g(perform)e(such)j(queries)f(we)g(need)g(a)g +(host)g(language)g(with)g(a)g(greater)f(e)o(xpressi)o(v)o(e)395 +3119 y(po)o(wer)h(than)h(SQL.)345 3223 y Fo(\017)25 b +Ft(W)l(e)11 b(simply)f(want)g(to)h(access)h(a)f(database)h(from)d(some) +i(application)g(that)f(is)h(written)g(in)f(the)h(host)395 +3283 y(language)g(\(e.g.)h(a)g(ticket)e(reserv)o(ation)h(system)h(with) +f(a)h(graphical)f(user)g(interface)g(is)h(written)e(in)395 +3342 y(C)h(and)g(the)g(information)f(about)g(which)h(tickets)g(are)g +(still)g(left)g(is)g(stored)g(in)g(a)g(database)h(that)f(can)395 +3402 y(be)h(accessed)i(using)e(embedded)g(SQL\).)p eop +%%Page: 25 25 +25 24 bop 198 60 a Fm(1.3.)29 b(THE)13 b(SQL)f(LANGU)n(A)n(GE)1160 +b Ft(25)198 234 y(A)19 b(program)f(using)h(embedded)g(SQL)h(in)f(a)g +(host)h(language)f(consists)h(of)e(statements)i(of)f(the)g(host)198 +294 y(language)c(and)g(of)g(embedded)g(SQL)g(\(ESQL\))g(statements.)25 +b(Ev)o(ery)15 b(ESQL)h(statement)f(be)o(gins)g(with)198 +354 y(the)d(ke)o(ywords)g(EXEC)h(SQL.)g(The)g(ESQL)g(statements)g(are)f +(transformed)g(to)g(statements)h(of)f(the)g(host)198 +413 y(language)j(by)g(a)g Fp(pr)n(ecompiler)h Ft(\(mostly)e(calls)h(to) +g(library)f(routines)g(that)h(perform)f(the)g(v)o(arious)h(SQL)198 +473 y(commands\).)273 533 y(When)i(we)g(look)f(at)h(the)g(e)o(xamples)g +(throughout)f(section)h(1.3.1)h(we)f(realize)f(that)h(the)g(result)g +(of)198 593 y(the)e(queries)g(is)g(v)o(ery)g(often)g(a)g(set)g(of)g +(tuples.)24 b(Most)15 b(host)g(languages)h(are)f(not)f(designed)i(to)e +(operate)198 653 y(on)h(sets)g(so)g(we)g(need)g(a)g(mechanism)g(to)g +(access)h(e)o(v)o(ery)e(single)h(tuple)g(of)f(the)h(set)g(of)f(tuples)h +(returned)198 712 y(by)h(a)g(SELECT)i(statement.)27 b(This)16 +b(mechanism)g(can)g(be)h(pro)o(vided)e(by)h(declaring)f(a)i +Fp(cursor)p Ft(.)27 b(After)198 772 y(that)11 b(we)g(can)g(use)g(the)g +(FETCH)g(command)g(to)g(retrie)o(v)o(e)f(a)h(tuple)f(and)h(set)g(the)g +(cursor)g(to)f(the)h(ne)o(xt)g(tuple.)198 892 y(F)o(or)h(a)g(detailed)h +(discussion)g(on)f(embedded)g(SQL)h(refer)e(to)h([D)n(A)-6 +b(TE96)q(],)12 b([D)n(A)-6 b(TE94)q(])12 b(or)g([ULL88].)p +eop +%%Page: 26 26 +26 25 bop 270 609 a Fj(Chapter)26 b(2)270 858 y Fq(P)n(ostgr)n(eSQL)k +(fr)n(om)g(the)g(User')-5 b(s)32 b(P)n(oint)270 1008 +y(of)f(V)-5 b(iew)270 1268 y Ft(This)13 b(chapter)f(contains)g +(information)f(that)h(will)f(be)i(useful)f(for)f(people)h(that)g(only)g +(want)g(to)g(use)h(Post-)270 1327 y(greSQL.)g(It)f(gi)o(v)o(es)h(a)g +(listing)f(and)h(description)f(of)g(the)g(a)o(v)o(ailable)h(features)f +(including)g(a)h(lot)f(of)g(e)o(xam-)270 1387 y(ples.)k(The)11 +b(users)h(interested)f(in)g(the)g(internals)g(of)g(PostgreSQL)f(should) +h(read)g(chapter)g(3)g Fp(P)l(ostgr)n(eSQL)270 1447 y(fr)n(om)h(the)h +(Pr)n(ogr)o(ammer')n(s)g(P)l(oint)f(of)h(V)l(ie)o(w)p +Ft(.)270 1620 y Fi(2.1)71 b(A)18 b(Short)f(History)g(of)h(P)o(ostgr)o +(eSQL)270 1732 y Ft(PostgreSQL)c(is)h(an)g(enhancement)f(of)g(the)h +(POSTGRES)f(database)i(management)e(system,)i(a)e(ne)o(xt-)270 +1792 y(generation)f(relational)g(DBMS)h(research)g(prototype)f(running) +g(on)g(almost)h(an)o(y)g(UNIX)g(based)g(oper)o(-)270 +1852 y(ating)f(system.)20 b(The)14 b(original)e(POSTGRES)i(code,)g +(from)f(which)g(PostgreSQL)g(is)h(deri)o(v)o(ed,)g(was)f(the)270 +1912 y(ef)o(fort)f(of)i(man)o(y)g(graduate)g(students,)h(under)o +(graduate)e(students,)i(and)f(staf)o(f)g(programmers)e(working)270 +1971 y(under)d(the)h(direction)f(of)h(Professor)f(Michael)h +(Stonebraker)e(at)i(the)f(Uni)o(v)o(ersity)h(of)f(California,)h(Berke-) +270 2031 y(le)o(y)m(.)16 b(Originally)11 b(POSTGRES)i(implemented)e +(its)i(o)o(wn)f(query)g(language)g(called)g(POSTQUEL.)345 +2092 y(In)18 b(1995)g(Andre)o(w)g(Y)-6 b(u)19 b(and)f(Jolly)h(Chen)g +(adapted)f(the)h(last)f(of)o(\002cial)g(release)h(of)f(POSTGRES)270 +2152 y(\(v)o(ersion)d(4.2\))h(to)f(meet)h(their)f(o)o(wn)g +(requirements)g(and)g(made)h(some)g(major)e(changes)j(to)e(the)g(code.) +270 2211 y(The)i(most)g(important)e(change)i(is)f(the)h(replacement)f +(of)g(POSTQUEL)h(by)f(an)h(e)o(xtended)f(subset)i(of)270 +2271 y(SQL92.)f(The)c(name)g(was)g(changed)f(to)h(Postgres95)f(and)h +(since)g(that)g(time)f(man)o(y)h(other)f(people)h(ha)o(v)o(e)270 +2331 y(contrib)o(uted)h(to)h(the)g(porting,)g(testing,)h(deb)o(ugging)f +(and)g(enhancement)g(of)g(the)g(code.)24 b(In)14 b(late)h(1996)270 +2391 y(the)d(name)h(was)f(changed)h(again)f(to)g(the)g(ne)o(w)g(of)o +(\002cial)g(name)g(PostgreSQL.)270 2563 y Fi(2.2)71 b(An)18 +b(Ov)o(er)o(view)f(on)h(the)g(F)n(eatur)o(es)e(of)i(P)o(ostgr)o(eSQL) +270 2676 y Ft(As)d(mentioned)f(earlier)g(PostgreSQL)h(is)g(a)g +(relational)f(database)h(management)f(system)h(\(RDBMS\))270 +2736 y(b)o(ut)h(in)f(contrast)h(to)f(the)h(most)g(traditional)f(RDBMSs) +h(it)g(is)g(designed)g(to)f(pro)o(vide)h(more)f(\003e)o(xibility)270 +2796 y(to)j(the)f(user)m(.)33 b(One)18 b(e)o(xample)g(for)f(the)h +(impro)o(v)o(ed)f(\003e)o(xibility)g(is)h(the)g(support)f(for)g +Fp(user)i(de\002ned)f Ft(or)270 2855 y Fp(abstr)o(act)11 +b(data)f(types)h Ft(\(ADTs\).)k(Another)10 b(e)o(xample)h(is)f(the)h +(support)f(of)g(user)g(de\002ned)h(SQL)f(functions.)270 +2915 y(\(W)l(e)j(will)g(discuss)h(these)f(features)g(later)g(in)g +(section)g(2.5)h Fp(Some)f(of)g(P)l(ostgr)n(eSQL)n(')n(s)h(Special)e(F) +l(eatur)n(es)270 2975 y(in)g(Detail)p Ft(\))270 3095 +y(Here)g(is)h(a)f(list)h(of)f(the)g(features)g(PostgreSQL)g(pro)o +(vides:)345 3197 y Fo(\017)25 b Ft(An)12 b(e)o(xtended)g(subset)h(of)f +(SQL92)h(as)g(query)f(language.)345 3299 y Fo(\017)25 +b Ft(A)12 b(commandline)g(interface)f(called)h Fr(psql)g +Ft(using)h(GNU)f(readline.)345 3402 y Fo(\017)25 b Ft(A)12 +b(client/serv)o(er)g(architecture)f(allo)o(wing)h(concurrent)f(access)j +(to)e(the)h(databases.)1145 3552 y(26)p eop +%%Page: 27 27 +27 26 bop 198 60 a Fm(2.3.)29 b(WHERE)13 b(T)o(O)g(GET)g(POSTGRESQL)956 +b Ft(27)273 234 y Fo(\017)25 b Ft(Support)11 b(for)g(btree,)i(hash)g +(or)e(rtree)h(inde)o(x)o(es.)273 331 y Fo(\017)25 b Ft(A)13 +b(transaction)f(mechanism)h(based)h(on)f(the)g(two)f(phase)i(commit)e +(protocol)g(is)i(used)f(to)g(ensure)323 391 y(data)f(inte)o(grity)f +(throughout)h(concurrent)f(data)h(access.)273 488 y Fo(\017)25 +b Ft(Host)17 b(based,)i(password,)f(crypt,)g(ident)e(\(RFC)h(1413\))f +(or)h(K)o(erberos)f(V4/V5)h(authentication)323 547 y(can)12 +b(be)h(used)f(to)h(ensure)f(authorized)g(data)g(access.)273 +644 y Fo(\017)25 b Ft(A)12 b(huge)g(amount)g(of)g(prede\002ned)g(data)g +(types.)273 741 y Fo(\017)25 b Ft(Support)11 b(for)g(user)i(de\002ned)f +(data)g(types.)273 838 y Fo(\017)25 b Ft(Support)11 b(for)g(user)i +(de\002ned)f(SQL)g(functions.)273 935 y Fo(\017)25 b +Ft(Support)11 b(for)g(reco)o(v)o(ery)h(after)g(a)h(crash.)273 +1032 y Fo(\017)25 b Ft(A)12 b(precompiler)f(for)h(embedded)g(SQL)g(in)h +(C.)273 1129 y Fo(\017)25 b Ft(An)12 b(ODBC)h(interface.)273 +1225 y Fo(\017)25 b Ft(A)12 b(JDBC)h(interface.)273 1322 +y Fo(\017)25 b Ft(A)12 b(Tcl/Tk)h(interface.)273 1419 +y Fo(\017)25 b Ft(A)12 b(Perl)g(interface.)198 1586 y +Fi(2.3)71 b(Wher)o(e)17 b(to)h(Get)f(P)o(ostgr)o(eSQL)198 +1697 y Ft(PostgreSQL)26 b(is)h(a)o(v)o(ailable)f(as)i(source)e(distrib) +o(ution)g(\(v6.3.2)g(at)h(the)g(time)f(of)g(writing\))f(from)198 +1757 y Fr(ftp://ftp.postgresql.org/pub/)p Ft(.)63 b(There)30 +b(is)f(also)h(an)f(of)o(\002cial)f(homepage)h(for)198 +1817 y(PostgreSQL)15 b(at)g Fr(http://www.postgresgl.org/)p +Ft(.)21 b(There)15 b(are)g(a)g(lot)g(of)g(hosts)g(mirroring)198 +1877 y(the)d(contents)h(of)f(the)g(abo)o(v)o(e)h(mentioned)f(ones)h +(all)f(o)o(v)o(er)g(the)h(world.)198 2008 y Fn(Copyright)e(of)h(P)o +(ostgr)o(eSQL)198 2101 y Ft(PostgreSQL)17 b(is)h(not)f(public)g(domain) +g(software.)30 b(It)17 b(is)h(copyrighted)e(by)h(the)h(Uni)o(v)o +(ersity)e(of)h(Cali-)198 2161 y(fornia)e(b)o(ut)h(may)g(be)g(used)h +(according)f(to)g(the)g(licensing)g(terms)g(of)g(the)g(the)g(copyright) +e(included)i(in)198 2221 y(e)o(v)o(ery)h(distrib)o(ution)g(\(refer)f +(to)h(the)h(\002le)f Fr(COPYRIGHT)g Ft(included)g(in)g(e)o(v)o(ery)h +(distrib)o(ution)e(for)h(more)198 2281 y(information\).)198 +2412 y Fn(Support)11 b(f)o(or)h(P)o(ostgr)o(eSQL)198 +2506 y Ft(There)g(is)g(no)g(of)o(\002cial)e(support)i(for)f +(PostgreSQL.)g(That)h(means)h(there)e(is)h(no)g(obligation)e(for)h(an)o +(ybody)198 2565 y(to)h(pro)o(vide)g(maintenance,)h(support,)f(updates,) +h(enhancements)g(or)f(modi\002cations)g(to)g(the)g(code.)17 +b(The)198 2625 y(whole)c(PostgreSQL)g(project)g(is)h(maintained)e +(through)h(v)o(olunteer)f(ef)o(fort)g(only)m(.)18 b(Ho)o(we)o(v)o(er)13 +b(there)g(are)198 2685 y(man)o(y)f(mailing)g(lists)h(which)f(can)h(be)f +(subscribed)h(to)f(in)g(case)h(of)f(problems:)198 2804 +y(Support)f(Mailing)h(Lists:)273 2864 y Fr(announce@postgreSQL.org)e +Ft(for)h(announcements.)273 2924 y Fr(ports@postgreSQL.org)f +Ft(for)h(OS-speci\002c)h(b)o(ugs.)273 2984 y Fr(bugs@postgreSQL.org)e +Ft(for)i(other)f(unsolv)o(ed)i(b)o(ugs.)273 3044 y Fr +(questions@postgreSQL.org)c Ft(for)j(general)g(discussion.)198 +3163 y(Mailing)g(Lists)i(for)d(De)o(v)o(elopers:)273 +3223 y Fr(hackers@postgreSQL.org)f Ft(for)h(serv)o(er)i(internals)f +(discussion.)273 3283 y Fr(docs@postgreSQL.org)e Ft(for)i(the)g +(documentation)f(project.)273 3342 y Fr(patches@postgreSQL.org)f +Ft(for)h(patches)i(and)f(discussion.)273 3402 y Fr +(mirrors@postgreSQL.org)e Ft(for)h(mirror)g(site)i(announcements.)p +eop +%%Page: 28 28 +28 27 bop 270 60 a Ft(28)307 b Fm(CHAPTER)14 b(2.)28 +b(POSTGRESQL)13 b(FR)n(OM)f(THE)i(USER'S)e(POINT)g(OF)g(VIEW)270 +234 y Ft(T)l(o)i(subscribe)h(to)f(the)g(mailing)f(list)h +Fr(questions@postgreSQL.org)d Ft(for)i(e)o(xample)i(just)f(send)270 +294 y(an)e(email)h(to)f Fr(questions-request@postgreSQL.o)o(rg)e +Ft(with)i(the)g(lines)360 401 y Fr(subscribe)360 461 +y(end)270 567 y Ft(in)g(the)h(body)f(\(not)f(the)i(subject)f(line\).) +270 746 y Fi(2.4)71 b(Ho)o(w)18 b(to)g(use)f(P)o(ostgr)o(eSQL)270 +861 y Ft(Before)11 b(we)h(can)g(use)g(PostgreSQL)g(we)g(ha)o(v)o(e)g +(to)f(get)h(and)g(install)f(it.)16 b(W)l(e)c(won')o(t)e(talk)i(about)g +(installing)270 921 y(PostgreSQL)g(here)h(because)g(the)g(installation) +f(procedure)g(is)h(straight)g(forward)e(and)i(described)f(v)o(ery)270 +980 y(detailed)h(in)h(the)f(\002le)g Fr(INSTALL)g Ft(contained)g(in)g +(the)h(distrib)o(ution.)k(W)l(e)13 b(want)g(to)h(concentrate)f(on)g +(the)270 1040 y(basic)g(usage)g(of)f(PostgreSQL)g(after)f(a)i +(successful)g(setup)g(has)g(taken)e(place.)270 1194 y +Fh(2.4.1)59 b(Starting)14 b(The)h(P)o(ostmaster)270 1291 +y Ft(As)j(mentioned)g(earlier)f(PostgreSQL)g(uses)i(a)f(traditional)f +(client/serv)o(er)h(architecture)f(to)h(pro)o(vide)270 +1351 y(multi)c(user)g(access.)24 b(The)15 b(serv)o(er)g(is)g +(represented)f(by)g(a)h(program)e(called)i Fr(postmaster)e +Ft(which)i(is)270 1410 y(started)c(only)h(once)f(at)h(each)g(host.)j +(This)e(master)e(serv)o(er)h(process)g(listens)g(at)f(a)h(speci\002ed)g +(TCP/IP)f(port)270 1470 y(for)j(incoming)h(connections)g(by)g(a)h +(client.)24 b(F)o(or)15 b(e)o(v)o(ery)g(incoming)f(connection)h(the)g +Fr(postmaster)270 1530 y Ft(spa)o(wns)e(a)e(ne)o(w)h(serv)o(er)g +(process)g(\()p Fr(postgres)p Ft(\))e(and)h(continues)h(listening)f +(for)g(further)g(connections.)270 1590 y(Ev)o(ery)18 +b(serv)o(er)f(process)g(spa)o(wned)h(in)f(this)h(way)f(handles)g(e)o +(xactly)g(one)h(connection)f(to)g(one)g(client.)270 1649 +y(The)f Fr(postgres)e Ft(serv)o(er)i(processes)g(communicate)f(with)f +(each)i(other)f(using)g(UNIX)g(semaphores)270 1709 y(and)k(shared)h +(memory)e(to)i(ensure)f(data)h(inte)o(grity)e(throughout)g(concurrent)h +(data)g(access.)38 b(\(F)o(or)19 b(a)270 1769 y(more)d(detailed)g +(description)f(on)h(these)h(architectural)e(concepts)h(see)h(chapter)f +(3)g Fp(P)l(ostgr)n(eSQL)h(fr)n(om)270 1829 y(the)12 +b(Pr)n(ogr)o(ammer')n(s)i(P)l(oint)e(of)g(V)l(ie)o(w)p +Ft(.\))270 1948 y(T)l(o)h(start)f(the)g(master)h(serv)o(er)f(process)h +(use)g(the)f(follo)o(wing)f(command:)330 2056 y Fr($)30 +b(nohup)f(postmaster)g(>)g(server.log)g(2>&1)h(&)270 +2161 y Ft(which)11 b(will)g(start)g Fr(postmaster)g Ft(in)g(the)g +(background)g(and)g(e)o(v)o(en)h(if)f(you)g(log)g(out)g(of)g(the)g +(system)h(the)270 2221 y(process)h(remains)f(acti)o(v)o(e.)k(All)c +(errors)g(and)g(messages)i(will)e(be)g(logged)g(to)g(the)h(\002le)f +Fr(server.log)p Ft(.)270 2341 y Fn(Note:)35 b Ft(The)23 +b Fr(postmaster)e Ft(process)i(is)g(usually)g(started)f(by)g(a)h +(special)g Fp(database)g(superuser)270 2401 y Ft(called)c +Fr(postgres)f Ft(which)h(is)g(a)g(normal)g(UNIX)f(user)h(b)o(ut)g(has)g +(more)g(rights)f(concerning)h(Post-)270 2460 y(greSQL.)f(F)o(or)g +(security)g(reasons)h(it)f(is)g(strongly)g(recommended)f(not)h(to)g +(run)g(the)g Fr(postmaster)270 2520 y Ft(process)13 b(as)g(the)f +Fp(system)h(super)h(user)f Fr(root)p Ft(.)270 2674 y +Fh(2.4.2)59 b(Cr)o(eating)14 b(a)h(New)g(Database)270 +2771 y Ft(Once)c(the)g Fr(postmaster)f Ft(daemon)g(is)i(running)e(we)h +(can)g(create)g(a)g(ne)o(w)f(database)i(using)f(the)g(follo)o(w-)270 +2830 y(ing)h(command:)330 2938 y Fr($)30 b(createdb)f(testdb)270 +3044 y Ft(which)22 b(will)g(create)g(a)g(database)h(called)f +Fr(testdb)p Ft(.)45 b(The)23 b(user)f(e)o(x)o(ecuting)h(the)f(command)f +(will)270 3103 y(become)12 b(the)f(database)h(administrator)f(and)g +(will)g(therefore)g(be)h(the)f(only)g(user)h(\(e)o(xcept)g(the)f +Fp(database)270 3163 y(superuser)j Fr(postgres)p Ft(\))d(who)h(can)h +(destroy)e(the)i(database)g(again.)270 3283 y Fn(Note:)35 +b Ft(T)l(o)22 b(create)h(the)f(database)h(you)f(don')o(t)g(need)g(to)g +(kno)o(w)g(an)o(ything)g(about)g(the)g(tables)h(\(re-)270 +3342 y(lations\))16 b(that)h(will)f(be)h(used)h(within)e(the)h +(database.)29 b(The)18 b(tables)f(will)f(be)h(de\002ned)g(later)f +(using)h(the)270 3402 y(SQL)c(statements)f(sho)o(wn)h(in)f(section)g +(2.4.4)h Fp(De\002ning)f(and)h(P)l(opulating)f(T)-5 b(ables)p +Ft(.)p eop +%%Page: 29 29 +29 28 bop 198 60 a Fm(2.4.)29 b(HO)n(W)12 b(T)o(O)h(USE)g(POSTGRESQL) +1018 b Ft(29)198 234 y Fh(2.4.3)59 b(Connecting)15 b(T)-5 +b(o)14 b(a)h(Database)198 335 y Ft(After)g(ha)o(ving)g(created)h(at)g +(least)g(one)g(database)g(we)g(can)g(make)g(our)f(\002rst)g(client)h +(connection)f(to)h(the)198 395 y(database)g(system)g(to)f(be)g(able)g +(to)g(de\002ne)g(tables,)i(populate)e(them,)h(retrie)o(v)o(e)f(data,)h +(update)f(data)g(etc.)198 455 y(Note)20 b(that)g(most)f(database)i +(manipulation)e(is)h(done)g(this)g(way)f(\(just)h(creating)f(and)h +(destroying)f(a)198 514 y(database)11 b(is)f(done)g(by)g(separate)h +(commands)f(which)g(are)g(in)g(fact)f(just)i(shell)f(scripts)g(also)h +(using)f Fr(psql)p Ft(\))198 634 y(The)j(connection)f(to)g(the)g(DBMS)h +(is)g(established)g(by)f(the)g(follo)o(wing)f(command:)258 +749 y Fr($)30 b(psql)f(testdb)198 861 y Ft(which)18 b(will)f(make)g(a)h +(connection)g(to)f(a)h(database)g(called)g Fr(testdb)p +Ft(.)32 b Fr(psql)17 b Ft(is)h(a)g(command)f(line)198 +920 y(interface)d(using)h(GNU)g(readline.)23 b(It)15 +b(can)g(handle)g(a)g(connection)g(to)f(only)h(one)g(database)h(at)f(a)g +(time.)198 980 y(When)d(the)h(connection)f(is)g(established)h +Fr(psql)f Ft(presents)h(itself)f(as)h(follo)o(ws:)258 +1095 y Fr(Welcome)29 b(to)h(the)f(POSTGRESQL)g(interactive)g(sql)g +(monitor:)318 1155 y(Please)g(read)g(the)h(file)f(COPYRIGHT)g(for)h +(copyright)f(terms)g(of)318 1215 y(POSTGRESQL)347 1334 +y(type)h(\\?)g(for)f(help)h(on)f(slash)h(commands)347 +1394 y(type)g(\\q)g(to)f(quit)347 1454 y(type)h(\\g)g(or)f(terminate)g +(with)h(semicolon)e(to)i(execute)f(query)288 1514 y(You)g(are)h +(currently)f(connected)g(to)g(the)h(database:)f(testdb)258 +1633 y(testdb=>)198 1745 y Ft(No)o(w)16 b(you)g(can)g(either)g(enter)g +(an)o(y)g(v)o(alid)g(SQL)g(statement)h(terminated)e(by)h(a)g(';')i(or)d +(use)i(one)f(of)g(the)198 1805 y Fp(slash)d(commands)p +Ft(.)j(A)c(list)h(of)f(all)g(a)o(v)o(ailable)g Fp(slash)h(commands)f +Ft(can)h(be)f(obtained)g(by)h(typing)e Fr(')p Fo(n)p +Fr(?')p Ft(.)198 1924 y(Here)h(is)h(a)f(list)h(of)f(the)g(most)g +(important)g Fp(slash)h(commands)p Ft(:)273 2035 y Fo(\017)25 +b(n)p Fr(?)f Ft(lists)13 b(all)f(a)o(v)o(ailable)g Fp(slash)h(commands) +g Ft(and)f(gi)o(v)o(es)h(a)f(short)g(description.)273 +2151 y Fo(\017)25 b(n)p Fr(q)f Ft(quits)13 b Fr(psql)p +Ft(.)273 2266 y Fo(\017)25 b(n)p Fr(d)f Ft(lists)13 b(all)f(tables,)h +(vie)o(ws)g(and)f(inde)o(x)o(es)h(e)o(xisting)g(in)f(the)g(current)g +(database.)273 2381 y Fo(\017)25 b(n)p Fr(dt)f Ft(lists)13 +b(only)f(tables.)273 2497 y Fo(\017)25 b(n)p Fr(dT)f +Ft(lists)13 b(all)f(a)o(v)o(ailable)g(data)h(types.)273 +2612 y Fo(\017)25 b(n)p Fr(i)k Fk(<)p Fr(filename)p Fk(>)24 +b Ft(reads)12 b(and)h(e)o(x)o(ecutes)g(the)f(queries)h(contained)f(in)g +Fr(filename)p Ft(.)273 2727 y Fo(\017)25 b(n)p Fr(l)f +Ft(lists)13 b(all)f(a)o(v)o(ailable)g(databases)i(kno)o(wn)d(to)i(the)f +(system.)273 2843 y Fo(\017)25 b(n)p Fr(connect)k Fk(<)p +Fr(database)p Fk(>)37 b Ft(terminates)19 b(the)g(current)g(connection)g +(and)g(opens)h(a)f(ne)o(w)323 2902 y(connection)12 b(to)g +Fr(database)p Ft(.)273 3018 y Fo(\017)25 b(n)p Fr(o)k +Fl([)p Fk(<)p Fr(filename)p Fk(>)p Fl(])23 b Ft(sends)14 +b(all)e(query)g(output)f(to)i Fr(file)p Ft(.)198 3182 +y Fh(2.4.4)59 b(De\002ning)15 b(and)g(P)o(opulating)f(T)-5 +b(ables)198 3283 y Ft(De\002ning)13 b(tables)i(and)f(inserting)f +(tuples)h(is)g(done)g(by)g(the)g(SQL)g(statements)g Fr(CREATE)30 +b(TABLE)13 b Ft(and)198 3342 y Fr(INSERT)29 b(INTO)p +Ft(.)14 b(F)o(or)f(a)g(detailed)h(description)e(on)i(the)f(syntax)h(of) +f(these)h(commands)f(refer)g(to)g(sec-)198 3402 y(tion)f(1.3.2)h +Fp(Data)f(De\002nition)p Ft(.)p eop +%%Page: 30 30 +30 29 bop 270 60 a Ft(30)310 b Fm(CHAPTER)14 b(2.)25 +b(POSTGRESQL)13 b(FR)n(OM)f(THE)i(USER'S)e(POINT)g(OF)g(VIEW)270 +234 y Fn(Example)h(2.1)25 b Ft(T)l(o)12 b(create)g(and)g(populate)g +(the)g(table)g(SUPPLIER)g(used)g(in)g(\002gure)g(1.1)g +Fp(The)g(suppliers)270 294 y(and)g(parts)h(database)f +Ft(we)h(could)f(use)h(the)f(follo)o(wing)f(session:)330 +403 y Fr($)30 b(psql)f(testdb)330 522 y(Welcome)g(to)h(the)f +(POSTGRESQL)g(interactive)g(sql)g(monitor:)390 582 y(Please)g(read)g +(the)h(file)f(COPYRIGHT)g(for)h(copyright)f(terms)g(of)390 +642 y(POSTGRESQL)419 761 y(type)h(\\?)g(for)f(help)h(on)f(slash)h +(commands)419 821 y(type)g(\\q)g(to)f(quit)419 881 y(type)h(\\g)g(or)f +(terminate)g(with)h(semicolon)e(to)i(execute)f(query)360 +941 y(You)g(are)h(currently)f(connected)g(to)g(the)h(database:)f +(testdb)330 1060 y(testdb=>)g(create)g(table)g(supplier)g(\(sno)h +(int4,)330 1120 y(testdb->)f(sname)g(varchar\(20\),)330 +1180 y(testdb->)g(city)g(varchar\(20\)\);)330 1239 y(CREATE)330 +1299 y(testdb=>)g(insert)g(into)g(supplier)g(\(sno,)h(sname,)f(city\)) +330 1359 y(testdb->)g(values)g(\(1,'Smith','London'\);)330 +1419 y(INSERT)g(26187)g(1)330 1479 y(testdb=>)g(insert)g(into)g +(supplier)g(\(sno,)h(sname,)f(city\))330 1538 y(testdb->)g(values)g +(\(2,'Jones','Paris'\);)330 1598 y(INSERT)g(26188)g(1)330 +1658 y(testdb=>)g(insert)g(into)g(supplier)g(\(sno,)h(sname,)f(city\)) +330 1718 y(testdb->)g(values)g(\(3,'Adams','Vienna'\);)330 +1777 y(INSERT)g(26189)g(1)330 1837 y(testdb=>)g(insert)g(into)g +(supplier)g(\(sno,)h(sname,)f(city\))330 1897 y(testdb->)g(values)g +(\(4,'Blake','Rome'\);)330 1957 y(INSERT)g(26190)g(1)330 +2017 y(testdb=>)270 2123 y Ft(If)12 b(you)g(\002rst)g(put)g(all)g(the)h +(abo)o(v)o(e)f(commands)h(into)f(a)g(\002le)g(you)h(can)f(easily)h(e)o +(x)o(ecute)g(the)f(statements)h(by)270 2183 y(the)f Fp(slash)h(command) +25 b Fo(n)p Fr(i)k Fk(<)p Fr(file)p Fk(>)p Ft(.)270 2302 +y(Note:)34 b(The)22 b(data)g(type)f Fr(int4)h Ft(is)g(not)f(part)g(of)h +(the)f(SQL92)h(standard.)44 b(It)21 b(is)h(a)g(b)o(uilt)f(in)h(Post-) +270 2362 y(greSQL)13 b(type)g(denoting)g(a)g(four)f(byte)h(signed)g +(inte)o(ger)m(.)18 b(F)o(or)13 b(information)f(on)h(which)g(data)g +(types)g(are)270 2422 y(a)o(v)o(ailable)g(you)h(can)g(use)g(the)f +Fo(n)p Fr(dT)h Ft(command)f(which)h(will)f(gi)o(v)o(e)g(a)h(list)g(and) +f(short)h(description)f(of)g(all)270 2482 y(datatypes)g(currently)e +(kno)o(wn)h(to)g(PostgreSQL.)270 2637 y Fh(2.4.5)59 b(Retrie)o(ving)13 +b(Data)i(Fr)o(om)f(The)g(Database)270 2734 y Ft(After)19 +b(ha)o(ving)g(de\002ned)h(and)f(populated)h(the)f(tables)h(in)g(the)g +(database)g Fr(testdb)f Ft(we)h(are)f(able)h(to)270 2794 +y(retrie)o(v)o(e)10 b(data)h(by)g(formulating)e(queries)i(using)g +Fr(psql)p Ft(.)k(Ev)o(ery)d(query)e(has)h(to)g(be)g(terminated)f(by)h +(a)h(';'.)270 2927 y Fn(Example)h(2.2)25 b Ft(W)l(e)f(assume)h(that)f +(all)g(the)g(tables)g(form)f(\002gure)g(1.1)i Fp(The)e(suppliers)i(and) +f(parts)270 2987 y(database)19 b Ft(e)o(xist)h(in)f(the)g(database)g +Fr(testdb)p Ft(.)36 b(If)18 b(we)i(want)e(to)h(kno)o(w)g(all)g(parts)g +(that)g(are)g(sold)g(in)270 3047 y(London)12 b(we)h(use)g(the)f(follo)o +(wing)f(session:)330 3155 y Fr(testdb=>)29 b(select)g(p.pname)330 +3215 y(testdb->)g(from)g(supplier)g(s,)h(sells)f(se,)h(part)f(p)330 +3275 y(testdb->)g(where)g(s.sno=se.sno)g(and)330 3335 +y(testdb->)208 b(p.pno=se.pno)29 b(and)330 3395 y(testdb->)208 +b(s.city='London';)p eop +%%Page: 31 31 +31 30 bop 198 60 a Fm(2.5.)29 b(SOME)12 b(OF)h(POSTGRESQL)-5 +b('S)12 b(SPECIAL)h(FEA)-6 b(TURES)14 b(IN)e(DET)-5 b(AIL)340 +b Ft(31)258 234 y Fr(pname)258 294 y(-----)258 354 y(Screw)258 +413 y(Nut)258 473 y(\(2)29 b(rows\))258 593 y(testdb=>)198 +729 y Fn(Example)13 b(2.3)25 b Ft(W)l(e)18 b(use)h(again)f(the)g +(tables)g(gi)o(v)o(en)g(in)g(\002gure)f(1.1.)33 b(No)o(w)18 +b(we)g(want)g(to)g(retrie)o(v)o(e)f(all)198 789 y(suppliers)12 +b(selling)h(no)f(parts)g(at)h(all)f(\(to)g(remo)o(v)o(e)g(them)g(from)f +(the)i(suppliers)f(table)g(for)g(e)o(xample\):)258 900 +y Fr(testdb=>)29 b(select)g(*)h(from)f(supplier)g(s)258 +960 y(testdb->)g(where)g(not)h(exists)258 1020 y(testdb->)507 +b(\(select)29 b(sno)h(from)f(sells)g(se)258 1080 y(testdb->)537 +b(where)29 b(se.sno)g(=)h(s.sno\);)258 1139 y(sno|sname|city)258 +1199 y(---+-----+----)258 1259 y(\(0)f(rows\))258 1378 +y(testdb=>)198 1487 y Ft(The)15 b(result)f(relation)g(is)h(empty)f(in)h +(our)f(e)o(xample)h(telling)f(us)h(that)f(e)o(v)o(ery)g(supplier)g +(contained)h(in)f(the)198 1546 y(database)e(sells)f(at)g(least)h(one)f +(part.)k(Note)c(that)g(we)g(used)g(a)h(nested)f(subselect)h(to)f +(formulate)e(the)i(query)m(.)198 1730 y Fi(2.5)71 b(Some)18 +b(of)f(P)o(ostgr)o(eSQL)-8 b(')m(s)16 b(Special)i(F)n(eatur)o(es)e(in)i +(Detail)198 1847 y Ft(T)n(raditional)23 b(relational)g(database)h +(management)g(systems)g(\(RDMSs\))g(pro)o(vide)f(only)g(v)o(ery)h(fe)o +(w)198 1907 y(datatypes)16 b(including)e(\003oating)h(point)g(numbers,) +h(inte)o(gers,)g(character)f(strings,)i(mone)o(y)m(,)f(and)f(dates.)198 +1967 y(This)j(makes)f(the)g(implementation)f(of)h(man)o(y)g +(applications)g(v)o(ery)g(dif)o(\002cult)e(and)j(that')m(s)f(why)g +(Post-)198 2026 y(greSQL)12 b(of)o(fers)e(substantial)i(additional)f +(po)o(wer)h(by)f(incorporating)f(the)i(follo)o(wing)f(additional)g +(basic)198 2086 y(concepts)i(in)f(such)h(a)f(way)g(that)g(users)h(can)g +(easily)f(e)o(xtend)h(the)f(system:)273 2194 y Fo(\017)25 +b Ft(inheritance)273 2305 y Fo(\017)g Ft(user)12 b(de\002ned)g +(functions)273 2416 y Fo(\017)25 b Ft(user)12 b(de\002ned)g(types)273 +2527 y Fo(\017)25 b Ft(rules)198 2636 y(Some)11 b(other)g(features,)h +(implemented)e(in)h(most)h(modern)e(RDBMSs)j(pro)o(vide)e(additional)f +(po)o(wer)h(and)198 2695 y(\003e)o(xibility:)273 2804 +y Fo(\017)25 b Ft(constraints)12 b(\(gi)o(v)o(en)g(in)g(the)g +Fr(create)29 b(table)12 b Ft(command\))273 2915 y Fo(\017)25 +b Ft(triggers)273 3026 y Fo(\017)g Ft(transaction)12 +b(inte)o(grity)198 3184 y Fh(2.5.1)59 b(Inheritance)198 +3283 y Ft(Inheritance)14 b(is)h(a)g(feature)f(well)g(kno)o(wn)g(from)g +(object)h(oriented)f(programming)e(languages)j(such)h(as)198 +3342 y(Smalltalk)c(or)g(C++.)18 b(PostgreSQL)13 b(refers)f(to)h(tables) +g(as)g Fp(classes)h Ft(and)f(the)g(de\002nition)f(of)h(a)g +Fp(class)g Ft(may)198 3402 y(inherit)f(the)g(contents)g(of)g(another)g +Fp(class)p Ft(:)p eop +%%Page: 32 32 +32 31 bop 270 60 a Ft(32)307 b Fm(CHAPTER)14 b(2.)28 +b(POSTGRESQL)13 b(FR)n(OM)f(THE)i(USER'S)e(POINT)g(OF)g(VIEW)270 +234 y Fn(Example)h(2.4)25 b Ft(First)12 b(we)g(de\002ne)g(a)h(table)f +(\(class\))h Fr(city)p Ft(:)330 320 y Fr(testdb=>)29 +b(create)g(table)g(city)h(\()330 380 y(testdb->)f(name)g +(varchar\(20\),)330 440 y(testdb->)g(population)g(int4,)330 +500 y(testdb->)g(altitude)g(int4\);)330 560 y(CREATE)330 +619 y(testdb=>)270 706 y Ft(No)o(w)17 b(we)g(de\002ne)f(a)i(ne)o(w)e +(table)h(\(class\))g Fr(capital)f Ft(that)h(inherits)f(all)h(attrib)o +(utes)g(from)f Fr(city)g Ft(and)270 765 y(adds)d(a)f(ne)o(w)h(attrib)o +(ute)e Fr(country)h Ft(storing)g(the)g(country)f(which)i(it)f(is)g(the) +h(capital)f(of.)330 852 y Fr(testdb=>)29 b(create)g(table)g(capital)g +(\()330 912 y(testdb->)g(country)g(varchar\(20\))330 +971 y(testdb->)g(\))h(inherits)f(\(city\);)330 1031 y(CREATE)330 +1091 y(testdb=>)270 1177 y Fn(Note)p Ft(:)23 b(The)17 +b(class)g Fr(capital)f Ft(inherits)g(only)g(the)g(attrib)o(utes)g(of)g +Fr(city)g Ft(\(not)g(the)g(tuples)h(stored)f(in)270 1237 +y Fr(city)p Ft(\).)f(The)e(ne)o(w)f(table)g(can)h(be)g(used)f(as)h(if)f +(it)g(were)g(de\002ned)h(without)e(using)i(inheritance:)330 +1323 y Fr(testdb=>)29 b(insert)g(into)g(capital)h(\(name,)f +(population,)330 1383 y(testdb->)656 b(altitude,)29 b(state\))330 +1443 y(testdb->)g(values)g(\('Vienna',)g(1500000,)g(200,)g +('Austria'\);)330 1503 y(INSERT)g(26191)g(1)330 1562 +y(testdb=>)270 1649 y Ft(Let')m(s)18 b(assume)g(that)f(the)g(tables)h +Fr(city)f Ft(and)g Fr(capital)g Ft(ha)o(v)o(e)h(been)f(populated)g(in)g +(the)h(follo)o(wing)270 1709 y(way:)330 1795 y Fr(city)179 +b(name)149 b(|)29 b(population)g(|)h(altitude)629 1855 +y(---------+------------+------)o(---)629 1914 y(Linz)149 +b(|)g(200000)29 b(|)179 b(270)629 1974 y(Graz)149 b(|)g(250000)29 +b(|)179 b(350)629 2034 y(Villach)59 b(|)179 b(50000)29 +b(|)179 b(500)629 2094 y(Salzburg)29 b(|)149 b(150000)29 +b(|)179 b(420)330 2273 y(capital)89 b(name)149 b(|)29 +b(population)g(|)h(altitude)f(|)60 b(country)629 2333 +y(---------+------------+------)o(----+----)o(-----)629 +2393 y(Vienna)89 b(|)119 b(1500000)29 b(|)179 b(200)30 +b(|)60 b(Austria)270 2479 y Ft(Standard)12 b(SQL92)g(queries)g(against) +h(the)f(abo)o(v)o(e)h(tables)f(beha)o(v)o(e)h(e)o(xactly)g(as)g(e)o +(xpected:)330 2565 y Fr(testdb=>)29 b(select)g(*)h(from)f(city)330 +2625 y(testdb->)g(where)g(altitude)g(>)h(400;)330 2685 +y(name)149 b(|)30 b(population)e(|)i(altitude)330 2745 +y(---------+------------+-------)o(--)330 2804 y(Villach)59 +b(|)179 b(50000)29 b(|)180 b(500)330 2864 y(Salzburg)29 +b(|)149 b(150000)29 b(|)180 b(420)330 2924 y(\(2)29 b(rows\))330 +3044 y(testdb=>)g(select)g(*)h(from)f(capital;)330 3103 +y(name)149 b(|)30 b(population)e(|)i(altitude)f(|)60 +b(country)330 3163 y(---------+------------+-------)o(---+-----)o(----) +330 3223 y(Vienna)89 b(|)119 b(1500000)29 b(|)180 b(200)29 +b(|)60 b(Austria)330 3283 y(\(1)29 b(row\))330 3402 y(testdb=>)p +eop +%%Page: 33 33 +33 32 bop 198 60 a Fm(2.5.)29 b(SOME)12 b(OF)h(POSTGRESQL)-5 +b('S)12 b(SPECIAL)h(FEA)-6 b(TURES)14 b(IN)e(DET)-5 b(AIL)340 +b Ft(33)198 234 y(If)11 b(we)g(want)g(to)g(kno)o(w)g(the)g(names)h(of)f +(all)g(cities)h(\(including)e(capitals\))h(that)g(are)g(located)h(at)f +(an)h(altitude)198 294 y(o)o(v)o(er)g(100)h(meters)f(the)g(query)g(is:) +258 376 y Fr(testdb=>)29 b(select)g(*)h(from)f(city*)258 +436 y(testdb->)g(where)g(altitude)g(>)h(100;)258 495 +y(name)149 b(|)30 b(population)e(|)i(altitude)258 555 +y(---------+------------+-------)o(--)258 615 y(Linz)149 +b(|)g(200000)29 b(|)180 b(270)258 675 y(Graz)149 b(|)g(250000)29 +b(|)180 b(350)258 734 y(Villach)59 b(|)179 b(50000)29 +b(|)180 b(500)258 794 y(Salzburg)29 b(|)149 b(150000)29 +b(|)180 b(420)258 854 y(Vienna)89 b(|)119 b(1500000)29 +b(|)180 b(200)258 914 y(\(5)29 b(rows\))258 1033 y(testdb=>)198 +1115 y Ft(Here)14 b(the)h('*')f(after)g Fr(city)g Ft(indicates)h(that)f +(the)g(query)h(should)f(be)h(run)f(o)o(v)o(er)g Fr(city)h +Ft(and)f(all)h(classes)198 1175 y(belo)o(w)i Fr(city)g +Ft(in)g(the)g(inheritance)f(hierarchy)m(.)29 b(Man)o(y)18 +b(of)e(the)i(commands)f(that)g(we)g(ha)o(v)o(e)g(already)198 +1235 y(discussed)c(\(SELECT)l(,)i(UPD)n(A)-6 b(TE,)14 +b(DELETE,)h(etc\))d(support)g(this)g('*')g(notation.)198 +1373 y Fh(2.5.2)59 b(User)15 b(De\002ned)g(Functions)198 +1467 y Ft(PostgreSQL)i(allo)o(ws)g(the)g(de\002nition)f(and)h(usage)h +(of)e Fp(user)i(de\002ned)f(functions)p Ft(.)30 b(The)17 +b(ne)o(w)g(de\002ned)198 1527 y(functions)12 b(can)g(be)h(used)g +(within)e(e)o(v)o(ery)i(query)m(.)i(PostgreSQL)d(pro)o(vides)g(two)g +(types)g(of)g(functions:)273 1608 y Fo(\017)25 b Ft(Query)11 +b(Language)i(\(SQL\))f(Functions:)j(functions)d(written)f(in)h(SQL.)273 +1699 y Fo(\017)25 b Ft(Programming)14 b(Language)j(Functions:)22 +b(functions)16 b(written)f(in)h(a)h Fp(compiled)f Ft(language)g(such) +323 1759 y(as)c(C.)198 1888 y Fn(Query)g(Language)g(\(SQL\))f +(Functions)198 1981 y Ft(These)k(functions)d(are)i(de\002ned)f(using)h +(SQL.)g(Note)f(that)g Fp(query)h(language)e(functions)h +Ft(do)h(not)f(e)o(xtend)198 2041 y(the)k Fp(e)o(xpr)n(essive)h(power)g +Ft(of)e(the)h(SQL92)g(standard.)29 b(Ev)o(ery)17 b Fp(query)g(language) +f(function)g Ft(can)h(be)g(re-)198 2100 y(placed)10 b(by)g(an)g +(appropriate)f(nested)h(query)f(\()p Fp(subselect)p Ft(\))h(without)f +(changing)h(the)f(semantical)h(meaning)198 2160 y(of)j(the)g(whole)g +(query)m(.)k(Ho)o(we)o(v)o(er)n(,)d(since)f(PostgreSQL)g(does)h(not)f +(allo)o(w)f Fp(subselects)j Ft(in)e(the)g Fp(selectlist)198 +2220 y Ft(at)g(the)f(moment)g(b)o(ut)h(does)g(allo)o(w)f(the)g(usage)h +(of)g Fp(query)g(language)e(functions)p Ft(,)i(the)f +Fp(e)o(xpr)n(essive)i(power)198 2280 y Ft(of)e(PostgreSQL)-5 +b(')m(s)13 b(current)e(SQL)i(implementation)e(is)i(e)o(xtended.)273 +2340 y(The)44 b(de\002nition)f(of)h Fp(query)g(language)e(functions)i +Ft(is)g(done)g(using)g(the)g(command)198 2399 y Fr(create)29 +b(function)g Fk(<)p Fr(function)p 958 2399 15 2 v 17 +w(name)p Fk(>)o Ft(.)d(Ev)o(ery)16 b(function)f(can)h(take)f(zero)g(or) +h(more)f(ar)o(-)198 2459 y(guments.)23 b(The)16 b(type)f(of)f(e)o(v)o +(ery)h(ar)o(gument)f(is)h(speci\002ed)h(in)e(the)h(list)g(of)g(ar)o +(guments)f(in)h(the)g(function)198 2519 y(de\002nition.)28 +b(The)17 b(type)f(of)h(the)f(function')m(s)g(result)h(is)f(gi)o(v)o(en) +h(after)f(the)g(ke)o(yword)g Fr(returns)g Ft(in)g(the)198 +2579 y(function)d(de\002nition.)20 b(The)15 b(types)f(used)g(for)g(the) +g(ar)o(guments)f(and)h(the)g(return)g(v)o(alue)f(of)h(the)g(function) +198 2638 y(can)i(either)f(be)g Fp(base)h(types)g Ft(\(e.g.)25 +b(int4,)17 b(v)o(archar)n(,)f(.)7 b(.)g(.)g(\))27 b(or)15 +b Fp(composite)g(types)p Ft(.)26 b(\(F)o(or)15 b(each)g(class)i(\(ta-) +198 2698 y(ble\))c(that)g(is)h(created,)g(a)g(corresponding)f +Fp(composite)g(type)h Ft(is)g(de\002ned.)19 b Fr(supplier)12 +b Ft(and)i Fr(part)f Ft(are)198 2758 y(e)o(xamples)g(for)e +Fp(composite)i(types)g Ft(after)e(the)i(tables)f Fr(supplier)g +Ft(and)g Fr(part)g Ft(ha)o(v)o(e)h(been)g(created.\))198 +2864 y Fn(Example)g(2.5)25 b Ft(This)13 b(is)g(an)f(e)o(xample)g(using) +h(only)f Fp(base)h(types)p Ft(.)198 2984 y(Before)29 +b(PostgreSQL)g(was)g(e)o(xtended)g(to)h(support)e(nested)i(subqueries)f +(user)h(de\002ned)f(query)198 3044 y(language)11 b(\(SQL\))f(functions) +h(could)g(be)g(used)g(to)g(simulate)g(them.)k(Consider)c(e)o(xample)h +(2.3)f(where)g(we)198 3103 y(ha)o(v)o(e)k(wanted)g(to)f(kno)o(w)h(the)f +(names)i(of)e(all)h(suppliers)f(that)h(do)g(not)f(sell)i(an)o(y)f(part) +f(at)h(all.)23 b(Normally)198 3163 y(we)13 b(would)f(formulate)g(the)h +(query)f(as)i(we)f(did)g(in)f(e)o(xample)i(2.3.)j(Here)c(we)g(want)g +(to)g(sho)o(w)g(a)g(possible)198 3223 y(way)h(of)g(formulating)f(the)h +(query)g(without)g(using)g(a)h(subquery)m(.)21 b(This)15 +b(is)g(done)f(in)h(two)e(steps.)23 b(In)14 b(the)198 +3283 y(\002rst)j(step)h(we)f(de\002ne)h(the)f(function)f +Fr(my)p 930 3283 V 18 w(exists)p Ft(.)30 b(In)17 b(the)h(second)g(step) +f(we)h(formulate)e(a)i(query)198 3342 y(using)12 b(the)h(ne)o(w)f +(function.)p eop +%%Page: 34 34 +34 33 bop 270 60 a Ft(34)307 b Fm(CHAPTER)14 b(2.)28 +b(POSTGRESQL)13 b(FR)n(OM)f(THE)i(USER'S)e(POINT)g(OF)g(VIEW)270 +234 y Ft(In)f(the)h(\002rst)f(step)h(we)g(de\002ne)g(the)f(ne)o(w)h +(function)f Fr(my)p 1188 234 15 2 v 18 w(exists\(int4\))f +Ft(which)i(takes)f(an)h(inte)o(ger)g(as)270 294 y(ar)o(gument:)330 +374 y Fr(testdb=>)29 b(create)g(function)g(my_exists\(int4\))f(returns) +h(int4)330 434 y(testdb->)g(as)g('select)h(count\(pno\))e(from)i(sells) +330 494 y(testdb->)148 b(where)30 b(sno)f(=)h($1;')f(language)g('sql';) +330 554 y(CREATE)330 613 y(testdb=>)270 694 y Ft(Here)12 +b(is)h(the)f(second)h(step)g(which)f(performs)f(the)i(intended)f +(retrie)o(v)o(e:)330 774 y Fr(testdb=>)29 b(select)g(s.sname)g(from)h +(supplier)f(s)330 834 y(testdb->)g(where)g(my_exists\(s.sno\))f(=)i(0;) +330 894 y(sname)330 953 y(-----)330 1013 y(\(0)f(rows\))330 +1133 y(testdb=>)270 1213 y Ft(No)o(w)12 b(let')m(s)h(ha)o(v)o(e)f(a)h +(look)f(at)g(what)h(is)f(happening)g(here.)k(The)d(function)e +Fr(my)p 1582 1213 V 18 w(exists\(int4\))g Ft(takes)270 +1273 y(one)j(ar)o(gument)f(which)h(must)g(be)g(of)f(type)h(inte)o(ger)m +(.)20 b(W)n(ithin)13 b(the)h(function)f(de\002nition)g(this)h(ar)o +(gument)270 1332 y(can)20 b(be)f(refered)g(to)g(using)h(the)f($1)h +(notation)f(\(if)f(there)h(were)h(furhter)e(ar)o(guments)h(the)o(y)h +(could)f(be)270 1392 y(referred)13 b(to)i(by)f($2,)h($3,)h(.)7 +b(.)g(.)g(\).)25 b Fr(my)p 889 1392 V 17 w(exists\(int4\))14 +b Ft(returns)g(the)g(number)g(of)g(tuples)h(from)e(table)270 +1452 y Fr(sells)19 b Ft(where)f(the)h(attrib)o(ute)f +Fr(sno)h Ft(is)h(equal)f(to)f(the)h(gi)o(v)o(en)g(ar)o(gument)g($1)f +(\()p Fr(sno)30 b(=)f($1)p Ft(\).)36 b(The)270 1512 y(ke)o(yword)12 +b Fr(language)29 b('sql')13 b Ft(tells)h(PostgreSQL)f(that)h(the)f(ne)o +(w)h(function)e(is)i(a)g(query)f(language)270 1572 y(function.)345 +1631 y(The)e(query)f(in)g(the)h(second)g(step)g(e)o(xamines)g(e)o(v)o +(ery)f(tuple)h(from)e(table)i Fr(supplier)f Ft(and)g(checks)i(if)270 +1691 y(it)f(sati\002es)g(the)g(gi)o(v)o(en)g(quali\002cation.)j(It)d +(does)g(so)g(by)g(taking)g(the)f(supplier)h(id)g Fr(sno)f +Ft(of)h(e)o(v)o(ery)f(tuple)h(and)270 1751 y(gi)o(ving)g(it)i(as)f(an)h +(ar)o(gument)e(to)i(the)f(function)f Fr(my)p 1127 1751 +V 18 w(exists\(int4\))p Ft(.)j(In)e(other)g(words)g(the)g(function)270 +1811 y Fr(my)p 333 1811 V 18 w(exists\(int4\))17 b Ft(is)h(called)h +(once)f(for)g(e)o(v)o(ery)g(tuple)g(of)g(table)g Fr(supplier)p +Ft(.)33 b(The)19 b(function)270 1870 y(returns)10 b(the)h(number)f(of)h +(tuples)g(ha)o(ving)f(the)h(gi)o(v)o(en)f(supplier)h(id)g +Fr(sno)f Ft(contained)h(in)f(table)h Fr(sells)p Ft(.)k(A)270 +1930 y(result)c(of)f(zero)h(means)h(that)f(no)g(such)g(tuple)g(is)g(a)o +(v)o(ailable)g(meaning)g(that)f(the)h(corresponding)g(supplier)270 +1990 y(does)i(not)g(sell)g(a)g(single)g(part.)k(W)l(e)c(can)h(see)f +(that)g(this)g(query)f(is)i(semantically)e(equi)o(v)o(alent)g(to)h(the) +g(one)270 2050 y(gi)o(v)o(en)f(in)g(e)o(xample)h(2.3.)270 +2155 y Fn(Example)g(2.6)25 b Ft(This)13 b(e)o(xample)f(sho)o(ws)h(ho)o +(w)f(to)g(use)h(a)g Fp(composite)f(type)h Ft(in)f(a)g(function)g +(de\002nition.)270 2274 y(Imagine)21 b(that)g(the)h(price)f(of)g(e)o(v) +o(ery)g(part)g(was)h(doubled)f(o)o(v)o(er)h(night.)42 +b(If)21 b(you)h(want)e(to)i(look)f(at)270 2334 y(the)d(part)f(table)h +(with)f(the)h(ne)o(w)g(v)o(alues)f(you)h(could)g(use)g(the)g(follo)o +(wing)e(function)h(which)g(uses)i(the)270 2394 y Fp(composite)12 +b(type)h Fr(part)f Ft(for)f(its)i(ar)o(gument:)330 2474 +y Fr(testdb=>)29 b(create)g(function)g(new_price\(part\))f(returns)h +(float)330 2534 y(testdb->)g(as)g('select)h($1.price)f(*)g(2;')h +(language)f('sql';)330 2594 y(CREATE)330 2654 y(testdb=>)g(select)g +(pno,)g(pname,)h(new_price\(price\))e(as)h(new_price)330 +2713 y(testdb->)g(from)g(part;)330 2773 y(pno)g(|)60 +b(pname)f(|)h(new_price)330 2833 y(----+---------+-----------)360 +2893 y(1)f(|)h(Screw)f(|)269 b(20)360 2952 y(2)59 b(|)h(Nut)119 +b(|)269 b(16)360 3012 y(3)59 b(|)h(Bolt)89 b(|)269 b(30)360 +3072 y(4)59 b(|)h(Cam)119 b(|)269 b(50)330 3132 y(\(4)29 +b(rows\))330 3251 y(testdb=>)270 3332 y Ft(Note)12 b(that)h(this)g +(could)f(ha)o(v)o(e)h(been)g(done)f(by)g(a)h(normal)f(query)g +(\(without)g(using)g(a)h(user)g(de\002ned)f(func-)270 +3391 y(tion\))g(as)g(well)h(b)o(ut)f(it')m(s)g(an)h(easy)g(to)f +(understand)g(e)o(xample)g(for)g(the)g(usage)h(of)f(functions.)p +eop +%%Page: 35 35 +35 34 bop 198 60 a Fm(2.5.)29 b(SOME)12 b(OF)h(POSTGRESQL)-5 +b('S)12 b(SPECIAL)h(FEA)-6 b(TURES)14 b(IN)e(DET)-5 b(AIL)340 +b Ft(35)198 234 y Fn(Pr)o(ogramming)13 b(Language)f(Functions)198 +328 y Ft(PostgreSQL)h(also)g(supports)g Fp(user)g(de\002ned)g +(functions)g Ft(written)f(in)h(C.)g(This)h(is)f(a)g(v)o(ery)g(po)o +(werful)f(fea-)198 387 y(ture)18 b(because)h(you)g(can)f(add)h(an)o(y)g +(function)e(that)i(can)f(be)h(formulated)e(in)i(C.)g(F)o(or)f(e)o +(xample)h(Post-)198 447 y(greSQL)c(lacks)h(the)f(function)f +Fr(sqrt\(\))g Ft(b)o(ut)h(it)g(can)h(be)f(easily)g(added)h(using)f(a)g +(programming)f(lan-)198 507 y(guage)e(function.)198 626 +y Fn(Example)h(2.7)25 b Ft(W)l(e)18 b(sho)o(w)g(ho)o(w)g(to)g(realize)g +(the)g(user)g(de\002ned)g(function)f Fr(pg)p 1594 626 +15 2 v 18 w(my)p 1672 626 V 18 w(sqrt\(int4\))p Ft(.)198 +686 y(The)c(implementation)e(can)i(be)f(di)o(vided)g(into)g(three)g +(steps:)273 785 y Fo(\017)25 b Ft(formulating)10 b(the)j(ne)o(w)f +(function)f(in)h(C)273 885 y Fo(\017)25 b Ft(compiling)11 +b(and)h(linking)g(it)g(to)g(a)h(shared)f(library)273 +984 y Fo(\017)25 b Ft(making)11 b(the)i(ne)o(w)f(function)f(kno)o(wn)h +(to)g(PostgreSQL)198 1093 y Fn(F)o(ormulating)g(the)g(New)g(Function)f +(in)h(C:)25 b Ft(W)l(e)16 b(create)g(a)h(ne)o(w)e(\002le)h(called)g +Fr(sqrt.c)g Ft(and)g(add)g(the)323 1153 y(follo)o(wing)10 +b(lines:)382 1272 y Fr(#include)29 b()382 +1332 y(#include)g()382 1392 y(#include)g()382 +1511 y(int4)h(pg_my_sqrt\(int4)e(arg1\))382 1571 y({)442 +1631 y(return)h(\(ceil\(sqrt\(arg1\)\)\);)382 1691 y(})323 +1810 y Ft(The)17 b(function)g Fr(pg)p 664 1810 V 18 w(my)p +742 1810 V 17 w(sqrt\(\))g Ft(takes)h(one)f(ar)o(gument)g(of)g(type)g +Fr(int4)g Ft(which)g(is)h(a)g(Post-)323 1870 y(greSQL)i(type)g +(de\002ned)h(in)f Fr(postgres.h)f Ft(and)i(returns)f(the)h(inte)o(ger)f +(v)o(alue)g(ne)o(xt)h(to)f(the)323 1929 y(square)c(root)g(of)g(the)g +(ar)o(gument.)27 b(As)17 b(with)f Fp(query)h(language)d(functions)i +Ft(\(see)h(pre)o(vious)f(sec-)323 1989 y(tion\))c(the)h(ar)o(guments)g +(can)g(be)h(of)e Fp(base)i Ft(or)f(of)f Fp(composite)i(type)p +Ft(.)k(Special)13 b(care)g(must)g(be)h(taken)323 2049 +y(when)d(using)g Fp(base)h(types)g Ft(that)f(are)h(lar)o(ger)e(than)i +(four)e(bytes)i(in)f(length.)k(PostgreSQL)c(supports)323 +2109 y(three)h(types)g(of)g(passing)h(a)g(v)o(alue)f(to)g(the)g(user)h +(de\002ned)f(function:)382 2208 y Fo(\017)25 b Ft(pass)13 +b(by)g(v)o(alue,)f(\002x)o(ed)h(length)382 2288 y Fo(\017)25 +b Ft(pass)13 b(by)g(reference,)f(\002x)o(ed)g(length)382 +2367 y Fo(\017)25 b Ft(pass)13 b(by)g(reference,)f(v)o(ariable)f +(length)323 2467 y(Only)k(data)h(types)g(that)g(are)g(1,)h(2)f(or)f(4)h +(bytes)g(in)g(length)g(can)g(be)g Fp(passed)g(by)g(value)p +Ft(.)27 b(W)l(e)16 b(just)323 2527 y(gi)o(v)o(e)d(an)g(e)o(xample)g +(for)g(the)g(usage)h(of)f Fp(base)g(types)h Ft(that)f(can)h(be)f(used)h +(for)e Fp(pass)i(by)g(value)f Ft(here.)323 2586 y(F)o(or)j(information) +g(on)h(ho)o(w)g(to)g(use)h(types)f(that)g(require)g Fp(pass)h(by)f(r)n +(efer)n(ence)i Ft(or)e(ho)o(w)g(to)g(use)323 2646 y Fp(composite)12 +b(types)h Ft(refer)e(to)h([LOCK98].)198 2746 y Fn(Compiling)g(and)f +(Linking)h(It)g(to)g(a)h(Shar)o(ed)e(Library:)25 b Ft(PostgreSQL)14 +b(binds)i(the)f(ne)o(w)g(function)f(to)323 2805 y(the)f(runtime)g +(system)i(by)f(using)g(a)g(shared)g(library)f(containing)g(the)h +(function.)20 b(Therefore)13 b(we)323 2865 y(ha)o(v)o(e)i(to)g(create)g +(a)g(shared)g(library)f(out)g(of)h(the)g(object\002le\(s\))f +(containing)g(the)h(function\(s\).)23 b(It)323 2925 y(depends)18 +b(on)f(the)h(system)g(and)g(the)f(compiler)g(ho)o(w)h(this)f(can)h(be)g +(done.)32 b(On)18 b(a)g(Linux)f(ELF)323 2985 y(system)12 +b(using)h Fr(gcc)f Ft(it)g(can)h(be)f(done)g(by)h(using)f(the)g(follo)o +(wing)f(commands:)382 3104 y Fr($)30 b(gcc)g(-I$PGROOT/include)e(-fpic) +h(-c)59 b(sqrt.c)30 b(-o)f(sqrt.o)382 3164 y($)h(gcc)g(-shared)f +(sqrt.o)g(-o)h(sqrt.so)323 3283 y Ft(where)17 b Fr($PGROOT)g +Ft(is)g(the)h(path)f(PostgreSQL)g(was)h(installed)f(to.)31 +b(The)18 b(important)e(options)323 3342 y(gi)o(v)o(en)11 +b(to)g Fr(gcc)g Ft(here)g(are)g Fr(-fpic)g Ft(in)g(the)g(\002rst)g +(line)g(which)g(tells)g Fr(gcc)g Ft(to)g(produce)g Fp(position)g(in-) +323 3402 y(dependent)e(code)h Ft(that)g(can)g(be)g(loaded)g(to)f(an)o +(y)h(address)h(of)e(the)h(process)g(image)g(and)g Fr(-shared)p +eop +%%Page: 36 36 +36 35 bop 270 60 a Ft(36)307 b Fm(CHAPTER)14 b(2.)28 +b(POSTGRESQL)13 b(FR)n(OM)f(THE)i(USER'S)e(POINT)g(OF)g(VIEW)395 +234 y Ft(in)g(the)g(second)h(line)g(telling)f Fr(gcc)g +Ft(to)g(produce)h(a)f(shared)h(library)m(.)i(If)d(you)g(got)h(another)f +(system)395 294 y(where)k(the)g(abo)o(v)o(e)h(described)f(steps)h(do)f +(not)g(work)g(you)g(will)g(ha)o(v)o(e)g(to)h(refer)e(to)h(the)g(manual) +395 354 y(pages)i(of)g(your)g(c-compiler)f(\(often)g +Fr(man)30 b(cc)p Ft(\))18 b(and)g(your)f(linker)h(\()p +Fr(man)29 b(ld)p Ft(\))17 b(to)i(see)f(ho)o(w)395 413 +y(shared)12 b(libraries)g(can)g(be)h(b)o(uilt.)270 599 +y Fn(Making)f(the)f(New)i(Function)e(Known)g(to)h(P)o(ostgr)o(eSQL:)25 +b Ft(No)o(w)f(we)g(ha)o(v)o(e)g(to)g(tell)f(PostgreSQL)395 +659 y(about)18 b(the)g(ne)o(w)h(function.)34 b(W)l(e)18 +b(do)h(so)g(by)f(using)h(the)g Fr(create)29 b(function)18 +b Ft(command)395 719 y(within)11 b Fr(psql)h Ft(as)h(we)g(did)f(for)f +Fp(query)i(language)e(functions)p Ft(:)454 924 y Fr(testdb=>)29 +b(create)h(function)f(pg_my_sqrt\(int4\))f(returns)h(int4)454 +984 y(testdb->)g(as)h('//sqrt.)o(so')454 +1044 y(testdb->)f(language)g('c';)454 1103 y(CREATE)454 +1163 y(testdb=>)395 1369 y Ft(From)13 b(no)o(w)h(on)g(the)g(function)f +Fr(pg)p 998 1369 15 2 v 18 w(my)p 1076 1369 V 17 w(sqrt\(int4\))h +Ft(can)g(be)g(used)h(in)f(e)o(v)o(ery)g(query)m(.)20 +b(Here)395 1429 y(is)12 b(a)h(query)f(against)g(table)g +Fr(part)g Ft(using)h(the)f(ne)o(w)g(function:)454 1634 +y Fr(testdb=>)29 b(select)h(pname,)f(price,)g(pg_my_sqrt\(price\))454 +1694 y(testdb->)g(from)h(part)454 1754 y(testdb->)f(where)h +(pg_my_sqrt\(price\))e(<)h(10;)454 1813 y(pname)149 b +(|price|pg_my_sqrt)454 1873 y(----------+-----+----------)454 +1933 y(Screw)g(|)60 b(10)30 b(|)239 b(4)454 1993 y(Nut)209 +b(|)90 b(8)30 b(|)239 b(3)454 2053 y(Bolt)179 b(|)60 +b(15)30 b(|)239 b(4)454 2112 y(Cam)209 b(|)60 b(25)30 +b(|)239 b(5)454 2172 y(\(4)30 b(rows\))454 2292 y(testdb=>)270 +2552 y Fh(2.5.3)59 b(User)15 b(De\002ned)g(T)l(ypes)270 +2687 y Ft(Adding)10 b(a)g(ne)o(w)g(data)h(type)f(to)g(PostgreSQL)g +(also)h(requires)e(the)i(de\002nition)e(of)h(an)g Fp(input)g +Ft(and)g(an)h Fp(output)270 2746 y(function)p Ft(.)19 +b(These)c(functions)e(are)g(implemented)g(using)h(the)f(techniques)h +(presented)g(in)f(the)h(pre)o(vious)270 2806 y(section)f +Fp(Pr)n(ogr)o(amming)f(Language)f(Functions)p Ft(.)16 +b(The)d(functions)f(determine)f(ho)o(w)h(the)h(type)f(appears)270 +2866 y(in)19 b(strings)g(\(for)f(input)h(by)g(the)g(user)g(and)g +(output)g(to)g(the)g(user\))g(and)g(ho)o(w)g(the)g(type)g(is)h(or)o +(ganized)270 2926 y(in)g(memory)m(.)36 b(The)20 b(input)g(function)f +(takes)g(a)h(null-delimited)e(character)h(string)h(as)g(its)g(input)f +(and)270 2986 y(returns)14 b(the)g(internal)g(\(in)f(memory\))g +(representation)h(of)g(the)g(type.)22 b(The)15 b(output)e(function)h +(takes)g(the)270 3045 y(internal)d(representation)g(of)g(the)g(type)h +(and)f(returns)g(a)h(null)f(delimited)g(character)g(string.)k(Besides)e +(the)270 3105 y(de\002nition)c(of)g Fp(input)h Ft(and)f +Fp(output)h(functions)f Ft(it)h(is)g(often)f(necessary)i(to)e(enhance)i +(operators)e(\(e.g.)16 b Fr('+')p Ft(\))270 3165 y(and)10 +b(aggre)o(gate)g(functions)f(for)h(the)g(ne)o(w)g(data)g(type.)15 +b(Ho)o(w)9 b(this)h(is)h(done)f(is)g(described)g(in)g(section)g(2.5.4) +270 3225 y Fp(Extending)i(Oper)o(ators)h Ft(and)g(section)f(2.5.5)h +Fp(Extending)g(Aggr)n(e)n(gates)p Ft(.)p eop +%%Page: 37 37 +37 36 bop 198 60 a Fm(2.5.)29 b(SOME)12 b(OF)h(POSTGRESQL)-5 +b('S)12 b(SPECIAL)h(FEA)-6 b(TURES)14 b(IN)e(DET)-5 b(AIL)340 +b Ft(37)198 234 y Fn(Example)13 b(2.8)25 b Ft(Suppose)13 +b(we)h(want)f(to)g(de\002ne)h(a)g(comple)o(x)f(type)g(which)h +(represents)f(comple)o(x)h(num-)198 294 y(bers.)i(Therefore)c(we)g +(create)h(a)f(ne)o(w)g(\002le)g(called)h Fr(complex.c)e +Ft(with)h(the)h(follo)o(wing)e(contents:)258 381 y Fr(#include)29 +b()258 441 y(#include)g()258 +500 y(#include)g()258 620 y(/*)g(Type)h(definition)f(of)g +(Complex)g(*/)258 680 y(typedef)g(struct)g(Complex)g({)377 +739 y(double)179 b(x;)377 799 y(double)g(y;)258 859 y(})30 +b(Complex;)258 979 y(/*)f(Input)h(function:)f(takes)g(a)h(char)f +(string)g(of)h(the)g(from)288 1038 y(*)f('x,y')h(as)f(argument)g(where) +h(x)g(and)f(y)h(must)f(be)h(string)288 1098 y(*)f(representations)g(of) +g(double)h(numbers.)f(It)g(returns)g(a)288 1158 y(*)g(pointer)h(to)f +(an)h(instance)f(of)h(structure)e(Complex)i(that)288 +1218 y(*)f(is)h(setup)f(with)h(the)f(given)h(x)g(and)f(y)h(values.)f +(*/)258 1277 y(Complex)g(*)258 1337 y(complex_in\(char)f(*str\))258 +1397 y({)318 1457 y(double)h(x,)g(y;)318 1517 y(Complex)g(*result;)318 +1636 y(/*)g(scan)h(the)f(input)h(string)f(and)g(set)h(x)g(and)f(y)h(to) +g(the)347 1696 y(*)g(corresponding)f(double)g(numbers)g(*/)318 +1756 y(if)g(\(sscanf\(str,)g(")h(\()f(\045lf)h(,)g(\045lf)f(\)",)h(&x,) +f(&y\))h(!=)g(2\))f({)377 1815 y(elog\(ERROR,)g("complex_in:)g(error)g +(in)h(parsing"\);)377 1875 y(return)g(NULL;)318 1935 +y(})318 1995 y(/*)f(reserve)g(memory)h(for)f(the)h(Complex)f(data)g +(structure)347 2055 y(*)h(Note:)g(we)f(use)h(palloc)f(here)g(because)h +(the)f(memory)347 2114 y(*)h(allocated)f(using)g(palloc)h(is)f(freed)h +(automatically)347 2174 y(*)g(by)g(PostgreSQL)f(when)g(it)h(is)f(not)h +(used)f(any)h(more)f(*/)318 2234 y(result)g(=)h(\(Complex)f +(*\)palloc\(sizeof\(Complex\)\);)318 2294 y(result->x)f(=)i(x;)318 +2353 y(result->y)e(=)i(y;)318 2413 y(return)f(\(result\);)258 +2473 y(})258 2593 y(/*)g(Output)h(Function)f(*/)258 2652 +y(/*)g(Takes)h(a)g(pointer)f(to)g(an)h(instance)f(of)h(structure)f +(Complex)288 2712 y(*)g(as)h(argument)f(and)h(returns)f(a)h(character)e +(pointer)i(to)f(a)288 2772 y(*)g(string)h(representation)e(of)i(the)f +(given)h(argument)f(*/)258 2832 y(char)g(*)258 2891 y +(complex_out\(Complex)f(*complex\))258 2951 y({)318 3011 +y(char)h(*result;)318 3131 y(if)g(\(complex)g(==)h(NULL\))f +(return\(NULL\);)318 3190 y(result)g(=)h(\(char)f(*\))h(palloc\(60\);) +318 3250 y(sprintf\(result,)e("\(\045g,\045g\)",)h(complex->x,)f +(complex->y\);)318 3310 y(return\(result\);)258 3370 +y(})p eop +%%Page: 38 38 +38 37 bop 270 60 a Ft(38)310 b Fm(CHAPTER)14 b(2.)25 +b(POSTGRESQL)13 b(FR)n(OM)f(THE)i(USER'S)e(POINT)g(OF)g(VIEW)270 +234 y Ft(Note)h(that)g(the)g(functions)g(de\002ned)g(abo)o(v)o(e)h +(operate)f(on)g(types)g(that)g(require)g Fp(pass)g(by)h(r)n(efer)n +(ence)p Ft(.)20 b(The)270 294 y(functions)c(take)h(a)g(pointer)f(to)h +(the)g(data)g(as)h(ar)o(gument)e(and)h(return)f(a)i(pointer)e(to)h(the) +g(deri)o(v)o(ed)f(data)270 354 y(instead)h(of)g(passing)g(and)g +(returning)e(the)i(data)g(itself.)29 b(That')m(s)18 b(why)e(we)h(ha)o +(v)o(e)g(to)g(reserv)o(e)g(memory)270 413 y(using)f Fr(palloc)f +Ft(within)g(the)h(functions.)26 b(\(If)14 b(we)i(would)f(just)h +(de\002ne)f(a)h(local)g(v)o(ariable)f(and)h(return)270 +473 y(the)e(addresses)h(of)f(these)h(v)o(ariables)f(the)g(system)h +(would)e(fail,)i(because)g(the)f(memory)f(used)i(by)f(local)270 +533 y(v)o(ariables)e(is)h(freed)e(when)i(the)f(function)g(de\002ning)f +(these)i(v)o(ariables)f(completes.\))345 593 y(The)e(ne)o(xt)g(step)g +(is)g(to)g(compile)f(the)h(C-functions)f(and)h(create)f(the)h(shared)g +(library)f Fr(complex.so)p Ft(.)270 653 y(This)h(is)g(done)f(in)g(the)h +(way)f(described)g(in)h(the)f(pre)o(vious)g(section)g +Fp(Pr)n(ogr)o(amming)h(Language)e(Functions)270 712 y +Ft(and)j(depends)g(on)g(the)g(system)h(you)f(are)g(using.)k(On)c(a)g +(Linux)g(ELF)h(system)g(using)f Fr(gcc)f Ft(it)h(would)f(look)270 +772 y(like)i(this:)330 868 y Fr($)30 b(gcc)f(-I$PGROOT/include)f(-fpic) +h(-c)60 b(complex.c)29 b(-o)h(complex.o)330 928 y($)g(gcc)f(-shared)g +(-o)h(complex.so)f(complex.o)270 1023 y Ft(No)o(w)11 +b(we)h(are)f(ready)g(to)g(de\002ne)h(the)f(ne)o(w)g(datatype)g(b)o(ut)g +(before)g(that)g(we)h(ha)o(v)o(e)g(to)f(make)g(the)g +Fp(input)g Ft(and)270 1083 y Fp(output)h(function)g Ft(kno)o(wn)f(to)i +(PostgreSQL:)330 1179 y Fr(testdb=>)29 b(create)g(function)g +(complex_in\(opaque\))330 1238 y(testdb->)g(returns)g(complex)330 +1298 y(testdb->)g(as)g('//complex.so)o(')330 +1358 y(testdb->)g(language)g('c';)330 1418 y(NOTICE:)59 +b(ProcedureCreate:)28 b(type)h('complex')g(is)h(not)599 +1477 y(yet)f(defined)330 1537 y(CREATE)330 1597 y(testdb=>)g(create)g +(function)g(complex_out\(opaque\))330 1657 y(testdb->)g(returns)g +(opaque)330 1717 y(testdb->)g(as)g +('//complex.so)o(')330 1776 y(testdb->)g +(language)g('c';)330 1836 y(CREATE)330 1896 y(testdb=>)g(create)g(type) +g(complex)h(\()330 1956 y(testdb->)f(internallength)f(=)i(16,)330 +2015 y(testdb->)f(input)g(=)h(complex_in,)330 2075 y(testdb->)f(output) +g(=)h(complex_out)330 2135 y(testdb->)f(\);)330 2195 +y(CREATE)330 2255 y(testdb=>)270 2350 y Ft(Note)37 b(that)f(the)h(ar)o +(gument)f(type)h(gi)o(v)o(en)f(in)h(the)f(de\002nition)g(of)h +Fr(complex)p 1798 2350 15 2 v 17 w(out\(\))f Ft(and)270 +2410 y Fr(complex)p 483 2410 V 17 w(in\(\))28 b Ft(-)g +Fr(opaque)f Ft(-)h(is)h(needed)f(by)g(PostgreSQL)g(to)g(be)g(able)g(to) +g(pro)o(vide)g(an)270 2470 y(uniform)14 b(mechanism)i(for)f(the)h +(de\002nition)e(of)i(the)f Fp(input)h Ft(and)f Fp(output)g(functions)h +Ft(needed)g(by)f(a)h(ne)o(w)270 2530 y(data)k(type.)40 +b(It)20 b(is)h(not)f(necessary)h(to)f(specify)h(the)f(e)o(xact)h(type)f +(of)g(the)h(ar)o(guments)f(gi)o(v)o(en)g(to)g(the)270 +2589 y(functions.)34 b(The)19 b Fp(input)f(function)g +Ft(is)h(ne)o(v)o(er)f(called)g(e)o(xplicitly)g(and)h(when)g(it)f(is)h +(called)f(implicitly)270 2649 y(\(e.g.)24 b(by)15 b(a)g(statement)h +(like)e Fr(insert)29 b(into)p Ft(\))15 b(it)f(is)i(clear)f(that)g(a)g +(character)g(string)f(\(i.e.)25 b(a)15 b(part)g(of)270 +2709 y(the)h Fp(insert)h Ft(query\))e(will)g(be)i(passed)g(to)f(it.)26 +b(The)17 b Fp(output)e(function)h Ft(is)g(only)g(called)g(\()g(by)g(an) +g(internal)270 2769 y(mechanism)h(of)g(PostgreSQL\))g(when)g(data)g(of) +g(the)g(corresponding)g(user)g(de\002ned)g(type)g(has)h(to)f(be)270 +2828 y(displayed.)32 b(In)18 b(this)g(case)h(it)e(is)h(also)h(clear)e +(that)h(the)g(input)f(is)i(of)e(the)h(type)g(used)g(for)f(the)h +(internal)270 2888 y(representation)12 b(\(e.g.)k Fr(complex)p +Ft(\).)e(The)f(output)f(is)h(of)f(type)g(character)g(string.)270 +3008 y(The)h(ne)o(w)f(type)g(can)h(no)o(w)f(be)g(used)h(as)g(if)f(it)g +(were)g(another)g(base)h(type:)330 3103 y Fr(testdb=>)29 +b(create)g(table)g(complex_test)330 3163 y(testdb->)g(\(val)g +(complex\);)330 3223 y(CREATE)330 3283 y(testdb=>)g(insert)g(into)g +(complex_test)330 3342 y(testdb->)g(\(val\))g(values)g(\('\(1,2\)'\);) +330 3402 y(INSERT)59 b(155872)29 b(1)p eop +%%Page: 39 39 +39 38 bop 198 60 a Fm(2.5.)29 b(SOME)12 b(OF)h(POSTGRESQL)-5 +b('S)12 b(SPECIAL)h(FEA)-6 b(TURES)14 b(IN)e(DET)-5 b(AIL)340 +b Ft(39)258 234 y Fr(testdb=>)29 b(insert)g(into)g(complex_test)258 +294 y(testdb->)g(\(val\))g(values)g(\('\(3,4\)'\);)258 +354 y(INSERT)59 b(155873)29 b(1)258 413 y(testdb=>)g(insert)g(into)g +(complex_test)258 473 y(testdb->)g(\(val\))g(values)g(\('\(5,6\)'\);) +258 533 y(INSERT)59 b(155874)29 b(1)258 653 y(testdb=>)g(select)g(*)h +(from)f(complex_test;)318 712 y(val)258 772 y(-----)258 +832 y(\(1,2\))258 892 y(\(3,4\))258 951 y(\(5,6\))258 +1011 y(\(3)g(rows\))258 1131 y(testdb=>)198 1272 y Fh(2.5.4)59 +b(Extending)15 b(Operators)198 1365 y Ft(So)i(far)g(we)g(are)h(able)f +(to)h(de\002ne)f(a)h(ne)o(w)f(type,)i(create)f(tables)f(that)h(use)g +(the)f(ne)o(w)g(type)h(for)e(one)i(\(or)198 1425 y(more\))13 +b(attrib)o(ute\(s\))g(and)g(populate)h(the)g(ne)o(w)g(tables)g(with)f +(data.)21 b(W)l(e)14 b(are)g(also)g(able)g(to)g(retrie)o(v)o(e)f(data) +198 1485 y(from)d(those)h(tables)h(as)g(long)e(as)i(we)f(do)g(not)g +(use)h(the)f(ne)o(w)g(data)g(types)h(within)e(the)h(quali\002cation)f +(of)h(the)198 1544 y(query)m(.)23 b(If)14 b(we)h(want)f(to)h(use)g(the) +g(ne)o(w)g(data)g(types)g(in)g(the)g Fr(where)f Ft(clause)i(we)f(ha)o +(v)o(e)g(to)g(adapt)g(some)198 1604 y(\(or)d(all\))f(of)h(the)h +(operators.)198 1718 y Fn(Example)g(2.9)25 b Ft(W)l(e)10 +b(sho)o(w)h(ho)o(w)f(the)g(operator)g('=')g(can)g(be)h(adapted)f(for)g +(the)g(usage)h(on)f(the)h Fr(complex)198 1778 y Ft(data)17 +b(type)g(de\002ned)g(in)f(section)i(2.5.3)f Fp(User)h(De\002ned)f(T)l +(ypes)p Ft(.)31 b(W)l(e)17 b(need)g(a)g(user)g(de\002ned)g(function)198 +1838 y Fr(complex)p 411 1838 15 2 v 17 w(cmp\(complex,complex\))10 +b Ft(that)j(returns)f Fr(true)g Ft(if)g(the)g(comple)o(x)g(numbers)g +(gi)o(v)o(en)198 1898 y(as)g(ar)o(guments)g(are)g(equal)f(and)h +Fr(false)g Ft(otherwise.)j(This)d(function)f(is)h(de\002ned)g(as)g +(described)g(in)g(sec-)198 1957 y(tion)h(2.5.2)i Fp(User)f(De\002ned)g +(Functions)p Ft(.)20 b(In)13 b(our)g(case)h(there)g(are)f(already)g +(two)g(functions)g(present)h(for)198 2017 y(the)f(usage)h(of)f(type)h +Fr(complex)e Ft(-the)h Fp(input)g Ft(and)h Fp(output)f(function)f +Ft(de\002ned)i(in)f(e)o(xample)g(2.8.)20 b(So)13 b(we)198 +2077 y(can)k(add)f(the)h(ne)o(w)f(function)f Fr(complex)p +943 2077 V 18 w(cmp\(complex,complex\))f Ft(by)i(simply)g(appending)198 +2137 y(the)c(follo)o(wing)f(lines)i(to)f(the)g(\002le)g +Fr(complex.c)g Ft(gi)o(v)o(en)g(in)g(e)o(xample)h(2.8:)258 +2229 y Fr(/*)29 b(Comparison)g(Function)g(*/)258 2289 +y(/*)g(returns)h(true)f(if)h(arg1)f(and)h(arg2)f(are)h(equal)f(*/)258 +2348 y(bool)g(complex_cmp\(Complex)f(*arg1,)h(Complex)g(*arg2\))258 +2408 y({)318 2468 y(if\(\(arg1->x)f(==)i(arg2->x\))f(&&)407 +2528 y(\(arg1->y)g(==)h(arg2->y\)\))318 2588 y({)377 +2647 y(return)g(true;)318 2707 y(})318 2767 y(else)318 +2827 y({)377 2886 y(return)g(false;)318 2946 y(})258 +3006 y(})198 3098 y Ft(No)o(w)12 b(we)h(create)f(the)g(shared)h +(library)e(again:)258 3190 y Fr($)30 b(gcc)f(-I$PGROOT/include)f(-fpic) +h(-c)60 b(complex.c)29 b(-o)h(complex.o)258 3250 y($)g(gcc)f(-shared)g +(-o)h(complex.so)f(complex.o)198 3342 y Ft(Note)10 b(that)f(all)h(the)f +(functions)h(de\002ned)f(in)h Fr(complex.c)e Ft(\()p +Fr(complex)p 1428 3342 V 17 w(in\(\),)29 b(complex)p +1834 3342 V 18 w(out\(\))198 3402 y Ft(and)12 b Fr(complex)p +495 3402 V 18 w(cmp\(\))p Ft(\))f(are)h(no)o(w)g(contained)g(in)h(the)f +(shared)g(library)g Fr(complex.so)p Ft(.)p eop +%%Page: 40 40 +40 39 bop 270 60 a Ft(40)307 b Fm(CHAPTER)14 b(2.)28 +b(POSTGRESQL)13 b(FR)n(OM)f(THE)i(USER'S)e(POINT)g(OF)g(VIEW)270 +234 y Ft(No)o(w)k(we)h(make)g(the)f(ne)o(w)h(function)f(kno)o(wn)g(to)h +(PostgreSQL)f(and)h(after)f(that)h(we)g(de\002ne)f(the)h(ne)o(w)270 +294 y(operator)11 b('=')h(for)g(the)g Fr(complex)g Ft(type:)330 +394 y Fr(testdb=>)29 b(create)g(function)g +(complex_cmp\(complex,complex\))330 454 y(testdb->)g(returns)g(complex) +330 513 y(testdb->)g(as)g('//complex.so)o(')330 +573 y(testdb->)g(language)g('c';)330 633 y(CREATE)330 +693 y(testdb=>)g(create)g(operator)g(=)h(\()330 753 y(testdb->)f +(leftarg)g(=)h(complex,)330 812 y(testdb->)f(rightarg)g(=)h(complex,) +330 872 y(testdb->)f(procedure)g(=)g(complex_cmp,)330 +932 y(testdb->)g(commutator)g(=)g(=)330 992 y(testdb->)g(\);)330 +1051 y(CREATE)330 1111 y(testdb=>)270 1211 y Ft(From)12 +b(no)o(w)h(on)h(we)f(are)h(able)f(to)g(perform)f(comparisons)i(between) +f(comple)o(x)g(numbers)g(in)h(a)f(query')m(s)270 1271 +y(quali\002cation)f(\(W)l(e)g(use)h(the)f(table)g Fr(complex)p +1100 1271 15 2 v 17 w(test)g Ft(as)h(de\002ned)f(in)h(e)o(xample)f +(2.8\):)330 1371 y Fr(testdb=>)29 b(select)g(*)h(from)f(complex_test) +330 1431 y(testdb->)g(where)g(val)h(=)f('\(1,2\)';)390 +1491 y(val)330 1550 y(-----)330 1610 y(\(1,2\))330 1670 +y(\(1)g(row\))330 1789 y(testdb=>)g(select)g(*)h(from)f(complex_test) +330 1849 y(testdb->)g(where)g(val)h(=)f('\(7,8\)';)390 +1909 y(val)330 1969 y(-----)330 2029 y(\(0)g(rows\))330 +2148 y(testdb=>)270 2291 y Fh(2.5.5)59 b(Extending)15 +b(Aggr)o(egates)270 2385 y Ft(If)e(we)i(want)e(to)h(use)h(aggre)o(gate) +f(functions)f(on)h(attrib)o(utes)g(of)g(a)g(user)g(de\002ned)g(type,)h +(we)g(ha)o(v)o(e)f(to)g(add)270 2445 y(aggre)o(gate)19 +b(functions)f(designed)h(to)g(work)f(on)h(the)g(ne)o(w)f(type.)36 +b(Aggre)o(gates)19 b(in)g(PostgreSQL)f(are)270 2504 y(realized)12 +b(using)h(three)f(functions:)345 2604 y Fo(\017)25 b +Fr(sfunc1)13 b Ft(\(state)i(function)e(one\):)19 b(is)c(called)g(for)e +(e)o(v)o(ery)i(tuple)f(of)g(the)g(current)g(group)g(and)g(the)395 +2664 y(appropriate)d(attrib)o(ute')m(s)h(v)o(alue)h(of)f(the)h(current) +f(tuple)g(is)h(passed)h(to)e(the)h(function.)j(The)d(gi)o(v)o(en)395 +2724 y(ar)o(gument)f(is)h(used)h(to)e(change)i(the)f(internal)f(state)h +(of)g(the)g(function)f(in)h(the)g(way)f(gi)o(v)o(en)h(by)g(the)395 +2784 y(body)f(of)h(the)g(function.)k(F)o(or)c(e)o(xample)g +Fr(sfunc1)g Ft(of)g(the)g(aggre)o(gate)f(function)h Fr(sum)g +Ft(is)g(called)395 2843 y(for)f(e)o(v)o(ery)h(tuple)g(of)g(the)h +(current)e(group.)19 b(The)14 b(v)o(alue)f(of)g(the)g(attrib)o(ute)g +(the)g(sum)h(is)g(b)o(uilt)e(on)i(is)395 2903 y(taken)d(from)h(the)g +(current)g(tuple)g(and)g(added)g(to)h(the)f(internal)g(sum)g(state)h +(of)f Fr(sfunc1)p Ft(.)345 3003 y Fo(\017)25 b Fr(sfunc2)12 +b Ft(is)h(also)g(called)g(for)g(e)o(v)o(ery)f(tuple)h(of)f(the)h(group) +g(b)o(ut)f(it)h(does)g(not)g(use)h(an)o(y)f(ar)o(gument)395 +3063 y(from)g(outside)h(to)g(manipulate)g(its)h(state.)22 +b(It)13 b(just)i(keeps)f(track)g(of)g(the)g(o)o(wn)g(internal)g(state.) +22 b(A)395 3123 y(typical)10 b(application)g(for)g Fr(sfunc2)h +Ft(is)g(a)g(counter)f(that)h(is)g(incremented)f(for)g(e)o(v)o(ery)h +(tuple)g(of)f(the)395 3183 y(group)h(that)h(has)h(been)g(processed.)345 +3283 y Fo(\017)25 b Fr(finalfunc)14 b Ft(is)i(called)f(after)g(all)g +(tuples)g(of)g(the)g(current)g(group)f(ha)o(v)o(e)i(been)f(processed.) +26 b(It)395 3342 y(takes)10 b(the)f(internal)h(state)g(of)g +Fr(sfunc1)f Ft(and)h(the)g(state)h(of)e Fr(sfunc2)h Ft(as)g(ar)o +(guments)g(and)g(deri)o(v)o(es)395 3402 y(the)h(result)h(of)f(the)h +(aggre)o(gate)g(function)f(from)f(the)i(two)f(gi)o(v)o(en)h(ar)o +(guments.)j(F)o(or)d(e)o(xample)f(with)p eop +%%Page: 41 41 +41 40 bop 198 60 a Fm(2.5.)29 b(SOME)12 b(OF)h(POSTGRESQL)-5 +b('S)12 b(SPECIAL)h(FEA)-6 b(TURES)14 b(IN)e(DET)-5 b(AIL)340 +b Ft(41)323 234 y(the)9 b(aggre)o(gate)h(function)f Fr(average)p +Ft(,)h Fr(sfunc1)f Ft(sums)h(up)g(the)f(attrib)o(ute)g(v)o(alues)h(of)f +(each)h(tuple)323 294 y(in)j(the)g(group,)g Fr(sfunc2)f +Ft(counts)i(the)f(tuples)g(in)g(the)g(group.)18 b Fr(finalfunc)12 +b Ft(di)o(vides)h(the)g Fp(sum)323 354 y Ft(by)f(the)g +Fp(count)g Ft(to)g(deri)o(v)o(e)g(the)h(a)o(v)o(erage.)198 +462 y(If)e(we)g(de\002ne)g(an)g(aggre)o(gate)g(using)h(only)f +Fr(sfunc1)f Ft(we)i(get)f(an)g(aggre)o(gate)g(that)g(computes)h(a)f +(running)198 522 y(function)h(of)h(the)g(attrib)o(ute)f(v)o(alues)h +(from)f(each)i(tuple.)j Fr(sum)c Ft(is)h(an)f(e)o(xample)g(for)f(this)h +(kind)g(of)g(aggre-)198 582 y(gate.)18 b(On)13 b(the)g(other)g(hand,)h +(if)e(we)h(create)h(an)f(aggre)o(gate)g(function)f(using)h(only)g +Fr(sfunc2)g Ft(we)g(get)g(an)198 642 y(aggre)o(gate)i(that)g(is)g +(independent)g(of)g(the)g(attrib)o(ute)f(v)o(alues)h(from)g(each)g +(tuple.)24 b Fr(count)15 b Ft(is)g(a)g(typical)198 702 +y(e)o(xample)d(of)g(this)h(kind)f(of)g(aggre)o(gate.)198 +840 y Fn(Example)h(2.10)25 b Ft(Here)h(we)g(want)g(to)g(realize)g(the)g +(aggre)o(gate)g(functions)g Fr(complex)p 1796 840 15 +2 v 17 w(sum)g Ft(and)198 899 y Fr(complex)p 411 899 +V 17 w(avg)12 b Ft(for)g(the)g(user)h(de\002ned)f(type)g +Fr(complex)g Ft(\(see)g(e)o(xample)h(2.8\).)198 1019 +y(First)53 b(we)h(ha)o(v)o(e)g(to)f(create)g(the)h(user)f(de\002ned)h +(functions)f Fr(complex)p 1769 1019 V 17 w(add)g Ft(and)198 +1079 y Fr(complex)p 411 1079 V 17 w(scalar)p 608 1079 +V 17 w(div)p Ft(.)34 b(W)l(e)19 b(can)g(append)f(these)h(two)f +(functions)g(to)g(the)h(\002le)f Fr(complex.c)198 1138 +y Ft(from)11 b(e)o(xample)i(2.8)f(again)h(\(as)f(we)h(did)f(with)g +Fr(complex)p 1214 1138 V 17 w(cmp)p Ft(\):)258 1250 y +Fr(/*)29 b(Add)h(Complex)f(numbers)g(*/)258 1310 y(Complex)g(*)258 +1370 y(complex_add\(Complex)f(*arg1,)h(Complex)g(*arg2\))258 +1430 y({)318 1489 y(Complex)g(*result;)318 1609 y(result)g(=)h +(\(Complex)f(*\)palloc\(sizeof\(Complex\)\);)318 1669 +y(result->x)f(=)i(arg1->x)f(+)h(arg2->x;)318 1729 y(result->y)e(=)i +(arg1->y)f(+)h(arg2->y;)318 1788 y(return\(result\);)258 +1848 y(})258 1968 y(/*)f(Final)h(function)f(for)g(complex)g(average)h +(*/)258 2027 y(/*)f(Transform)g(arg1)h(to)f(polar)h(coordinate)f(form) +288 2087 y(*)g(R)h(*)g(e\210\(j*phi\))f(and)g(divide)h(R)f(by)h(arg2.) +288 2147 y(*)f(Transform)g(the)h(new)f(result)h(back)f(to)h(cartesian) +288 2207 y(*)f(coordinates)g(*/)258 2267 y(Complex)g(*)258 +2326 y(complex_scalar_div\(Complex)e(*sum,)i(int)h(count\))258 +2386 y({)318 2446 y(Complex)f(*result;)318 2506 y(double)g(R,)g(phi;) +318 2625 y(result)g(=)h(\(Complex)f(*\)palloc\(sizeof\(Complex\)\);)318 +2745 y(/*)g(transform)g(to)h(polar)f(coordinates)g(*/)318 +2804 y(R)g(=)h(hypot\(sum->x,sum->y\);)318 2864 y(phi)f(=)h +(atan\(sum->y)f(/)g(sum->x\);)318 2984 y(/*)g(divide)g(by)h(the)g +(scalar)f(count)g(*/)318 3044 y(R)g(=)h(R)g(/)g(count;)318 +3163 y(/*)f(transform)g(back)h(to)f(cartesian)g(coordinates)g(*/)318 +3223 y(result->x)f(=)i(R)g(*)g(cos\(phi\);)318 3283 y(result->y)e(=)i +(R)g(*)g(sin\(phi\);)318 3342 y(return\(result\);)258 +3402 y(})p eop +%%Page: 42 42 +42 41 bop 270 60 a Ft(42)307 b Fm(CHAPTER)14 b(2.)28 +b(POSTGRESQL)13 b(FR)n(OM)f(THE)i(USER'S)e(POINT)g(OF)g(VIEW)270 +234 y Ft(Ne)o(xt)23 b(we)h(create)f(the)h(shared)f(library)f +Fr(complex.so)g Ft(again,)27 b(which)c(will)g(contain)g(all)g(func-)270 +294 y(tions)16 b(de\002ned)g(in)h(the)f(pre)o(vious)g(e)o(xamples)g(as) +h(well)g(as)g(the)f(ne)o(w)g(functions)g Fr(complex)p +1878 294 15 2 v 17 w(add)g Ft(and)270 354 y Fr(complex)p +483 354 V 17 w(scalar)p 680 354 V 17 w(div)p Ft(:)330 +538 y Fr($)30 b(gcc)f(-I$PGROOT/include)f(-fpic)h(-c)60 +b(complex.c)29 b(-o)h(complex.o)330 598 y($)g(gcc)f(-shared)g(-o)h +(complex.so)f(complex.o)270 761 y Ft(No)o(w)13 b(we)g(ha)o(v)o(e)h(to)f +(make)g(the)g(functions)g(needed)g(by)h(the)f(ne)o(w)g(aggre)o(gates)g +(kno)o(wn)g(to)g(PostgreSQL.)270 821 y(After)f(that)g(we)h(de\002ne)g +(the)f(two)g(ne)o(w)h(aggre)o(gate)f(functions)g Fr(complex)p +1552 821 V 17 w(sum)h Ft(and)f Fr(complex)p 1966 821 +V 17 w(avg)270 881 y Ft(that)g(make)g(use)h(of)f(the)g(functions)g +Fr(complex)p 1094 881 V 17 w(add)g Ft(and)h Fr(complex)p +1508 881 V 17 w(scalar)p 1705 881 V 17 w(div)p Ft(:)330 +1066 y Fr(testdb=>)29 b(create)g(function)g +(complex_add\(complex,complex\))330 1125 y(testdb->)g(returns)g +(complex)330 1185 y(testdb->)g(as)g +('//complex.so)o(')330 1245 y(testdb->)g +(language)g('c';)330 1305 y(CREATE)330 1365 y(testdb=>)g(create)g +(function)g(complex_scalar_div\(complex,int\))330 1424 +y(testdb->)g(returns)g(complex)330 1484 y(testdb->)g(as)g +('//complex.so)o(')330 1544 y(testdb->)g +(language)g('c';)330 1604 y(CREATE)330 1663 y(testdb=>)g(create)g +(aggregate)g(complex_sum)g(\()330 1723 y(testdb->)g(sfunc1)g(=)h +(complex_add,)330 1783 y(testdb->)f(basetype)g(=)h(complex,)330 +1843 y(testdb->)f(stype1)g(=)h(complex,)330 1903 y(testdb->)f +(initcond1)g(=)g('\(0,0\)')330 1962 y(testdb->)g(\);)330 +2022 y(CREATE)330 2082 y(testdb=>)g(create)g(aggregate)g(complex_avg)g +(\()330 2142 y(testdb->)g(sfunc1)g(=)h(complex_add,)330 +2201 y(testdb->)f(basetype)g(=)h(complex,)330 2261 y(testdb->)f(stype1) +g(=)h(complex,)330 2321 y(testdb->)f(sfunc2)g(=)h(int4inc,)330 +2381 y(testdb->)f(stype2)g(=)h(int4,)330 2441 y(testdb->)f(finalfunc)g +(=)g(complex_scalar_div,)330 2500 y(testdb->)g(initcond1)g(=)g +('\(0,0\)',)330 2560 y(testdb->)g(initcond2)g(=)g('0')330 +2620 y(testdb->)g(\);)330 2680 y(CREATE)270 2843 y Ft(The)20 +b(aggre)o(gate)e(function)g Fr(complex)p 976 2843 V 17 +w(sum)h Ft(is)g(de\002ned)g(using)g(only)g Fr(sfunc1)p +Ft(.)35 b Fr(basetype)18 b Ft(is)270 2903 y(the)e(type)g(of)g(the)h +(result)f(of)g(the)g(aggre)o(gate)g(function.)27 b(The)17 +b(function)e Fr(complex)p 1751 2903 V 17 w(add)h Ft(is)h(used)g(as)270 +2963 y Fr(sfunc1)d Ft(and)h Fr(stype1)e Ft(de\002nes)i(the)g(type)f +Fr(sfunc1)g Ft(will)g(operate)g(on.)23 b Fr(initcond1)13 +b Ft(gi)o(v)o(es)i(the)270 3022 y(initial)d(v)o(alue)g(of)g(the)g +(internal)g(state)g(of)g Fr(sfunc1)p Ft(.)270 3103 y(If)20 +b(we)h(look)f(at)g(the)h(de\002nition)e(of)i(the)f(aggre)o(gate)g +(function)g Fr(complex)p 1618 3103 V 17 w(avg)h Ft(we)f(can)h(see)g +(that)270 3163 y(the)k(part)f(concerning)h Fr(sfunc1)f +Ft(is)i(identical)e(to)h(the)g(corresponding)f(part)h(of)f(the)h +(de\002nition)270 3223 y(of)e Fr(complex)p 548 3223 V +17 w(sum)p Ft(.)49 b(The)25 b(only)e(dif)o(ference)f(is)i(the)f +(additional)g(de\002nition)g(of)g Fr(sfunc2)g Ft(and)270 +3283 y Fr(finalfunc)p Ft(.)34 b(The)19 b(b)o(uilt)f(in)g(function)g +Fr(int4inc)g Ft(is)h(used)g(as)g Fr(sfunc2)f Ft(and)h(increments)f(the) +270 3342 y(internal)c(state)i(of)e Fr(sfunc2)g Ft(for)h(e)o(v)o(ery)f +(tuple)h(processed.)24 b(After)14 b(all)h(tuples)g(ha)o(v)o(e)g(been)h +(processed)270 3402 y Fr(complex)p 483 3402 V 17 w(scalar)p +680 3402 V 17 w(div)d Ft(is)f(used)h(as)g Fr(finalfunc)e +Ft(to)i(create)f(the)g(a)o(v)o(erage.)p eop +%%Page: 43 43 +43 42 bop 198 60 a Fm(2.5.)29 b(SOME)12 b(OF)h(POSTGRESQL)-5 +b('S)12 b(SPECIAL)h(FEA)-6 b(TURES)14 b(IN)e(DET)-5 b(AIL)340 +b Ft(43)198 234 y(From)11 b(no)o(w)h(on)h(we)f(can)h(use)g(the)f(ne)o +(w)g(aggre)o(gate)g(functions:)258 334 y Fr(testdb=>)29 +b(select)g(*)h(from)f(complex_test;)318 394 y(val)258 +454 y(-----)258 514 y(\(1,2\))258 573 y(\(3,4\))258 633 +y(\(5,6\))258 693 y(\(3)g(rows\))258 813 y(testdb=>)g(select)g +(complex_sum\(val\))f(from)i(complex_test;)347 872 y(val)258 +932 y(------)258 992 y(\(9,12\))258 1052 y(\(1)f(row\))258 +1171 y(testdb=>)g(select)g(complex_avg\(val\))f(from)i(complex_test;) +318 1231 y(val)258 1291 y(-----)258 1351 y(\(3,4\))258 +1410 y(\(1)f(row\))258 1530 y(testdb=>)198 1673 y Fh(2.5.6)59 +b(T)l(riggers)198 1767 y Ft(PostgreSQL)14 b(supports)h(the)f(calling)g +(of)g(C)h(functions)f(as)h(trigger)f(actions.)22 b(T)n(riggers)15 +b(are)g(not)f(a)h(fea-)198 1827 y(ture)d(that)h(is)g(only)f(present)h +(in)f(PostgreSQL.)h(In)f(fact)g(most)h(modern)f(RDMSs)h(support)g +(triggers.)j(W)l(e)198 1887 y(describe)g(them)g(here)g(because)i(the)e +(pre)o(vious)f(sections)i(are)g(necessary)g(to)f(understand)g(the)g +(imple-)198 1946 y(mentation)c(chosen.)273 2006 y(At)g(the)h(moment)f +(it)g(is)h(possible)g(to)f(de\002ne)h(trigger)e(actions)i(that)f(are)h +(e)o(x)o(ecuted)g Fp(befor)n(e)g Ft(and)g Fp(after)198 +2066 y Ft(the)k(SQL)h(commands)f Fr(insert,)29 b(update)17 +b Ft(or)g Fr(delete)g Ft(for)g(a)g(tuple.)31 b(T)n(riggers)18 +b(can)f(be)h(used)198 2126 y(to)e(ensure)g(data)g(inte)o(grity)m(.)26 +b(F)o(or)15 b(e)o(xample)h(we)h(can)f(de\002ne)g(a)g(trigger)f(action)h +(that)g(returns)f(an)h(error)198 2186 y(whene)o(v)o(er)11 +b(somebody)g(wants)f(to)h(insert)g(\(or)f(update\))h(a)g(tuple)g(with)f +(a)h(ne)o(gati)o(v)o(e)g(supplier)g(id)g Fr(sno)f Ft(into)198 +2245 y(table)i Fr(supplier)g Ft(de\002ned)g(in)g(\002gure)g(1.1.)273 +2305 y(The)36 b(system)g(stores)h(information)d(about)h(when)h(a)g +(trigger)f(action)h(has)g(to)g(be)g(per)o(-)198 2365 +y(formed.)75 b(Whene)o(v)o(er)33 b(a)g(command)f(triggering)f(an)i +(action)f(is)h(detected,)38 b(the)33 b Fr(trigger)198 +2425 y(manager)g Ft(is)h(called)f(within)g(PostgreSQL,)h(which)f +(initializes)g(a)h(global)f(data)h(structure)198 2485 +y Fr(TriggerData)29 b(*CurrentTriggerData)10 b Ft(and)i(calls)h(the)f +(appropriate)g(trigger)f(function.)198 2604 y(A)44 b(central)f(role)h +(in)f(the)h(de\002nition)f(of)h(trigger)e(functions)i(plays)g(the)g +(global)f(data)198 2664 y(structure)84 b Fr(TriggerData)29 +b(*CurrentTriggerData)83 b Ft(\(The)h(global)h(pointer)198 +2724 y Fr(CurrentTriggerData)10 b Ft(can)j(be)g(accessed)g(from)e +(within)h(e)o(v)o(ery)g(trigger)g(function\):)258 2824 +y Fr(typedef)29 b(struct)g(TriggerData)258 2884 y({)318 +2944 y(TriggerEvent)118 b(tg_event;)318 3003 y(Relation)238 +b(tg_relation;)318 3063 y(HeapTuple)208 b(tg_trigtuple;)318 +3123 y(HeapTuple)g(tg_newtuple;)318 3183 y(Trigger)268 +b(*tg_trigger;)258 3242 y(})30 b(TriggerData;)198 3342 +y Ft(No)o(w)12 b(we)g(gi)o(v)o(e)g(a)g(short)g(description)f(of)h(the)f +(structure')m(s)h(contents)g(rele)o(v)o(ant)f(for)g(the)h(e)o(xample)g +(belo)o(w)m(.)198 3402 y(F)o(or)g(a)g(detailed)h(description)e(of)h +(this)h(and)f(other)g(structures)g(and)h(functions)e(refer)h(to)g +([LOCK98]:)p eop +%%Page: 44 44 +44 43 bop 270 60 a Ft(44)307 b Fm(CHAPTER)14 b(2.)28 +b(POSTGRESQL)13 b(FR)n(OM)f(THE)i(USER'S)e(POINT)g(OF)g(VIEW)345 +234 y Fo(\017)25 b Fr(tg)p 458 234 15 2 v 17 w(event)p +Ft(:)j(Describes)19 b(the)f(e)o(v)o(ent)h(the)f(function)g(is)h(called) +g(for)m(.)34 b(Contains)19 b(information)395 294 y(about)11 +b(when)g(the)g(function)g(was)g(called)h(\()p Fp(befor)n(e)f +Ft(or)g Fp(after)23 b Ft(the)11 b(command)g(e)o(x)o(ecution\))h(and)f +(for)395 354 y(which)h(command)g(it)g(was)g(called)h(\()p +Fr(insert,)28 b(update)12 b Ft(or)g Fr(delete)p Ft(\).)345 +450 y Fo(\017)25 b Fr(tg)p 458 450 V 17 w(relation)p +Ft(:)87 b(Is)49 b(a)g(pointer)e(to)i(a)g(structure)f(describing)g(the)g +(relation.)395 510 y Fr(tg)p 458 510 V 17 w(relation-)p +Fk(>)p Fr(rd)p 844 510 V 17 w(att)12 b Ft(is)g(of)g(special)h(interest) +f(for)g(us)h(because)g(it)f(can)g(be)h(gi)o(v)o(en)f(as)h(an)395 +570 y(ar)o(gument)e(to)h(the)h(function)e Fr(SPI)p 990 +570 V 18 w(getbinval\(\))g Ft(described)h(later)m(.)345 +667 y Fo(\017)25 b Fr(tg)p 458 667 V 17 w(trigtuple)p +Ft(:)16 b(Is)e(a)f(pointer)g(to)g(the)g(tuple)g(for)g(which)g(the)g +(trigger)f(is)i(\002red.)k(If)12 b(the)i(com-)395 726 +y(mand)e(is)g Fr(insert)g Ft(or)g Fr(delete)g Ft(this)g(is)h(the)f +(tuple)g(to)h(be)f(returned)f(by)i(the)f(trigger)f(function.)345 +823 y Fo(\017)25 b Fr(tg)p 458 823 V 17 w(newtuple)p +Ft(:)18 b(If)c(the)g(command)g(is)g Fr(update)g Ft(this)g(is)g(a)h +(pointer)e(to)h(the)g(ne)o(w)g(v)o(ersion)h(of)395 883 +y(tuple)d(and)g(NULL)h(otherwise.)i(This)e(is)g(what)f(has)h(to)f(be)g +(returned)g(by)g(the)g(trigger)f(function)h(if)395 942 +y(the)g(command)g(is)g Fr(update)p Ft(.)270 1058 y Fn(Example)h(2.11)25 +b Ft(W)l(e)16 b(de\002ne)g(a)h(trigger)e(function)g(called)i +Fr(trigf\(\))e Ft(that)h(is)h(designed)f(to)h(pre)o(v)o(ent)270 +1117 y(inserting)12 b(\(updating\))f(tuples)h(with)g(a)h(ne)o(gati)o(v) +o(e)f(supplier)g(id)g Fr(sno)g Ft(into)g(table)h Fr(supplier)p +Ft(.)270 1237 y(First)26 b(we)g(ha)o(v)o(e)h(to)f(de\002ne)g(the)h +(function)e Fr(trigf\(\))h Ft(using)g(C)h(and)f(therefore)f(we)i +(create)f(a)270 1297 y(ne)o(w)14 b(\002le)g Fr(trigger.c)p +Ft(.)20 b(The)15 b(function)e(de\002nition)h(is)g(done)g(in)g(e)o +(xactly)h(the)f(same)g(way)g(as)h(for)e(the)270 1356 +y(de\002nition)e(of)h(user)h(de\002ned)f(functions)g(\(see)g(section)h +(2.5.2\).)270 1476 y(Here)f(are)h(the)f(contents)g(of)g +Fr(trigger.c)p Ft(:)270 1570 y Fr(#include)29 b()270 +1629 y(#include)g()270 1749 y(HeapTuple)270 +1809 y(trigf\(\))270 1868 y({)h(TupleDesc)208 b(tupdesc;)330 +1928 y(HeapTuple)g(rettuple;)330 1988 y(bool)358 b(isnull;)330 +2048 y(int)388 b(val;)330 2167 y(if)29 b(\(!CurrentTriggerData\))390 +2227 y(elog\(ERROR,)f("trigf:)h(triggers)g(are)h(not)f(initialized"\);) +330 2347 y(/*)g(tuple)h(to)f(return)h(to)f(Executor)g(*/)330 +2406 y(if)g(\(TRIGGER_FIRED_BY_UPDATE\(CurrentTrig)o(gerData->)o +(tg_event)o(\)\))390 2466 y(rettuple)g(=)g +(CurrentTriggerData->tg_newtuple;)330 2526 y(else)390 +2586 y(rettuple)g(=)g(CurrentTriggerData->tg_trigtuple;)330 +2705 y(tupdesc)g(=)h(CurrentTriggerData->tg_relati)o(on->rd_at)o(t;)330 +2765 y(CurrentTriggerData)e(=)h(NULL;)330 2885 y(/*)g(get)h(the)g +(value)f(of)h(attribute)e(1)i(of)g(the)f(current)h(tuple)f(*/)330 +2944 y(val)g(=)h(SPI_getbinval\(rettuple,)d(tupdesc,)i(1,)h(&isnull\);) +330 3064 y(/*)f(if)h(the)g(value)f(is)h(NULL)f(or)h(<)g(0)f(return)h +(an)f(error)h(*/)330 3124 y(if)f(\(isnull)h(||)f(val)h(<)g(0\))f({)419 +3184 y(elog\(ERROR,"insert/update:)e(sno)j(must)f(be)h(a)g(value)f(>)h +(0"\);)330 3243 y(})330 3303 y(return)f(\(rettuple\);)270 +3363 y(})p eop +%%Page: 45 45 +45 44 bop 198 60 a Fm(2.5.)29 b(SOME)12 b(OF)h(POSTGRESQL)-5 +b('S)12 b(SPECIAL)h(FEA)-6 b(TURES)14 b(IN)e(DET)-5 b(AIL)340 +b Ft(45)198 234 y(The)20 b(function)e Fr(SPI)p 573 234 +15 2 v 18 w(getbinval)g Ft(is)i(part)e(of)h(the)g Fp(Server)i(Pr)n(ogr) +o(amming)e(Interface)g(\(SPI\))f Ft(de-)198 294 y(scribed)13 +b(in)g(section)g(2.5.7.)19 b(It)13 b(takes)g(the)g(current)f(tuple,)h +(the)g(description)g(of)g(the)g(relation,)g(the)g(num-)198 +354 y(ber)k(of)g(the)h(attrib)o(ute)f(and)g(the)h(address)g(of)f(a)h(v) +o(ariable)f Fr(isnull)g Ft(as)h(ar)o(guments)f(and)h(returns)f(the)198 +413 y(binary)c(v)o(alue)h(of)f(the)h(gi)o(v)o(en)f(attrib)o(ute)g(from) +g(the)h(current)f(tuple.)20 b(If)13 b(the)g(attrib)o(ute')m(s)h(v)o +(alue)f(is)h(NULL)198 473 y Fr(isnull)e Ft(is)g(set)h(to)f +Fr(true)g Ft(otherwise)h(to)f Fr(false)p Ft(.)273 533 +y Fr(trigf\(\))23 b Ft(\002rst)g(checks)h(whether)f(it)h(was)f(called)h +(by)f(an)h Fr(update)f Ft(command)g(or)g(by)h(an)198 +593 y Fr(insert)19 b Ft(and)g(sets)h Fr(rettuple)e Ft(accordingly)m(.) +36 b(Then)19 b(it)g(gets)h(the)f(v)o(alue)g(of)g(the)g(\002rst)g +(attrib)o(ute)198 653 y(of)e(the)g(current)g(tuple)g(\(remember)f +Fr(sno)i Ft(is)f(the)h(\002rst)f(attrib)o(ute)f(in)i(the)f(relation)g +Fr(supplier)p Ft(\).)30 b(If)198 712 y(the)14 b(v)o(alue)h(is)f +(greater)g(than)g(zero)h(the)f(current)g(tuple)g(is)h(returned)e(\(and) +h(inserted)h(or)f(updated)g(by)g(the)198 772 y(e)o(x)o(ecutor)e(of)f +(PostgreSQL\))g(otherwise)h(an)g(error)f(is)h(returned)f(\()p +Fr(elog\(ERROR,)p Fk(:)d(:)g(:)n Fr(\))k Ft(logs)g(an)g(error)198 +832 y(and)g(aborts)h(processing\))f(and)g(the)g(table)h +Fr(supplier)e Ft(won')o(t)g(be)i(af)o(fected.)198 951 +y(T)l(o)g(create)f(a)h(shared)f(library)f(out)i(of)f +Fr(trigger.c)f Ft(we)h(use)h(the)g(commands:)258 1035 +y Fr($)30 b(gcc)f(-I$PGROOT/include)f(-I$PGSRC/include/)g(-fpic)h(\\) +258 1095 y(>)h(-c)f(trigger.c)g(-o)h(trigger.o)258 1155 +y($)g(gcc)f(-shared)g(-o)h(trigger.so)f(trigger.o)198 +1238 y Ft(Note)24 b(that)f(for)g(the)g(compilation)g(of)g(trigger)g +(functions)g(the)h(source)f(code)h(of)g(PostgreSQL)f(is)198 +1298 y(necessary)m(.)16 b Fr($PGSRC)c Ft(points)g(to)h(the)f(place)g +(where)h(the)f(sources)h(are)f(installed.)198 1418 y(Ne)o(xt)20 +b(we)h(ha)o(v)o(e)g(to)f(make)f(the)i(function)e Fr(trigf\(\))h +Ft(kno)o(wn)f(to)h(PostgreSQL)g(by)g(the)h Fr(create)198 +1477 y(function)13 b Ft(command)h(in)f(the)h(same)h(way)e(we)h(did)g +(for)f(the)h(functions)g(in)f(the)h(pre)o(vious)g(e)o(xamples)198 +1537 y(\(e.g.)19 b(e)o(xample)14 b(2.8\).)k(After)13 +b(that)g(we)h(can)f(de\002ne)g(the)h(trigger)e Fr(tbefore)p +Ft(.)18 b(The)c(de\002nition)f(ensures)198 1597 y(that)e(function)g +Fr(trigf\(\))g Ft(gi)o(v)o(en)g(as)i(the)e(trigger)g(action)g(will)g +(be)h(e)o(x)o(ecuted)g Fr(before)f Ft(the)h(e)o(x)o(ecution)198 +1657 y(of)24 b(the)g(commands)g Fr(insert)g Ft(and)g +Fr(update)g Ft(af)o(fecting)f(the)h(table)g Fr(supplier)p +Ft(.)51 b(Note)24 b(that)198 1717 y Fr(insert)17 b Ft(and)h +Fr(update)f Ft(commands)h(e)o(x)o(ecuted)g(against)g(tables)g(other)g +(than)f Fr(supplier)g Ft(won')o(t)198 1776 y(cause)c(the)f(e)o(x)o +(ecution)h(of)f(function)f Fr(trigf\(\))p Ft(.)258 1860 +y Fr(testdb=>)29 b(create)g(function)g(trigf\(\))g(returns)g(opaque)258 +1920 y(testdb->)g(as)g('/)g(language)g('c';)258 2039 y(CREATE)258 +2099 y(testdb=>)g(create)g(trigger)g(tbefore)258 2159 +y(testdb->)g(before)g(insert)g(or)h(update)f(on)h(supplier)258 +2219 y(testdb->)f(for)g(each)h(row)f(execute)g(procedure)g(trigf\(\);) +258 2278 y(CREATE)258 2338 y(testdb=>)198 2422 y Ft(No)o(w)14 +b(we)g(can)g(check)g(if)g(the)g(trigger)f(is)h(working)f(correctly)m(.) +20 b(If)13 b(the)h(v)o(alue)g(for)f Fr(sno)g Ft(is)i(greater)e(than)198 +2482 y(zero)f(the)h Fr(insert)e Ft(and)i Fr(update)e +Ft(commands)i(against)f(table)g Fr(supplier)g Ft(are)g(not)g(af)o +(fected.)258 2565 y Fr(testdb=>)29 b(insert)g(into)g(supplier)258 +2625 y(testdb->)g(\(sno,)g(sname,)g(city\))258 2685 y(testdb->)g +(values\(5,)g('Miles',)g('Berlin'\);)258 2745 y(INSERT)g(156064)g(1)258 +2864 y(testdb=>)g(insert)g(into)g(supplier)258 2924 y(testdb->)g +(\(sno,)g(sname,)g(city\))258 2984 y(testdb->)g(values\(-2,)g('Huber',) +g('Munich'\);)258 3044 y(ERROR:)59 b(insert/update:)28 +b(sno)i(must)f(be)h(a)g(value)f(>)h(0)258 3163 y(testdb=>)f(update)g +(supplier)258 3223 y(testdb->)g(set)g(sno)h(=)g(-2)258 +3283 y(testdb->)f(where)g(sname)g(=)h('Adams';)258 3342 +y(ERROR:)59 b(insert/update:)28 b(sno)i(must)f(be)h(a)g(value)f(>)h(0) +258 3402 y(testdb=>)p eop +%%Page: 46 46 +46 45 bop 270 60 a Ft(46)307 b Fm(CHAPTER)14 b(2.)28 +b(POSTGRESQL)13 b(FR)n(OM)f(THE)i(USER'S)e(POINT)g(OF)g(VIEW)270 +234 y Fh(2.5.7)59 b(Ser)o(v)o(er)14 b(Pr)o(ogramming)f(Interface)g +(\(SPI\))270 328 y Ft(The)20 b Fp(Server)g(Pr)n(ogr)o(amming)g +(Interface)f(\(SPI\))g Ft(gi)o(v)o(es)g(the)h(user)f(the)h(ability)e +(to)i(run)f(SQL)g(queries)270 387 y(from)10 b(inside)i(user)f +(de\002ned)h(functions.)j(SPI)10 b(is)i(just)f(a)h(set)g(of)f(nati)o(v) +o(e)g(interface)g(functions)g(to)g(simplify)270 447 y(the)29 +b(access)h(to)f(the)g Fr(query)g(parser,)g(planner,)g(optimizer)f +Ft(and)h Fr(executor)g Ft(of)270 507 y(PostgreSQL)12 +b(\(refer)f(to)h(chapter)g(3)h Fp(P)l(ostgr)n(eSQL)g(fr)n(om)f(the)g +(Pr)n(ogr)o(ammer')n(s)i(P)l(oint)e(of)g(V)l(ie)o(w)p +Ft(\).)270 626 y(The)h(set)g(of)f(functions)g(of)f(SPI)h(can)g(be)h(di) +o(vided)f(into)g(the)g(follo)o(wing)f(parts:)345 724 +y Fo(\017)25 b Ft(Interface)11 b(Functions:)17 b(These)d(functions)e +(are)h(used)h(to)f(establish)h(a)f(connection)g(to)g(a)g(running)395 +784 y(backend.)i(Whene)o(v)o(er)c(you)h(want)g(to)f(e)o(x)o(ecute)i(a)f +(SQL)g(query)g(within)f(a)h(user)g(de\002ned)g(function)395 +844 y(you)g(will)g(ha)o(v)o(e)g(to)h(connect)f(to)g(a)h(backend)f(by)g +Fr(SPI)p 1314 844 15 2 v 18 w(connect\(\))p Ft(.)454 +943 y Fn(\226)25 b Fr(SPI)p 597 943 V 18 w(connect\(\))11 +b Ft(opens)i(a)f(connection)g(to)h(the)f(PostgreSQL)g(backend.)454 +1022 y Fn(\226)25 b Fr(SPI)p 597 1022 V 18 w(finish\(\))11 +b Ft(closes)i(a)g(connection)f(to)g(the)h(PostgreSQL)f(backend.)454 +1101 y Fn(\226)25 b Fr(SPI)p 597 1101 V 18 w(exec\(\))15 +b Ft(takes)g(a)h(character)f(string)h(containing)f(a)g(SQL)h(query)f +(and)h(a)g(number)504 1160 y Fr(tcount)11 b Ft(as)h(ar)o(guments)f(and) +g(e)o(x)o(ecutes)h(the)g(query)m(.)i(The)e(result)f(can)h(be)f +(obtained)g(from)504 1220 y(the)17 b(global)g(data)g(structure)f +Fr(SPI)p 1108 1220 V 18 w(tuptable)g Ft(which)h(is)g(set)h(by)f +Fr(SPI)p 1801 1220 V 18 w(exec\(\))p Ft(.)29 b(If)504 +1280 y Fr(tcount)12 b Ft(is)i(zero)e(then)h(the)g(query)f(is)i(e)o(x)o +(ecuted)f(for)f(all)h(tuples)g(returned)f(by)h(the)g(query)504 +1340 y(scan.)27 b(Using)16 b Fr(tcount)f Fk(>)h Ft(0)g(restricts)g(the) +f(number)h(of)f(tuples)h(for)f(which)h(the)g(query)504 +1399 y(will)d(be)h(e)o(x)o(ecuted.)21 b(This)14 b(function)f(should)g +(only)h(be)g(called)f(after)g Fr(SPI)p 1786 1399 V 18 +w(connect\(\))504 1459 y Ft(has)g(been)f(processed)h(and)g(a)f +(connection)g(has)h(been)g(established.)454 1538 y Fn(\226)25 +b Fr(SPI)p 597 1538 V 18 w(prepare\(\))85 b Ft(creates)h(and)g(returns) +f(an)h(e)o(x)o(ecution)g(plan)504 1598 y(\(parser+planner+optimizer\)) +23 b(b)o(ut)j(doesn')o(t)g(e)o(x)o(ecute)g(the)g(query)m(.)56 +b(\(The)26 b(function)504 1658 y(performs)15 b(the)i(same)f(steps)h(as) +g Fr(SPI)p 1163 1658 V 18 w(exec\(\))f Ft(e)o(xcept)g(that)g(it)g(does) +h(not)f(e)o(x)o(ecute)h(the)504 1717 y(plan.)f(Should)11 +b(only)h(be)h(called)f(after)g(a)h(connection)f(has)g(been)h +(established.)454 1796 y Fn(\226)25 b Fr(SPI)p 597 1796 +V 18 w(saveplan\(\))10 b Ft(stores)h(a)g(plan)g(prepared)f(by)h +Fr(SPI)p 1518 1796 V 18 w(prepare\(\))f Ft(in)h(safe)g(mem-)504 +1856 y(ory)h(protected)g(from)f(freeing)h(by)g Fr(SPI)p +1199 1856 V 17 w(finish\(\))p Ft(.)454 1935 y Fn(\226)25 +b Fr(SPI)p 597 1935 V 18 w(execp\(\))12 b Ft(e)o(x)o(ecutes)h(a)g(plan) +f(prepared)g(by)g Fr(SPI)p 1491 1935 V 18 w(prepare\(\))g +Ft(or)g(returned)f(by)504 1995 y Fr(SPI)p 597 1995 V +18 w(saveplan\(\))p Ft(.)345 2094 y Fo(\017)25 b Ft(Interface)8 +b(Support)i(Functions:)j(These)f(functions)e(can)g(be)h(used)g(from)e +(within)h(a)g(connected)h(or)395 2153 y(within)g(an)g(unconnected)h +(user)f(de\002ned)h(function.)j(An)c(e)o(xample)h(for)f(the)g(use)h +(from)f(within)g(an)395 2213 y(unconnected)k(function)g(was)h(gi)o(v)o +(en)g(in)f(e)o(xample)h(2.11)g(where)g Fr(SPI)p 1634 +2213 V 17 w(getbinval\(\))f Ft(was)395 2273 y(used)h(to)g(deli)o(v)o +(er)g(the)g(v)o(alue)g(of)g(attrib)o(ute)g Fr(sno)g Ft(from)f(the)h(ne) +o(w)g(\(to)g(be)g(inserted\))g(tuple.)27 b(An)395 2333 +y(e)o(xample)12 b(for)f(the)h(use)g(from)f(within)g(a)h(connected)g +(function)f(will)h(be)g(gi)o(v)o(en)g(in)f(e)o(xample)h(2.12.)454 +2432 y Fn(\226)25 b Fr(SPI)p 597 2432 V 18 w(copytuple\(\))11 +b Ft(makes)h(a)h(copy)f(of)f(the)i(tuple)f(gi)o(v)o(en)g(as)h(ar)o +(gument.)454 2510 y Fn(\226)25 b Fr(SPI)p 597 2510 V +18 w(modifytuple\(\))j Ft(modi\002es)i(one)g(or)f(more)h(attrib)o(utes) +f(of)h(a)g(gi)o(v)o(en)g(tu-)504 2570 y(ple.)73 b(The)32 +b(ne)o(w)g(v)o(alues)f(for)g(the)g(attrib)o(utes)g(to)g(be)h(changed)g +(are)f(passed)h(to)504 2630 y Fr(SPI)p 597 2630 V 18 +w(modifytuple\(\))11 b Ft(as)i(ar)o(guments.)454 2709 +y Fn(\226)25 b Fr(SPI)p 597 2709 V 18 w(fnumber\(\))11 +b Ft(takes)h(the)g(description)g(of)g(a)g(tuple)g(and)g(the)h +Fp(name)f Ft(of)g(an)g(attrib)o(ute)504 2769 y(as)h(ar)o(guments)f(and) +h(returns)e(the)i Fp(number)f Ft(of)g(the)h(attrib)o(ute.)454 +2848 y Fn(\226)25 b Fr(SPI)p 597 2848 V 18 w(fname\(\))13 +b Ft(takes)g(the)g(description)g(of)h(a)f(tuple)g(and)h(the)f +Fp(number)h Ft(of)f(an)h(attrib)o(ute)504 2907 y(as)f(ar)o(guments)f +(and)h(returns)e(the)i Fp(name)f Ft(of)g(the)g(attrib)o(ute.)454 +2986 y Fn(\226)25 b Fr(SPI)p 597 2986 V 18 w(getvalue\(\))13 +b Ft(takes)g(the)h(description)g(of)f(a)h(tuple,)h(the)e(tuple)h(and)g +(the)g(number)504 3046 y(of)k(an)g(attrib)o(ute)f(as)i(ar)o(guments)e +(and)i(returns)e(a)h Fp(string)h(r)n(epr)n(esentation)g +Ft(of)e(the)h(gi)o(v)o(en)504 3106 y(attrib)o(ute')m(s)12 +b(v)o(alue.)454 3185 y Fn(\226)25 b Fr(SPI)p 597 3185 +V 18 w(getbinval\(\))10 b Ft(takes)h(the)g(description)g(of)f(a)i +(tuple,)f(the)h(tuple)e(and)i(the)f(number)504 3244 y(of)h(an)h(attrib) +o(ute)e(as)i(ar)o(guments)f(and)g(returns)g(the)h(binary)e(v)o(alue)h +(of)g(the)h(gi)o(v)o(en)f(attrib)o(ute.)454 3323 y Fn(\226)25 +b Fr(SPI)p 597 3323 V 18 w(gettype\(\))11 b Ft(returns)h(a)h(copy)e(of) +h(the)h(type)f(name)g(for)g(the)g(speci\002ed)h(attrib)o(ute.)454 +3402 y Fn(\226)25 b Fr(SPI)p 597 3402 V 18 w(gettypeid\(\))11 +b Ft(returns)h(the)g(type)g(OID)g(for)g(the)g(speci\002ed)h(attrib)o +(ute.)p eop +%%Page: 47 47 +47 46 bop 198 60 a Fm(2.5.)26 b(SOME)12 b(OF)h(POSTGRESQL)-5 +b('S)12 b(SPECIAL)h(FEA)-6 b(TURES)14 b(IN)e(DET)-5 b(AIL)343 +b Ft(47)382 234 y Fn(\226)25 b Fr(SPI)p 525 234 15 2 +v 18 w(getrelname\(\))11 b Ft(returns)h(the)g(name)g(of)g(the)h +(speci\002ed)f(relation.)382 315 y Fn(\226)25 b Fr(SPI)p +525 315 V 18 w(palloc\(\))e Ft(allocates)i(memory)m(.)50 +b(In)23 b(contrast)h(to)g Fr(malloc\(\))g Ft(\(normally)432 +375 y(used\))15 b(it)g(allocates)h(memory)e(in)h(such)h(a)f(way)g(that) +g(it)g(can)g(be)g(freed)g(automatically)f(by)432 434 +y Fr(SPI)p 525 434 V 18 w(finish\(\))p Ft(.)382 515 y +Fn(\226)25 b Fr(SPI)p 525 515 V 18 w(repalloc\(\))12 +b Ft(reallocates)i(memory)f(that)h(has)g(originally)f(been)g(allocated) +h(us-)432 575 y(ing)e Fr(SPI)p 601 575 V 18 w(palloc\(\))p +Ft(.)382 656 y Fn(\226)25 b Fr(SPI)p 525 656 V 18 w(pfree\(\))11 +b Ft(frees)i(memory)e(allocated)h(by)h Fr(SPI)p 1397 +656 V 17 w(palloc\(\))p Ft(.)198 778 y Fn(Example)g(2.12)25 +b Ft(W)l(e)14 b(want)g(PostgreSQL)f(to)h(automatically)g(generate)g(a)g +(v)o(alue)g(for)f(the)i(supplier)e(id)198 838 y Fr(sno)e +Ft(whene)o(v)o(er)g(a)g(ne)o(w)h(tuple)f(is)g(inserted)g(into)g(table)g +Fr(supplier)p Ft(.)k(Therefore)c(we)g(de\002ne)g(a)h +Fp(trigger)198 898 y(function)k Fr(trigf)p 531 898 V +17 w(sno\(\))g Ft(that)g(is)g(called)h(before)e(the)i(e)o(x)o(ecution)f +(of)g(e)o(v)o(ery)g Fr(insert)g Ft(statement.)198 958 +y Fr(trigf)p 351 958 V 17 w(sno\(\))c Ft(has)h(to)f(perform)f(the)i +(follo)o(wing)d(steps:)273 1059 y Fo(\017)25 b Ft(establish)12 +b(a)h(connection)f(to)g(the)g(PostgreSQL)g(backend)g(using)h +Fr(SPI)p 1547 1059 V 17 w(connect\(\))273 1161 y Fo(\017)25 +b Ft(get)12 b(the)g(greatest)h(supplier)f(id)g Fr(sno)g +Ft(contained)g(in)g(table)g Fr(supplier)g Ft(using)g +Fr(SPI)p 1794 1161 V 18 w(exec\(\))273 1262 y Fo(\017)25 +b Ft(modify)13 b(attrib)o(ute)h Fr(sno)h Ft(of)g(the)f(tuple)h(to)g(be) +g(inserted)f(to)h(contain)g(the)g(ne)o(xt)g(greater)f(number)323 +1322 y(using)e Fr(SPI)p 536 1322 V 18 w(modifytuple\(\))273 +1424 y Fo(\017)25 b Ft(disconnect)12 b(from)f(the)i(backend)f(using)g +Fr(SPI)p 1122 1424 V 18 w(finish\(\))273 1526 y Fo(\017)25 +b Ft(return)11 b(the)h(modi\002ed)g(tuple)198 1627 y(Here)26 +b(are)h(the)f(contents)h(of)f(function)g Fr(trigf)p 1103 +1627 V 17 w(sno\(\))g Ft(that)h(can)f(be)h(appended)f(to)h(the)f +(\002le)198 1687 y Fr(trigger.c)11 b Ft(from)h(e)o(xample)g(2.11:)258 +1788 y Fr(HeapTuple)258 1848 y(trigf_sno\(\))258 1908 +y({)30 b(HeapTuple)208 b(rettuple;)318 1968 y(bool)358 +b(isnull;)318 2027 y(int)388 b(ret,)29 b(max;)318 2087 +y(int)388 b(atts_to_be_changed[1];)318 2147 y(Datum)328 +b(new_value[1];)318 2207 y(char)358 b(nulls;)318 2326 +y(if)29 b(\(!CurrentTriggerData\))377 2386 y(elog\(ERROR,)527 +2446 y("trigf:)g(triggers)g(are)g(not)h(initialized"\);)318 +2565 y(/*)f(This)h(is)f(the)h(tuple)f(to)h(be)g(inserted)f(*/)318 +2625 y(rettuple)g(=)g(CurrentTriggerData->tg_trigtuple;)318 +2745 y(/*)g(Connect)g(to)h(backend)f(*/)318 2804 y(if)g(\(\(ret)h(=)f +(SPI_connect\(\)\))g(<)g(0\))377 2864 y(elog\(ERROR,)527 +2924 y("trigf_sno:)f(SPI_connect)h(returned)g(\045d",ret\);)318 +3044 y(/*)g(Get)h(greatest)f(sno)g(in)h(relation)f(supplier)g(*/)318 +3103 y(/*)g(Execute)g(the)h(query)f(*/)318 3163 y(ret)g(=)h +(SPI_exec\("select)e(max\(sno\))h(from)g(supplier",0\);)318 +3223 y(if)g(\(ret)h(<)f(0\))407 3283 y(elog\(ERROR,)557 +3342 y("trigf_sno:)f(SPI_exec)h(returned)g(\045d",ret\);)p +eop +%%Page: 48 48 +48 47 bop 270 60 a Ft(48)307 b Fm(CHAPTER)14 b(2.)28 +b(POSTGRESQL)13 b(FR)n(OM)f(THE)i(USER'S)e(POINT)g(OF)g(VIEW)390 +234 y Fr(/*)29 b(extract)g(the)h(number)f(from)h(the)f(result)419 +294 y(*)h(returned)f(by)h(the)f(query.)h(SPI_exec\(\))e(puts)419 +354 y(*)i(the)g(result)f(into)g(the)h(global)f(structure)419 +413 y(*)h(SPI_tuptable)f(*/)390 473 y(max)g(=)h +(SPI_getbinval\(SPI_tuptable->val)o(s[0],)987 533 y +(SPI_tuptable->tupdesc,)e(1,)987 593 y(&isnull\);)390 +712 y(/*)h(disconnect)g(from)g(backend)h(*/)390 772 y(SPI_finish\(\);) +390 892 y(/*)f(array)h(containing)e(the)i(numbers)f(of)h(attributes)419 +951 y(*)g(to)g(be)g(changed:)f(sno)g(has)h(attno)f(1)h(*/)390 +1011 y(atts_to_be_changed[0])d(=)j(1;)390 1131 y(/*)f(new)h(values)f +(for)h(attributes)e(to)i(be)g(changed:)419 1191 y(*)g(the)g(next)f +(number)g(for)h(sno)g(is)f(max+1)h(*/)390 1250 y(new_value[0])e(=)i +(\(max+1\);)390 1370 y(/*)f(modify)g(the)h(tuple)f(to)h(be)g(inserted)f +(to)g(contain)419 1430 y(*)h(max+1)g(as)f(sno)h(*/)390 +1489 y(rettuple)f(=)449 1549 y(SPI_modifytuple\(CurrentTriggerData-)o +(>tg_relat)o(ion,)928 1609 y(rettuple,)928 1669 y(1,)928 +1729 y(atts_to_be_changed,)928 1788 y(new_value,)928 +1848 y(&nulls\);)390 1968 y(if)g(\(rettuple)g(==)h(NULL\))479 +2027 y(elog\(ERROR,)629 2087 y("trigf_sno:)e(SPI_modifytuple)h +(failed"\);)390 2207 y(CurrentTriggerData)e(=)j(NULL;)390 +2267 y(return)f(\(rettuple\);)330 2326 y(})270 2456 y +Ft(W)l(e)13 b(again)f(create)g(the)g(shared)h(library)e +Fr(trigger.so)g Ft(out)i(of)e Fr(trigger.c)p Ft(:)330 +2595 y Fr($)30 b(gcc)f(-I$PGROOT/include)f(-I$PGSRC/include/)g(-fpic)h +(\\)330 2655 y(>)h(-c)f(trigger.c)g(-o)h(trigger.o)330 +2714 y($)g(gcc)f(-shared)g(-o)h(trigger.so)f(trigger.o)270 +2844 y Ft(Ne)o(xt)16 b(we)g(ha)o(v)o(e)h(to)f(make)f(the)h(function)f +Fr(trigf)p 1155 2844 15 2 v 18 w(sno\(\))g Ft(kno)o(wn)g(to)h +(PostgreSQL)g(and)g(after)f(that)270 2904 y(we)j(can)f(de\002ne)h(the)f +(trigger)g Fr(sno)p 894 2904 V 17 w(before)g Ft(which)h(is)f(called)h +(before)f(an)g Fr(insert)g Ft(to)h(the)f(table)270 2963 +y Fr(supplier)p Ft(.)30 b(The)18 b(trigger)e(function)g(ensures)i(that) +f(the)h(ne)o(xt)f(greater)g(number)f(for)h Fr(sno)g Ft(will)g(be)270 +3023 y(used.)330 3162 y Fr(testdb=>)29 b(create)g(function)g +(trigf_sno\(\))g(returns)g(opaque)330 3222 y(testdb->)g(as)g +('//trigger.so)o(')330 3282 y(testdb->)g +(language)g('c';)330 3342 y(CREATE)p eop +%%Page: 49 49 +49 48 bop 198 60 a Fm(2.5.)29 b(SOME)12 b(OF)h(POSTGRESQL)-5 +b('S)12 b(SPECIAL)h(FEA)-6 b(TURES)14 b(IN)e(DET)-5 b(AIL)340 +b Ft(49)258 234 y Fr(testdb=>)29 b(create)g(trigger)g(sno_before)258 +294 y(testdb->)g(before)g(insert)g(on)h(supplier)258 +354 y(testdb->)f(for)g(each)h(row)f(execute)g(procedure)g +(trigf_sno\(\);)258 413 y(CREATE)258 473 y(testdb=>)198 +585 y Ft(Ev)o(ery)12 b(time)f(a)h(ne)o(w)g(tuple)f(is)h(inserted)f(to)h +(the)f(table)h Fr(supplier)f Ft(a)h(ne)o(w)f Fr(sno)h +Ft(is)g(assigned)g(automat-)198 645 y(ically)g(re)o(gardless)h(of)e +(the)i(v)o(alue)f(gi)o(v)o(en)g(in)g(the)h Fr(insert)e +Ft(statement:)258 747 y Fr(testdb=>)29 b(select)g(*)h(from)f(supplier;) +258 806 y(sno|sname)g(|city)258 866 y(---+------+------)318 +926 y(1|Smith)g(|London)318 986 y(2|Jones)g(|Paris)318 +1046 y(3|Adams)g(|Vienna)318 1105 y(4|Blake)g(|Rome)258 +1165 y(\(4)g(rows\))258 1285 y(testdb=>)g(insert)g(into)g(supplier)258 +1344 y(testdb->)g(\(sno,)g(sname,)g(city\))258 1404 y(testdb->)g +(values)g(\(200,'Cook',)g('Boston'\);)258 1464 y(INSERT)g(15606)g(1)258 +1584 y(testdb=>)g(select)g(*)h(from)f(supplier;)258 1643 +y(sno|sname)g(|city)258 1703 y(---+------+------)318 +1763 y(1|Smith)g(|London)318 1823 y(2|Jones)g(|Paris)318 +1882 y(3|Adams)g(|Vienna)318 1942 y(4|Blake)g(|Rome)318 +2002 y(5|Cook)59 b(|Boston)258 2062 y(\(5)29 b(rows\))258 +2181 y(testdb=>)198 2327 y Fh(2.5.8)59 b(Rules)15 b(in)g(P)o(ostgr)o +(eSQL)198 2421 y Ft(PostgreSQL)f(supports)f(a)i(po)o(werful)d +Fp(rule)j(system)p Ft(.)21 b(The)15 b(user)f(can)g(de\002ne)g(a)g(rule) +f(and)h(connect)g(it)g(to)198 2481 y(an)g(e)o(v)o(ent.)19 +b(Whene)o(v)o(er)13 b(the)h(e)o(v)o(ent)f(occurs)h(the)g(rule)f(body)g +(is)h(e)o(x)o(ecuted)g(in)f(addition)g(to)h(or)f(instead)h(of)198 +2541 y(the)e(commands)h(of)f(the)g(e)o(v)o(ent.)198 2661 +y(A)g(rule)g(is)h(created)f(using)h(the)f(follo)o(wing)f(SQL)h +(statement:)258 2762 y Fr(create)29 b(rule)g(rule_name)258 +2822 y(as)g(on)h(event)258 2882 y(to)f(object)h([where)f(clause])258 +2942 y(do)g([instead])258 3002 y([action)g(|)h(nothing)f(|)h +([actions...]])198 3103 y Ft(where)20 b Fr(event)f Ft(is)h(one)g(of)f +Fr(select,)29 b(update,)g(delete)19 b Ft(or)h Fr(insert)p +Ft(.)39 b Fr(object)19 b Ft(is)h(the)198 3163 y(name)14 +b(of)g(a)h Fp(table)f Ft(or)f Fp(table)o(.column)p Ft(.)22 +b(The)15 b Fr(where)f Ft(clause,)i(and)e(the)g Fr(action)g +Ft(are)g(a)g(normal)g(SQL)198 3222 y Fr(where)e Ft(clause)h(and)f +(collection)g(of)g(SQL)h(commands.)273 3283 y(One)k(application)g(of)h +(rules)f(is)h(the)g(implementation)e(of)h Fp(vie)o(ws)i +Ft(in)e(PostgreSQL.)h(A)g Fp(vie)o(w)g Ft(is)g(a)198 +3342 y Fp(virtual)e Ft(table)g(that)g(does)g(not)g(physically)g(e)o +(xist)g(within)g(the)g(database)g(b)o(ut)g(looks)g(to)g(the)g(user)g +(as)h(if)198 3402 y(it)f(did.)28 b(T)l(o)17 b(realize)f(a)h +Fp(vie)o(w)g Ft(we)g(can)f(create)h(an)f(empty)g(table)h(with)f(the)g +(name)h(of)f(the)g Fp(vie)o(w)p Ft(.)29 b(Then)p eop +%%Page: 50 50 +50 49 bop 270 60 a Ft(50)307 b Fm(CHAPTER)14 b(2.)28 +b(POSTGRESQL)13 b(FR)n(OM)f(THE)i(USER'S)e(POINT)g(OF)g(VIEW)270 +234 y Ft(we)h(de\002ne)g(a)g(rule)g(that)f(is)i(\002red)e(e)o(v)o(ery)h +(time)f(the)h(ne)o(w)g(table)g(is)g(accessed.)19 b(Instead)13 +b(of)g(retrie)o(ving)e(the)270 294 y(data)k(from)e(the)i +Fp(virtual)f Ft(table)h(the)f(rule)g(body)g(is)h(e)o(x)o(ecuted)g +(retrie)o(ving)e(the)i(data)g(from)e(one)i(or)f(more)270 +354 y(physically)e(stored)g(tables.)270 473 y Fn(Example)h(2.13)25 +b Ft(W)l(e)15 b(want)g(to)g(sho)o(w)g(ho)o(w)g(a)g(vie)o(w)g(could)g +(be)h(realized)f(in)g(PostgreSQL.)g(Note)g(that)270 533 +y(there)d(is)i(of)e(course)h(an)g(o)o(wn)f(command)g(to)h(create)g +Fp(vie)o(ws)h Fr(create)29 b(view)12 b Ft(in)h(PostgreSQL)f(which)270 +593 y(performs)f(the)i(steps)g(of)f(our)f(e)o(xample)i(internally)m(.) +270 712 y(First)f(we)g(create)h(a)f(ne)o(w)m(,)h(empty)f(table)g +Fr(my)p 1023 712 15 2 v 18 w(view)p Ft(:)330 812 y Fr(testdb=>)29 +b(create)g(table)g(my_view)g(\()330 872 y(testdb->)g(sname)g +(varchar\(20\),)330 932 y(testdb->)g(pname)g(varchar\(20\))330 +991 y(testdb->)g(\);)270 1091 y Ft(Ne)o(xt)14 b(we)g(create)g(the)g +(rule)f(that)h(will)f(be)h(\002red)f(whene)o(v)o(er)h(a)g +Fr(select)f Ft(against)h(the)g(table)g Fr(my)p 1936 1091 +V 17 w(view)270 1151 y Ft(sho)o(ws)f(up:)330 1250 y Fr(testdb=>)29 +b(create)g(rule)g(my_view_rule)330 1310 y(testdb->)g(as)g(on)h(select)f +(to)h(my_view)330 1370 y(testdb->)f(do)g(instead)h(select)f(s.sname,)g +(p.pname)330 1430 y(testdb->)g(from)g(supplier)g(s,)h(part)f(p,)h +(sells)f(se)330 1489 y(testdb->)g(where)g(s.sno=se.sno)g(and)g +(p.pno=se.pno;)330 1549 y(CREATE)330 1609 y(testdb=>)270 +1709 y Ft(No)o(w)12 b(we)h(can)f(use)h(the)f(table)h +Fr(my)p 855 1709 V 17 w(view)f Ft(as)h(if)f(it)g(were)h(populated)e +(with)i(tuples:)330 1808 y Fr(testdb=>)29 b(select)g(*)h(from)f +(my_view;)330 1868 y(sname)g(|pname)330 1928 y(------+-----)330 +1988 y(Smith)g(|Screw)330 2047 y(Smith)g(|Nut)330 2107 +y(Jones)g(|Cam)330 2167 y(Adams)g(|Screw)330 2227 y(Adams)g(|Bolt)330 +2286 y(Blake)g(|Nut)330 2346 y(Blake)g(|Bolt)330 2406 +y(Blake)g(|Cam)330 2466 y(\(8)g(rows\))330 2585 y(testdb=>)g(select)g +(*)h(from)f(my_view)330 2645 y(testdb->)g(where)g(sname)g(=)h('Blake';) +330 2705 y(sname)f(|pname)330 2765 y(------+-----)330 +2824 y(Blake)g(|Nut)330 2884 y(Blake)g(|Bolt)330 2944 +y(Blake)g(|Cam)330 3004 y(\(3)g(rows\))330 3123 y(testdb=>)p +eop +%%Page: 51 51 +51 50 bop 198 608 a Fj(Chapter)26 b(3)198 857 y Fq(P)n(ostgr)n(eSQL)k +(fr)n(om)i(the)198 1006 y(Pr)n(ogrammer')-5 b(s)32 b(P)n(oint)f(of)g(V) +-5 b(iew)198 1265 y Ft(This)10 b(chapter)f(gi)o(v)o(es)h(an)f(o)o(v)o +(ervie)o(w)g(of)g(the)h(internal)e(structure)h(of)g(the)g(backend)g(of) +g(PostgreSQL.)h(After)198 1325 y(ha)o(ving)15 b(read)g(the)h(follo)o +(wing)e(sections)i(you)f(should)g(ha)o(v)o(e)h(an)f(idea)h(of)f(ho)o(w) +g(a)h(query)e(is)i(processed.)198 1385 y(Don')o(t)g(e)o(xpect)g(a)h +(detailed)f(description)g(here)g(\(I)g(think)g(such)g(a)h(description)f +(dealing)g(with)g(all)g(data)198 1445 y(structures)11 +b(and)h(functions)f(used)h(within)f(PostgreSQL)g(would)g(e)o(xceed)h +(1000)f(pages!\).)k(This)d(chapter)198 1504 y(is)f(intended)f(to)g +(help)g(understanding)g(the)g(general)h(control)e(and)i(data)f(\003o)o +(w)g(within)g(the)g(backend)g(from)198 1564 y(recei)o(ving)i(a)g(query) +g(to)g(sending)h(the)f(results.)198 1729 y Fi(3.1)71 +b(The)18 b(W)-5 b(ay)18 b(of)f(a)h(Query)198 1841 y Ft(Here)12 +b(we)h(gi)o(v)o(e)f(a)h(short)f(o)o(v)o(ervie)o(w)g(of)g(the)g(stages)h +(a)g(query)f(has)g(to)h(pass)g(in)f(order)g(to)g(obtain)g(a)g(result:) +273 1927 y Fo(\017)25 b Ft(First)14 b(a)h(connection)f(from)g(an)h +(application)f(program)g(to)g(the)h(PostgreSQL)f(serv)o(er)h(has)g(to)g +(be)323 1987 y(established.)g(The)d(application)f(program)f(transmits)i +(a)f(query)g(to)g(the)h(serv)o(er)f(and)g(recei)o(v)o(es)h(the)323 +2047 y(results)g(sent)h(back)f(by)h(the)f(serv)o(er)m(.)273 +2140 y Fo(\017)25 b Ft(The)17 b Fp(parser)g(stage)f Ft(checks)i(the)e +(query)h(transmitted)f(by)h(the)f(application)h(program)e(\(client\)) +323 2200 y(for)c(correct)h(syntax)g(and)h(creates)f(a)h +Fp(query)g(tr)n(ee)p Ft(.)273 2293 y Fo(\017)25 b Ft(The)18 +b Fp(r)n(e)o(write)h(system)f Ft(takes)f(the)h Fp(query)g(tr)n(ee)g +Ft(created)g(by)f(the)h Fp(parser)g(stage)f Ft(looks)g(for)g(an)o(y)323 +2352 y Fp(rules)11 b Ft(\(stored)g(in)g(the)g Fp(system)h(catalogs)p +Ft(\))e(to)h(apply)f(to)h(the)g Fp(querytr)n(ee)i Ft(and)e(performs)f +(the)h(trans-)323 2412 y(formations)j(gi)o(v)o(en)g(in)h(the)g +Fp(rule)h(bodies)p Ft(.)24 b(One)15 b(application)g(of)f(the)h +Fp(r)n(e)o(write)i(system)f Ft(is)f(gi)o(v)o(en)323 2472 +y(in)f(the)g(realization)f(of)h Fp(vie)o(ws)p Ft(.)23 +b(Whene)o(v)o(er)14 b(a)g(query)g(against)g(a)g Fp(vie)o(w)h +Ft(\(i.e.)22 b(a)14 b Fp(virtual)g(table)p Ft(\))g(is)323 +2532 y(made,)h(the)f Fp(r)n(e)o(write)h(system)g Ft(re)o(writes)f(the)g +(user')m(s)h(query)e(to)h(a)h(query)f(that)g(accesses)i(the)e +Fp(base)323 2592 y(tables)e Ft(gi)o(v)o(en)g(in)g(the)h +Fp(vie)o(w)g(de\002nition)e Ft(instead.)273 2685 y Fo(\017)25 +b Ft(The)17 b Fp(planner/optimizer)f Ft(takes)h(the)g(\()p +Fp(r)n(e)o(written)p Ft(\))f Fp(querytr)n(ee)i Ft(and)f(creates)g(a)g +Fp(queryplan)f Ft(that)323 2744 y(will)10 b(be)i(the)f(input)f(to)h +(the)g Fp(e)o(xecutor)p Ft(.)16 b(It)11 b(does)h(so)f(by)g(\002rst)g +(creating)g(all)g(possible)g Fp(paths)g Ft(leading)323 +2804 y(to)16 b(the)g(same)h(result.)29 b(\()16 b(F)o(or)g(e)o(xample)h +(if)f(there)g(is)h(an)f(inde)o(x)h(on)f(a)h(relation)f(to)g(be)h +(scanned,)323 2864 y(there)c(are)g(two)g Fp(paths)h Ft(for)f(the)g +(scan.)20 b(One)14 b(possibility)f(is)h(a)g(simple)g(sequential)f(scan) +i(and)e(the)323 2924 y(other)g(possibility)g(is)h(to)f(use)h(the)g +(inde)o(x.\))19 b(Ne)o(xt)14 b(the)f(cost)h(for)f(the)h(e)o(x)o +(ecution)f(of)h(each)g Fp(plan)f Ft(is)323 2984 y(estimated)f(and)g +(the)h(cheapest)g Fp(plan)f Ft(is)g(chosen)h(and)f(handed)h(back.)273 +3077 y Fo(\017)25 b Ft(The)14 b Fp(e)o(xecutor)h Ft(recursi)o(v)o(ely)f +(steps)h(through)e(the)h Fp(plan)g(tr)n(ee)h Ft(and)f(retrie)o(v)o(es)g +(tuples)g(in)g(the)h(way)323 3136 y(represented)f(by)g(the)g +Fp(plan)p Ft(.)21 b(The)15 b Fp(e)o(xecutor)g Ft(makes)f(use)h(of)f +(the)g Fp(stor)o(age)h(system)g Ft(while)f(scan-)323 +3196 y(ning)i(relations,)j(performs)d Fp(sorts)i Ft(and)f +Fp(joins)p Ft(,)i(e)o(v)o(aluates)e Fp(quali\002cations)g +Ft(and)g(\002nally)g(hands)323 3256 y(back)12 b(the)g(tuples)h(deri)o +(v)o(ed.)198 3342 y(In)j(the)g(follo)o(wing)g(sections)h(we)f(will)g +(co)o(v)o(er)h(e)o(v)o(ery)f(of)g(the)h(abo)o(v)o(e)g(listed)f(items)h +(in)f(more)g(detail)g(to)198 3402 y(gi)o(v)o(e)c(a)h(better)f +(understanding)f(on)i(PostgreSQL)-5 b(')m(s)12 b(internal)g(control)f +(and)i(data)f(structures.)1073 3552 y(51)p eop +%%Page: 52 52 +52 51 bop 270 60 a Ft(52)82 b Fm(CHAPTER)14 b(3.)28 b(POSTGRESQL)13 +b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW)270 +234 y Fi(3.2)71 b(Ho)o(w)18 b(Connections)f(ar)o(e)g(Established)270 +370 y Ft(PostgreSQL)c(is)g(implemented)f(using)h(a)g(simple)g +(\224process)h(per)o(-user\224)e(client/serv)o(er)h(model.)k(In)c(this) +270 430 y(model)k(there)f(is)h(one)g Fp(client)g(pr)n(ocess)h +Ft(connected)f(to)f(e)o(xactly)i(one)e Fp(server)j(pr)n(ocess)p +Ft(.)30 b(As)18 b(we)f(don')o(t)270 490 y(kno)o(w)f Fp(per)h(se)g +Ft(ho)o(w)f(man)o(y)h(connections)g(will)f(be)g(made,)j(we)d(ha)o(v)o +(e)h(to)g(use)g(a)f Fp(master)i(pr)n(ocess)f Ft(that)270 +549 y(spa)o(wns)h(a)e(ne)o(w)h Fp(server)h(pr)n(ocess)f +Ft(e)o(v)o(ery)f(time)h(a)f(connection)h(is)f(requested.)29 +b(This)17 b Fp(master)g(pr)n(ocess)270 609 y Ft(is)f(called)g +Fr(postmaster)e Ft(and)i(listens)g(at)f(a)h(speci\002ed)g(TCP/IP)f +(port)g(for)g(incoming)g(connections.)270 669 y(Whene)o(v)o(er)e(a)h +(request)f(for)f(a)i(connection)f(is)h(detected)f(the)g +Fr(postmaster)g Ft(process)g(spa)o(wns)i(a)e(ne)o(w)270 +729 y Fp(server)i(pr)n(ocess)f Ft(called)g Fr(postgres)p +Ft(.)j(The)d(serv)o(er)g(tasks)g(\()p Fr(postgres)e Ft(processes\))i +(communicate)270 788 y(with)k(each)g(other)f(using)h +Fp(semaphor)n(es)h Ft(and)f Fp(shar)n(ed)h(memory)g Ft(to)e(ensure)h +(data)g(inte)o(grity)f(through-)270 848 y(out)j(concurrent)e(data)i +(access.)40 b(Figure)19 b(3.1)h(illustrates)f(the)h(interaction)f(of)g +(the)h(master)g(process)270 908 y Fr(postmaster)11 b +Ft(the)i(serv)o(er)f(process)h Fr(postgres)e Ft(and)i(a)f(client)h +(application.)345 981 y(The)e(client)g(process)g(can)h(either)e(be)h +(the)g Fr(psql)g Ft(frontend)f(\(for)f Fp(inter)o(active)j +Ft(SQL)f(queries\))f(or)h(an)o(y)270 1041 y(user)f(application)f +(implemented)g(using)h(the)f Fr(libpg)h Ft(library)m(.)j(Note)d(that)f +(applications)h(implemented)270 1100 y(using)i Fr(ecpq)g +Ft(\(i.e.)k(the)d(postgres)f(embedded)g(C)h(compiler\))e(also)i(use)g +(this)f(library)m(.)345 1173 y(Once)e(a)g(connection)f(is)i +(established)f(the)g(client)f(process)i(can)f(send)g(a)g(query)f(to)h +(the)g Fp(bac)o(kend)p Ft(.)15 b(The)270 1233 y(query)f(is)h +(transmitted)e(using)i Fp(plain)f(te)o(xt)p Ft(,)h(i.e.)23 +b(there)14 b(is)h(no)f(parsing)g(done)h(in)f(the)h Fp(fr)n(ontend)f +Ft(\(client\).)270 1293 y(The)i(serv)o(er)g Fp(parses)g +Ft(the)g(query)m(,)g(creates)g(an)g Fp(e)o(xecution)f(plan)p +Ft(,)i(e)o(x)o(ecutes)g(the)e Fp(plan)g Ft(and)h(returns)f(the)270 +1352 y(retrie)o(v)o(ed)c(tuples)i(to)f(the)g(client)h(by)f +(transmitting)f(them)h(o)o(v)o(er)h(the)f(established)h(connection.)543 +2309 y @beginspecial 180 @llx 310 @lly 431 @urx 482 @ury +2510 @rwi @setspecial +%%BeginDocument: figures/connection.ps +%Magnification: 1.05 +/$F2psDict 200 dict def +$F2psDict begin +$F2psDict /mtrx matrix put +/col-1 {0 setgray} bind def +/col0 {0.000 0.000 0.000 srgb} bind def +/col1 {0.000 0.000 1.000 srgb} bind def +/col2 {0.000 1.000 0.000 srgb} bind def +/col3 {0.000 1.000 1.000 srgb} bind def +/col4 {1.000 0.000 0.000 srgb} bind def +/col5 {1.000 0.000 1.000 srgb} bind def +/col6 {1.000 1.000 0.000 srgb} bind def +/col7 {1.000 1.000 1.000 srgb} bind def +/col8 {0.000 0.000 0.560 srgb} bind def +/col9 {0.000 0.000 0.690 srgb} bind def +/col10 {0.000 0.000 0.820 srgb} bind def +/col11 {0.530 0.810 1.000 srgb} bind def +/col12 {0.000 0.560 0.000 srgb} bind def +/col13 {0.000 0.690 0.000 srgb} bind def +/col14 {0.000 0.820 0.000 srgb} bind def +/col15 {0.000 0.560 0.560 srgb} bind def +/col16 {0.000 0.690 0.690 srgb} bind def +/col17 {0.000 0.820 0.820 srgb} bind def +/col18 {0.560 0.000 0.000 srgb} bind def +/col19 {0.690 0.000 0.000 srgb} bind def +/col20 {0.820 0.000 0.000 srgb} bind def +/col21 {0.560 0.000 0.560 srgb} bind def +/col22 {0.690 0.000 0.690 srgb} bind def +/col23 {0.820 0.000 0.820 srgb} bind def +/col24 {0.500 0.190 0.000 srgb} bind def +/col25 {0.630 0.250 0.000 srgb} bind def +/col26 {0.750 0.380 0.000 srgb} bind def +/col27 {1.000 0.500 0.500 srgb} bind def +/col28 {1.000 0.630 0.630 srgb} bind def +/col29 {1.000 0.750 0.750 srgb} bind def +/col30 {1.000 0.880 0.880 srgb} bind def +/col31 {1.000 0.840 0.000 srgb} bind def + +end +save +175.5 498.0 translate +1 -1 scale + +/cp {closepath} bind def +/ef {eofill} bind def +/gr {grestore} bind def +/gs {gsave} bind def +/sa {save} bind def +/rs {restore} bind def +/l {lineto} bind def +/m {moveto} bind def +/rm {rmoveto} bind def +/n {newpath} bind def +/s {stroke} bind def +/sh {show} bind def +/slc {setlinecap} bind def +/slj {setlinejoin} bind def +/slw {setlinewidth} bind def +/srgb {setrgbcolor} bind def +/rot {rotate} bind def +/sc {scale} bind def +/sd {setdash} bind def +/ff {findfont} bind def +/sf {setfont} bind def +/scf {scalefont} bind def +/sw {stringwidth} bind def +/tr {translate} bind def +/tnt {dup dup currentrgbcolor + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add srgb} + bind def +/shd {dup dup currentrgbcolor 4 -2 roll mul 4 -2 roll mul + 4 -2 roll mul srgb} bind def + /DrawEllipse { + /endangle exch def + /startangle exch def + /yrad exch def + /xrad exch def + /y exch def + /x exch def + /savematrix mtrx currentmatrix def + x y tr xrad yrad sc 0 0 1 startangle endangle arc + closepath + savematrix setmatrix + } def + +/$F2psBegin {$F2psDict begin /$F2psEnteredState save def} def +/$F2psEnd {$F2psEnteredState restore end} def + +$F2psBegin +10 setmiterlimit +n 0 792 m 0 0 l 612 0 l 612 792 l cp clip + 0.06299 0.06299 sc +7.500 slw +% Polyline +n 2835 1980 m 3645 1980 l 3645 2250 l 2835 2250 l cp gs col-1 s gr +/Times-Roman ff 150.00 scf sf +2925 2160 m +gs 1 -1 sc (Postmaster) col-1 sh gr +% Polyline +n 2790 540 m 3600 540 l 3600 810 l 2790 810 l cp gs col-1 s gr +/Times-Roman ff 150.00 scf sf +2880 720 m +gs 1 -1 sc (Postmaster) col-1 sh gr +% Ellipse +n 3240 2385 810 585 0 360 DrawEllipse gs col-1 s gr + +% Ellipse +n 2520 2115 45 45 0 360 DrawEllipse gs col-1 s gr + +% Ellipse +n 900 2206 765 495 0 360 DrawEllipse gs col-1 s gr + +% Ellipse +n 3195 945 810 585 0 360 DrawEllipse gs col-1 s gr + +% Ellipse +n 2475 675 45 45 0 360 DrawEllipse gs col-1 s gr + +% Ellipse +n 855 766 765 495 0 360 DrawEllipse gs col-1 s gr + +% Polyline +gs clippath +2704 2493 m 2809 2556 l 2686 2550 l 2840 2598 l 2858 2541 l cp clip +n 1395 2115 m 2835 2565 l gs col-1 s gr gr + +% arrowhead +n 2704 2493 m 2809 2556 l 2686 2550 l 2695 2521 l 2704 2493 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 2565 2115 m 2835 2115 l gs col-1 s gr +% Polyline +n 855 1890 m 855 2340 l gs col-1 s gr +% Polyline +n 405 1890 m 1395 1890 l 1395 2340 l 405 2340 l cp gs col-1 s gr +% Polyline +n 2835 2430 m 3645 2430 l 3645 2700 l 2835 2700 l cp gs col-1 s gr +% Polyline +gs clippath +2283 645 m 2403 675 l 2283 705 l 2445 705 l 2445 645 l cp clip +n 1350 675 m 2430 675 l gs col-1 s gr gr + +% arrowhead +n 2283 645 m 2403 675 l 2283 705 l 2283 675 l 2283 645 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 2520 675 m 2790 675 l gs col-1 s gr +% Polyline +n 810 450 m 810 900 l gs col-1 s gr +% Polyline +n 360 450 m 1350 450 l 1350 900 l 360 900 l cp gs col-1 s gr +/Times-Roman ff 150.00 scf sf +2880 2880 m +gs 1 -1 sc (Server Host) col-1 sh gr +/Times-Roman ff 150.00 scf sf +495 2070 m +gs 1 -1 sc (User ) col-1 sh gr +/Times-Roman ff 150.00 scf sf +495 2265 m +gs 1 -1 sc (App) col-1 sh gr +/Times-Roman ff 150.00 scf sf +900 2160 m +gs 1 -1 sc (LIBPQ) col-1 sh gr +/Times-Roman ff 150.00 scf sf +585 2610 m +gs 1 -1 sc (Client Host) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3015 2610 m +gs 1 -1 sc (Postgres) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2835 1440 m +gs 1 -1 sc (Server Host) col-1 sh gr +/Times-Roman ff 150.00 scf sf +450 630 m +gs 1 -1 sc (User ) col-1 sh gr +/Times-Roman ff 150.00 scf sf +450 825 m +gs 1 -1 sc (App) col-1 sh gr +/Times-Roman ff 150.00 scf sf +855 720 m +gs 1 -1 sc (LIBPQ) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 1170 m +gs 1 -1 sc (Client Host) col-1 sh gr +showpage +$F2psEnd +rs +%%EndDocument + @endspecial 733 2418 a(Figure)e(3.1:)16 b(Ho)o(w)c(a)g(connection)g +(is)h(established)270 2780 y Fi(3.3)71 b(The)18 b(P)o(arser)f(Stage)270 +2916 y Ft(The)c Fp(parser)g(stage)f Ft(consists)h(of)f(two)f(parts:)345 +3055 y Fo(\017)25 b Ft(The)17 b Fp(parser)g Ft(de\002ned)g(in)f +Fr(gram.y)h Ft(and)f Fr(scan.l)h Ft(is)g(b)o(uilt)f(using)h(the)f(UNIX) +h(tools)f Fr(yacc)395 3115 y Ft(and)c Fr(lex)p Ft(.)345 +3266 y Fo(\017)25 b Ft(The)11 b Fp(tr)o(ansformation)g(pr)n(ocess)h +Ft(does)f(some)g(necessary)h(transformation)d(to)i(the)g(data)g +(structure)395 3326 y(returned)g(by)h(the)h Fp(parser)p +Ft(.)p eop +%%Page: 53 53 +53 52 bop 198 60 a Fm(3.3.)29 b(THE)13 b(P)-5 b(ARSER)13 +b(ST)-5 b(A)n(GE)1189 b Ft(53)198 234 y Fh(3.3.1)59 b(P)o(arser)198 +328 y Ft(The)14 b Fp(parser)g Ft(has)g(to)f(check)h(the)f(query)g +(string)g(\(which)g(arri)o(v)o(es)g(as)h Fp(plain)f(ASCII)h(te)o(xt)p +Ft(\))f(for)f(v)o(alid)h(syn-)198 388 y(tax.)22 b(If)14 +b(the)g(syntax)h(is)g(correct)e(a)i Fp(parse)g(tr)n(ee)g +Ft(is)g(b)o(uilt)f(up)g(and)h(handed)f(back)h(otherwise)f(an)g(error)g +(is)198 448 y(returned.)h(F)o(or)d(the)g(implementation)f(the)i(well)f +(kno)o(wn)g(UNIX)g(tools)g Fr(lex)g Ft(and)g Fr(yacc)g +Ft(are)h(used.)273 508 y(The)i Fp(le)o(xer)g Ft(is)g(de\002ned)f(in)h +(the)f(\002le)g Fr(scan.l)g Ft(and)h(is)g(responsible)f(for)g +(recognizing)g Fp(identi\002ers)p Ft(,)198 567 y(the)h +Fp(SQL)g(ke)o(ywor)n(ds)h Ft(etc.)24 b(F)o(or)15 b(e)o(v)o(ery)g +Fp(ke)o(ywor)n(d)g Ft(or)g Fp(identi\002er)g Ft(that)g(is)h(found,)g(a) +f Fp(token)g Ft(is)g(generated)198 627 y(and)d(handed)h(to)f(the)g +Fp(parser)p Ft(.)273 687 y(The)k Fp(parser)g Ft(is)g(de\002ned)f(in)g +(the)h(\002le)f Fr(gram.y)g Ft(and)g(consists)i(of)e(a)h(set)g(of)f +Fp(gr)o(ammar)h(rules)g Ft(and)198 747 y Fp(actions)10 +b Ft(that)g(are)g(e)o(x)o(ecuted)h(whene)o(v)o(er)f(a)h(rule)f(is)g +(\002red.)15 b(The)10 b(code)h(of)f(the)g Fp(actions)g +Ft(\(which)g(is)g(actually)198 807 y(C-code\))i(is)h(used)f(to)h(b)o +(uild)e(up)i(the)f Fp(parse)h(tr)n(ee)p Ft(.)273 867 +y(The)h(\002le)g Fr(scan.l)f Ft(is)h(transformed)f(to)g(the)h(C-source) +g(\002le)g Fr(scan.c)f Ft(using)h(the)g(program)e Fr(lex)198 +927 y Ft(and)17 b Fr(gram.y)g Ft(is)h(transformed)e(to)h +Fr(gram.c)g Ft(using)g Fr(yacc)p Ft(.)30 b(After)17 b(these)h +(transformations)e(ha)o(v)o(e)198 987 y(taken)11 b(place)g(a)g(normal)f +(C-compiler)g(can)h(be)h(used)f(to)g(create)g(the)g Fp(parser)p +Ft(.)16 b(Ne)o(v)o(er)11 b(make)f(an)o(y)i(changes)198 +1046 y(to)j(the)g(generated)g(C-\002les)g(as)h(the)o(y)f(will)g(be)h(o) +o(v)o(erwritten)e(the)h(ne)o(xt)h(time)e Fr(lex)h Ft(or)g +Fr(yacc)g Ft(is)h(called.)198 1106 y(\(Note)g(that)h(the)g(mentioned)f +(transformations)g(and)h(compilations)f(are)h(normally)f(done)h +(automati-)198 1166 y(cally)12 b(using)h(the)f Fr(makefiles)f +Ft(shipped)i(with)f(the)g(PostgreSQL)g(source)h(distrib)o(ution.\))273 +1226 y(A)20 b(detailed)g(description)g(of)g Fr(yacc)g +Ft(or)f(the)i Fp(gr)o(ammar)g(rules)g Ft(gi)o(v)o(en)f(in)g +Fr(gram.y)g Ft(would)f(be)198 1286 y(be)o(yond)c(the)h(scope)g(of)f +(this)h(paper)m(.)25 b(There)16 b(are)f(man)o(y)g(books)h(and)g +(documents)f(dealing)g(with)g Fr(lex)198 1345 y Ft(and)c +Fr(yacc)p Ft(.)k(Y)-5 b(ou)11 b(should)g(be)h(familiar)d(with)i +Fr(yacc)p Ft(,)h(before)e(you)h(start)g(to)h(study)f(the)g(grammar)f +(gi)o(v)o(en)198 1405 y(in)i Fr(gram.y)g Ft(otherwise)g(you)g(won')o(t) +g(understand)g(what)g(happens)h(there.)198 1525 y(F)o(or)27 +b(a)h(better)f(understanding)g(of)g(the)g(data)h(structures)f(used)h +(in)g(PostgreSQL)f(for)g(the)g(pro-)198 1585 y(cessing)12 +b(of)e(a)h(query)g(we)g(use)g(an)g(e)o(xample)h(to)e(illustrate)h(the)g +(changes)g(made)g(to)g(these)g(data)g(structures)198 +1644 y(in)h(e)o(v)o(ery)g(stage.)198 1766 y Fn(Example)h(3.1)25 +b Ft(This)10 b(e)o(xample)g(contains)f(the)h(follo)o(wing)e(simple)h +(query)g(that)h(will)f(be)g(used)h(in)g(v)o(arious)198 +1825 y(descriptions)18 b(and)g(\002gures)g(throughout)f(the)h(follo)o +(wing)e(sections.)34 b(The)18 b(query)g(assumes)h(that)f(the)198 +1885 y(tables)13 b(gi)o(v)o(en)f(in)g(e)o(xample)g(1.1)h(ha)o(v)o(e)g +(already)f(been)h(de\002ned.)258 1986 y Fr(select)29 +b(s.sname,)g(se.pno)258 2046 y(from)g(supplier)g(s,)h(sells)f(se)258 +2106 y(where)g(s.sno)g(>)h(2)g(and)437 2165 y(s.sno)f(=)h(se.sno;)198 +2266 y Ft(Figure)13 b(3.2)h(sho)o(ws)h(the)e Fp(parse)i(tr)n(ee)f +Ft(b)o(uilt)g(by)f(the)h Fp(gr)o(ammar)h(rules)f Ft(and)g +Fp(actions)g Ft(gi)o(v)o(en)g(in)g Fr(gram.y)198 2326 +y Ft(for)g(the)h(query)f(gi)o(v)o(en)h(in)f(e)o(xample)h(3.1)g +(\(without)f(the)h Fp(oper)o(ator)g(tr)n(ee)h Ft(for)e(the)g +Fp(wher)n(e)i(clause)f Ft(which)198 2385 y(is)f(sho)o(wn)f(in)h +(\002gure)f(3.3)h(because)g(there)f(was)h(not)f(enough)h(space)g(to)f +(sho)o(w)h(both)f(data)h(structures)f(in)198 2445 y(one)f(\002gure\).) +273 2505 y(The)f(top)g(node)g(of)f(the)h(tree)g(is)g(a)g +Fr(SelectStmt)f Ft(node.)15 b(F)o(or)10 b(e)o(v)o(ery)h(entry)f +(appearing)h(in)f(the)h Fp(fr)n(om)198 2565 y(clause)k +Ft(of)f(the)h(SQL)g(query)f(a)h Fr(RangeVar)e Ft(node)i(is)g(created)f +(holding)g(the)h(name)g(of)f(the)g Fp(alias)h Ft(and)198 +2625 y(a)e(pointer)f(to)h(a)g Fr(RelExpr)f Ft(node)h(holding)f(the)h +(name)g(of)f(the)h Fp(r)n(elation)p Ft(.)k(All)c Fr(RangeVar)f +Ft(nodes)h(are)198 2685 y(collected)f(in)g(a)h(list)f(which)h(is)f +(attached)h(to)f(the)g(\002eld)g Fr(fromClause)g Ft(of)g(the)g +Fr(SelectStmt)f Ft(node.)273 2745 y(F)o(or)19 b(e)o(v)o(ery)g(entry)h +(appearing)f(in)g(the)h Fp(select)g(list)g Ft(of)g(the)f(SQL)h(query)f +(a)h Fr(ResTarget)f Ft(node)198 2804 y(is)e(created)g(holding)f(a)h +(pointer)f(to)h(an)g Fr(Attr)g Ft(node.)29 b(The)17 b +Fr(Attr)g Ft(node)f(holds)h(the)g Fp(r)n(elation)g(name)198 +2864 y Ft(of)22 b(the)g(entry)g(and)h(a)f(pointer)g(to)g(a)h +Fr(Value)f Ft(node)g(holding)g(the)g(name)g(of)g(the)h +Fp(attrib)o(ute)p Ft(.)45 b(All)198 2924 y Fr(ResTarget)11 +b Ft(nodes)h(are)g(collected)g(to)f(a)h(list)g(which)g(is)g(connected)g +(to)f(the)h(\002eld)g Fr(targetList)f Ft(of)198 2984 +y(the)h Fr(SelectStmt)g Ft(node.)198 3103 y(Figure)28 +b(3.3)i(sho)o(ws)f(the)g Fp(oper)o(ator)h(tr)n(ee)g Ft(b)o(uilt)e(for)g +(the)h Fp(wher)n(e)h(clause)g Ft(of)e(the)h(SQL)h(query)198 +3163 y(gi)o(v)o(en)13 b(in)g(e)o(xample)h(3.1)f(which)g(is)h(attached)f +(to)g(the)h(\002eld)f Fr(qual)g Ft(of)g(the)g Fr(SelectStmt)f +Ft(node.)19 b(The)198 3223 y(top)f(node)g(of)g(the)g +Fp(oper)o(ator)h(tr)n(ee)g Ft(is)g(an)f Fr(A)p 970 3223 +15 2 v 18 w(Expr)g Ft(node)g(representing)f(an)i Fr(AND)f +Ft(operation.)32 b(This)198 3283 y(node)14 b(has)g(two)f(successors)i +(called)e Fr(lexpr)h Ft(and)f Fr(rexpr)h Ft(pointing)e(to)i(two)f +Fp(subtr)n(ees)p Ft(.)21 b(The)14 b Fp(subtr)n(ee)198 +3342 y Ft(attached)g(to)f Fr(lexpr)g Ft(represents)h(the)g +(quali\002cation)e Fk(s:sno)17 b(>)f Fl(2)e Ft(and)f(the)h(one)f +(attached)h(to)g Fr(rexpr)198 3402 y Ft(represents)f +Fk(s:sno)i Fl(=)f Fk(se:sno)p Ft(.)j(F)o(or)c(e)o(v)o(ery)f +Fp(attrib)o(ute)g Ft(an)h Fr(Attr)f Ft(node)h(is)g(created)g(holding)e +(the)i(name)p eop +%%Page: 54 54 +54 53 bop 270 60 a Ft(54)82 b Fm(CHAPTER)14 b(3.)28 b(POSTGRESQL)13 +b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW)270 +234 y Ft(of)j(the)f Fp(r)n(elation)h Ft(and)g(a)g(pointer)g(to)f(a)i +Fr(Value)e Ft(node)h(holding)f(the)h(name)g(of)g(the)f +Fp(attrib)o(ute)p Ft(.)24 b(F)o(or)14 b(the)270 294 y +Fp(constant)e Ft(appearing)g(in)g(the)h(query)f(a)g Fr(Const)g +Ft(node)g(is)h(created)f(holding)g(the)g(v)o(alue.)363 +2301 y @beginspecial 144 @llx 201 @lly 467 @urx 590 @ury +3230 @rwi @setspecial +%%BeginDocument: figures/parsetree.ps +%Magnification: 1.05 +/$F2psDict 200 dict def +$F2psDict begin +$F2psDict /mtrx matrix put +/col-1 {0 setgray} bind def +/col0 {0.000 0.000 0.000 srgb} bind def +/col1 {0.000 0.000 1.000 srgb} bind def +/col2 {0.000 1.000 0.000 srgb} bind def +/col3 {0.000 1.000 1.000 srgb} bind def +/col4 {1.000 0.000 0.000 srgb} bind def +/col5 {1.000 0.000 1.000 srgb} bind def +/col6 {1.000 1.000 0.000 srgb} bind def +/col7 {1.000 1.000 1.000 srgb} bind def +/col8 {0.000 0.000 0.560 srgb} bind def +/col9 {0.000 0.000 0.690 srgb} bind def +/col10 {0.000 0.000 0.820 srgb} bind def +/col11 {0.530 0.810 1.000 srgb} bind def +/col12 {0.000 0.560 0.000 srgb} bind def +/col13 {0.000 0.690 0.000 srgb} bind def +/col14 {0.000 0.820 0.000 srgb} bind def +/col15 {0.000 0.560 0.560 srgb} bind def +/col16 {0.000 0.690 0.690 srgb} bind def +/col17 {0.000 0.820 0.820 srgb} bind def +/col18 {0.560 0.000 0.000 srgb} bind def +/col19 {0.690 0.000 0.000 srgb} bind def +/col20 {0.820 0.000 0.000 srgb} bind def +/col21 {0.560 0.000 0.560 srgb} bind def +/col22 {0.690 0.000 0.690 srgb} bind def +/col23 {0.820 0.000 0.820 srgb} bind def +/col24 {0.500 0.190 0.000 srgb} bind def +/col25 {0.630 0.250 0.000 srgb} bind def +/col26 {0.750 0.380 0.000 srgb} bind def +/col27 {1.000 0.500 0.500 srgb} bind def +/col28 {1.000 0.630 0.630 srgb} bind def +/col29 {1.000 0.750 0.750 srgb} bind def +/col30 {1.000 0.880 0.880 srgb} bind def +/col31 {1.000 0.840 0.000 srgb} bind def + +end +save +131.5 603.5 translate +1 -1 scale + +/cp {closepath} bind def +/ef {eofill} bind def +/gr {grestore} bind def +/gs {gsave} bind def +/sa {save} bind def +/rs {restore} bind def +/l {lineto} bind def +/m {moveto} bind def +/rm {rmoveto} bind def +/n {newpath} bind def +/s {stroke} bind def +/sh {show} bind def +/slc {setlinecap} bind def +/slj {setlinejoin} bind def +/slw {setlinewidth} bind def +/srgb {setrgbcolor} bind def +/rot {rotate} bind def +/sc {scale} bind def +/sd {setdash} bind def +/ff {findfont} bind def +/sf {setfont} bind def +/scf {scalefont} bind def +/sw {stringwidth} bind def +/tr {translate} bind def +/tnt {dup dup currentrgbcolor + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add srgb} + bind def +/shd {dup dup currentrgbcolor 4 -2 roll mul 4 -2 roll mul + 4 -2 roll mul srgb} bind def + /DrawSplineSection { + /y3 exch def + /x3 exch def + /y2 exch def + /x2 exch def + /y1 exch def + /x1 exch def + /xa x1 x2 x1 sub 0.666667 mul add def + /ya y1 y2 y1 sub 0.666667 mul add def + /xb x3 x2 x3 sub 0.666667 mul add def + /yb y3 y2 y3 sub 0.666667 mul add def + x1 y1 lineto + xa ya xb yb x3 y3 curveto + } def + +/$F2psBegin {$F2psDict begin /$F2psEnteredState save def} def +/$F2psEnd {$F2psEnteredState restore end} def + +$F2psBegin +10 setmiterlimit +n 0 792 m 0 0 l 612 0 l 612 792 l cp clip + 0.06299 0.06299 sc +7.500 slw +% Polyline +n 1215 450 m 1485 720 l gs col-1 s gr +% Polyline +n 1485 450 m 1215 720 l gs col-1 s gr +% Polyline +n 1215 1800 m 1485 2070 l gs col-1 s gr +% Polyline +n 1485 1800 m 1215 2070 l gs col-1 s gr +% Polyline +n 1215 2070 m 1485 2340 l gs col-1 s gr +% Polyline +n 1485 2070 m 1215 2340 l gs col-1 s gr +% Polyline +n 1215 2340 m 1485 2610 l gs col-1 s gr +% Polyline +n 1485 2340 m 1215 2610 l gs col-1 s gr +% Polyline +n 2430 450 m 3240 450 l gs col-1 s gr +% Polyline +n 2430 225 m 3240 225 l 3240 720 l 2430 720 l cp gs col-1 s gr +% Polyline +n 2970 450 m 2970 720 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +2520 630 m +gs 1 -1 sc (val) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2520 405 m +gs 1 -1 sc (ResTarget) col-1 sh gr +% Polyline +n 3510 450 m 4410 450 l gs col-1 s gr +% Polyline +n 3510 720 m 4410 720 l gs col-1 s gr +% Polyline +n 3510 225 m 4410 225 l 4410 990 l 3510 990 l cp gs col-1 s gr +% Polyline +n 4140 450 m 4140 990 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +3825 405 m +gs 1 -1 sc (Attr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3600 900 m +gs 1 -1 sc (attrs) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3600 630 m +gs 1 -1 sc (relname) col-1 sh gr +% Polyline +n 4635 720 m 5175 720 l 5175 990 l 4635 990 l cp gs col-1 s gr +% Polyline +n 4905 720 m 4905 990 l gs col-1 s gr +% Polyline +n 4905 720 m 5175 990 l gs col-1 s gr +% Polyline +n 5175 720 m 4905 990 l gs col-1 s gr +% Polyline +n 4365 1215 m 5175 1215 l 5175 1710 l 4365 1710 l cp gs col-1 s gr +% Polyline +n 4365 1440 m 5175 1440 l gs col-1 s gr +% Polyline +n 4905 1440 m 4905 1710 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +4590 1395 m +gs 1 -1 sc (Value) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4455 1620 m +gs 1 -1 sc (val.str) col-1 sh gr +% Polyline +n 2430 5265 m 3330 5265 l gs col-1 s gr +% Polyline +n 2430 5535 m 3330 5535 l gs col-1 s gr +% Polyline +n 2430 5040 m 3330 5040 l 3330 5805 l 2430 5805 l cp gs col-1 s gr +% Polyline +n 3060 5265 m 3060 5805 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +2520 5715 m +gs 1 -1 sc (relExpr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2520 5445 m +gs 1 -1 sc (name) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2565 5220 m +gs 1 -1 sc (RangeVar) col-1 sh gr +% Polyline +n 3600 5670 m 4500 5670 l gs col-1 s gr +% Polyline +n 3600 5445 m 4500 5445 l 4500 5940 l 3600 5940 l cp gs col-1 s gr +% Polyline +n 4230 5670 m 4230 5940 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +3690 5850 m +gs 1 -1 sc (relname) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3690 5625 m +gs 1 -1 sc (RelExpr) col-1 sh gr +% Polyline +gs clippath +3453 5640 m 3573 5670 l 3453 5700 l 3615 5700 l 3615 5640 l cp clip +n 3195 5670 m 3600 5670 l gs col-1 s gr gr + +% arrowhead +n 3453 5640 m 3573 5670 l 3453 5700 l 3453 5670 l 3453 5640 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +4395 6018 m 4365 6138 l 4335 6018 l 4335 6180 l 4395 6180 l cp clip +n 4365 5805 m 4365 6165 l gs col-1 s gr gr + +% arrowhead +n 4395 6018 m 4365 6138 l 4335 6018 l 4365 6018 l 4395 6018 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3588 5190 m 3708 5220 l 3588 5250 l 3750 5250 l 3750 5190 l cp clip +n 3240.0 5400.0 m 3375.0 5400.0 l + 3375.0 5400.0 3510.0 5400.0 3510.0 5310.0 DrawSplineSection + 3510.0 5310.0 3510.0 5220.0 3622.5 5220.0 DrawSplineSection + 3735.0 5220.0 l gs col-1 s gr + gr + +% arrowhead +n 3588 5190 m 3708 5220 l 3588 5250 l 3588 5220 l 3588 5190 l cp gs 0.00 setgray ef gr col-1 s +/Times-Roman ff 150.00 scf sf +3825 5265 m +gs 1 -1 sc ("se") col-1 sh gr +/Times-Roman ff 150.00 scf sf +4185 6345 m +gs 1 -1 sc ("sells") col-1 sh gr +% Polyline +n 1935 855 m 1935 315 l 2205 315 l 2205 855 l cp gs col-1 s gr +% Polyline +n 1935 585 m 2205 585 l gs col-1 s gr +% Polyline +n 2205 2115 m 2205 2655 l 1935 2655 l 1935 2115 l cp gs col-1 s gr +% Polyline +n 2205 2385 m 1935 2385 l gs col-1 s gr +% Polyline +n 2205 2385 m 1935 2655 l gs col-1 s gr +% Polyline +n 2205 2655 m 1935 2385 l gs col-1 s gr +% Polyline +gs clippath +2283 420 m 2403 450 l 2283 480 l 2445 480 l 2445 420 l cp clip +n 2070 450 m 2430 450 l gs col-1 s gr gr + +% arrowhead +n 2283 420 m 2403 450 l 2283 480 l 2283 450 l 2283 420 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +2283 2220 m 2403 2250 l 2283 2280 l 2445 2280 l 2445 2220 l cp clip +n 2070 2250 m 2430 2250 l gs col-1 s gr gr + +% arrowhead +n 2283 2220 m 2403 2250 l 2283 2280 l 2283 2250 l 2283 2220 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +2100 1968 m 2070 2088 l 2040 1968 l 2040 2130 l 2100 2130 l cp clip +n 2070 720 m 2070 2115 l gs col-1 s gr gr + +% arrowhead +n 2100 1968 m 2070 2088 l 2040 1968 l 2070 1968 l 2100 1968 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 1935 4455 m 1935 3915 l 2205 3915 l 2205 4455 l cp gs col-1 s gr +% Polyline +n 1935 4185 m 2205 4185 l gs col-1 s gr +% Polyline +n 2205 5265 m 2205 5805 l 1935 5805 l 1935 5265 l cp gs col-1 s gr +% Polyline +n 2205 5535 m 1935 5535 l gs col-1 s gr +% Polyline +n 2205 5535 m 1935 5805 l gs col-1 s gr +% Polyline +n 2205 5805 m 1935 5535 l gs col-1 s gr +% Polyline +n 2430 3915 m 3330 3915 l gs col-1 s gr +% Polyline +n 2430 4185 m 3330 4185 l gs col-1 s gr +% Polyline +n 2430 3690 m 3330 3690 l 3330 4455 l 2430 4455 l cp gs col-1 s gr +% Polyline +n 3060 3915 m 3060 4455 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +2520 4365 m +gs 1 -1 sc (relExpr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2520 4095 m +gs 1 -1 sc (name) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2565 3870 m +gs 1 -1 sc (RangeVar) col-1 sh gr +% Polyline +n 3600 4320 m 4500 4320 l gs col-1 s gr +% Polyline +n 3600 4095 m 4500 4095 l 4500 4590 l 3600 4590 l cp gs col-1 s gr +% Polyline +n 4230 4320 m 4230 4590 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +3690 4500 m +gs 1 -1 sc (relname) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3690 4275 m +gs 1 -1 sc (RelExpr) col-1 sh gr +% Polyline +n 2430 2250 m 3240 2250 l gs col-1 s gr +% Polyline +n 2430 2025 m 3240 2025 l 3240 2520 l 2430 2520 l cp gs col-1 s gr +% Polyline +n 2970 2250 m 2970 2520 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +2520 2430 m +gs 1 -1 sc (val) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2520 2205 m +gs 1 -1 sc (ResTarget) col-1 sh gr +% Polyline +n 3510 2250 m 4410 2250 l gs col-1 s gr +% Polyline +n 3510 2520 m 4410 2520 l gs col-1 s gr +% Polyline +n 3510 2025 m 4410 2025 l 4410 2790 l 3510 2790 l cp gs col-1 s gr +% Polyline +n 4140 2250 m 4140 2790 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +3825 2205 m +gs 1 -1 sc (Attr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3600 2700 m +gs 1 -1 sc (attrs) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3600 2430 m +gs 1 -1 sc (relname) col-1 sh gr +% Polyline +n 4635 2520 m 5175 2520 l 5175 2790 l 4635 2790 l cp gs col-1 s gr +% Polyline +n 4905 2520 m 4905 2790 l gs col-1 s gr +% Polyline +n 4905 2520 m 5175 2790 l gs col-1 s gr +% Polyline +n 5175 2520 m 4905 2790 l gs col-1 s gr +% Polyline +n 4365 3015 m 5175 3015 l 5175 3510 l 4365 3510 l cp gs col-1 s gr +% Polyline +n 4365 3240 m 5175 3240 l gs col-1 s gr +% Polyline +n 4905 3240 m 4905 3510 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +4590 3195 m +gs 1 -1 sc (Value) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4455 3420 m +gs 1 -1 sc (val.str) col-1 sh gr +% Polyline +n 225 450 m 1485 450 l gs col-1 s gr +% Polyline +n 1215 990 m 1215 2610 l gs col-1 s gr +% Polyline +n 225 720 m 1485 720 l gs col-1 s gr +% Polyline +n 225 990 m 1485 990 l gs col-1 s gr +% Polyline +n 225 1260 m 1485 1260 l gs col-1 s gr +% Polyline +n 225 1530 m 1485 1530 l gs col-1 s gr +% Polyline +n 225 1800 m 1485 1800 l gs col-1 s gr +% Polyline +n 225 2070 m 1485 2070 l gs col-1 s gr +% Polyline +n 225 225 m 1485 225 l 1485 2610 l 225 2610 l cp gs col-1 s gr +% Polyline +n 225 2340 m 1485 2340 l gs col-1 s gr +% Polyline +n 1215 450 m 1215 720 l gs col-1 s gr +% Polyline +gs clippath +3363 555 m 3483 585 l 3363 615 l 3525 615 l 3525 555 l cp clip +n 3105 585 m 3510 585 l gs col-1 s gr gr + +% arrowhead +n 3363 555 m 3483 585 l 3363 615 l 3363 585 l 3363 555 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +4488 555 m 4608 585 l 4488 615 l 4650 615 l 4650 555 l cp clip +n 4275 585 m 4635 585 l gs col-1 s gr gr + +% arrowhead +n 4488 555 m 4608 585 l 4488 615 l 4488 585 l 4488 555 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +4488 825 m 4608 855 l 4488 885 l 4650 885 l 4650 825 l cp clip +n 4275 855 m 4635 855 l gs col-1 s gr gr + +% arrowhead +n 4488 825 m 4608 855 l 4488 885 l 4488 855 l 4488 825 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +4800 1068 m 4770 1188 l 4740 1068 l 4740 1230 l 4800 1230 l cp clip +n 4770 855 m 4770 1215 l gs col-1 s gr gr + +% arrowhead +n 4800 1068 m 4770 1188 l 4740 1068 l 4770 1068 l 4800 1068 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +5070 1788 m 5040 1908 l 5010 1788 l 5010 1950 l 5070 1950 l cp clip +n 5040 1575 m 5040 1935 l gs col-1 s gr gr + +% arrowhead +n 5070 1788 m 5040 1908 l 5010 1788 l 5040 1788 l 5070 1788 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +2283 4020 m 2403 4050 l 2283 4080 l 2445 4080 l 2445 4020 l cp clip +n 2070 4050 m 2430 4050 l gs col-1 s gr gr + +% arrowhead +n 2283 4020 m 2403 4050 l 2283 4080 l 2283 4050 l 2283 4020 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +2100 5118 m 2070 5238 l 2040 5118 l 2040 5280 l 2100 5280 l cp clip +n 2070 4320 m 2070 5265 l gs col-1 s gr gr + +% arrowhead +n 2100 5118 m 2070 5238 l 2040 5118 l 2070 5118 l 2100 5118 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +2283 5370 m 2403 5400 l 2283 5430 l 2445 5430 l 2445 5370 l cp clip +n 2070 5400 m 2430 5400 l gs col-1 s gr gr + +% arrowhead +n 2283 5370 m 2403 5400 l 2283 5430 l 2283 5400 l 2283 5370 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +3453 4290 m 3573 4320 l 3453 4350 l 3615 4350 l 3615 4290 l cp clip +n 3195 4320 m 3600 4320 l gs col-1 s gr gr + +% arrowhead +n 3453 4290 m 3573 4320 l 3453 4350 l 3453 4320 l 3453 4290 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +4395 4668 m 4365 4788 l 4335 4668 l 4335 4830 l 4395 4830 l cp clip +n 4365 4455 m 4365 4815 l gs col-1 s gr gr + +% arrowhead +n 4395 4668 m 4365 4788 l 4335 4668 l 4365 4668 l 4395 4668 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +3363 2355 m 3483 2385 l 3363 2415 l 3525 2415 l 3525 2355 l cp clip +n 3105 2385 m 3510 2385 l gs col-1 s gr gr + +% arrowhead +n 3363 2355 m 3483 2385 l 3363 2415 l 3363 2385 l 3363 2355 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +4488 2355 m 4608 2385 l 4488 2415 l 4650 2415 l 4650 2355 l cp clip +n 4275 2385 m 4635 2385 l gs col-1 s gr gr + +% arrowhead +n 4488 2355 m 4608 2385 l 4488 2415 l 4488 2385 l 4488 2355 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +4488 2625 m 4608 2655 l 4488 2685 l 4650 2685 l 4650 2625 l cp clip +n 4275 2655 m 4635 2655 l gs col-1 s gr gr + +% arrowhead +n 4488 2625 m 4608 2655 l 4488 2685 l 4488 2655 l 4488 2625 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +4800 2868 m 4770 2988 l 4740 2868 l 4740 3030 l 4800 3030 l cp clip +n 4770 2655 m 4770 3015 l gs col-1 s gr gr + +% arrowhead +n 4800 2868 m 4770 2988 l 4740 2868 l 4770 2868 l 4800 2868 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +5070 3588 m 5040 3708 l 5010 3588 l 5010 3750 l 5070 3750 l cp clip +n 5040 3375 m 5040 3735 l gs col-1 s gr gr + +% arrowhead +n 5070 3588 m 5040 3708 l 5010 3588 l 5040 3588 l 5070 3588 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +1788 555 m 1908 585 l 1788 615 l 1950 615 l 1950 555 l cp clip +n 1350.0 1125.0 m 1530.0 1125.0 l + 1530.0 1125.0 1710.0 1125.0 1687.5 855.0 DrawSplineSection + 1687.5 855.0 1665.0 585.0 1800.0 585.0 DrawSplineSection + 1935.0 585.0 l gs col-1 s gr + gr + +% arrowhead +n 1788 555 m 1908 585 l 1788 615 l 1788 585 l 1788 555 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +2100 3768 m 2070 3888 l 2040 3768 l 2040 3930 l 2100 3930 l cp clip +n 1350.0 1395.0 m 1620.0 1395.0 l + 1620.0 1395.0 1890.0 1395.0 1845.0 2272.5 DrawSplineSection + 1845.0 2272.5 1800.0 3150.0 1935.0 3285.0 DrawSplineSection + 1935.0 3285.0 2070.0 3420.0 2070.0 3667.5 DrawSplineSection + 2070.0 3915.0 l gs col-1 s gr + gr + +% arrowhead +n 2100 3768 m 2070 3888 l 2040 3768 l 2070 3768 l 2100 3768 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +1155 3228 m 1125 3348 l 1095 3228 l 1095 3390 l 1155 3390 l cp clip +n 1350.0 1665.0 m 1507.5 1665.0 l + 1507.5 1665.0 1665.0 1665.0 1665.0 2340.0 DrawSplineSection + 1665.0 2340.0 1665.0 3015.0 1395.0 3015.0 DrawSplineSection + 1395.0 3015.0 1125.0 3015.0 1125.0 3195.0 DrawSplineSection + 1125.0 3375.0 l gs col-1 s gr + gr + +% arrowhead +n 1155 3228 m 1125 3348 l 1095 3228 l 1125 3228 l 1155 3228 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3543 3840 m 3663 3870 l 3543 3900 l 3705 3900 l 3705 3840 l cp clip +n 3195.0 4050.0 m 3330.0 4050.0 l + 3330.0 4050.0 3465.0 4050.0 3465.0 3960.0 DrawSplineSection + 3465.0 3960.0 3465.0 3870.0 3577.5 3870.0 DrawSplineSection + 3690.0 3870.0 l gs col-1 s gr + gr + +% arrowhead +n 3543 3840 m 3663 3870 l 3543 3900 l 3543 3870 l 3543 3840 l cp gs 0.00 setgray ef gr col-1 s +/Times-Roman ff 150.00 scf sf +315 900 m +gs 1 -1 sc (unionall: false) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 405 m +gs 1 -1 sc (SelectStmt) col-1 sh gr +/Times-Roman ff 150.00 scf sf +315 630 m +gs 1 -1 sc (unique) col-1 sh gr +/Times-Roman ff 150.00 scf sf +315 1170 m +gs 1 -1 sc (targetList) col-1 sh gr +/Times-Roman ff 150.00 scf sf +315 1440 m +gs 1 -1 sc (fromClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +315 1710 m +gs 1 -1 sc (whereClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +315 1980 m +gs 1 -1 sc (groupClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +315 2250 m +gs 1 -1 sc (havingClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +315 2520 m +gs 1 -1 sc (sortClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4815 2115 m +gs 1 -1 sc ("sname") col-1 sh gr +/Times-Roman ff 150.00 scf sf +4725 630 m +gs 1 -1 sc ("s") col-1 sh gr +/Times-Roman ff 150.00 scf sf +720 3600 m +gs 1 -1 sc (Operator Tree) col-1 sh gr +/Times-Roman ff 150.00 scf sf +765 3795 m +gs 1 -1 sc (representing ) col-1 sh gr +/Times-Roman ff 150.00 scf sf +630 3990 m +gs 1 -1 sc (the qualifications) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3780 3915 m +gs 1 -1 sc ("s") col-1 sh gr +/Times-Roman ff 150.00 scf sf +4095 4995 m +gs 1 -1 sc ("supplier") col-1 sh gr +/Times-Roman ff 150.00 scf sf +4725 2430 m +gs 1 -1 sc ("se") col-1 sh gr +/Times-Roman ff 150.00 scf sf +4905 3915 m +gs 1 -1 sc ("sno") col-1 sh gr +showpage +$F2psEnd +rs +%%EndDocument + @endspecial 561 2411 a(Figure)g(3.2:)j Fp(T)-5 b(ar)n(getList)12 +b Ft(and)h Fp(F)m(r)n(omList)g Ft(for)e(query)h(of)g(e)o(xample)h(3.1) +270 2651 y Fh(3.3.2)59 b(T)l(ransf)o(ormation)13 b(Pr)o(ocess)270 +2745 y Ft(The)18 b Fp(tr)o(ansformation)f(pr)n(ocess)i +Ft(takes)e(the)g Fp(tr)n(ee)h Ft(handed)f(back)g(by)h(the)f +Fp(parser)h Ft(as)f(input)g(and)g(steps)270 2804 y(recursi)o(v)o(ely)g +(through)f(it.)31 b(If)17 b(a)h Fr(SelectStmt)e Ft(node)i(is)g(found,)g +(it)f(is)h(transformed)f(to)g(a)h Fr(Query)270 2864 y +Ft(node)g(which)g(will)g(be)g(the)h(top)f(most)g(node)g(of)g(the)g(ne)o +(w)g(data)h(structure.)32 b(Figure)18 b(3.4)g(sho)o(ws)h(the)270 +2924 y(transformed)12 b(data)h(structure)f(\(the)g(part)h(for)f(the)g +(transformed)g Fp(wher)n(e)i(clause)f Ft(is)g(gi)o(v)o(en)g(in)g +(\002gure)f(3.5)270 2984 y(because)h(there)f(was)h(not)f(enough)g +(space)h(to)f(sho)o(w)g(all)h(parts)f(in)g(one)h(\002gure\).)345 +3044 y(No)o(w)i(a)i(check)f(is)g(made,)i(if)d(the)h Fp(r)n(elation)g +(names)g Ft(in)g(the)g Fp(fr)n(omClause)h Ft(are)e(kno)o(wn)h(to)g(the) +g(sys-)270 3103 y(tem.)21 b(F)o(or)14 b(e)o(v)o(ery)f +Fp(r)n(elation)h(name)h Ft(that)e(is)i(present)f(in)g(the)g +Fp(system)h(catalogs)f Ft(a)g Fr(RTE)g Ft(node)g(is)g(created)270 +3163 y(containing)e(the)g Fp(r)n(elation)g(name)p Ft(,)h(the)f +Fp(alias)g(name)g Ft(and)h(the)f Fp(r)n(elation)g(id)p +Ft(.)k(From)11 b(no)o(w)h(on)g(the)g Fp(r)n(elation)270 +3223 y(ids)h Ft(are)g(used)h(to)f(refer)f(to)h(the)g +Fp(r)n(elations)g Ft(gi)o(v)o(en)g(in)g(the)g(query)m(.)k(All)c +Fr(RTE)g Ft(nodes)g(are)g(collected)g(in)g(the)270 3283 +y Fp(r)o(ange)k(table)f(entry)h(list)g Ft(which)g(is)g(connected)g(to)f +(the)h(\002eld)f Fr(rtable)h Ft(of)f(the)h Fr(Query)f +Ft(node.)29 b(If)16 b(a)270 3342 y(name)d(of)f(a)i Fp(r)n(elation)f +Ft(that)f(is)i(not)e(kno)o(wn)h(to)g(the)g(system)g(is)g(detected)g(in) +g(the)g(query)f(an)i(error)d(will)i(be)270 3402 y(returned)e(and)i(the) +f Fp(query)h(pr)n(ocessing)g Ft(will)f(be)h(aborted.)p +eop +%%Page: 55 55 +55 54 bop 198 60 a Fm(3.3.)29 b(THE)13 b(P)-5 b(ARSER)13 +b(ST)-5 b(A)n(GE)1189 b Ft(55)276 2863 y @beginspecial +141 @llx 165 @lly 470 @urx 627 @ury 3290 @rwi @setspecial +%%BeginDocument: figures/where_clause.ps +%Magnification: 1.05 +/$F2psDict 200 dict def +$F2psDict begin +$F2psDict /mtrx matrix put +/col-1 {0 setgray} bind def +/col0 {0.000 0.000 0.000 srgb} bind def +/col1 {0.000 0.000 1.000 srgb} bind def +/col2 {0.000 1.000 0.000 srgb} bind def +/col3 {0.000 1.000 1.000 srgb} bind def +/col4 {1.000 0.000 0.000 srgb} bind def +/col5 {1.000 0.000 1.000 srgb} bind def +/col6 {1.000 1.000 0.000 srgb} bind def +/col7 {1.000 1.000 1.000 srgb} bind def +/col8 {0.000 0.000 0.560 srgb} bind def +/col9 {0.000 0.000 0.690 srgb} bind def +/col10 {0.000 0.000 0.820 srgb} bind def +/col11 {0.530 0.810 1.000 srgb} bind def +/col12 {0.000 0.560 0.000 srgb} bind def +/col13 {0.000 0.690 0.000 srgb} bind def +/col14 {0.000 0.820 0.000 srgb} bind def +/col15 {0.000 0.560 0.560 srgb} bind def +/col16 {0.000 0.690 0.690 srgb} bind def +/col17 {0.000 0.820 0.820 srgb} bind def +/col18 {0.560 0.000 0.000 srgb} bind def +/col19 {0.690 0.000 0.000 srgb} bind def +/col20 {0.820 0.000 0.000 srgb} bind def +/col21 {0.560 0.000 0.560 srgb} bind def +/col22 {0.690 0.000 0.690 srgb} bind def +/col23 {0.820 0.000 0.820 srgb} bind def +/col24 {0.500 0.190 0.000 srgb} bind def +/col25 {0.630 0.250 0.000 srgb} bind def +/col26 {0.750 0.380 0.000 srgb} bind def +/col27 {1.000 0.500 0.500 srgb} bind def +/col28 {1.000 0.630 0.630 srgb} bind def +/col29 {1.000 0.750 0.750 srgb} bind def +/col30 {1.000 0.880 0.880 srgb} bind def +/col31 {1.000 0.840 0.000 srgb} bind def + +end +save +128.5 640.0 translate +1 -1 scale + +/cp {closepath} bind def +/ef {eofill} bind def +/gr {grestore} bind def +/gs {gsave} bind def +/sa {save} bind def +/rs {restore} bind def +/l {lineto} bind def +/m {moveto} bind def +/rm {rmoveto} bind def +/n {newpath} bind def +/s {stroke} bind def +/sh {show} bind def +/slc {setlinecap} bind def +/slj {setlinejoin} bind def +/slw {setlinewidth} bind def +/srgb {setrgbcolor} bind def +/rot {rotate} bind def +/sc {scale} bind def +/sd {setdash} bind def +/ff {findfont} bind def +/sf {setfont} bind def +/scf {scalefont} bind def +/sw {stringwidth} bind def +/tr {translate} bind def +/tnt {dup dup currentrgbcolor + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add srgb} + bind def +/shd {dup dup currentrgbcolor 4 -2 roll mul 4 -2 roll mul + 4 -2 roll mul srgb} bind def + /DrawSplineSection { + /y3 exch def + /x3 exch def + /y2 exch def + /x2 exch def + /y1 exch def + /x1 exch def + /xa x1 x2 x1 sub 0.666667 mul add def + /ya y1 y2 y1 sub 0.666667 mul add def + /xb x3 x2 x3 sub 0.666667 mul add def + /yb y3 y2 y3 sub 0.666667 mul add def + x1 y1 lineto + xa ya xb yb x3 y3 curveto + } def + +/$F2psBegin {$F2psDict begin /$F2psEnteredState save def} def +/$F2psEnd {$F2psEnteredState restore end} def + +$F2psBegin +10 setmiterlimit +n 0 792 m 0 0 l 612 0 l 612 792 l cp clip + 0.06299 0.06299 sc +7.500 slw +% Polyline +n 1215 450 m 1485 720 l gs col-1 s gr +% Polyline +n 1485 450 m 1215 720 l gs col-1 s gr +% Polyline +n 1215 1800 m 1485 2070 l gs col-1 s gr +% Polyline +n 1485 1800 m 1215 2070 l gs col-1 s gr +% Polyline +n 1215 2070 m 1485 2340 l gs col-1 s gr +% Polyline +n 1485 2070 m 1215 2340 l gs col-1 s gr +% Polyline +n 1215 2340 m 1485 2610 l gs col-1 s gr +% Polyline +n 1485 2340 m 1215 2610 l gs col-1 s gr +% Polyline +n 2790 1260 m 1800 1260 l gs col-1 s gr +% Polyline +n 1800 1530 m 2790 1530 l gs col-1 s gr +% Polyline +n 1800 1800 m 2790 1800 l gs col-1 s gr +% Polyline +n 1800 2070 m 2790 2070 l gs col-1 s gr +% Polyline +n 1800 1035 m 2790 1035 l 2790 2340 l 1800 2340 l cp gs col-1 s gr +% Polyline +n 2520 1800 m 2520 2340 l gs col-1 s gr +% Polyline +n 2520 1260 m 2520 1530 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +2070 1215 m +gs 1 -1 sc (A_Expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1890 1710 m +gs 1 -1 sc (oper) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1890 1440 m +gs 1 -1 sc (opname) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1890 1980 m +gs 1 -1 sc (rexpr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1890 2250 m +gs 1 -1 sc (lexpr) col-1 sh gr +% Polyline +n 2520 1260 m 2790 1530 l gs col-1 s gr +% Polyline +n 2790 1260 m 2520 1530 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +2385 1710 m +gs 1 -1 sc (AND) col-1 sh gr +% Polyline +n 1350 6120 m 1890 6120 l 1890 6390 l 1350 6390 l cp gs col-1 s gr +% Polyline +n 1620 6120 m 1620 6390 l gs col-1 s gr +% Polyline +n 1620 6120 m 1890 6390 l gs col-1 s gr +% Polyline +n 1890 6120 m 1620 6390 l gs col-1 s gr +% Polyline +n 1080 6615 m 1890 6615 l 1890 7110 l 1080 7110 l cp gs col-1 s gr +% Polyline +n 1080 6840 m 1890 6840 l gs col-1 s gr +% Polyline +n 1620 6840 m 1620 7110 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +1305 6795 m +gs 1 -1 sc (Value) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1170 7020 m +gs 1 -1 sc (val.str) col-1 sh gr +% Polyline +n 225 5850 m 1125 5850 l gs col-1 s gr +% Polyline +n 225 6120 m 1125 6120 l gs col-1 s gr +% Polyline +n 225 5625 m 1125 5625 l 1125 6390 l 225 6390 l cp gs col-1 s gr +% Polyline +n 855 5850 m 855 6390 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +540 5805 m +gs 1 -1 sc (Attr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +315 6300 m +gs 1 -1 sc (attrs) col-1 sh gr +/Times-Roman ff 150.00 scf sf +315 6030 m +gs 1 -1 sc (relname) col-1 sh gr +% Polyline +gs clippath +1785 7188 m 1755 7308 l 1725 7188 l 1725 7350 l 1785 7350 l cp clip +n 1755 6975 m 1755 7335 l gs col-1 s gr gr + +% arrowhead +n 1785 7188 m 1755 7308 l 1725 7188 l 1755 7188 l 1785 7188 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +1203 5955 m 1323 5985 l 1203 6015 l 1365 6015 l 1365 5955 l cp clip +n 990 5985 m 1350 5985 l gs col-1 s gr gr + +% arrowhead +n 1203 5955 m 1323 5985 l 1203 6015 l 1203 5985 l 1203 5955 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +1203 6225 m 1323 6255 l 1203 6285 l 1365 6285 l 1365 6225 l cp clip +n 990 6255 m 1350 6255 l gs col-1 s gr gr + +% arrowhead +n 1203 6225 m 1323 6255 l 1203 6285 l 1203 6255 l 1203 6225 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +1515 6468 m 1485 6588 l 1455 6468 l 1455 6630 l 1515 6630 l cp clip +n 1485 6255 m 1485 6615 l gs col-1 s gr gr + +% arrowhead +n 1515 6468 m 1485 6588 l 1455 6468 l 1485 6468 l 1515 6468 l cp gs 0.00 setgray ef gr col-1 s +/Times-Roman ff 150.00 scf sf +1620 7515 m +gs 1 -1 sc ("sno") col-1 sh gr +/Times-Roman ff 150.00 scf sf +1440 6030 m +gs 1 -1 sc ("s") col-1 sh gr +% Polyline +n 1350 5130 m 2340 5130 l gs col-1 s gr +% Polyline +n 1350 4905 m 2340 4905 l 2340 5400 l 1350 5400 l cp gs col-1 s gr +/Times-Roman ff 150.00 scf sf +1440 5310 m +gs 1 -1 sc (val.val.ival: 2) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1575 5085 m +gs 1 -1 sc (A_Const) col-1 sh gr +% Polyline +n 2475 5850 m 3375 5850 l gs col-1 s gr +% Polyline +n 2475 6120 m 3375 6120 l gs col-1 s gr +% Polyline +n 2475 5625 m 3375 5625 l 3375 6390 l 2475 6390 l cp gs col-1 s gr +% Polyline +n 3105 5850 m 3105 6390 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +2790 5805 m +gs 1 -1 sc (Attr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2565 6300 m +gs 1 -1 sc (attrs) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2565 6030 m +gs 1 -1 sc (relname) col-1 sh gr +% Polyline +n 3600 6120 m 4140 6120 l 4140 6390 l 3600 6390 l cp gs col-1 s gr +% Polyline +n 3870 6120 m 3870 6390 l gs col-1 s gr +% Polyline +n 3870 6120 m 4140 6390 l gs col-1 s gr +% Polyline +n 4140 6120 m 3870 6390 l gs col-1 s gr +% Polyline +n 3330 6615 m 4140 6615 l 4140 7110 l 3330 7110 l cp gs col-1 s gr +% Polyline +n 3330 6840 m 4140 6840 l gs col-1 s gr +% Polyline +n 3870 6840 m 3870 7110 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +3555 6795 m +gs 1 -1 sc (Value) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3420 7020 m +gs 1 -1 sc (val.str) col-1 sh gr +% Polyline +gs clippath +3453 5955 m 3573 5985 l 3453 6015 l 3615 6015 l 3615 5955 l cp clip +n 3240 5985 m 3600 5985 l gs col-1 s gr gr + +% arrowhead +n 3453 5955 m 3573 5985 l 3453 6015 l 3453 5985 l 3453 5955 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +3453 6225 m 3573 6255 l 3453 6285 l 3615 6285 l 3615 6225 l cp clip +n 3240 6255 m 3600 6255 l gs col-1 s gr gr + +% arrowhead +n 3453 6225 m 3573 6255 l 3453 6285 l 3453 6255 l 3453 6225 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +3765 6468 m 3735 6588 l 3705 6468 l 3705 6630 l 3765 6630 l cp clip +n 3735 6255 m 3735 6615 l gs col-1 s gr gr + +% arrowhead +n 3765 6468 m 3735 6588 l 3705 6468 l 3735 6468 l 3765 6468 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +4035 7188 m 4005 7308 l 3975 7188 l 3975 7350 l 4035 7350 l cp clip +n 4005 6975 m 4005 7335 l gs col-1 s gr gr + +% arrowhead +n 4035 7188 m 4005 7308 l 3975 7188 l 4005 7188 l 4035 7188 l cp gs 0.00 setgray ef gr col-1 s +/Times-Roman ff 150.00 scf sf +3690 6030 m +gs 1 -1 sc ("s") col-1 sh gr +/Times-Roman ff 150.00 scf sf +3870 7515 m +gs 1 -1 sc ("sno") col-1 sh gr +% Polyline +n 3690 5130 m 4590 5130 l gs col-1 s gr +% Polyline +n 3690 5400 m 4590 5400 l gs col-1 s gr +% Polyline +n 3690 4905 m 4590 4905 l 4590 5670 l 3690 5670 l cp gs col-1 s gr +% Polyline +n 4320 5130 m 4320 5670 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +4005 5085 m +gs 1 -1 sc (Attr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3780 5580 m +gs 1 -1 sc (attrs) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3780 5310 m +gs 1 -1 sc (relname) col-1 sh gr +% Polyline +n 4815 5400 m 5355 5400 l 5355 5670 l 4815 5670 l cp gs col-1 s gr +% Polyline +n 5085 5400 m 5085 5670 l gs col-1 s gr +% Polyline +n 5085 5400 m 5355 5670 l gs col-1 s gr +% Polyline +n 5355 5400 m 5085 5670 l gs col-1 s gr +% Polyline +n 4545 5895 m 5355 5895 l 5355 6390 l 4545 6390 l cp gs col-1 s gr +% Polyline +n 4545 6120 m 5355 6120 l gs col-1 s gr +% Polyline +n 5085 6120 m 5085 6390 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +4770 6075 m +gs 1 -1 sc (Value) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4635 6300 m +gs 1 -1 sc (val.str) col-1 sh gr +% Polyline +gs clippath +4668 5235 m 4788 5265 l 4668 5295 l 4830 5295 l 4830 5235 l cp clip +n 4455 5265 m 4815 5265 l gs col-1 s gr gr + +% arrowhead +n 4668 5235 m 4788 5265 l 4668 5295 l 4668 5265 l 4668 5235 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +4668 5505 m 4788 5535 l 4668 5565 l 4830 5565 l 4830 5505 l cp clip +n 4455 5535 m 4815 5535 l gs col-1 s gr gr + +% arrowhead +n 4668 5505 m 4788 5535 l 4668 5565 l 4668 5535 l 4668 5505 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +4980 5748 m 4950 5868 l 4920 5748 l 4920 5910 l 4980 5910 l cp clip +n 4950 5535 m 4950 5895 l gs col-1 s gr gr + +% arrowhead +n 4980 5748 m 4950 5868 l 4920 5748 l 4950 5748 l 4980 5748 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +5250 6468 m 5220 6588 l 5190 6468 l 5190 6630 l 5250 6630 l cp clip +n 5220 6255 m 5220 6615 l gs col-1 s gr gr + +% arrowhead +n 5250 6468 m 5220 6588 l 5190 6468 l 5220 6468 l 5250 6468 l cp gs 0.00 setgray ef gr col-1 s +/Times-Roman ff 150.00 scf sf +4905 5310 m +gs 1 -1 sc ("se") col-1 sh gr +/Times-Roman ff 150.00 scf sf +5085 6795 m +gs 1 -1 sc ("sno") col-1 sh gr +% Polyline +n 3465 3375 m 2475 3375 l gs col-1 s gr +% Polyline +n 2475 3645 m 3465 3645 l gs col-1 s gr +% Polyline +n 2475 3915 m 3465 3915 l gs col-1 s gr +% Polyline +n 2475 4185 m 3465 4185 l gs col-1 s gr +% Polyline +n 2475 3150 m 3465 3150 l 3465 4455 l 2475 4455 l cp gs col-1 s gr +% Polyline +n 3195 3915 m 3195 4455 l gs col-1 s gr +% Polyline +n 3195 3375 m 3195 3645 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +2745 3330 m +gs 1 -1 sc (A_Expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2565 3825 m +gs 1 -1 sc (oper) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2565 3555 m +gs 1 -1 sc (opname) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2565 4095 m +gs 1 -1 sc (rexpr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2565 4365 m +gs 1 -1 sc (lexpr) col-1 sh gr +% Polyline +n 225 450 m 1485 450 l gs col-1 s gr +% Polyline +n 1215 990 m 1215 2610 l gs col-1 s gr +% Polyline +n 225 720 m 1485 720 l gs col-1 s gr +% Polyline +n 225 990 m 1485 990 l gs col-1 s gr +% Polyline +n 225 1260 m 1485 1260 l gs col-1 s gr +% Polyline +n 225 1530 m 1485 1530 l gs col-1 s gr +% Polyline +n 225 1800 m 1485 1800 l gs col-1 s gr +% Polyline +n 225 2070 m 1485 2070 l gs col-1 s gr +% Polyline +n 225 225 m 1485 225 l 1485 2610 l 225 2610 l cp gs col-1 s gr +% Polyline +n 225 2340 m 1485 2340 l gs col-1 s gr +% Polyline +n 1215 450 m 1215 720 l gs col-1 s gr +% Polyline +gs clippath +1653 1635 m 1773 1665 l 1653 1695 l 1815 1695 l 1815 1635 l cp clip +n 1350 1665 m 1800 1665 l gs col-1 s gr gr + +% arrowhead +n 1653 1635 m 1773 1665 l 1653 1695 l 1653 1665 l 1653 1635 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +1293 3480 m 1413 3510 l 1293 3540 l 1455 3540 l 1455 3480 l cp clip +n 1080 3510 m 1440 3510 l gs col-1 s gr gr + +% arrowhead +n 1293 3480 m 1413 3510 l 1293 3540 l 1293 3510 l 1293 3480 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 1215 3375 m 225 3375 l gs col-1 s gr +% Polyline +n 225 3645 m 1215 3645 l gs col-1 s gr +% Polyline +n 225 3915 m 1215 3915 l gs col-1 s gr +% Polyline +n 225 4185 m 1215 4185 l gs col-1 s gr +% Polyline +n 225 3150 m 1215 3150 l 1215 4455 l 225 4455 l cp gs col-1 s gr +% Polyline +n 945 3915 m 945 4455 l gs col-1 s gr +% Polyline +n 945 3375 m 945 3645 l gs col-1 s gr +% Polyline +gs clippath +3543 3480 m 3663 3510 l 3543 3540 l 3705 3540 l 3705 3480 l cp clip +n 3330 3510 m 3690 3510 l gs col-1 s gr gr + +% arrowhead +n 3543 3480 m 3663 3510 l 3543 3540 l 3543 3510 l 3543 3480 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +705 5478 m 675 5598 l 645 5478 l 645 5640 l 705 5640 l cp clip +n 1080.0 4320.0 m 1237.5 4320.0 l + 1237.5 4320.0 1395.0 4320.0 1395.0 4522.5 DrawSplineSection + 1395.0 4522.5 1395.0 4725.0 1035.0 4725.0 DrawSplineSection + 1035.0 4725.0 675.0 4725.0 675.0 5175.0 DrawSplineSection + 675.0 5625.0 l gs col-1 s gr + gr + +% arrowhead +n 705 5478 m 675 5598 l 645 5478 l 675 5478 l 705 5478 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +1875 4758 m 1845 4878 l 1815 4758 l 1815 4920 l 1875 4920 l cp clip +n 1080.0 4050.0 m 1282.5 4050.0 l + 1282.5 4050.0 1485.0 4050.0 1665.0 4095.0 DrawSplineSection + 1665.0 4095.0 1845.0 4140.0 1845.0 4522.5 DrawSplineSection + 1845.0 4905.0 l gs col-1 s gr + gr + +% arrowhead +n 1875 4758 m 1845 4878 l 1815 4758 l 1845 4758 l 1875 4758 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +823 3041 m 734 3127 l 772 3009 l 687 3147 l 737 3179 l cp clip +n 2655.0 2205.0 m 2835.0 2205.0 l + 2835.0 2205.0 3015.0 2205.0 3015.0 2452.5 DrawSplineSection + 3015.0 2452.5 3015.0 2700.0 1980.0 2745.0 DrawSplineSection + 1980.0 2745.0 945.0 2790.0 832.5 2970.0 DrawSplineSection + 720.0 3150.0 l gs col-1 s gr + gr + +% arrowhead +n 823 3041 m 734 3127 l 772 3009 l 798 3025 l 823 3041 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +2955 5478 m 2925 5598 l 2895 5478 l 2895 5640 l 2955 5640 l cp clip +n 3330.0 4320.0 m 3487.5 4320.0 l + 3487.5 4320.0 3645.0 4320.0 3645.0 4522.5 DrawSplineSection + 3645.0 4522.5 3645.0 4725.0 3285.0 4725.0 DrawSplineSection + 3285.0 4725.0 2925.0 4725.0 2925.0 5175.0 DrawSplineSection + 2925.0 5625.0 l gs col-1 s gr + gr + +% arrowhead +n 2955 5478 m 2925 5598 l 2895 5478 l 2925 5478 l 2955 5478 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +4170 4758 m 4140 4878 l 4110 4758 l 4110 4920 l 4170 4920 l cp clip +n 3330.0 4050.0 m 3577.5 4050.0 l + 3577.5 4050.0 3825.0 4050.0 3982.5 4162.5 DrawSplineSection + 3982.5 4162.5 4140.0 4275.0 4140.0 4590.0 DrawSplineSection + 4140.0 4905.0 l gs col-1 s gr + gr + +% arrowhead +n 4170 4758 m 4140 4878 l 4110 4758 l 4140 4758 l 4170 4758 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3000 3003 m 2970 3123 l 2940 3003 l 2940 3165 l 3000 3165 l cp clip +n 2655.0 1935.0 m 3015.0 1935.0 l + 3015.0 1935.0 3375.0 1935.0 3375.0 2272.5 DrawSplineSection + 3375.0 2272.5 3375.0 2610.0 3172.5 2700.0 DrawSplineSection + 3172.5 2700.0 2970.0 2790.0 2970.0 2970.0 DrawSplineSection + 2970.0 3150.0 l gs col-1 s gr + gr + +% arrowhead +n 3000 3003 m 2970 3123 l 2940 3003 l 2970 3003 l 3000 3003 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +1833 375 m 1953 405 l 1833 435 l 1995 435 l 1995 375 l cp clip +n 1350.0 1125.0 m 1485.0 1125.0 l + 1485.0 1125.0 1620.0 1125.0 1597.5 765.0 DrawSplineSection + 1597.5 765.0 1575.0 405.0 1777.5 405.0 DrawSplineSection + 1980.0 405.0 l gs col-1 s gr + gr + +% arrowhead +n 1833 375 m 1953 405 l 1833 435 l 1833 405 l 1833 375 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +1833 735 m 1953 765 l 1833 795 l 1995 795 l 1995 735 l cp clip +n 1350.0 1395.0 m 1530.0 1395.0 l + 1530.0 1395.0 1710.0 1395.0 1687.5 1080.0 DrawSplineSection + 1687.5 1080.0 1665.0 765.0 1822.5 765.0 DrawSplineSection + 1980.0 765.0 l gs col-1 s gr + gr + +% arrowhead +n 1833 735 m 1953 765 l 1833 795 l 1833 765 l 1833 735 l cp gs 0.00 setgray ef gr col-1 s +/Times-Roman ff 150.00 scf sf +315 900 m +gs 1 -1 sc (unionall: false) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 405 m +gs 1 -1 sc (SelectStmt) col-1 sh gr +/Times-Roman ff 150.00 scf sf +315 630 m +gs 1 -1 sc (unique) col-1 sh gr +/Times-Roman ff 150.00 scf sf +315 1170 m +gs 1 -1 sc (targetList) col-1 sh gr +/Times-Roman ff 150.00 scf sf +315 1440 m +gs 1 -1 sc (fromClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +315 1710 m +gs 1 -1 sc (whereClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +315 1980 m +gs 1 -1 sc (groupClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +315 2250 m +gs 1 -1 sc (havingClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +315 2520 m +gs 1 -1 sc (sortClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2025 450 m +gs 1 -1 sc (TargetList) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2025 810 m +gs 1 -1 sc (FromList) col-1 sh gr +/Times-Roman ff 150.00 scf sf +900 3825 m +gs 1 -1 sc (OP) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1485 3555 m +gs 1 -1 sc (">") col-1 sh gr +/Times-Roman ff 150.00 scf sf +495 3330 m +gs 1 -1 sc (A_Expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +315 3825 m +gs 1 -1 sc (oper) col-1 sh gr +/Times-Roman ff 150.00 scf sf +315 3555 m +gs 1 -1 sc (opname) col-1 sh gr +/Times-Roman ff 150.00 scf sf +315 4095 m +gs 1 -1 sc (rexpr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +315 4365 m +gs 1 -1 sc (lexpr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3105 3825 m +gs 1 -1 sc (OP) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3735 3555 m +gs 1 -1 sc ("=") col-1 sh gr +showpage +$F2psEnd +rs +%%EndDocument + @endspecial 595 2973 a(Figure)11 b(3.3:)16 b Fp(Wher)n(eClause)e +Ft(for)e(query)f(of)h(e)o(xample)h(3.1)p eop +%%Page: 56 56 +56 55 bop 270 60 a Ft(56)82 b Fm(CHAPTER)14 b(3.)28 b(POSTGRESQL)13 +b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW)270 +234 y Ft(Ne)o(xt)k(it)h(is)f(checked)g(if)g(the)g Fp(attrib)o(ute)g +(names)h Ft(used)g(are)f(contained)g(in)g(the)g Fp(r)n(elations)h +Ft(gi)o(v)o(en)f(in)g(the)270 294 y(query)m(.)39 b(F)o(or)19 +b(e)o(v)o(ery)h Fp(attrib)o(ute)g Ft(that)g(is)h(found)e(a)i +Fr(TLE)f Ft(node)g(is)g(created)g(holding)g(a)g(pointer)g(to)g(a)270 +354 y Fr(Resdom)13 b Ft(node)h(\(which)f(holds)h(the)g(name)g(of)f(the) +h(column\))f(and)h(a)g(pointer)f(to)h(a)g Fr(VAR)g Ft(node.)20 +b(There)270 413 y(are)c(two)g(important)f(numbers)h(in)h(the)f +Fr(VAR)g Ft(node.)28 b(The)17 b(\002eld)f Fr(varno)g +Ft(gi)o(v)o(es)h(the)f(position)g(of)g(the)270 473 y +Fp(r)n(elation)h Ft(containing)f(the)h(current)f Fp(attrib)o(ute)h +Ft(in)f(the)h Fp(r)o(ange)g(table)g(entry)g(list)g Ft(created)g(abo)o +(v)o(e.)30 b(The)270 533 y(\002eld)14 b Fr(varattno)g +Ft(gi)o(v)o(es)h(the)f(position)h(of)f(the)g Fp(attrib)o(ute)h +Ft(within)f(the)g Fp(r)n(elation)p Ft(.)23 b(If)14 b(the)g(name)h(of)f +(an)270 593 y Fp(attrib)o(ute)c Ft(cannot)g(be)g(found)f(an)i(error)e +(will)g(be)i(returned)e(and)h(the)g Fp(query)g(pr)n(ocessing)h +Ft(will)f(be)g(aborted.)310 2392 y @beginspecial 134 +@llx 230 @lly 478 @urx 561 @ury 3440 @rwi @setspecial +%%BeginDocument: figures/transform.ps +%Magnification: 1.05 +/$F2psDict 200 dict def +$F2psDict begin +$F2psDict /mtrx matrix put +/col-1 {0 setgray} bind def +/col0 {0.000 0.000 0.000 srgb} bind def +/col1 {0.000 0.000 1.000 srgb} bind def +/col2 {0.000 1.000 0.000 srgb} bind def +/col3 {0.000 1.000 1.000 srgb} bind def +/col4 {1.000 0.000 0.000 srgb} bind def +/col5 {1.000 0.000 1.000 srgb} bind def +/col6 {1.000 1.000 0.000 srgb} bind def +/col7 {1.000 1.000 1.000 srgb} bind def +/col8 {0.000 0.000 0.560 srgb} bind def +/col9 {0.000 0.000 0.690 srgb} bind def +/col10 {0.000 0.000 0.820 srgb} bind def +/col11 {0.530 0.810 1.000 srgb} bind def +/col12 {0.000 0.560 0.000 srgb} bind def +/col13 {0.000 0.690 0.000 srgb} bind def +/col14 {0.000 0.820 0.000 srgb} bind def +/col15 {0.000 0.560 0.560 srgb} bind def +/col16 {0.000 0.690 0.690 srgb} bind def +/col17 {0.000 0.820 0.820 srgb} bind def +/col18 {0.560 0.000 0.000 srgb} bind def +/col19 {0.690 0.000 0.000 srgb} bind def +/col20 {0.820 0.000 0.000 srgb} bind def +/col21 {0.560 0.000 0.560 srgb} bind def +/col22 {0.690 0.000 0.690 srgb} bind def +/col23 {0.820 0.000 0.820 srgb} bind def +/col24 {0.500 0.190 0.000 srgb} bind def +/col25 {0.630 0.250 0.000 srgb} bind def +/col26 {0.750 0.380 0.000 srgb} bind def +/col27 {1.000 0.500 0.500 srgb} bind def +/col28 {1.000 0.630 0.630 srgb} bind def +/col29 {1.000 0.750 0.750 srgb} bind def +/col30 {1.000 0.880 0.880 srgb} bind def +/col31 {1.000 0.840 0.000 srgb} bind def + +end +save +107.0 574.5 translate +1 -1 scale + +/cp {closepath} bind def +/ef {eofill} bind def +/gr {grestore} bind def +/gs {gsave} bind def +/sa {save} bind def +/rs {restore} bind def +/l {lineto} bind def +/m {moveto} bind def +/rm {rmoveto} bind def +/n {newpath} bind def +/s {stroke} bind def +/sh {show} bind def +/slc {setlinecap} bind def +/slj {setlinejoin} bind def +/slw {setlinewidth} bind def +/srgb {setrgbcolor} bind def +/rot {rotate} bind def +/sc {scale} bind def +/sd {setdash} bind def +/ff {findfont} bind def +/sf {setfont} bind def +/scf {scalefont} bind def +/sw {stringwidth} bind def +/tr {translate} bind def +/tnt {dup dup currentrgbcolor + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add srgb} + bind def +/shd {dup dup currentrgbcolor 4 -2 roll mul 4 -2 roll mul + 4 -2 roll mul srgb} bind def + /DrawSplineSection { + /y3 exch def + /x3 exch def + /y2 exch def + /x2 exch def + /y1 exch def + /x1 exch def + /xa x1 x2 x1 sub 0.666667 mul add def + /ya y1 y2 y1 sub 0.666667 mul add def + /xb x3 x2 x3 sub 0.666667 mul add def + /yb y3 y2 y3 sub 0.666667 mul add def + x1 y1 lineto + xa ya xb yb x3 y3 curveto + } def + +/$F2psBegin {$F2psDict begin /$F2psEnteredState save def} def +/$F2psEnd {$F2psEnteredState restore end} def + +$F2psBegin +10 setmiterlimit +n 0 792 m 0 0 l 612 0 l 612 792 l cp clip + 0.06299 0.06299 sc +7.500 slw +% Polyline +n 1530 5040 m 1800 5310 l gs col-1 s gr +% Polyline +n 1800 5040 m 1530 5310 l gs col-1 s gr +% Polyline +n 1530 4770 m 1800 5040 l gs col-1 s gr +% Polyline +n 1800 4770 m 1530 5040 l gs col-1 s gr +% Polyline +n 1530 3960 m 1800 4230 l gs col-1 s gr +% Polyline +n 1800 3960 m 1530 4230 l gs col-1 s gr +% Polyline +n 1530 3690 m 1800 3960 l gs col-1 s gr +% Polyline +n 1800 3690 m 1530 3960 l gs col-1 s gr +% Polyline +n 1530 2340 m 1800 2610 l gs col-1 s gr +% Polyline +n 1800 2340 m 1530 2610 l gs col-1 s gr +% Polyline +n 1530 1260 m 1800 1530 l gs col-1 s gr +% Polyline +n 1800 1260 m 1530 1530 l gs col-1 s gr +% Polyline +n 1530 720 m 1800 990 l gs col-1 s gr +% Polyline +n 1800 720 m 1530 990 l gs col-1 s gr +% Polyline +n 2250 945 m 3150 945 l gs col-1 s gr +% Polyline +n 2250 1215 m 3150 1215 l gs col-1 s gr +% Polyline +n 2250 1485 m 3150 1485 l gs col-1 s gr +% Polyline +n 2250 720 m 3150 720 l 3150 1755 l 2250 1755 l cp gs col-1 s gr +% Polyline +n 2880 945 m 2880 1485 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +2340 1395 m +gs 1 -1 sc (refname) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2565 900 m +gs 1 -1 sc (RTE) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2340 1125 m +gs 1 -1 sc (relname) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2340 1665 m +gs 1 -1 sc (relid: 18208) col-1 sh gr +% Polyline +n 2835 225 m 2835 495 l gs col-1 s gr +% Polyline +n 2565 225 m 3105 225 l 3105 495 l 2565 495 l cp gs col-1 s gr +% Polyline +n 4860 225 m 4860 495 l gs col-1 s gr +% Polyline +n 4590 225 m 5130 225 l 5130 495 l 4590 495 l cp gs col-1 s gr +% Polyline +n 4860 225 m 5130 495 l gs col-1 s gr +% Polyline +n 5130 225 m 4860 495 l gs col-1 s gr +% Polyline +gs clippath +2730 573 m 2700 693 l 2670 573 l 2670 735 l 2730 735 l cp clip +n 2700 360 m 2700 720 l gs col-1 s gr gr + +% arrowhead +n 2730 573 m 2700 693 l 2670 573 l 2700 573 l 2730 573 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +4443 330 m 4563 360 l 4443 390 l 4605 390 l 4605 330 l cp clip +n 2970 360 m 4590 360 l gs col-1 s gr gr + +% arrowhead +n 4443 330 m 4563 360 l 4443 390 l 4443 360 l 4443 330 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +4755 573 m 4725 693 l 4695 573 l 4695 735 l 4755 735 l cp clip +n 4725 360 m 4725 720 l gs col-1 s gr gr + +% arrowhead +n 4755 573 m 4725 693 l 4695 573 l 4725 573 l 4755 573 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 2250 2745 m 3150 2745 l gs col-1 s gr +% Polyline +n 2250 3015 m 3150 3015 l gs col-1 s gr +% Polyline +n 2250 2520 m 3150 2520 l 3150 3285 l 2250 3285 l cp gs col-1 s gr +% Polyline +n 2880 2745 m 2880 3285 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +2565 2700 m +gs 1 -1 sc (TLE) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2340 2925 m +gs 1 -1 sc (resdom) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2340 3195 m +gs 1 -1 sc (expr) col-1 sh gr +% Polyline +n 4275 2745 m 5175 2745 l gs col-1 s gr +% Polyline +n 4275 3015 m 5175 3015 l gs col-1 s gr +% Polyline +n 4275 2520 m 5175 2520 l 5175 3285 l 4275 3285 l cp gs col-1 s gr +% Polyline +n 4905 2745 m 4905 3285 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +4590 2700 m +gs 1 -1 sc (TLE) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4365 2925 m +gs 1 -1 sc (resdom) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4365 3195 m +gs 1 -1 sc (expr) col-1 sh gr +% Polyline +n 2835 2025 m 2835 2295 l gs col-1 s gr +% Polyline +n 2565 2025 m 3105 2025 l 3105 2295 l 2565 2295 l cp gs col-1 s gr +% Polyline +n 4860 2025 m 4860 2295 l gs col-1 s gr +% Polyline +n 4590 2025 m 5130 2025 l 5130 2295 l 4590 2295 l cp gs col-1 s gr +% Polyline +n 4860 2025 m 5130 2295 l gs col-1 s gr +% Polyline +n 5130 2025 m 4860 2295 l gs col-1 s gr +% Polyline +n 450 450 m 1800 450 l gs col-1 s gr +% Polyline +n 450 720 m 1800 720 l gs col-1 s gr +% Polyline +n 450 990 m 1800 990 l gs col-1 s gr +% Polyline +n 450 1260 m 1800 1260 l gs col-1 s gr +% Polyline +n 450 1530 m 1800 1530 l gs col-1 s gr +% Polyline +n 450 1800 m 1800 1800 l gs col-1 s gr +% Polyline +n 450 2070 m 1800 2070 l gs col-1 s gr +% Polyline +n 450 2340 m 1800 2340 l gs col-1 s gr +% Polyline +n 450 2610 m 1800 2610 l gs col-1 s gr +% Polyline +n 450 2880 m 1800 2880 l gs col-1 s gr +% Polyline +n 450 3150 m 1800 3150 l gs col-1 s gr +% Polyline +n 450 3690 m 1800 3690 l gs col-1 s gr +% Polyline +n 450 3960 m 1800 3960 l gs col-1 s gr +% Polyline +n 450 4230 m 1800 4230 l gs col-1 s gr +% Polyline +n 450 3420 m 1800 3420 l gs col-1 s gr +% Polyline +n 450 4500 m 1800 4500 l gs col-1 s gr +% Polyline +n 450 4770 m 1800 4770 l gs col-1 s gr +% Polyline +n 450 5040 m 1800 5040 l gs col-1 s gr +% Polyline +n 450 225 m 1800 225 l 1800 5310 l 450 5310 l cp gs col-1 s gr +% Polyline +n 1530 4770 m 1530 5310 l gs col-1 s gr +% Polyline +n 1530 4230 m 1530 2880 l gs col-1 s gr +% Polyline +n 1530 2340 m 1530 2610 l gs col-1 s gr +% Polyline +n 1530 720 m 1530 990 l gs col-1 s gr +% Polyline +n 1530 1260 m 1530 1530 l gs col-1 s gr +% Polyline +n 1530 2610 m 1530 2880 l gs col-1 s gr +% Polyline +n 1530 2610 m 1800 2880 l gs col-1 s gr +% Polyline +n 1800 2610 m 1530 2880 l gs col-1 s gr +% Polyline +gs clippath +3228 1050 m 3348 1080 l 3228 1110 l 3390 1110 l 3390 1050 l cp clip +n 3015 1080 m 3375 1080 l gs col-1 s gr gr + +% arrowhead +n 3228 1050 m 3348 1080 l 3228 1110 l 3228 1080 l 3228 1050 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +3228 1320 m 3348 1350 l 3228 1380 l 3390 1380 l 3390 1320 l cp clip +n 3015 1350 m 3375 1350 l gs col-1 s gr gr + +% arrowhead +n 3228 1320 m 3348 1350 l 3228 1380 l 3228 1350 l 3228 1320 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +5253 1050 m 5373 1080 l 5253 1110 l 5415 1110 l 5415 1050 l cp clip +n 5040 1080 m 5400 1080 l gs col-1 s gr gr + +% arrowhead +n 5253 1050 m 5373 1080 l 5253 1110 l 5253 1080 l 5253 1050 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +5253 1320 m 5373 1350 l 5253 1380 l 5415 1380 l 5415 1320 l cp clip +n 5040 1350 m 5400 1350 l gs col-1 s gr gr + +% arrowhead +n 5253 1320 m 5373 1350 l 5253 1380 l 5253 1350 l 5253 1320 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 4275 945 m 5175 945 l gs col-1 s gr +% Polyline +n 4275 1215 m 5175 1215 l gs col-1 s gr +% Polyline +n 4275 1485 m 5175 1485 l gs col-1 s gr +% Polyline +n 4275 720 m 5175 720 l 5175 1755 l 4275 1755 l cp gs col-1 s gr +% Polyline +n 4905 945 m 4905 1485 l gs col-1 s gr +% Polyline +gs clippath +2730 2373 m 2700 2493 l 2670 2373 l 2670 2535 l 2730 2535 l cp clip +n 2700 2160 m 2700 2520 l gs col-1 s gr gr + +% arrowhead +n 2730 2373 m 2700 2493 l 2670 2373 l 2700 2373 l 2730 2373 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +4443 2130 m 4563 2160 l 4443 2190 l 4605 2190 l 4605 2130 l cp clip +n 2970 2160 m 4590 2160 l gs col-1 s gr gr + +% arrowhead +n 4443 2130 m 4563 2160 l 4443 2190 l 4443 2160 l 4443 2130 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +4755 2373 m 4725 2493 l 4695 2373 l 4695 2535 l 4755 2535 l cp clip +n 4725 2160 m 4725 2520 l gs col-1 s gr gr + +% arrowhead +n 4755 2373 m 4725 2493 l 4695 2373 l 4725 2373 l 4755 2373 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +3228 4200 m 3348 4230 l 3228 4260 l 3390 4260 l 3390 4200 l cp clip +n 3015 4230 m 3375 4230 l gs col-1 s gr gr + +% arrowhead +n 3228 4200 m 3348 4230 l 3228 4260 l 3228 4230 l 3228 4200 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +5253 4200 m 5373 4230 l 5253 4260 l 5415 4260 l 5415 4200 l cp clip +n 5040 4230 m 5400 4230 l gs col-1 s gr gr + +% arrowhead +n 5253 4200 m 5373 4230 l 5253 4260 l 5253 4230 l 5253 4200 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 2250 3825 m 3150 3825 l gs col-1 s gr +% Polyline +n 2250 4095 m 3150 4095 l gs col-1 s gr +% Polyline +n 2250 3600 m 3150 3600 l 3150 4365 l 2250 4365 l cp gs col-1 s gr +% Polyline +n 2880 4095 m 2880 4365 l gs col-1 s gr +% Polyline +n 4275 3825 m 5175 3825 l gs col-1 s gr +% Polyline +n 4275 4095 m 5175 4095 l gs col-1 s gr +% Polyline +n 4275 3600 m 5175 3600 l 5175 4365 l 4275 4365 l cp gs col-1 s gr +% Polyline +n 4905 4095 m 4905 4365 l gs col-1 s gr +% Polyline +n 2250 4905 m 3150 4905 l gs col-1 s gr +% Polyline +n 2250 5175 m 3150 5175 l gs col-1 s gr +% Polyline +n 4275 4905 m 5175 4905 l gs col-1 s gr +% Polyline +n 4275 5175 m 5175 5175 l gs col-1 s gr +% Polyline +n 2250 4680 m 3150 4680 l 3150 5445 l 2250 5445 l cp gs col-1 s gr +% Polyline +n 4275 4680 m 5175 4680 l 5175 5445 l 4275 5445 l cp gs col-1 s gr +% Open spline +gs clippath +2825 3517 m 2719 3580 l 2783 3475 l 2668 3589 l 2711 3632 l cp clip +n 3015.0 2880.0 m 3150.0 2880.0 l + 3150.0 2880.0 3285.0 2880.0 3285.0 2947.5 DrawSplineSection + 3285.0 2947.5 3285.0 3015.0 3285.0 3195.0 DrawSplineSection + 3285.0 3195.0 3285.0 3375.0 3105.0 3375.0 DrawSplineSection + 3105.0 3375.0 2925.0 3375.0 2812.5 3487.5 DrawSplineSection + 2700.0 3600.0 l gs col-1 s gr + gr + +% arrowhead +n 2825 3517 m 2719 3580 l 2783 3475 l 2804 3496 l 2825 3517 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +4850 3517 m 4744 3580 l 4808 3475 l 4693 3589 l 4736 3632 l cp clip +n 5040.0 2880.0 m 5175.0 2880.0 l + 5175.0 2880.0 5310.0 2880.0 5310.0 2947.5 DrawSplineSection + 5310.0 2947.5 5310.0 3015.0 5310.0 3195.0 DrawSplineSection + 5310.0 3195.0 5310.0 3375.0 5130.0 3375.0 DrawSplineSection + 5130.0 3375.0 4950.0 3375.0 4837.5 3487.5 DrawSplineSection + 4725.0 3600.0 l gs col-1 s gr + gr + +% arrowhead +n 4850 3517 m 4744 3580 l 4808 3475 l 4829 3496 l 4850 3517 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +2418 330 m 2538 360 l 2418 390 l 2580 390 l 2580 330 l cp clip +n 1665.0 3015.0 m 1800.0 3015.0 l + 1800.0 3015.0 1935.0 3015.0 1935.0 2902.5 DrawSplineSection + 1935.0 2902.5 1935.0 2790.0 1935.0 1687.5 DrawSplineSection + 1935.0 1687.5 1935.0 585.0 1935.0 472.5 DrawSplineSection + 1935.0 472.5 1935.0 360.0 2047.5 360.0 DrawSplineSection + 2047.5 360.0 2160.0 360.0 2362.5 360.0 DrawSplineSection + 2565.0 360.0 l gs col-1 s gr + gr + +% arrowhead +n 2418 330 m 2538 360 l 2418 390 l 2418 360 l 2418 330 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +2418 2130 m 2538 2160 l 2418 2190 l 2580 2190 l 2580 2130 l cp clip +n 1665.0 3285.0 m 1867.5 3285.0 l + 1867.5 3285.0 2070.0 3285.0 2070.0 3172.5 DrawSplineSection + 2070.0 3172.5 2070.0 3060.0 2070.0 2700.0 DrawSplineSection + 2070.0 2700.0 2070.0 2340.0 2070.0 2250.0 DrawSplineSection + 2070.0 2250.0 2070.0 2160.0 2160.0 2160.0 DrawSplineSection + 2160.0 2160.0 2250.0 2160.0 2407.5 2160.0 DrawSplineSection + 2565.0 2160.0 l gs col-1 s gr + gr + +% arrowhead +n 2418 2130 m 2538 2160 l 2418 2190 l 2418 2160 l 2418 2130 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +4857 4609 m 4745 4662 l 4819 4563 l 4694 4667 l 4733 4713 l cp clip +n 5040.0 3150.0 m 5332.5 3150.0 l + 5332.5 3150.0 5625.0 3150.0 5737.5 3150.0 DrawSplineSection + 5737.5 3150.0 5850.0 3150.0 5850.0 3262.5 DrawSplineSection + 5850.0 3262.5 5850.0 3375.0 5850.0 3780.0 DrawSplineSection + 5850.0 3780.0 5850.0 4185.0 5850.0 4320.0 DrawSplineSection + 5850.0 4320.0 5850.0 4455.0 5715.0 4455.0 DrawSplineSection + 5715.0 4455.0 5580.0 4455.0 5287.5 4455.0 DrawSplineSection + 5287.5 4455.0 4995.0 4455.0 4860.0 4567.5 DrawSplineSection + 4725.0 4680.0 l gs col-1 s gr + gr + +% arrowhead +n 4857 4609 m 4745 4662 l 4819 4563 l 4838 4586 l 4857 4609 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +2832 4609 m 2720 4662 l 2794 4563 l 2669 4667 l 2708 4713 l cp clip +n 3015.0 3150.0 m 3420.0 3150.0 l + 3420.0 3150.0 3825.0 3150.0 3937.5 3150.0 DrawSplineSection + 3937.5 3150.0 4050.0 3150.0 4050.0 3262.5 DrawSplineSection + 4050.0 3262.5 4050.0 3375.0 4050.0 3780.0 DrawSplineSection + 4050.0 3780.0 4050.0 4185.0 4050.0 4320.0 DrawSplineSection + 4050.0 4320.0 4050.0 4455.0 3915.0 4455.0 DrawSplineSection + 3915.0 4455.0 3780.0 4455.0 3375.0 4455.0 DrawSplineSection + 3375.0 4455.0 2970.0 4455.0 2835.0 4567.5 DrawSplineSection + 2700.0 4680.0 l gs col-1 s gr + gr + +% arrowhead +n 2832 4609 m 2720 4662 l 2794 4563 l 2813 4586 l 2832 4609 l cp gs 0.00 setgray ef gr col-1 s +/Times-Roman ff 150.00 scf sf +540 900 m +gs 1 -1 sc (utility) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 1455 m +gs 1 -1 sc (into) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 2790 m +gs 1 -1 sc (unique) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 3075 m +gs 1 -1 sc (rtable) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 3600 m +gs 1 -1 sc (qual) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 3315 m +gs 1 -1 sc (targetlist) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 3885 m +gs 1 -1 sc (groupClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 5220 m +gs 1 -1 sc (intersectClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 1170 m +gs 1 -1 sc (resultRelation: 0) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 1980 m +gs 1 -1 sc (isBinary: false) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 2265 m +gs 1 -1 sc (union_all: false) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 4410 m +gs 1 -1 sc (hasAggs: false) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 4695 m +gs 1 -1 sc (hasSublinks: false) col-1 sh gr +/Times-Roman ff 150.00 scf sf +945 360 m +gs 1 -1 sc (Query) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 630 m +gs 1 -1 sc (command: 1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3420 1125 m +gs 1 -1 sc ("supplier") col-1 sh gr +/Times-Roman ff 150.00 scf sf +3420 1395 m +gs 1 -1 sc ("s") col-1 sh gr +/Times-Roman ff 150.00 scf sf +5445 1125 m +gs 1 -1 sc ("sells") col-1 sh gr +/Times-Roman ff 150.00 scf sf +5445 1395 m +gs 1 -1 sc ("se") col-1 sh gr +/Times-Roman ff 150.00 scf sf +4365 1395 m +gs 1 -1 sc (refname) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4590 900 m +gs 1 -1 sc (RTE) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4365 1125 m +gs 1 -1 sc (relname) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4365 1665 m +gs 1 -1 sc (relid: 18219) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3420 4275 m +gs 1 -1 sc ("sname") col-1 sh gr +/Times-Roman ff 150.00 scf sf +5445 4275 m +gs 1 -1 sc ("pno") col-1 sh gr +/Times-Roman ff 150.00 scf sf +2340 4275 m +gs 1 -1 sc (resname ) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2340 4005 m +gs 1 -1 sc (resno: 1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4365 4275 m +gs 1 -1 sc (resname ) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4365 4005 m +gs 1 -1 sc (resno: 2) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4410 3780 m +gs 1 -1 sc (RESDOM) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2385 3780 m +gs 1 -1 sc (RESDOM) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2520 4860 m +gs 1 -1 sc (VAR) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2340 5085 m +gs 1 -1 sc (varno: 1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4365 5085 m +gs 1 -1 sc (varno: 2) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4545 4860 m +gs 1 -1 sc (VAR) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 1695 m +gs 1 -1 sc (isPortal: false) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 2505 m +gs 1 -1 sc (sortClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 4125 m +gs 1 -1 sc (havingQual) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 4935 m +gs 1 -1 sc (unionClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2340 5355 m +gs 1 -1 sc (varattno: 2) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4365 5355 m +gs 1 -1 sc (varattno: 2) col-1 sh gr +showpage +$F2psEnd +rs +%%EndDocument + @endspecial 427 2501 a(Figure)i(3.4:)j(T)n(ransformed)d +Fp(T)-5 b(ar)n(getList)12 b Ft(and)h Fp(F)m(r)n(omList)g +Ft(for)e(query)h(of)g(e)o(xample)h(3.1)270 2745 y(Figure)g(3.5)g(sho)o +(ws)h(the)g(transformed)e Fp(wher)n(e)i(clause)p Ft(.)20 +b(Ev)o(ery)13 b Fr(A)p 1411 2745 15 2 v 18 w(Expr)g Ft(node)h(is)f +(transformed)g(to)g(an)270 2804 y Fr(Expr)k Ft(node.)31 +b(The)18 b Fr(Attr)f Ft(nodes)g(representing)g(the)g(attrib)o(utes)g +(are)g(replaced)g(by)h Fr(VAR)f Ft(nodes)h(as)270 2864 +y(it)d(has)g(been)g(done)g(for)f(the)h Fp(tar)n(getlist)g +Ft(abo)o(v)o(e.)24 b(Checks)15 b(if)g(the)f(appearing)h +Fp(attrib)o(utes)g Ft(are)g(v)o(alid)f(and)270 2924 y(kno)o(wn)h(to)g +(the)h(system)g(are)f(made.)26 b(If)14 b(there)i(is)f(an)h +Fp(attrib)o(ute)f Ft(used)h(which)f(is)h(not)g(kno)o(wn)f(an)g(error) +270 2984 y(will)d(be)g(returned)g(and)g(the)h Fp(query)f(pr)n(ocessing) +i Ft(will)d(be)i(aborted.)270 3103 y(The)30 b(whole)g +Fp(tr)o(ansformation)g(pr)n(ocess)g Ft(performs)f(a)h(transformation)e +(of)h(the)h(data)g(structure)270 3163 y(handed)13 b(back)f(by)h(the)g +Fp(parser)g Ft(to)g(a)f(more)h(comfortable)e(form.)16 +b(The)d(character)f(strings)h(representing)270 3223 y(the)g +Fp(r)n(elations)h Ft(and)f Fp(attrib)o(utes)h Ft(in)f(the)g(original)g +(tree)g(are)g(replaced)g(by)g Fp(r)n(elation)h(ids)f +Ft(and)h Fr(VAR)f Ft(nodes)270 3283 y(whose)18 b(\002elds)g(are)g +(referring)e(to)i(the)f(entries)h(of)f(the)h Fp(r)o(ange)g(table)g +(entry)g(list)p Ft(.)32 b(In)17 b(addition)g(to)h(the)270 +3342 y(transformation,)c(also)g(v)o(arious)g(checks)h(if)f(the)g(used)h +Fp(r)n(elation)f Ft(and)g Fp(attrib)o(ute)g Ft(names)h(\(appearing)e +(in)270 3402 y(the)f(query\))g(are)g(v)o(alid)g(in)g(the)g(current)g +(conte)o(xt)g(are)h(performed.)p eop +%%Page: 57 57 +57 56 bop 198 60 a Fm(3.3.)29 b(THE)13 b(P)-5 b(ARSER)13 +b(ST)-5 b(A)n(GE)1189 b Ft(57)291 2826 y @beginspecial +144 @llx 172 @lly 467 @urx 619 @ury 3230 @rwi @setspecial +%%BeginDocument: figures/transform_where.ps +%Magnification: 1.05 +/$F2psDict 200 dict def +$F2psDict begin +$F2psDict /mtrx matrix put +/col-1 {0 setgray} bind def +/col0 {0.000 0.000 0.000 srgb} bind def +/col1 {0.000 0.000 1.000 srgb} bind def +/col2 {0.000 1.000 0.000 srgb} bind def +/col3 {0.000 1.000 1.000 srgb} bind def +/col4 {1.000 0.000 0.000 srgb} bind def +/col5 {1.000 0.000 1.000 srgb} bind def +/col6 {1.000 1.000 0.000 srgb} bind def +/col7 {1.000 1.000 1.000 srgb} bind def +/col8 {0.000 0.000 0.560 srgb} bind def +/col9 {0.000 0.000 0.690 srgb} bind def +/col10 {0.000 0.000 0.820 srgb} bind def +/col11 {0.530 0.810 1.000 srgb} bind def +/col12 {0.000 0.560 0.000 srgb} bind def +/col13 {0.000 0.690 0.000 srgb} bind def +/col14 {0.000 0.820 0.000 srgb} bind def +/col15 {0.000 0.560 0.560 srgb} bind def +/col16 {0.000 0.690 0.690 srgb} bind def +/col17 {0.000 0.820 0.820 srgb} bind def +/col18 {0.560 0.000 0.000 srgb} bind def +/col19 {0.690 0.000 0.000 srgb} bind def +/col20 {0.820 0.000 0.000 srgb} bind def +/col21 {0.560 0.000 0.560 srgb} bind def +/col22 {0.690 0.000 0.690 srgb} bind def +/col23 {0.820 0.000 0.820 srgb} bind def +/col24 {0.500 0.190 0.000 srgb} bind def +/col25 {0.630 0.250 0.000 srgb} bind def +/col26 {0.750 0.380 0.000 srgb} bind def +/col27 {1.000 0.500 0.500 srgb} bind def +/col28 {1.000 0.630 0.630 srgb} bind def +/col29 {1.000 0.750 0.750 srgb} bind def +/col30 {1.000 0.880 0.880 srgb} bind def +/col31 {1.000 0.840 0.000 srgb} bind def + +end +save +117.5 632.5 translate +1 -1 scale + +/cp {closepath} bind def +/ef {eofill} bind def +/gr {grestore} bind def +/gs {gsave} bind def +/sa {save} bind def +/rs {restore} bind def +/l {lineto} bind def +/m {moveto} bind def +/rm {rmoveto} bind def +/n {newpath} bind def +/s {stroke} bind def +/sh {show} bind def +/slc {setlinecap} bind def +/slj {setlinejoin} bind def +/slw {setlinewidth} bind def +/srgb {setrgbcolor} bind def +/rot {rotate} bind def +/sc {scale} bind def +/sd {setdash} bind def +/ff {findfont} bind def +/sf {setfont} bind def +/scf {scalefont} bind def +/sw {stringwidth} bind def +/tr {translate} bind def +/tnt {dup dup currentrgbcolor + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add srgb} + bind def +/shd {dup dup currentrgbcolor 4 -2 roll mul 4 -2 roll mul + 4 -2 roll mul srgb} bind def + /DrawSplineSection { + /y3 exch def + /x3 exch def + /y2 exch def + /x2 exch def + /y1 exch def + /x1 exch def + /xa x1 x2 x1 sub 0.666667 mul add def + /ya y1 y2 y1 sub 0.666667 mul add def + /xb x3 x2 x3 sub 0.666667 mul add def + /yb y3 y2 y3 sub 0.666667 mul add def + x1 y1 lineto + xa ya xb yb x3 y3 curveto + } def + +/$F2psBegin {$F2psDict begin /$F2psEnteredState save def} def +/$F2psEnd {$F2psEnteredState restore end} def + +$F2psBegin +10 setmiterlimit +n 0 792 m 0 0 l 612 0 l 612 792 l cp clip + 0.06299 0.06299 sc +7.500 slw +% Polyline +n 1530 5040 m 1800 5310 l gs col-1 s gr +% Polyline +n 1800 5040 m 1530 5310 l gs col-1 s gr +% Polyline +n 1530 4770 m 1800 5040 l gs col-1 s gr +% Polyline +n 1800 4770 m 1530 5040 l gs col-1 s gr +% Polyline +n 1530 3960 m 1800 4230 l gs col-1 s gr +% Polyline +n 1800 3960 m 1530 4230 l gs col-1 s gr +% Polyline +n 1530 3690 m 1800 3960 l gs col-1 s gr +% Polyline +n 1800 3690 m 1530 3960 l gs col-1 s gr +% Polyline +n 1530 2340 m 1800 2610 l gs col-1 s gr +% Polyline +n 1800 2340 m 1530 2610 l gs col-1 s gr +% Polyline +n 1530 1260 m 1800 1530 l gs col-1 s gr +% Polyline +n 1800 1260 m 1530 1530 l gs col-1 s gr +% Polyline +n 1530 720 m 1800 990 l gs col-1 s gr +% Polyline +n 1800 720 m 1530 990 l gs col-1 s gr +% Polyline +n 5130 1440 m 5130 1710 l gs col-1 s gr +% Polyline +n 4860 1440 m 5400 1440 l 5400 1710 l 4860 1710 l cp gs col-1 s gr +% Polyline +n 5130 1440 m 5400 1710 l gs col-1 s gr +% Polyline +n 5400 1440 m 5130 1710 l gs col-1 s gr +% Polyline +n 4140 1440 m 4140 1710 l gs col-1 s gr +% Polyline +n 3870 1440 m 4410 1440 l 4410 1710 l 3870 1710 l cp gs col-1 s gr +% Polyline +gs clippath +4713 1545 m 4833 1575 l 4713 1605 l 4875 1605 l 4875 1545 l cp clip +n 4275 1575 m 4860 1575 l gs col-1 s gr gr + +% arrowhead +n 4713 1545 m 4833 1575 l 4713 1605 l 4713 1575 l 4713 1545 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 4140 5940 m 4140 6210 l gs col-1 s gr +% Polyline +n 3870 5940 m 4410 5940 l 4410 6210 l 3870 6210 l cp gs col-1 s gr +% Polyline +n 4905 5940 m 4905 6210 l gs col-1 s gr +% Polyline +n 4635 5940 m 5175 5940 l 5175 6210 l 4635 6210 l cp gs col-1 s gr +% Polyline +n 4905 5940 m 5175 6210 l gs col-1 s gr +% Polyline +n 5175 5940 m 4905 6210 l gs col-1 s gr +% Polyline +n 3870 2295 m 4635 2295 l gs col-1 s gr +% Polyline +n 3870 2565 m 4635 2565 l gs col-1 s gr +% Polyline +n 3870 2070 m 4635 2070 l 4635 2835 l 3870 2835 l cp gs col-1 s gr +/Times-Roman ff 150.00 scf sf +4095 2250 m +gs 1 -1 sc (Oper) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3960 2475 m +gs 1 -1 sc (opno: 521) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3960 2745 m +gs 1 -1 sc (opid: 0) col-1 sh gr +% Polyline +n 4140 3015 m 4140 3285 l gs col-1 s gr +% Polyline +n 3870 3015 m 4410 3015 l 4410 3285 l 3870 3285 l cp gs col-1 s gr +% Polyline +n 4905 3015 m 4905 3285 l gs col-1 s gr +% Polyline +n 4635 3015 m 5175 3015 l 5175 3285 l 4635 3285 l cp gs col-1 s gr +% Polyline +n 4905 3015 m 5175 3285 l gs col-1 s gr +% Polyline +n 5175 3015 m 4905 3285 l gs col-1 s gr +% Polyline +n 450 450 m 1800 450 l gs col-1 s gr +% Polyline +n 450 720 m 1800 720 l gs col-1 s gr +% Polyline +n 450 990 m 1800 990 l gs col-1 s gr +% Polyline +n 450 1260 m 1800 1260 l gs col-1 s gr +% Polyline +n 450 1530 m 1800 1530 l gs col-1 s gr +% Polyline +n 450 1800 m 1800 1800 l gs col-1 s gr +% Polyline +n 450 2070 m 1800 2070 l gs col-1 s gr +% Polyline +n 450 2340 m 1800 2340 l gs col-1 s gr +% Polyline +n 450 2610 m 1800 2610 l gs col-1 s gr +% Polyline +n 450 2880 m 1800 2880 l gs col-1 s gr +% Polyline +n 450 3150 m 1800 3150 l gs col-1 s gr +% Polyline +n 450 3690 m 1800 3690 l gs col-1 s gr +% Polyline +n 450 3960 m 1800 3960 l gs col-1 s gr +% Polyline +n 450 4230 m 1800 4230 l gs col-1 s gr +% Polyline +n 450 3420 m 1800 3420 l gs col-1 s gr +% Polyline +n 450 4500 m 1800 4500 l gs col-1 s gr +% Polyline +n 450 4770 m 1800 4770 l gs col-1 s gr +% Polyline +n 450 5040 m 1800 5040 l gs col-1 s gr +% Polyline +n 450 225 m 1800 225 l 1800 5310 l 450 5310 l cp gs col-1 s gr +% Polyline +n 1530 4770 m 1530 5310 l gs col-1 s gr +% Polyline +n 1530 4230 m 1530 2880 l gs col-1 s gr +% Polyline +n 1530 2340 m 1530 2610 l gs col-1 s gr +% Polyline +n 1530 720 m 1530 990 l gs col-1 s gr +% Polyline +n 1530 1260 m 1530 1530 l gs col-1 s gr +% Polyline +n 1530 2610 m 1530 2880 l gs col-1 s gr +% Polyline +n 1530 2610 m 1800 2880 l gs col-1 s gr +% Polyline +n 1800 2610 m 1530 2880 l gs col-1 s gr +% Polyline +n 3150 1170 m 3420 1440 l gs col-1 s gr +% Polyline +n 3420 1170 m 3150 1440 l gs col-1 s gr +% Polyline +gs clippath +3723 1545 m 3843 1575 l 3723 1605 l 3885 1605 l 3885 1545 l cp clip +n 3285 1575 m 3870 1575 l gs col-1 s gr gr + +% arrowhead +n 3723 1545 m 3843 1575 l 3723 1605 l 3723 1575 l 3723 1545 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 2430 5220 m 3420 5220 l gs col-1 s gr +% Polyline +n 2430 5490 m 3420 5490 l gs col-1 s gr +% Polyline +n 2430 5760 m 3420 5760 l gs col-1 s gr +% Polyline +n 2430 4995 m 3420 4995 l 3420 6030 l 2430 6030 l cp gs col-1 s gr +% Polyline +n 3150 6030 m 3150 5490 l gs col-1 s gr +% Polyline +gs clippath +4488 6045 m 4608 6075 l 4488 6105 l 4650 6105 l 4650 6045 l cp clip +n 4275 6075 m 4635 6075 l gs col-1 s gr gr + +% arrowhead +n 4488 6045 m 4608 6075 l 4488 6105 l 4488 6075 l 4488 6045 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 3870 5220 m 4635 5220 l gs col-1 s gr +% Polyline +n 3870 5490 m 4635 5490 l gs col-1 s gr +% Polyline +n 3870 4995 m 4635 4995 l 4635 5760 l 3870 5760 l cp gs col-1 s gr +% Polyline +n 2970 6750 m 3870 6750 l gs col-1 s gr +% Polyline +n 2970 7020 m 3870 7020 l gs col-1 s gr +% Polyline +n 4275 6750 m 5175 6750 l gs col-1 s gr +% Polyline +n 4275 7020 m 5175 7020 l gs col-1 s gr +% Polyline +n 2970 6525 m 3870 6525 l 3870 7290 l 2970 7290 l cp gs col-1 s gr +% Polyline +n 4275 6525 m 5175 6525 l 5175 7290 l 4275 7290 l cp gs col-1 s gr +% Polyline +n 2430 2295 m 3420 2295 l gs col-1 s gr +% Polyline +n 2430 2565 m 3420 2565 l gs col-1 s gr +% Polyline +n 2430 2835 m 3420 2835 l gs col-1 s gr +% Polyline +n 2430 2070 m 3420 2070 l 3420 3105 l 2430 3105 l cp gs col-1 s gr +% Polyline +n 3150 3105 m 3150 2565 l gs col-1 s gr +% Polyline +gs clippath +4488 3120 m 4608 3150 l 4488 3180 l 4650 3180 l 4650 3120 l cp clip +n 4275 3150 m 4635 3150 l gs col-1 s gr gr + +% arrowhead +n 4488 3120 m 4608 3150 l 4488 3180 l 4488 3150 l 4488 3120 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 4275 3825 m 5175 3825 l gs col-1 s gr +% Polyline +n 4275 3600 m 5175 3600 l 5175 4095 l 4275 4095 l cp gs col-1 s gr +% Polyline +n 2970 3824 m 3870 3824 l gs col-1 s gr +% Polyline +n 2970 4094 m 3870 4094 l gs col-1 s gr +% Polyline +n 2970 3600 m 3870 3600 l 3870 4365 l 2970 4365 l cp gs col-1 s gr +% Polyline +n 2430 900 m 3420 900 l gs col-1 s gr +% Polyline +n 2430 1170 m 3420 1170 l gs col-1 s gr +% Polyline +n 2430 1440 m 3420 1440 l gs col-1 s gr +% Polyline +n 2430 675 m 3420 675 l 3420 1710 l 2430 1710 l cp gs col-1 s gr +% Polyline +n 3150 1710 m 3150 1170 l gs col-1 s gr +% Open spline +gs clippath +2955 528 m 2925 648 l 2895 528 l 2895 690 l 2955 690 l cp clip +n 1665.0 3555.0 m 1890.0 3555.0 l + 1890.0 3555.0 2115.0 3555.0 2115.0 3397.5 DrawSplineSection + 2115.0 3397.5 2115.0 3240.0 2115.0 2047.5 DrawSplineSection + 2115.0 2047.5 2115.0 855.0 2115.0 585.0 DrawSplineSection + 2115.0 585.0 2115.0 315.0 2340.0 315.0 DrawSplineSection + 2340.0 315.0 2565.0 315.0 2677.5 315.0 DrawSplineSection + 2677.5 315.0 2790.0 315.0 2857.5 360.0 DrawSplineSection + 2857.5 360.0 2925.0 405.0 2925.0 540.0 DrawSplineSection + 2925.0 675.0 l gs col-1 s gr + gr + +% arrowhead +n 2955 528 m 2925 648 l 2895 528 l 2925 528 l 2955 528 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3050 1987 m 2944 2050 l 3008 1945 l 2893 2059 l 2936 2102 l cp clip +n 4005.0 1575.0 m 4005.0 1687.5 l + 4005.0 1687.5 4005.0 1800.0 3937.5 1845.0 DrawSplineSection + 3937.5 1845.0 3870.0 1890.0 3487.5 1890.0 DrawSplineSection + 3487.5 1890.0 3105.0 1890.0 3015.0 1980.0 DrawSplineSection + 2925.0 2070.0 l gs col-1 s gr + gr + +% arrowhead +n 3050 1987 m 2944 2050 l 3008 1945 l 3029 1966 l 3050 1987 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3723 5325 m 3843 5355 l 3723 5385 l 3885 5385 l 3885 5325 l cp clip +n 3285.0 5625.0 m 3420.0 5625.0 l + 3420.0 5625.0 3555.0 5625.0 3555.0 5490.0 DrawSplineSection + 3555.0 5490.0 3555.0 5355.0 3712.5 5355.0 DrawSplineSection + 3870.0 5355.0 l gs col-1 s gr + gr + +% arrowhead +n 3723 5325 m 3843 5355 l 3723 5385 l 3723 5355 l 3723 5325 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3723 6045 m 3843 6075 l 3723 6105 l 3885 6105 l 3885 6045 l cp clip +n 3285.0 5895.0 m 3397.5 5895.0 l + 3397.5 5895.0 3510.0 5895.0 3532.5 5985.0 DrawSplineSection + 3532.5 5985.0 3555.0 6075.0 3712.5 6075.0 DrawSplineSection + 3870.0 6075.0 l gs col-1 s gr + gr + +% arrowhead +n 3723 6045 m 3843 6075 l 3723 6105 l 3723 6075 l 3723 6045 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +4783 6387 m 4730 6498 l 4724 6375 l 4693 6534 l 4751 6546 l cp clip +n 4770.0 6075.0 m 4770.0 6187.5 l + 4770.0 6187.5 4770.0 6300.0 4747.5 6412.5 DrawSplineSection + 4725.0 6525.0 l gs col-1 s gr + gr + +% arrowhead +n 4783 6387 m 4730 6498 l 4724 6375 l 4754 6381 l 4783 6387 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3554 6457 m 3441 6508 l 3516 6410 l 3390 6511 l 3427 6558 l cp clip +n 4005.0 6075.0 m 4005.0 6187.5 l + 4005.0 6187.5 4005.0 6300.0 3825.0 6322.5 DrawSplineSection + 3825.0 6322.5 3645.0 6345.0 3532.5 6435.0 DrawSplineSection + 3420.0 6525.0 l gs col-1 s gr + gr + +% arrowhead +n 3554 6457 m 3441 6508 l 3516 6410 l 3535 6433 l 3554 6457 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +2955 4848 m 2925 4968 l 2895 4848 l 2895 5010 l 2955 5010 l cp clip +n 4995.0 1575.0 m 4995.0 1755.0 l + 4995.0 1755.0 4995.0 1935.0 5062.5 1980.0 DrawSplineSection + 5062.5 1980.0 5130.0 2025.0 5332.5 2025.0 DrawSplineSection + 5332.5 2025.0 5535.0 2025.0 5535.0 2205.0 DrawSplineSection + 5535.0 2205.0 5535.0 2385.0 5535.0 3375.0 DrawSplineSection + 5535.0 3375.0 5535.0 4365.0 5535.0 4545.0 DrawSplineSection + 5535.0 4545.0 5535.0 4725.0 5310.0 4725.0 DrawSplineSection + 5310.0 4725.0 5085.0 4725.0 4162.5 4725.0 DrawSplineSection + 4162.5 4725.0 3240.0 4725.0 3082.5 4725.0 DrawSplineSection + 3082.5 4725.0 2925.0 4725.0 2925.0 4860.0 DrawSplineSection + 2925.0 4995.0 l gs col-1 s gr + gr + +% arrowhead +n 2955 4848 m 2925 4968 l 2895 4848 l 2925 4848 l 2955 4848 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3723 2400 m 3843 2430 l 3723 2460 l 3885 2460 l 3885 2400 l cp clip +n 3285.0 2700.0 m 3420.0 2700.0 l + 3420.0 2700.0 3555.0 2700.0 3555.0 2565.0 DrawSplineSection + 3555.0 2565.0 3555.0 2430.0 3712.5 2430.0 DrawSplineSection + 3870.0 2430.0 l gs col-1 s gr + gr + +% arrowhead +n 3723 2400 m 3843 2430 l 3723 2460 l 3723 2430 l 3723 2400 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3723 3120 m 3843 3150 l 3723 3180 l 3885 3180 l 3885 3120 l cp clip +n 3285.0 2970.0 m 3397.5 2970.0 l + 3397.5 2970.0 3510.0 2970.0 3532.5 3060.0 DrawSplineSection + 3532.5 3060.0 3555.0 3150.0 3712.5 3150.0 DrawSplineSection + 3870.0 3150.0 l gs col-1 s gr + gr + +% arrowhead +n 3723 3120 m 3843 3150 l 3723 3180 l 3723 3150 l 3723 3120 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +4783 3462 m 4730 3573 l 4724 3450 l 4693 3609 l 4751 3621 l cp clip +n 4770.0 3150.0 m 4770.0 3262.5 l + 4770.0 3262.5 4770.0 3375.0 4747.5 3487.5 DrawSplineSection + 4725.0 3600.0 l gs col-1 s gr + gr + +% arrowhead +n 4783 3462 m 4730 3573 l 4724 3450 l 4754 3456 l 4783 3462 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3554 3532 m 3441 3583 l 3516 3485 l 3390 3586 l 3427 3633 l cp clip +n 4005.0 3150.0 m 4005.0 3262.5 l + 4005.0 3262.5 4005.0 3375.0 3825.0 3397.5 DrawSplineSection + 3825.0 3397.5 3645.0 3420.0 3532.5 3510.0 DrawSplineSection + 3420.0 3600.0 l gs col-1 s gr + gr + +% arrowhead +n 3554 3532 m 3441 3583 l 3516 3485 l 3535 3508 l 3554 3532 l cp gs 0.00 setgray ef gr col-1 s +/Times-Roman ff 150.00 scf sf +540 900 m +gs 1 -1 sc (utility) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 2505 m +gs 1 -1 sc (sortClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 2790 m +gs 1 -1 sc (unique) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 3075 m +gs 1 -1 sc (rtable) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 3600 m +gs 1 -1 sc (qual) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 3315 m +gs 1 -1 sc (targetlist) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 3885 m +gs 1 -1 sc (groupClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 5220 m +gs 1 -1 sc (intersectClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 1170 m +gs 1 -1 sc (resultRelation: 0) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 1980 m +gs 1 -1 sc (isBinary: false) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 2265 m +gs 1 -1 sc (union_all: false) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 4410 m +gs 1 -1 sc (hasAggs: false) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 4695 m +gs 1 -1 sc (hasSublinks: false) col-1 sh gr +/Times-Roman ff 150.00 scf sf +945 360 m +gs 1 -1 sc (Query) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 630 m +gs 1 -1 sc (command: 1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2520 5400 m +gs 1 -1 sc (opType: OP) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2520 5925 m +gs 1 -1 sc (args) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2790 5175 m +gs 1 -1 sc (Expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4095 5175 m +gs 1 -1 sc (Oper) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3960 5400 m +gs 1 -1 sc (opno: 96) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3960 5670 m +gs 1 -1 sc (opid: 0) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3240 6705 m +gs 1 -1 sc (VAR) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3060 6930 m +gs 1 -1 sc (varno: 1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4365 6930 m +gs 1 -1 sc (varno: 2) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4545 6705 m +gs 1 -1 sc (VAR) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3060 7200 m +gs 1 -1 sc (varattno: 2) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4365 7200 m +gs 1 -1 sc (varattno: 2) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2520 2475 m +gs 1 -1 sc (opType: OP) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2520 3000 m +gs 1 -1 sc (args) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2790 2250 m +gs 1 -1 sc (Expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4545 3780 m +gs 1 -1 sc (Const) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3240 3780 m +gs 1 -1 sc (VAR) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3060 4004 m +gs 1 -1 sc (varno: 1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3060 4275 m +gs 1 -1 sc (varattno: 2) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4320 4005 m +gs 1 -1 sc (constvalue: 2) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 4935 m +gs 1 -1 sc (unionClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 4125 m +gs 1 -1 sc (havingQual) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 1455 m +gs 1 -1 sc (into) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 1695 m +gs 1 -1 sc (isPortal: false) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2520 5685 m +gs 1 -1 sc (oper) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2520 2760 m +gs 1 -1 sc (oper) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2520 1080 m +gs 1 -1 sc (opType: AND) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2520 1605 m +gs 1 -1 sc (args) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2790 855 m +gs 1 -1 sc (Expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2520 1365 m +gs 1 -1 sc (oper) col-1 sh gr +showpage +$F2psEnd +rs +%%EndDocument + @endspecial 464 2935 a(Figure)12 b(3.5:)j(T)n(ransformed)d +Fp(wher)n(e)i(clause)f Ft(for)e(query)h(of)g(e)o(xample)g(3.1)p +eop +%%Page: 58 58 +58 57 bop 270 60 a Ft(58)82 b Fm(CHAPTER)14 b(3.)28 b(POSTGRESQL)13 +b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW)270 +234 y Fi(3.4)71 b(The)18 b(P)o(ostgr)o(eSQL)e(Rule)h(System)270 +349 y Ft(PostgreSQL)c(supports)g(a)h(po)o(werful)e Fp(rule)h(system)i +Ft(for)d(the)h(speci\002cation)h(of)f Fp(vie)o(ws)h Ft(and)f(ambiguous) +270 409 y Fp(vie)o(w)g(updates)p Ft(.)j(Originally)11 +b(the)h(PostgreSQL)g Fp(rule)h(system)g Ft(consisted)g(of)f(two)g +(implementations.)345 471 y(The)18 b(\002rst)g(one)f(worked)g(using)h +Fp(tuple)f(le)o(vel)i Ft(processing)f(and)f(was)h(implemented)f(deep)h +(in)g(the)270 531 y Fp(e)o(xecutor)p Ft(.)35 b(The)19 +b Fp(rule)g(system)g Ft(was)g(called)f(whene)o(v)o(er)h(an)f(indi)o +(vidual)g(tuple)g(had)h(been)f(accessed.)270 591 y(This)11 +b(implementation)d(has)j(been)f(remo)o(v)o(ed)f(in)h(1995)g(when)g(the) +g(last)g(of)o(\002cial)f(release)h(of)f(the)h(Postgres)270 +650 y(project)i(was)g(further)f(enhanced)i(to)f(Postgres95.)345 +712 y(The)22 b(second)h(implementation)d(of)i(the)g Fp(rule)g(system)h +Ft(is)f(a)g(technique)g(called)g Fp(query)g(r)n(e)o(writ-)270 +772 y(ing)p Ft(.)32 b(The)18 b Fp(r)n(e)o(write)h(system)g +Ft(is)f(a)g(module)f(that)h(e)o(xists)g(between)g(the)g +Fp(parser)g(stage)f Ft(and)h(the)g Fp(plan-)270 832 y(ner/optimizer)p +Ft(.)e(This)d(technique)f(is)h(still)f(implemented.)345 +894 y(F)o(or)h(information)f(on)i(the)f(syntax)h(and)g(creation)f(of)g +Fp(rules)i Ft(in)e(the)h(PostgreSQL)f(system)h(refer)f(to)270 +953 y(section)g(2.5.8)g Fp(Rules)g(in)f(P)l(ostgr)n(eSQL)p +Ft(.)270 1107 y Fh(3.4.1)59 b(The)15 b(Rewrite)e(System)270 +1205 y Ft(The)g Fp(query)g(r)n(e)o(write)h Ft(system)e(is)h(a)g(module) +e(between)i(the)f Fp(parser)h(stage)f Ft(and)g(the)h +Fp(planner/optimizer)p Ft(.)270 1264 y(It)e(processes)h(the)g(tree)f +(handed)g(back)g(by)h(the)f Fp(parser)h(stage)f Ft(\(which)f +(represents)i(a)f(user)h(query\))e(and)i(if)270 1324 +y(there)h(is)g(a)h Fp(rule)f Ft(present)h(that)f(has)g(to)g(be)h +(applied)f(to)g(the)g(query)g(it)g Fp(r)n(e)o(writes)i +Ft(the)e(tree)g(to)g(an)g(alternate)270 1384 y(form.)270 +1528 y Fn(T)-5 b(echniques)12 b(T)-5 b(o)13 b(Implement)g(V)n(iews)270 +1625 y Ft(No)o(w)f(will)h(sketch)f(the)h(algorithm)f(of)g(the)h +Fp(query)g(r)n(e)o(write)h(system)p Ft(.)k(F)o(or)12 +b(better)g(illustration)g(we)h(sho)o(w)270 1685 y(ho)o(w)f(to)g +(implement)g Fp(vie)o(ws)h Ft(using)g(rules)f(as)h(an)f(e)o(xample.)270 +1805 y(Let)h(the)f(follo)o(wing)f Fp(rule)i Ft(be)f(gi)o(v)o(en:)330 +1913 y Fr(create)29 b(rule)g(view_rule)330 1972 y(as)g(on)h(select)330 +2032 y(to)f(test_view)330 2092 y(do)g(instead)419 2152 +y(select)h(s.sname,)f(p.pname)419 2211 y(from)h(supplier)f(s,)h(sells)f +(se,)g(part)h(p)419 2271 y(where)g(s.sno)f(=)h(se.sno)f(and)599 +2331 y(p.pno)g(=)h(se.pno;)270 2437 y Ft(The)22 b(gi)o(v)o(en)f +Fp(rule)h Ft(will)f(be)g Fp(\002r)n(ed)h Ft(whene)o(v)o(er)f(a)h +Fr(select)e Ft(against)i(the)f Fp(r)n(elation)g Fr(test)p +1881 2437 15 2 v 18 w(view)g Ft(is)270 2497 y(detected.)16 +b(Instead)c(of)f(selecting)h(the)g(tuples)g(from)f Fr(test)p +1298 2497 V 17 w(view)h Ft(the)f Fr(select)h Ft(statement)g(gi)o(v)o +(en)f(in)270 2556 y(the)h Fp(action)g(part)h Ft(of)f(the)g +Fp(rule)h Ft(is)f(e)o(x)o(ecuted.)270 2676 y(Let)h(the)f(follo)o(wing)f +(user)o(-query)h(against)g Fr(test)p 1128 2676 V 17 w(view)g +Ft(be)h(gi)o(v)o(en:)330 2784 y Fr(select)29 b(sname)330 +2844 y(from)g(test_view)330 2903 y(where)g(sname)g(<>)h('Smith';)270 +3009 y Ft(Here)17 b(is)g(a)g(list)g(of)f(the)h(steps)g(performed)f(by)g +(the)h Fp(query)h(r)n(e)o(write)g(system)f Ft(whene)o(v)o(er)g(a)g +(user)o(-query)270 3069 y(against)k Fr(test)p 555 3069 +V 17 w(view)g Ft(appears.)41 b(\(The)21 b(follo)o(wing)e(listing)h(is)h +(a)g(v)o(ery)g(informal)e(description)i(of)270 3129 y(the)e(algorithm)f +(just)h(intended)f(for)g(basic)i(understanding.)35 b(F)o(or)18 +b(a)h(detailed)g(description)f(refer)g(to)270 3189 y([ST)o(ON89]\).)345 +3294 y Fo(\017)25 b Ft(T)l(ake)12 b(the)g(query)g(gi)o(v)o(en)g(in)h +(the)f Fp(action)g(part)g Ft(of)g(the)h Fp(rule)p Ft(.)345 +3402 y Fo(\017)25 b Ft(Adapt)9 b(the)g Fp(tar)n(getlist)g +Ft(to)h(meet)f(the)h(number)e(and)i(order)f(of)g(attrib)o(utes)g(gi)o +(v)o(en)g(in)g(the)h(user)o(-query)m(.)p eop +%%Page: 59 59 +59 58 bop 198 60 a Fm(3.5.)29 b(PLANNER/OPTIMIZER)1139 +b Ft(59)273 234 y Fo(\017)25 b Ft(Add)12 b(the)g(quali\002cation)f(gi)o +(v)o(en)i(in)f(the)g Fp(wher)n(e)h(clause)g Ft(of)f(the)g(user)o +(-query)g(to)g(the)g(quali\002cation)323 294 y(of)f(the)i(query)f(gi)o +(v)o(en)g(in)g(the)g Fp(action)g(part)h Ft(of)f(the)g +Fp(rule)p Ft(.)198 394 y(Gi)o(v)o(en)e(the)g Fp(rule)g(de\002nition)g +Ft(abo)o(v)o(e,)h(the)f(user)o(-query)f(will)h(be)g(re)o(written)f(to)h +(the)g(follo)o(wing)f(form)g(\(Note)198 454 y(that)14 +b(the)h Fp(r)n(e)o(writing)g Ft(is)g(done)f(on)h(the)f(internal)g +(representation)g(of)g(the)g(user)o(-query)g(handed)h(back)f(by)198 +513 y(the)e Fp(parser)h(stage)f Ft(b)o(ut)g(the)g(deri)o(v)o(ed)g(ne)o +(w)g(data)h(structure)f(will)g(represent)g(the)g(follo)o(wing)f +(query\):)258 614 y Fr(select)29 b(s.sname)258 673 y(from)g(supplier)g +(s,)h(sells)f(se,)h(part)f(p)258 733 y(where)g(s.sno)g(=)h(se.sno)f +(and)437 793 y(p.pno)g(=)h(se.pno)f(and)437 853 y(s.sname)g(<>)h +('Smith;)198 1022 y Fi(3.5)71 b(Planner/Optimizer)198 +1133 y Ft(The)10 b(task)h(of)e(the)h Fp(planner/optimizer)g +Ft(is)g(to)f(create)h(an)g(optimal)f Fp(e)o(xecution)h(plan)p +Ft(.)15 b(It)9 b(\002rst)g(combines)h(all)198 1193 y(possible)k(ways)f +(of)g Fp(scanning)g Ft(and)g Fp(joining)g Ft(the)g Fp(r)n(elations)h +Ft(that)f(appear)g(in)g(a)g(query)m(.)18 b(All)13 b(the)g(created)198 +1253 y(paths)h(lead)g(to)g(the)g(same)g(result)g(and)g(it')m(s)f(the)h +Fp(optimizer')n(s)g Ft(task)h(to)e(estimate)h(the)g(cost)g(of)g(e)o(x)o +(ecuting)198 1313 y(each)f(path)f(and)g(\002nd)g(out)g(which)h(one)f +(is)h(the)f(cheapest.)198 1456 y Fh(3.5.1)59 b(Generating)13 +b(P)o(ossible)h(Plans)198 1550 y Ft(The)j Fp(planner/optimizer)f +Ft(decides)h(which)f(plans)g(should)g(be)g(generated)g(based)h(upon)f +(the)g(types)h(of)198 1609 y(indices)g(de\002ned)g(on)g(the)g +(relations)g(appearing)g(in)g(a)g(query)m(.)29 b(There)18 +b(is)f(always)g(the)g(possibility)g(of)198 1669 y(performing)10 +b(a)j Fp(sequential)f(scan)g Ft(on)g(a)h(relation,)f(so)g(a)g +Fp(plan)g Ft(using)g(only)g Fp(sequential)g(scans)h Ft(is)g(always)198 +1729 y(created.)j(Assume)c(an)h(inde)o(x)f(is)g(de\002ned)g(on)g(a)h +(relation)e(\(for)g(e)o(xample)h(a)h(B-tree)e(inde)o(x\))h(and)g(a)h +(query)198 1789 y(contains)20 b(the)f(restriction)g Fp(r)n +(elation.attrib)o(ute)12 b(OPR)i(constant)o Ft(.)38 b(If)19 +b Fp(r)n(elation.attrib)o(ute)g Ft(happens)h(to)198 1848 +y(match)e(the)g(ke)o(y)f(of)h(the)g(B-tree)f(inde)o(x)h(and)g +Fp(OPR)h Ft(is)f(an)o(ything)f(b)o(ut)h(')p Fo(6)p Fl(=)p +Ft(')f(another)g(plan)h(is)g(created)198 1908 y(using)h(the)f(B-tree)h +(inde)o(x)f(to)h(scan)g(the)g(relation.)34 b(If)18 b(there)g(are)h +(further)e(indices)i(present)f(and)h(the)198 1968 y(restrictions)10 +b(in)h(the)g(query)g(happen)f(to)h(match)g(a)g(ke)o(y)g(of)f(an)h(inde) +o(x)g(further)f(plans)h(will)g(be)g(considered.)273 2028 +y(After)g(all)h(feasible)h(plans)f(ha)o(v)o(e)h(been)g(found)e(for)h +(scanning)g(single)h Fp(r)n(elations)p Ft(,)g(plans)f(for)g(joining)198 +2088 y Fp(r)n(elations)i Ft(are)f(created.)20 b(The)14 +b Fp(planner/optimizer)g Ft(considers)f(only)h(joins)f(between)h(e)o(v) +o(ery)f(two)g Fp(r)n(ela-)198 2147 y(tions)j Ft(for)g(which)g(there)h +(e)o(xists)g(a)g(corresponding)e Fp(join)h(clause)h Ft(\(i.e.)28 +b(for)16 b(which)g(a)h(restriction)f(like)198 2207 y +Fk(:)8 b(:)g(:)18 b Fp(wher)n(e)g(r)n(el1.attr1=r)n(el2.attr2)h +Ft(e)o(xists\))f(in)f(the)h Fp(wher)n(e)g(quali\002cation)p +Ft(.)30 b(All)18 b(possible)f(plans)h(are)198 2267 y(generated)13 +b(for)g(e)o(v)o(ery)h(join)f(pair)g(considered)h(by)f(the)h +Fp(planner/optimizer)p Ft(.)20 b(The)14 b(three)f(possible)h(join)198 +2327 y(strate)o(gies)f(are:)273 2427 y Fo(\017)25 b Fp(nested)13 +b(iter)o(ation)g(join)p Ft(:)j(The)e(right)e Fp(r)n(elation)h +Ft(is)h(scanned)g(once)f(for)f(e)o(v)o(ery)h(tuple)g(found)f(in)h(the) +323 2487 y(left)e Fp(r)n(elation)p Ft(.)16 b(This)d(strate)o(gy)g(is)f +(easy)h(to)f(implement)g(b)o(ut)g(can)h(be)f(v)o(ery)g(time)g +(consuming.)273 2587 y Fo(\017)25 b Fp(mer)n(ge)15 b(sort)g(join)p +Ft(:)20 b(Each)c(relation)e(is)h(sorted)g(on)g(the)g +Fp(join)g(attrib)o(utes)g Ft(before)f(the)h(join)f(starts.)323 +2647 y(Then)i(the)h(two)e(relations)i(are)f Fp(mer)n(ged)g(together)g +Ft(taking)g(into)g(account)g(that)h(both)f Fp(r)n(elations)323 +2706 y Ft(are)d(ordered)f(on)h(the)g Fp(join)g(attrib)o(utes)p +Ft(.)18 b(This)c(kind)f(of)g(join)g(is)g(more)g(attracti)o(v)o(e)f +(because)i(e)o(v)o(ery)323 2766 y Fp(r)n(elation)e Ft(has)h(to)f(be)g +(scanned)h(only)f(once.)273 2866 y Fo(\017)25 b Fp(hash)11 +b(join)p Ft(:)j(the)d(right)f Fp(r)n(elation)h Ft(is)g(\002rst)g +(hashed)g(on)g(its)g Fp(join)g(attrib)o(utes)p Ft(.)k(Ne)o(xt)d(the)f +(left)f Fp(r)n(elation)323 2926 y Ft(is)k(scanned)i(and)e(the)h +(appropriate)e(v)o(alues)i(of)f(e)o(v)o(ery)g(tuple)h(found)e(are)i +(used)g(as)g Fp(hash)g(ke)o(ys)f Ft(to)323 2986 y(locate)e(the)g +(tuples)h(in)f(the)g(right)g Fp(r)n(elation)p Ft(.)198 +3129 y Fh(3.5.2)59 b(Data)15 b(Structur)o(e)f(of)g(the)h(Plan)198 +3223 y Ft(Here)e(we)g(will)g(gi)o(v)o(e)g(a)h(little)f(description)f +(of)h(the)g(nodes)h(appearing)e(in)i(the)f Fp(plan)p +Ft(.)18 b(Figure)12 b(3.6)i(sho)o(ws)198 3283 y(the)e +Fp(plan)g Ft(produced)g(for)g(the)g(query)g(in)g(e)o(xample)h(3.1.)273 +3342 y(The)d(top)g(node)g(of)g(the)g Fp(plan)f Ft(is)i(a)f +Fr(MergeJoin)f Ft(node)h(which)g(has)g(two)g(successors,)i(one)e +(attached)198 3402 y(to)18 b(the)f(\002eld)h Fr(lefttree)f +Ft(and)h(the)f(second)i(attached)e(to)h(the)g(\002eld)f +Fr(righttree)p Ft(.)31 b(Each)19 b(of)e(the)p eop +%%Page: 60 60 +60 59 bop 270 60 a Ft(60)82 b Fm(CHAPTER)14 b(3.)28 b(POSTGRESQL)13 +b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW)270 +234 y Ft(subnodes)f(represents)f(one)g Fp(r)n(elation)h +Ft(of)f(the)g(join.)15 b(As)10 b(mentioned)g(abo)o(v)o(e)h(a)f +Fp(mer)n(ge)h(sort)g(join)f Ft(requires)270 294 y(each)h +Fp(r)n(elation)f Ft(to)g(be)g(sorted.)15 b(That')m(s)c(why)f(we)h +(\002nd)e(a)i Fr(Sort)f Ft(node)g(in)g(each)h(subplan.)k(The)c +(additional)270 354 y(quali\002cation)19 b(gi)o(v)o(en)g(in)g(the)h +(query)f(\()p Fk(s:sno)27 b(>)f Fl(2)p Ft(\))20 b(is)f(pushed)h(do)o +(wn)f(as)h(far)e(as)i(possible)g(and)g(is)270 413 y(attached)12 +b(to)h(the)f Fr(qpqual)g Ft(\002eld)g(of)g(the)g(leaf)g +Fr(SeqScan)g Ft(node)g(of)g(the)g(corresponding)g(subplan.)345 +494 y(The)k(list)f(attached)g(to)g(the)h(\002eld)f Fr(mergeclauses)f +Ft(of)g(the)i Fr(MergeJoin)e Ft(node)h(contains)h(in-)270 +554 y(formation)e(about)h(the)g Fr(join)30 b(attributes)p +Ft(.)23 b(The)16 b(v)o(alues)g Fl(65000)f Ft(and)g Fl(65001)g +Ft(for)f(the)i Fr(varno)270 613 y Ft(\002elds)f(in)f(the)h +Fr(VAR)g Ft(nodes)g(appearing)f(in)h(the)g Fr(mergeclauses)e +Ft(list)i(\(and)f(also)h(in)g(the)g Fp(tar)n(getlist)p +Ft(\))270 673 y(mean)d(that)g(not)g(the)g(tuples)g(of)g(the)g(current)f +(node)i(should)f(be)g(considered)g(b)o(ut)g(the)g(tuples)g(of)g(the)g +(ne)o(xt)270 733 y(\224deeper\224)g(nodes)h(\(i.e.)j(the)c(top)g(nodes) +h(of)f(the)g(subplans\))h(should)f(be)h(used)f(instead.)345 +813 y(Note)i(that)g(e)o(v)o(ery)h Fr(Sort)f Ft(and)g +Fr(SeqScan)g Ft(node)h(appearing)f(in)g(\002gure)g(3.6)g(has)h(got)g(a) +f Fp(tar)n(getlist)270 873 y Ft(b)o(ut)g(because)h(there)g(was)f(not)g +(enough)h(space)g(only)f(the)g(one)h(for)e(the)i Fr(MergeJoin)e +Ft(node)i(could)f(be)270 933 y(dra)o(wn.)345 1013 y(Another)c(task)i +(performed)d(by)i(the)g Fp(planner/optimizer)g Ft(is)h(\002xing)e(the)h +Fp(oper)o(ator)h(ids)f Ft(in)g(the)g Fr(Expr)270 1073 +y Ft(and)16 b Fr(Oper)h Ft(nodes.)28 b(As)17 b(mentioned)e(earlier)n(,) +j(PostgreSQL)e(supports)g(a)h(v)o(ariety)e(of)h(dif)o(ferent)f(data)270 +1133 y(types)f(and)f(e)o(v)o(en)g(user)h(de\002ned)f(types)g(can)h(be)f +(used.)20 b(T)l(o)13 b(be)h(able)f(to)g(maintain)g(the)g(huge)h(amount) +f(of)270 1193 y(functions)h(and)g(operators)g(it)g(is)h(necessary)g(to) +f(store)h(them)f(in)g(a)h Fp(system)g(table)p Ft(.)22 +b(Each)15 b(function)e(and)270 1253 y(operator)e(gets)i(a)g(unique)f +Fp(oper)o(ator)h(id)p Ft(.)j(According)11 b(to)h(the)h(types)f(of)g +(the)h(attrib)o(utes)f(used)g(within)g(the)270 1312 y(quali\002cations) +g(etc.,)h(the)g(appropriate)e Fp(oper)o(ator)i(ids)g +Ft(ha)o(v)o(e)f(to)h(be)f(used.)270 1594 y Fi(3.6)71 +b(Executor)270 1745 y Ft(The)12 b Fp(e)o(xecutor)f Ft(takes)g(the)g +Fp(plan)g Ft(handed)g(back)g(by)g(the)g Fp(planner/optimizer)g +Ft(and)g(starts)g(processing)g(the)270 1804 y(top)16 +b(node.)27 b(In)15 b(the)h(case)h(of)f(our)f(e)o(xample)i(\(the)e +(query)h(gi)o(v)o(en)g(in)g(e)o(xample)g(3.1\))g(the)g(top)g(node)g(is) +g(a)270 1864 y Fr(MergeJoin)11 b Ft(node.)345 1945 y(Before)i(an)o(y)h +(mer)o(ge)f(can)g(be)h(done)f(two)g(tuples)h(ha)o(v)o(e)g(to)f(be)h +(fetched)f(\(one)g(from)f(each)i(subplan\).)270 2004 +y(So)i(the)g Fp(e)o(xecutor)h Ft(recursi)o(v)o(ely)f(calls)g(itself)g +(to)g(process)h(the)f(subplans)h(\(it)e(starts)i(with)f(the)g(subplan) +270 2064 y(attached)10 b(to)g Fr(lefttree)p Ft(\).)j(The)e(ne)o(w)f +(top)f(node)h(\(the)g(top)f(node)h(of)g(the)f(left)h(subplan\))f(is)i +(a)f Fr(SeqScan)270 2124 y Ft(node)19 b(and)f(again)h(a)g(tuple)f(has)h +(to)g(be)g(fetched)f(before)g(the)h(node)f(itself)h(can)f(be)h +(processed.)36 b(The)270 2184 y Fp(e)o(xecutor)13 b Ft(calls)g(itself)f +(recursi)o(v)o(ely)f(another)h(time)g(for)g(the)g(subplan)g(attached)h +(to)f Fr(lefttree)f Ft(of)h(the)270 2244 y Fr(SeqScan)g +Ft(node.)345 2324 y(No)o(w)g(the)g(ne)o(w)g(top)h(node)f(is)h(a)f +Fr(Sort)g Ft(node.)k(As)d(a)g(sort)f(has)h(to)f(be)g(done)h(on)f(the)g +(whole)h Fp(r)n(elation)p Ft(,)270 2384 y(the)18 b Fp(e)o(xecutor)h +Ft(starts)f(fetching)f(tuples)h(from)f(the)h Fr(Sort)g +Ft(node')m(s)g(subplan)g(and)g(sorts)h(them)e(into)h(a)270 +2444 y(temporary)13 b(relation)h(\(in)f(memory)h(or)f(a)i(\002le\))e +(when)i(the)f Fr(Sort)g Ft(node)g(is)g(visited)h(for)e(the)h(\002rst)g +(time.)270 2503 y(\(Further)e(e)o(xaminations)i(of)g(the)g +Fr(Sort)f Ft(node)h(will)g(always)f(return)g(just)h(one)g(tuple)g(from) +e(the)i(sorted)270 2563 y(temporary)d Fp(r)n(elation)p +Ft(.\))345 2644 y(Ev)o(ery)k(time)g(the)g(processing)g(of)f(the)h +Fr(Sort)g Ft(node)g(needs)g(a)h(ne)o(w)e(tuple)h(the)g +Fp(e)o(xecutor)h Ft(is)f(recur)o(-)270 2703 y(si)o(v)o(ely)i(called)g +(for)f(the)g Fr(SeqScan)g Ft(node)h(attached)g(as)g(subplan.)29 +b(The)17 b Fp(r)n(elation)g Ft(\(internally)e(refer)o(-)270 +2763 y(enced)i(by)g(the)f(v)o(alue)h(gi)o(v)o(en)f(in)h(the)f +Fr(scanrelid)g Ft(\002eld\))g(is)h(scanned)g(for)f(the)h(ne)o(xt)g +(tuple.)28 b(If)16 b(the)270 2823 y(tuple)h(satis\002es)h(the)f +(quali\002cation)g(gi)o(v)o(en)g(by)g(the)g(tree)g(attached)h(to)f +Fr(qpqual)g Ft(it)g(is)g(handed)h(back,)270 2883 y(otherwise)12 +b(the)h(ne)o(xt)f(tuple)h(is)g(fetched)f(until)g(the)g(quali\002cation) +g(is)h(satis\002ed.)k(If)11 b(the)i(last)g(tuple)f(of)g(the)270 +2942 y Fp(r)n(elation)g Ft(has)h(been)g(processed)g(a)f +Fr(NULL)g Ft(pointer)g(is)g(returned.)345 3023 y(After)23 +b(a)i(tuple)f(has)h(been)f(handed)h(back)f(by)g(the)h +Fr(lefttree)e Ft(of)h(the)h Fr(MergeJoin)e Ft(the)270 +3083 y Fr(righttree)16 b Ft(is)h(processed)g(in)g(the)g(same)g(way)m(.) +28 b(If)17 b(both)f(tuples)h(are)g(present)f(the)h(e)o(x)o(ecutor)g +(pro-)270 3142 y(cesses)d(the)e Fr(MergeJoin)f Ft(node.)16 +b(Whene)o(v)o(er)c(a)h(ne)o(w)f(tuple)g(from)f(one)h(of)g(the)g +(subplans)h(is)f(needed)h(a)270 3202 y(recursi)o(v)o(e)g(call)f(to)h +(the)g Fp(e)o(xecutor)h Ft(is)f(performed)e(to)i(obtain)f(it.)18 +b(If)12 b(a)h Fp(joined)f Ft(tuple)h(could)g(be)g(created)f(it)270 +3262 y(is)h(handed)f(back)g(and)h(one)f(complete)g(processing)h(of)f +(the)g Fp(plan)g(tr)n(ee)h Ft(has)g(\002nished.)345 3342 +y(No)o(w)j(the)g(described)g(steps)h(are)f(performed)f(once)h(for)g(e)o +(v)o(ery)g(tuple,)h(until)f(a)g Fr(NULL)g Ft(pointer)g(is)270 +3402 y(returned)11 b(for)h(the)g(processing)h(of)f(the)g +Fr(MergeJoin)g Ft(node,)g(indicating)g(that)g(we)h(are)f(\002nished.)p +eop +%%Page: 61 61 +61 60 bop 198 60 a Fm(3.6.)29 b(EXECUT)o(OR)1384 b Ft(61)243 +3011 y @beginspecial 135 @llx 135 @lly 477 @urx 656 @ury +3420 @rwi @setspecial +%%BeginDocument: figures/plan.ps +%Magnification: 1.05 +/$F2psDict 200 dict def +$F2psDict begin +$F2psDict /mtrx matrix put +/col-1 {0 setgray} bind def +/col0 {0.000 0.000 0.000 srgb} bind def +/col1 {0.000 0.000 1.000 srgb} bind def +/col2 {0.000 1.000 0.000 srgb} bind def +/col3 {0.000 1.000 1.000 srgb} bind def +/col4 {1.000 0.000 0.000 srgb} bind def +/col5 {1.000 0.000 1.000 srgb} bind def +/col6 {1.000 1.000 0.000 srgb} bind def +/col7 {1.000 1.000 1.000 srgb} bind def +/col8 {0.000 0.000 0.560 srgb} bind def +/col9 {0.000 0.000 0.690 srgb} bind def +/col10 {0.000 0.000 0.820 srgb} bind def +/col11 {0.530 0.810 1.000 srgb} bind def +/col12 {0.000 0.560 0.000 srgb} bind def +/col13 {0.000 0.690 0.000 srgb} bind def +/col14 {0.000 0.820 0.000 srgb} bind def +/col15 {0.000 0.560 0.560 srgb} bind def +/col16 {0.000 0.690 0.690 srgb} bind def +/col17 {0.000 0.820 0.820 srgb} bind def +/col18 {0.560 0.000 0.000 srgb} bind def +/col19 {0.690 0.000 0.000 srgb} bind def +/col20 {0.820 0.000 0.000 srgb} bind def +/col21 {0.560 0.000 0.560 srgb} bind def +/col22 {0.690 0.000 0.690 srgb} bind def +/col23 {0.820 0.000 0.820 srgb} bind def +/col24 {0.500 0.190 0.000 srgb} bind def +/col25 {0.630 0.250 0.000 srgb} bind def +/col26 {0.750 0.380 0.000 srgb} bind def +/col27 {1.000 0.500 0.500 srgb} bind def +/col28 {1.000 0.630 0.630 srgb} bind def +/col29 {1.000 0.750 0.750 srgb} bind def +/col30 {1.000 0.880 0.880 srgb} bind def +/col31 {1.000 0.840 0.000 srgb} bind def + +end +save +116.0 655.5 translate +1 -1 scale + +/cp {closepath} bind def +/ef {eofill} bind def +/gr {grestore} bind def +/gs {gsave} bind def +/sa {save} bind def +/rs {restore} bind def +/l {lineto} bind def +/m {moveto} bind def +/rm {rmoveto} bind def +/n {newpath} bind def +/s {stroke} bind def +/sh {show} bind def +/slc {setlinecap} bind def +/slj {setlinejoin} bind def +/slw {setlinewidth} bind def +/srgb {setrgbcolor} bind def +/rot {rotate} bind def +/sc {scale} bind def +/sd {setdash} bind def +/ff {findfont} bind def +/sf {setfont} bind def +/scf {scalefont} bind def +/sw {stringwidth} bind def +/tr {translate} bind def +/tnt {dup dup currentrgbcolor + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add srgb} + bind def +/shd {dup dup currentrgbcolor 4 -2 roll mul 4 -2 roll mul + 4 -2 roll mul srgb} bind def + /DrawSplineSection { + /y3 exch def + /x3 exch def + /y2 exch def + /x2 exch def + /y1 exch def + /x1 exch def + /xa x1 x2 x1 sub 0.666667 mul add def + /ya y1 y2 y1 sub 0.666667 mul add def + /xb x3 x2 x3 sub 0.666667 mul add def + /yb y3 y2 y3 sub 0.666667 mul add def + x1 y1 lineto + xa ya xb yb x3 y3 curveto + } def + +/$F2psBegin {$F2psDict begin /$F2psEnteredState save def} def +/$F2psEnd {$F2psEnteredState restore end} def + +$F2psBegin +10 setmiterlimit +n 0 792 m 0 0 l 612 0 l 612 792 l cp clip + 0.06299 0.06299 sc +7.500 slw +% Polyline +n 315 2025 m 1215 2025 l 1215 2790 l 315 2790 l cp gs col-1 s gr +% Polyline +n 315 2250 m 1215 2250 l gs col-1 s gr +% Polyline +n 315 2520 m 1215 2520 l gs col-1 s gr +% Polyline +n 945 2250 m 945 2790 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +495 2205 m +gs 1 -1 sc (SeqScan) col-1 sh gr +/Times-Roman ff 150.00 scf sf +405 2700 m +gs 1 -1 sc (lefttree) col-1 sh gr +/Times-Roman ff 150.00 scf sf +675 2475 m +gs 1 -1 sc 90.0 rot (. . . ) col-1 sh gr +% Polyline +n 630 3150 m 1530 3150 l 1530 3915 l 630 3915 l cp gs col-1 s gr +% Polyline +n 630 3375 m 1530 3375 l gs col-1 s gr +% Polyline +n 630 3645 m 1530 3645 l gs col-1 s gr +% Polyline +n 1260 3375 m 1260 3915 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +720 3825 m +gs 1 -1 sc (lefttree) col-1 sh gr +/Times-Roman ff 150.00 scf sf +990 3600 m +gs 1 -1 sc 90.0 rot (. . . ) col-1 sh gr +/Times-Roman ff 150.00 scf sf +945 3330 m +gs 1 -1 sc (Sort) col-1 sh gr +% Polyline +gs clippath +1110 3003 m 1080 3123 l 1050 3003 l 1050 3165 l 1110 3165 l cp clip +n 1080 2655 m 1080 3150 l gs col-1 s gr gr + +% arrowhead +n 1110 3003 m 1080 3123 l 1050 3003 l 1080 3003 l 1110 3003 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +1425 4128 m 1395 4248 l 1365 4128 l 1365 4290 l 1425 4290 l cp clip +n 1395 3780 m 1395 4275 l gs col-1 s gr gr + +% arrowhead +n 1425 4128 m 1395 4248 l 1365 4128 l 1395 4128 l 1425 4128 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 945 4500 m 1845 4500 l gs col-1 s gr +% Polyline +n 945 4770 m 1845 4770 l gs col-1 s gr +% Polyline +n 1575 5310 m 1575 5580 l gs col-1 s gr +% Polyline +n 945 4275 m 1845 4275 l 1845 5580 l 945 5580 l cp gs col-1 s gr +% Polyline +n 945 5040 m 1845 5040 l gs col-1 s gr +% Polyline +n 945 5310 m 1845 5310 l gs col-1 s gr +% Polyline +n 1845 5310 m 1575 5580 l gs col-1 s gr +% Polyline +n 1575 5310 m 1845 5580 l gs col-1 s gr +% Polyline +n 1575 4500 m 1575 5040 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +1125 4455 m +gs 1 -1 sc (SeqScan) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1305 4725 m +gs 1 -1 sc 90.0 rot (. . . ) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1035 5490 m +gs 1 -1 sc (lefttree) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1035 4950 m +gs 1 -1 sc (qpqual) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1035 5220 m +gs 1 -1 sc (scanrelid: 1) col-1 sh gr +% Polyline +n 4590 5400 m 4590 5670 l gs col-1 s gr +% Polyline +n 4320 5400 m 4860 5400 l 4860 5670 l 4320 5670 l cp gs col-1 s gr +% Polyline +n 5355 5400 m 5355 5670 l gs col-1 s gr +% Polyline +n 5085 5400 m 5625 5400 l 5625 5670 l 5085 5670 l cp gs col-1 s gr +% Polyline +n 5355 5400 m 5625 5670 l gs col-1 s gr +% Polyline +n 5625 5400 m 5355 5670 l gs col-1 s gr +% Polyline +n 2430 855 m 2430 1125 l gs col-1 s gr +% Polyline +n 2430 855 m 2700 1125 l gs col-1 s gr +% Polyline +n 2700 855 m 2430 1125 l gs col-1 s gr +% Polyline +n 2160 855 m 2700 855 l 2700 1125 l 2160 1125 l cp gs col-1 s gr +% Polyline +n 1575 2025 m 2475 2025 l 2475 2790 l 1575 2790 l cp gs col-1 s gr +% Polyline +n 1575 2250 m 2475 2250 l gs col-1 s gr +% Polyline +n 1575 2520 m 2475 2520 l gs col-1 s gr +% Polyline +n 2205 2250 m 2205 2790 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +1755 2205 m +gs 1 -1 sc (SeqScan) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1665 2700 m +gs 1 -1 sc (lefttree) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1935 2475 m +gs 1 -1 sc 90.0 rot (. . . ) col-1 sh gr +% Polyline +n 1890 3150 m 2790 3150 l 2790 3915 l 1890 3915 l cp gs col-1 s gr +% Polyline +n 1890 3375 m 2790 3375 l gs col-1 s gr +% Polyline +n 1890 3645 m 2790 3645 l gs col-1 s gr +% Polyline +n 2520 3375 m 2520 3915 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +1980 3825 m +gs 1 -1 sc (lefttree) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2250 3600 m +gs 1 -1 sc 90.0 rot (. . . ) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2205 3330 m +gs 1 -1 sc (Sort) col-1 sh gr +% Polyline +n 3105 225 m 3645 225 l 3645 495 l 3105 495 l cp gs col-1 s gr +% Polyline +n 3375 225 m 3375 495 l gs col-1 s gr +% Polyline +n 3915 225 m 4455 225 l 4455 495 l 3915 495 l cp gs col-1 s gr +% Polyline +n 4185 225 m 4185 495 l gs col-1 s gr +% Polyline +n 4455 495 m 4185 225 l gs col-1 s gr +% Polyline +n 4455 225 m 4185 495 l gs col-1 s gr +% Polyline +n 3240 945 m 4140 945 l 4140 1710 l 3240 1710 l cp gs col-1 s gr +% Polyline +n 3240 1170 m 4140 1170 l gs col-1 s gr +% Polyline +n 3240 1440 m 4140 1440 l gs col-1 s gr +% Polyline +n 3870 1170 m 3870 1710 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +3555 1125 m +gs 1 -1 sc (TLE) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3330 1620 m +gs 1 -1 sc (expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3330 1350 m +gs 1 -1 sc (resdom) col-1 sh gr +% Polyline +n 4590 945 m 5490 945 l 5490 1710 l 4590 1710 l cp gs col-1 s gr +% Polyline +n 4590 1170 m 5490 1170 l gs col-1 s gr +% Polyline +n 4590 1440 m 5490 1440 l gs col-1 s gr +% Polyline +n 5220 1170 m 5220 1710 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +4905 1125 m +gs 1 -1 sc (TLE) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4680 1620 m +gs 1 -1 sc (expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4680 1350 m +gs 1 -1 sc (resdom) col-1 sh gr +% Polyline +n 2655 6885 m 2655 7155 l gs col-1 s gr +% Polyline +n 2385 6885 m 2925 6885 l 2925 7155 l 2385 7155 l cp gs col-1 s gr +% Polyline +n 3420 6885 m 3420 7155 l gs col-1 s gr +% Polyline +n 3150 6885 m 3690 6885 l 3690 7155 l 3150 7155 l cp gs col-1 s gr +% Polyline +n 3420 6885 m 3690 7155 l gs col-1 s gr +% Polyline +n 3690 6885 m 3420 7155 l gs col-1 s gr +% Polyline +gs clippath +4938 5505 m 5058 5535 l 4938 5565 l 5100 5565 l 5100 5505 l cp clip +n 4725 5535 m 5085 5535 l gs col-1 s gr gr + +% arrowhead +n 4938 5505 m 5058 5535 l 4938 5565 l 4938 5535 l 4938 5505 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 4725 5940 m 5625 5940 l 5625 6705 l 4725 6705 l cp gs col-1 s gr +% Polyline +gs clippath +2013 960 m 2133 990 l 2013 1020 l 2175 1020 l 2175 960 l cp clip +n 1395 990 m 2160 990 l gs col-1 s gr gr + +% arrowhead +n 2013 960 m 2133 990 l 2013 1020 l 2013 990 l 2013 960 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 315 855 m 1530 855 l gs col-1 s gr +% Polyline +n 315 1125 m 1530 1125 l gs col-1 s gr +% Polyline +n 315 1395 m 1530 1395 l gs col-1 s gr +% Polyline +n 315 585 m 1530 585 l gs col-1 s gr +% Polyline +n 315 225 m 1530 225 l gs col-1 s gr +% Polyline +n 2835 4770 m 3105 5040 l gs col-1 s gr +% Polyline +n 3105 4770 m 2835 5040 l gs col-1 s gr +% Polyline +gs clippath +2370 3003 m 2340 3123 l 2310 3003 l 2310 3165 l 2370 3165 l cp clip +n 2340 2655 m 2340 3150 l gs col-1 s gr gr + +% arrowhead +n 2370 3003 m 2340 3123 l 2310 3003 l 2340 3003 l 2370 3003 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +2685 4128 m 2655 4248 l 2625 4128 l 2625 4290 l 2685 4290 l cp clip +n 2655 3780 m 2655 4275 l gs col-1 s gr gr + +% arrowhead +n 2685 4128 m 2655 4248 l 2625 4128 l 2655 4128 l 2685 4128 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 2205 4500 m 3105 4500 l gs col-1 s gr +% Polyline +n 2205 4770 m 3105 4770 l gs col-1 s gr +% Polyline +n 2835 5310 m 2835 5580 l gs col-1 s gr +% Polyline +n 2205 4275 m 3105 4275 l 3105 5580 l 2205 5580 l cp gs col-1 s gr +% Polyline +n 2205 5040 m 3105 5040 l gs col-1 s gr +% Polyline +n 2205 5310 m 3105 5310 l gs col-1 s gr +% Polyline +n 3105 5310 m 2835 5580 l gs col-1 s gr +% Polyline +n 2835 5310 m 3105 5580 l gs col-1 s gr +% Polyline +n 2835 4500 m 2835 5040 l gs col-1 s gr +% Polyline +gs clippath +3768 330 m 3888 360 l 3768 390 l 3930 390 l 3930 330 l cp clip +n 3510 360 m 3915 360 l gs col-1 s gr gr + +% arrowhead +n 3768 330 m 3888 360 l 3768 390 l 3768 360 l 3768 330 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 4500 2250 m 5580 2250 l gs col-1 s gr +% Polyline +n 3150 2250 m 4230 2250 l gs col-1 s gr +% Polyline +n 3150 2025 m 4230 2025 l 4230 2520 l 3150 2520 l cp gs col-1 s gr +% Polyline +n 4500 2025 m 5580 2025 l 5580 2520 l 4500 2520 l cp gs col-1 s gr +% Polyline +n 3240 2835 m 4140 2835 l 4140 3600 l 3240 3600 l cp gs col-1 s gr +% Polyline +n 3240 3060 m 4140 3060 l gs col-1 s gr +% Polyline +n 3240 3330 m 4140 3330 l gs col-1 s gr +% Polyline +n 4590 2835 m 5490 2835 l 5490 3600 l 4590 3600 l cp gs col-1 s gr +% Polyline +n 4590 3060 m 5490 3060 l gs col-1 s gr +% Polyline +n 4590 3330 m 5490 3330 l gs col-1 s gr +% Polyline +n 4725 6165 m 5625 6165 l gs col-1 s gr +% Polyline +n 4725 6435 m 5625 6435 l gs col-1 s gr +% Polyline +n 3600 6165 m 4500 6165 l gs col-1 s gr +% Polyline +n 3600 6435 m 4500 6435 l gs col-1 s gr +% Polyline +n 3600 5940 m 4500 5940 l 4500 6705 l 3600 6705 l cp gs col-1 s gr +% Polyline +n 945 6165 m 1935 6165 l gs col-1 s gr +% Polyline +n 945 6435 m 1935 6435 l gs col-1 s gr +% Polyline +n 945 6705 m 1935 6705 l gs col-1 s gr +% Polyline +n 945 5940 m 1935 5940 l 1935 6975 l 945 6975 l cp gs col-1 s gr +% Polyline +n 1665 6975 m 1665 6435 l gs col-1 s gr +% Polyline +gs clippath +3003 6990 m 3123 7020 l 3003 7050 l 3165 7050 l 3165 6990 l cp clip +n 2790 7020 m 3150 7020 l gs col-1 s gr gr + +% arrowhead +n 3003 6990 m 3123 7020 l 3003 7050 l 3003 7020 l 3003 6990 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 2385 6165 m 3150 6165 l gs col-1 s gr +% Polyline +n 2385 6435 m 3150 6435 l gs col-1 s gr +% Polyline +n 2385 5940 m 3150 5940 l 3150 6705 l 2385 6705 l cp gs col-1 s gr +% Polyline +n 1485 7695 m 2385 7695 l gs col-1 s gr +% Polyline +n 1485 7965 m 2385 7965 l gs col-1 s gr +% Polyline +n 2790 7695 m 3690 7695 l gs col-1 s gr +% Polyline +n 2790 7470 m 3690 7470 l 3690 7965 l 2790 7965 l cp gs col-1 s gr +% Polyline +n 1485 7470 m 2385 7470 l 2385 8235 l 1485 8235 l cp gs col-1 s gr +% Polyline +n 3375 4275 m 4365 4275 l gs col-1 s gr +% Polyline +n 3375 4545 m 4365 4545 l gs col-1 s gr +% Polyline +n 3375 4815 m 4365 4815 l gs col-1 s gr +% Polyline +n 3375 4050 m 4365 4050 l 4365 5085 l 3375 5085 l cp gs col-1 s gr +% Polyline +n 4095 5085 m 4095 4545 l gs col-1 s gr +% Polyline +n 4815 4275 m 5580 4275 l gs col-1 s gr +% Polyline +n 4815 4545 m 5580 4545 l gs col-1 s gr +% Polyline +n 4815 4050 m 5580 4050 l 5580 4815 l 4815 4815 l cp gs col-1 s gr +% Polyline +n 315 0 m 1530 0 l 1530 1665 l 315 1665 l cp gs col-1 s gr +% Polyline +n 1260 225 m 1260 1665 l gs col-1 s gr +% Open spline +gs clippath +750 1878 m 720 1998 l 690 1878 l 690 2040 l 750 2040 l cp clip +n 1395.0 1260.0 m 1462.5 1260.0 l + 1462.5 1260.0 1530.0 1260.0 1597.5 1260.0 DrawSplineSection + 1597.5 1260.0 1665.0 1260.0 1665.0 1327.5 DrawSplineSection + 1665.0 1327.5 1665.0 1395.0 1665.0 1530.0 DrawSplineSection + 1665.0 1530.0 1665.0 1665.0 1665.0 1732.5 DrawSplineSection + 1665.0 1732.5 1665.0 1800.0 1597.5 1800.0 DrawSplineSection + 1597.5 1800.0 1530.0 1800.0 1192.5 1800.0 DrawSplineSection + 1192.5 1800.0 855.0 1800.0 787.5 1800.0 DrawSplineSection + 787.5 1800.0 720.0 1800.0 720.0 1912.5 DrawSplineSection + 720.0 2025.0 l gs col-1 s gr + gr + +% arrowhead +n 750 1878 m 720 1998 l 690 1878 l 720 1878 l 750 1878 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +1547 5834 m 1454 5917 l 1497 5801 l 1407 5936 l 1457 5969 l cp clip +n 1710.0 4905.0 m 1800.0 4905.0 l + 1800.0 4905.0 1890.0 4905.0 1957.5 4905.0 DrawSplineSection + 1957.5 4905.0 2025.0 4905.0 2025.0 4995.0 DrawSplineSection + 2025.0 4995.0 2025.0 5085.0 2025.0 5355.0 DrawSplineSection + 2025.0 5355.0 2025.0 5625.0 2025.0 5692.5 DrawSplineSection + 2025.0 5692.5 2025.0 5760.0 1957.5 5760.0 DrawSplineSection + 1957.5 5760.0 1890.0 5760.0 1755.0 5760.0 DrawSplineSection + 1755.0 5760.0 1620.0 5760.0 1575.0 5782.5 DrawSplineSection + 1575.0 5782.5 1530.0 5805.0 1485.0 5872.5 DrawSplineSection + 1440.0 5940.0 l gs col-1 s gr + gr + +% arrowhead +n 1547 5834 m 1454 5917 l 1497 5801 l 1522 5818 l 1547 5834 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +2055 1878 m 2025 1998 l 1995 1878 l 1995 2040 l 2055 2040 l cp clip +n 1395.0 1530.0 m 1642.5 1530.0 l + 1642.5 1530.0 1890.0 1530.0 1957.5 1530.0 DrawSplineSection + 1957.5 1530.0 2025.0 1530.0 2025.0 1620.0 DrawSplineSection + 2025.0 1620.0 2025.0 1710.0 2025.0 1867.5 DrawSplineSection + 2025.0 2025.0 l gs col-1 s gr + gr + +% arrowhead +n 2055 1878 m 2025 1998 l 1995 1878 l 2025 1878 l 2055 1878 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +5229 5800 m 5179 5913 l 5170 5790 l 5143 5950 l 5202 5960 l cp clip +n 5220.0 5535.0 m 5220.0 5602.5 l + 5220.0 5602.5 5220.0 5670.0 5197.5 5805.0 DrawSplineSection + 5175.0 5940.0 l gs col-1 s gr + gr + +% arrowhead +n 5229 5800 m 5179 5913 l 5170 5790 l 5199 5795 l 5229 5800 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +4175 5857 m 4069 5920 l 4133 5815 l 4018 5929 l 4061 5972 l cp clip +n 4455.0 5535.0 m 4455.0 5647.5 l + 4455.0 5647.5 4455.0 5760.0 4320.0 5782.5 DrawSplineSection + 4320.0 5782.5 4185.0 5805.0 4117.5 5872.5 DrawSplineSection + 4050.0 5940.0 l gs col-1 s gr + gr + +% arrowhead +n 4175 5857 m 4069 5920 l 4133 5815 l 4154 5836 l 4175 5857 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +4620 5253 m 4590 5373 l 4560 5253 l 4560 5415 l 4620 5415 l cp clip +n 4230.0 4950.0 m 4342.5 4950.0 l + 4342.5 4950.0 4455.0 4950.0 4522.5 4950.0 DrawSplineSection + 4522.5 4950.0 4590.0 4950.0 4590.0 5017.5 DrawSplineSection + 4590.0 5017.5 4590.0 5085.0 4590.0 5242.5 DrawSplineSection + 4590.0 5400.0 l gs col-1 s gr + gr + +% arrowhead +n 4620 5253 m 4590 5373 l 4560 5253 l 4590 5253 l 4620 5253 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3843 3902 m 3859 4024 l 3788 3925 l 3848 4075 l 3903 4053 l cp clip +n 2295.0 990.0 m 2340.0 1170.0 l + 2340.0 1170.0 2385.0 1350.0 2587.5 1485.0 DrawSplineSection + 2587.5 1485.0 2790.0 1620.0 2857.5 2677.5 DrawSplineSection + 2857.5 2677.5 2925.0 3735.0 3352.5 3780.0 DrawSplineSection + 3352.5 3780.0 3780.0 3825.0 3825.0 3937.5 DrawSplineSection + 3870.0 4050.0 l gs col-1 s gr + gr + +% arrowhead +n 3843 3902 m 3859 4024 l 3788 3925 l 3815 3914 l 3843 3902 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +2958 330 m 3078 360 l 2958 390 l 3120 390 l 3120 330 l cp clip +n 1395.0 720.0 m 1552.5 720.0 l + 1552.5 720.0 1710.0 720.0 1845.0 540.0 DrawSplineSection + 1845.0 540.0 1980.0 360.0 2542.5 360.0 DrawSplineSection + 3105.0 360.0 l gs col-1 s gr + gr + +% arrowhead +n 2958 330 m 3078 360 l 2958 390 l 2958 360 l 2958 330 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3607 820 m 3670 925 l 3565 862 l 3679 977 l 3722 934 l cp clip +n 3240.0 360.0 m 3307.5 495.0 l + 3307.5 495.0 3375.0 630.0 3532.5 787.5 DrawSplineSection + 3690.0 945.0 l gs col-1 s gr + gr + +% arrowhead +n 3607 820 m 3670 925 l 3565 862 l 3586 841 l 3607 820 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +4957 820 m 5020 925 l 4915 862 l 5029 977 l 5072 934 l cp clip +n 4050.0 360.0 m 4095.0 495.0 l + 4095.0 495.0 4140.0 630.0 4455.0 652.5 DrawSplineSection + 4455.0 652.5 4770.0 675.0 4905.0 810.0 DrawSplineSection + 5040.0 945.0 l gs col-1 s gr + gr + +% arrowhead +n 4957 820 m 5020 925 l 4915 862 l 4936 841 l 4957 820 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3802 1925 m 3706 2003 l 3754 1889 l 3657 2019 l 3705 2055 l cp clip +n 4005.0 1305.0 m 4095.0 1305.0 l + 4095.0 1305.0 4185.0 1305.0 4230.0 1305.0 DrawSplineSection + 4230.0 1305.0 4275.0 1305.0 4275.0 1372.5 DrawSplineSection + 4275.0 1372.5 4275.0 1440.0 4275.0 1575.0 DrawSplineSection + 4275.0 1575.0 4275.0 1710.0 4275.0 1777.5 DrawSplineSection + 4275.0 1777.5 4275.0 1845.0 4207.5 1845.0 DrawSplineSection + 4207.5 1845.0 4140.0 1845.0 4050.0 1845.0 DrawSplineSection + 4050.0 1845.0 3960.0 1845.0 3892.5 1845.0 DrawSplineSection + 3892.5 1845.0 3825.0 1845.0 3757.5 1935.0 DrawSplineSection + 3690.0 2025.0 l gs col-1 s gr + gr + +% arrowhead +n 3802 1925 m 3706 2003 l 3754 1889 l 3778 1907 l 3802 1925 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +5152 1925 m 5056 2003 l 5104 1889 l 5007 2019 l 5055 2055 l cp clip +n 5355.0 1305.0 m 5445.0 1305.0 l + 5445.0 1305.0 5535.0 1305.0 5580.0 1305.0 DrawSplineSection + 5580.0 1305.0 5625.0 1305.0 5625.0 1372.5 DrawSplineSection + 5625.0 1372.5 5625.0 1440.0 5625.0 1575.0 DrawSplineSection + 5625.0 1575.0 5625.0 1710.0 5625.0 1777.5 DrawSplineSection + 5625.0 1777.5 5625.0 1845.0 5557.5 1845.0 DrawSplineSection + 5557.5 1845.0 5490.0 1845.0 5400.0 1845.0 DrawSplineSection + 5400.0 1845.0 5310.0 1845.0 5242.5 1845.0 DrawSplineSection + 5242.5 1845.0 5175.0 1845.0 5107.5 1935.0 DrawSplineSection + 5040.0 2025.0 l gs col-1 s gr + gr + +% arrowhead +n 5152 1925 m 5056 2003 l 5104 1889 l 5128 1907 l 5152 1925 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3815 2752 m 3709 2815 l 3773 2710 l 3658 2824 l 3701 2867 l cp clip +n 4005.0 1575.0 m 4140.0 1575.0 l + 4140.0 1575.0 4275.0 1575.0 4320.0 1575.0 DrawSplineSection + 4320.0 1575.0 4365.0 1575.0 4365.0 1620.0 DrawSplineSection + 4365.0 1620.0 4365.0 1665.0 4365.0 2092.5 DrawSplineSection + 4365.0 2092.5 4365.0 2520.0 4365.0 2610.0 DrawSplineSection + 4365.0 2610.0 4365.0 2700.0 4297.5 2700.0 DrawSplineSection + 4297.5 2700.0 4230.0 2700.0 4027.5 2700.0 DrawSplineSection + 4027.5 2700.0 3825.0 2700.0 3757.5 2767.5 DrawSplineSection + 3690.0 2835.0 l gs col-1 s gr + gr + +% arrowhead +n 3815 2752 m 3709 2815 l 3773 2710 l 3794 2731 l 3815 2752 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +5165 2752 m 5059 2815 l 5123 2710 l 5008 2824 l 5051 2867 l cp clip +n 5355.0 1575.0 m 5467.5 1575.0 l + 5467.5 1575.0 5580.0 1575.0 5647.5 1575.0 DrawSplineSection + 5647.5 1575.0 5715.0 1575.0 5715.0 1620.0 DrawSplineSection + 5715.0 1620.0 5715.0 1665.0 5715.0 2092.5 DrawSplineSection + 5715.0 2092.5 5715.0 2520.0 5715.0 2610.0 DrawSplineSection + 5715.0 2610.0 5715.0 2700.0 5647.5 2700.0 DrawSplineSection + 5647.5 2700.0 5580.0 2700.0 5377.5 2700.0 DrawSplineSection + 5377.5 2700.0 5175.0 2700.0 5107.5 2767.5 DrawSplineSection + 5040.0 2835.0 l gs col-1 s gr + gr + +% arrowhead +n 5165 2752 m 5059 2815 l 5123 2710 l 5144 2731 l 5165 2752 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +2238 6270 m 2358 6300 l 2238 6330 l 2400 6330 l 2400 6270 l cp clip +n 1800.0 6570.0 m 1935.0 6570.0 l + 1935.0 6570.0 2070.0 6570.0 2070.0 6435.0 DrawSplineSection + 2070.0 6435.0 2070.0 6300.0 2227.5 6300.0 DrawSplineSection + 2385.0 6300.0 l gs col-1 s gr + gr + +% arrowhead +n 2238 6270 m 2358 6300 l 2238 6330 l 2238 6300 l 2238 6270 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +2238 6990 m 2358 7020 l 2238 7050 l 2400 7050 l 2400 6990 l cp clip +n 1800.0 6840.0 m 1912.5 6840.0 l + 1912.5 6840.0 2025.0 6840.0 2047.5 6930.0 DrawSplineSection + 2047.5 6930.0 2070.0 7020.0 2227.5 7020.0 DrawSplineSection + 2385.0 7020.0 l gs col-1 s gr + gr + +% arrowhead +n 2238 6990 m 2358 7020 l 2238 7050 l 2238 7020 l 2238 6990 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3298 7332 m 3245 7443 l 3239 7320 l 3208 7479 l 3266 7491 l cp clip +n 3285.0 7020.0 m 3285.0 7132.5 l + 3285.0 7132.5 3285.0 7245.0 3262.5 7357.5 DrawSplineSection + 3240.0 7470.0 l gs col-1 s gr + gr + +% arrowhead +n 3298 7332 m 3245 7443 l 3239 7320 l 3269 7326 l 3298 7332 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +2069 7402 m 1956 7453 l 2031 7355 l 1905 7456 l 1942 7503 l cp clip +n 2520.0 7020.0 m 2520.0 7132.5 l + 2520.0 7132.5 2520.0 7245.0 2340.0 7267.5 DrawSplineSection + 2340.0 7267.5 2160.0 7290.0 2047.5 7380.0 DrawSplineSection + 1935.0 7470.0 l gs col-1 s gr + gr + +% arrowhead +n 2069 7402 m 1956 7453 l 2031 7355 l 2050 7378 l 2069 7402 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +4668 4380 m 4788 4410 l 4668 4440 l 4830 4440 l 4830 4380 l cp clip +n 4230.0 4680.0 m 4365.0 4680.0 l + 4365.0 4680.0 4500.0 4680.0 4500.0 4545.0 DrawSplineSection + 4500.0 4545.0 4500.0 4410.0 4657.5 4410.0 DrawSplineSection + 4815.0 4410.0 l gs col-1 s gr + gr + +% arrowhead +n 4668 4380 m 4788 4410 l 4668 4440 l 4668 4410 l 4668 4380 l cp gs 0.00 setgray ef gr col-1 s +/Times-Roman ff 150.00 scf sf +405 1035 m +gs 1 -1 sc (mergeclauses) col-1 sh gr +/Times-Roman ff 150.00 scf sf +405 1305 m +gs 1 -1 sc (lefttree) col-1 sh gr +/Times-Roman ff 150.00 scf sf +405 1575 m +gs 1 -1 sc (righttree) col-1 sh gr +/Times-Roman ff 150.00 scf sf +405 765 m +gs 1 -1 sc (targetList) col-1 sh gr +/Times-Roman ff 150.00 scf sf +810 495 m +gs 1 -1 sc 90.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2385 4455 m +gs 1 -1 sc (SeqScan) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2565 4725 m +gs 1 -1 sc 90.0 rot (. . . ) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2295 5490 m +gs 1 -1 sc (lefttree) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2295 4950 m +gs 1 -1 sc (qpqual) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2295 5220 m +gs 1 -1 sc (scanrelid: 2) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4815 2205 m +gs 1 -1 sc (Resdom) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4590 2430 m +gs 1 -1 sc (resname: pno) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3465 2205 m +gs 1 -1 sc (Resdom) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3240 2430 m +gs 1 -1 sc (resname: sname) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3510 3015 m +gs 1 -1 sc (VAR) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4860 3015 m +gs 1 -1 sc (VAR) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4995 6120 m +gs 1 -1 sc (VAR) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4770 6615 m +gs 1 -1 sc (varattno: 1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4770 6345 m +gs 1 -1 sc (varno: 65000) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3870 6120 m +gs 1 -1 sc (VAR) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3645 6615 m +gs 1 -1 sc (varattno: 1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3645 6345 m +gs 1 -1 sc (varno: 65001) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4635 3510 m +gs 1 -1 sc (varattno: 1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4635 3240 m +gs 1 -1 sc (varno: 65000) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3285 3240 m +gs 1 -1 sc (varno: 65001) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3285 3510 m +gs 1 -1 sc (varattno: 1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +585 180 m +gs 1 -1 sc (MergeJoin) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1035 6345 m +gs 1 -1 sc (opType: OP) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1035 6870 m +gs 1 -1 sc (args) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1305 6120 m +gs 1 -1 sc (Expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2610 6120 m +gs 1 -1 sc (Oper) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2475 6345 m +gs 1 -1 sc (opno: 521) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2475 6615 m +gs 1 -1 sc (opid: 147) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1755 7650 m +gs 1 -1 sc (VAR) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1575 7875 m +gs 1 -1 sc (varno: 1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3060 7650 m +gs 1 -1 sc (Const) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1575 8145 m +gs 1 -1 sc (varattno 1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3465 4455 m +gs 1 -1 sc (opType: OP) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3465 4980 m +gs 1 -1 sc (args) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3735 4230 m +gs 1 -1 sc (Expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +5040 4230 m +gs 1 -1 sc (Oper) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4905 4455 m +gs 1 -1 sc (opno: 96) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4905 4725 m +gs 1 -1 sc (opid: 65) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2835 7875 m +gs 1 -1 sc (constvalue: 2) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1035 6630 m +gs 1 -1 sc (oper) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3465 4740 m +gs 1 -1 sc (oper) col-1 sh gr +showpage +$F2psEnd +rs +%%EndDocument + @endspecial 681 3120 a(Figure)12 b(3.6:)j Fp(Plan)e +Ft(for)e(query)h(of)g(e)o(xample)h(3.1)p eop +%%Page: 62 62 +62 61 bop 270 60 a Ft(62)82 b Fm(CHAPTER)14 b(3.)28 b(POSTGRESQL)13 +b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW)270 +234 y Fi(3.7)71 b(The)18 b(Realization)f(of)g(the)h(Ha)n(ving)f(Clause) +270 354 y Ft(The)h Fp(having)g(clause)g Ft(has)g(been)g(designed)g(in)g +(SQL)g(to)f(be)h(able)g(to)g(use)g(the)g(results)f(of)h +Fp(aggr)n(e)n(gate)270 414 y(functions)12 b Ft(within)g(a)h(query)e +(quali\002cation.)k(The)e(handling)f(of)g(the)h Fp(having)f(clause)g +Ft(is)h(v)o(ery)f(similar)g(to)270 474 y(the)h(handling)f(of)h(the)g +Fp(wher)n(e)h(clause)p Ft(.)k(Both)13 b(are)g(formulas)f(in)h(\002rst)g +(order)f(logic)h(\(FOL\))f(that)h(ha)o(v)o(e)g(to)270 +534 y(e)o(v)o(aluate)f(to)g(true)g(for)g(a)g(certain)g(object)g(to)h +(be)f(handed)g(back:)345 648 y Fo(\017)25 b Ft(The)13 +b(formula)f(gi)o(v)o(en)g(in)h(the)g Fp(wher)n(e)h(clause)f +Ft(is)g(e)o(v)o(aluated)f(for)g(e)o(v)o(ery)h(tuple.)k(If)12 +b(the)h(e)o(v)o(aluation)395 707 y(returns)18 b Fr(true)i +Ft(the)f(tuple)g(is)h(returned,)h(e)o(v)o(ery)e(tuple)g(not)g +(satisfying)h(the)f(quali\002cation)g(is)395 767 y(ignored.)345 +886 y Fo(\017)25 b Ft(In)10 b(the)h(case)h(of)e Fp(gr)n(oups)i +Ft(the)f Fp(having)f(clause)i Ft(is)f(e)o(v)o(aluated)f(for)g(e)o(v)o +(ery)h(group.)k(If)10 b(the)h(e)o(v)o(aluation)395 945 +y(returns)g Fr(true)h Ft(the)h(group)e(is)i(taken)f(into)g(account)g +(otherwise)g(it)g(is)h(ignored.)270 1114 y Fh(3.7.1)59 +b(Ho)o(w)15 b(Aggr)o(egate)e(Functions)i(ar)o(e)f(Implemented)270 +1216 y Ft(Before)g(we)h(can)g(describe)f(ho)o(w)g(the)h +Fp(having)f(clause)h Ft(is)g(implemented)f(we)g(will)h(ha)o(v)o(e)g(a)f +(look)h(at)f(the)270 1276 y(implementation)h(of)g Fp(aggr)n(e)n(gate)g +(functions)h Ft(as)h(long)e(as)i(the)o(y)f(just)g(appear)f(in)h(the)g +Fp(tar)n(getlist)p Ft(.)26 b(Note)270 1336 y(that)12 +b Fp(aggr)n(e)n(gate)g(functions)g Ft(are)g(applied)g(to)g(groups)h(so) +f(the)h(query)e(must)i(contain)f(a)g Fp(gr)n(oup)h(clause)p +Ft(.)270 1484 y Fn(Example)g(3.2)25 b Ft(Here)18 b(is)g(an)g(e)o +(xample)g(of)g(the)g(usage)g(of)g(the)g Fp(aggr)n(e)n(gate)f(function)h +Fr(count)f Ft(which)270 1544 y(counts)c(the)h(number)e(of)h(part)g +(numbers)g(\()p Fr(pno)p Ft(\))f(of)h(e)o(v)o(ery)g(group.)18 +b(\(The)c(table)f Fr(sells)g Ft(is)g(de\002ned)g(in)270 +1604 y(e)o(xample)f(1.1.\))330 1722 y Fr(select)29 b(sno,)g +(count\(pno\))330 1782 y(from)g(sells)330 1842 y(group)g(by)h(sno;)270 +1955 y Ft(A)12 b(query)g(like)g(the)g(one)h(in)f(e)o(xample)g(3.2)h(is) +g(processed)g(by)f(the)g(usual)h(stages:)345 2069 y Fo(\017)25 +b Ft(the)12 b(parser)g(stage)345 2188 y Fo(\017)25 b +Ft(the)12 b(re)o(write)f(system)345 2306 y Fo(\017)25 +b Ft(the)12 b(planner/optimizer)345 2425 y Fo(\017)25 +b Ft(the)12 b(e)o(x)o(ecutor)270 2539 y(and)i(in)f(the)g(follo)o(wing)f +(sections)j(we)e(will)g(describe)h(what)f(e)o(v)o(ery)h(stage)g(does)g +(to)f(the)g(query)h(in)f(order)270 2598 y(to)f(obtain)g(the)h +(appropriate)e(result.)270 2757 y Fn(The)h(Parser)i(Stage)270 +2860 y Ft(The)h(parser)e(stage)i(b)o(uilds)f(up)g(a)g +Fp(querytr)n(ee)h Ft(containing)f(the)g Fp(wher)n(e)h +Ft(quali\002cation)e(and)h(information)270 2919 y(about)h(the)f +Fp(gr)n(ouping)h Ft(that)f(has)i(to)e(be)h(done)g(\(i.e.)23 +b(a)15 b(list)g(of)f(all)h(attrib)o(utes)f(to)h(group)f(for)g(is)h +(attached)270 2979 y(to)e(the)h(\002eld)f Fr(groupClause)p +Ft(\).)18 b(The)c(main)f(dif)o(ference)f(to)h Fp(querytr)n(ees)i +Ft(b)o(uilt)e(up)h(for)e(queries)i(with-)270 3039 y(out)j +Fp(aggr)n(e)n(gate)f(functions)h Ft(is)h(gi)o(v)o(en)f(in)g(the)g +(\002eld)g Fr(hasAggs)g Ft(which)g(is)g(set)h(to)f Fr(true)g +Ft(and)g(in)g(the)270 3099 y Fp(tar)n(getlist)p Ft(.)30 +b(The)18 b Fr(expr)e Ft(\002eld)h(of)g(the)g(second)h +Fr(TLE)e Ft(node)i(of)e(the)h Fp(tar)n(getlist)g Ft(sho)o(wn)g(in)g +(\002gure)g(3.7)270 3158 y(does)e(not)f(point)f(directly)h(to)g(a)g +Fr(VAR)g Ft(node)g(b)o(ut)g(to)g(an)g Fr(Aggreg)g Ft(node)g +(representing)g(the)g Fp(aggr)n(e)n(gate)270 3218 y(function)e +Ft(used)g(in)h(the)f(query)m(.)345 3283 y(A)17 b(check)g(is)h(made)f +(that)g(e)o(v)o(ery)g(attrib)o(ute)g(grouped)f(for)h(appears)g(only)g +(without)f(an)i Fp(aggr)n(e)n(gate)270 3342 y(function)12 +b Ft(in)h(the)f Fp(tar)n(getlist)h Ft(and)f(that)h(e)o(v)o(ery)f +(attrib)o(ute)g(which)h(appears)g(without)f(an)h Fp(aggr)n(e)n(gate)f +(func-)270 3402 y(tion)g Ft(in)g(the)g Fp(tar)n(getlist)h +Ft(is)f(grouped)g(for)m(.)p eop +%%Page: 63 63 +63 62 bop 198 60 a Fm(3.7.)29 b(THE)13 b(REALIZA)-6 b(TION)14 +b(OF)e(THE)h(HA)-7 b(VING)12 b(CLA)m(USE)622 b Ft(63)393 +1754 y @beginspecial 165 @llx 239 @lly 447 @urx 553 @ury +2820 @rwi @setspecial +%%BeginDocument: figures/parse_having.ps +%Magnification: 1.05 +/$F2psDict 200 dict def +$F2psDict begin +$F2psDict /mtrx matrix put +/col-1 {0 setgray} bind def +/col0 {0.000 0.000 0.000 srgb} bind def +/col1 {0.000 0.000 1.000 srgb} bind def +/col2 {0.000 1.000 0.000 srgb} bind def +/col3 {0.000 1.000 1.000 srgb} bind def +/col4 {1.000 0.000 0.000 srgb} bind def +/col5 {1.000 0.000 1.000 srgb} bind def +/col6 {1.000 1.000 0.000 srgb} bind def +/col7 {1.000 1.000 1.000 srgb} bind def +/col8 {0.000 0.000 0.560 srgb} bind def +/col9 {0.000 0.000 0.690 srgb} bind def +/col10 {0.000 0.000 0.820 srgb} bind def +/col11 {0.530 0.810 1.000 srgb} bind def +/col12 {0.000 0.560 0.000 srgb} bind def +/col13 {0.000 0.690 0.000 srgb} bind def +/col14 {0.000 0.820 0.000 srgb} bind def +/col15 {0.000 0.560 0.560 srgb} bind def +/col16 {0.000 0.690 0.690 srgb} bind def +/col17 {0.000 0.820 0.820 srgb} bind def +/col18 {0.560 0.000 0.000 srgb} bind def +/col19 {0.690 0.000 0.000 srgb} bind def +/col20 {0.820 0.000 0.000 srgb} bind def +/col21 {0.560 0.000 0.560 srgb} bind def +/col22 {0.690 0.000 0.690 srgb} bind def +/col23 {0.820 0.000 0.820 srgb} bind def +/col24 {0.500 0.190 0.000 srgb} bind def +/col25 {0.630 0.250 0.000 srgb} bind def +/col26 {0.750 0.380 0.000 srgb} bind def +/col27 {1.000 0.500 0.500 srgb} bind def +/col28 {1.000 0.630 0.630 srgb} bind def +/col29 {1.000 0.750 0.750 srgb} bind def +/col30 {1.000 0.880 0.880 srgb} bind def +/col31 {1.000 0.840 0.000 srgb} bind def + +end +save +155.0 566.0 translate +1 -1 scale + +/cp {closepath} bind def +/ef {eofill} bind def +/gr {grestore} bind def +/gs {gsave} bind def +/sa {save} bind def +/rs {restore} bind def +/l {lineto} bind def +/m {moveto} bind def +/rm {rmoveto} bind def +/n {newpath} bind def +/s {stroke} bind def +/sh {show} bind def +/slc {setlinecap} bind def +/slj {setlinejoin} bind def +/slw {setlinewidth} bind def +/srgb {setrgbcolor} bind def +/rot {rotate} bind def +/sc {scale} bind def +/sd {setdash} bind def +/ff {findfont} bind def +/sf {setfont} bind def +/scf {scalefont} bind def +/sw {stringwidth} bind def +/tr {translate} bind def +/tnt {dup dup currentrgbcolor + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add srgb} + bind def +/shd {dup dup currentrgbcolor 4 -2 roll mul 4 -2 roll mul + 4 -2 roll mul srgb} bind def + /DrawSplineSection { + /y3 exch def + /x3 exch def + /y2 exch def + /x2 exch def + /y1 exch def + /x1 exch def + /xa x1 x2 x1 sub 0.666667 mul add def + /ya y1 y2 y1 sub 0.666667 mul add def + /xb x3 x2 x3 sub 0.666667 mul add def + /yb y3 y2 y3 sub 0.666667 mul add def + x1 y1 lineto + xa ya xb yb x3 y3 curveto + } def + +/$F2psBegin {$F2psDict begin /$F2psEnteredState save def} def +/$F2psEnd {$F2psEnteredState restore end} def + +$F2psBegin +10 setmiterlimit +n 0 792 m 0 0 l 612 0 l 612 792 l cp clip + 0.06299 0.06299 sc +7.500 slw +% Polyline +n 1665 720 m 2205 720 l 2205 990 l 1665 990 l cp gs col-1 s gr +% Polyline +n 1935 720 m 1935 990 l gs col-1 s gr +% Polyline +n 2475 720 m 3015 720 l 3015 990 l 2475 990 l cp gs col-1 s gr +% Polyline +n 2745 720 m 2745 990 l gs col-1 s gr +% Polyline +n 3015 990 m 2745 720 l gs col-1 s gr +% Polyline +n 3015 720 m 2745 990 l gs col-1 s gr +% Polyline +n 3690 225 m 4230 225 l 4230 495 l 3690 495 l cp gs col-1 s gr +% Polyline +n 3960 225 m 3960 495 l gs col-1 s gr +% Polyline +n 4230 495 m 3960 225 l gs col-1 s gr +% Polyline +n 4230 225 m 3960 495 l gs col-1 s gr +% Polyline +n 3690 945 m 4590 945 l gs col-1 s gr +% Polyline +n 3690 720 m 4590 720 l 4590 1215 l 3690 1215 l cp gs col-1 s gr +/Times-Roman ff 150.00 scf sf +4005 900 m +gs 1 -1 sc (RTE) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3735 1125 m +gs 1 -1 sc (relname: sells) col-1 sh gr +% Polyline +n 1800 1440 m 2700 1440 l 2700 2205 l 1800 2205 l cp gs col-1 s gr +% Polyline +n 1800 1665 m 2700 1665 l gs col-1 s gr +% Polyline +n 1800 1935 m 2700 1935 l gs col-1 s gr +% Polyline +n 2430 1665 m 2430 2205 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +2115 1620 m +gs 1 -1 sc (TLE) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1890 2115 m +gs 1 -1 sc (expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1890 1845 m +gs 1 -1 sc (resdom) col-1 sh gr +% Polyline +n 3150 1440 m 4050 1440 l 4050 2205 l 3150 2205 l cp gs col-1 s gr +% Polyline +n 3150 1665 m 4050 1665 l gs col-1 s gr +% Polyline +n 3150 1935 m 4050 1935 l gs col-1 s gr +% Polyline +n 3780 1665 m 3780 2205 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +3465 1620 m +gs 1 -1 sc (TLE) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3240 2115 m +gs 1 -1 sc (expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3240 1845 m +gs 1 -1 sc (resdom) col-1 sh gr +% Polyline +n 405 4005 m 945 4005 l 945 4275 l 405 4275 l cp gs col-1 s gr +% Polyline +n 675 4005 m 675 4275 l gs col-1 s gr +% Polyline +n 945 4275 m 675 4005 l gs col-1 s gr +% Polyline +n 945 4005 m 675 4275 l gs col-1 s gr +% Polyline +n 1125 450 m 1125 1530 l gs col-1 s gr +% Polyline +n 180 450 m 1395 450 l gs col-1 s gr +% Polyline +n 180 720 m 1395 720 l gs col-1 s gr +% Polyline +n 180 990 m 1395 990 l gs col-1 s gr +% Polyline +n 180 1260 m 1395 1260 l gs col-1 s gr +% Polyline +n 180 1530 m 1395 1530 l gs col-1 s gr +% Polyline +n 180 1800 m 1395 1800 l gs col-1 s gr +% Polyline +n 180 225 m 1395 225 l 1395 2205 l 180 2205 l cp gs col-1 s gr +% Polyline +n 1125 1800 m 1125 2205 l gs col-1 s gr +% Polyline +n 1125 990 m 1395 1260 l gs col-1 s gr +% Polyline +n 1395 990 m 1125 1260 l gs col-1 s gr +% Polyline +gs clippath +1518 825 m 1638 855 l 1518 885 l 1680 885 l 1680 825 l cp clip +n 1260 855 m 1665 855 l gs col-1 s gr gr + +% arrowhead +n 1518 825 m 1638 855 l 1518 885 l 1518 855 l 1518 825 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +2328 825 m 2448 855 l 2328 885 l 2490 885 l 2490 825 l cp clip +n 2070 855 m 2475 855 l gs col-1 s gr gr + +% arrowhead +n 2328 825 m 2448 855 l 2328 885 l 2328 855 l 2328 825 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 3105 2745 m 4095 2745 l gs col-1 s gr +% Polyline +n 3105 2520 m 4095 2520 l 4095 3015 l 3105 3015 l cp gs col-1 s gr +% Polyline +n 1755 2745 m 2745 2745 l gs col-1 s gr +% Polyline +n 1755 2520 m 2745 2520 l 2745 3015 l 1755 3015 l cp gs col-1 s gr +% Polyline +n 3060 3555 m 4140 3555 l gs col-1 s gr +% Polyline +n 3060 3825 m 4140 3825 l gs col-1 s gr +% Polyline +n 3150 4410 m 4050 4410 l 4050 5175 l 3150 5175 l cp gs col-1 s gr +% Polyline +n 3150 4635 m 4050 4635 l gs col-1 s gr +% Polyline +n 3150 4905 m 4050 4905 l gs col-1 s gr +% Polyline +n 3060 3330 m 4140 3330 l 4140 4095 l 3060 4095 l cp gs col-1 s gr +% Polyline +n 3870 3825 m 3870 4095 l gs col-1 s gr +% Polyline +n 1800 3330 m 2700 3330 l 2700 4095 l 1800 4095 l cp gs col-1 s gr +% Polyline +n 1800 3555 m 2700 3555 l gs col-1 s gr +% Polyline +n 1800 3825 m 2700 3825 l gs col-1 s gr +% Polyline +n 225 4680 m 1125 4680 l 1125 5175 l 225 5175 l cp gs col-1 s gr +% Polyline +n 225 4905 m 1125 4905 l gs col-1 s gr +% Polyline +n 855 4905 m 855 5175 l gs col-1 s gr +% Open spline +gs clippath +2167 1315 m 2230 1420 l 2125 1357 l 2239 1472 l 2282 1429 l cp clip +n 1800.0 855.0 m 1867.5 990.0 l + 1867.5 990.0 1935.0 1125.0 2092.5 1282.5 DrawSplineSection + 2250.0 1440.0 l gs col-1 s gr + gr + +% arrowhead +n 2167 1315 m 2230 1420 l 2125 1357 l 2146 1336 l 2167 1315 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3517 1315 m 3580 1420 l 3475 1357 l 3589 1472 l 3632 1429 l cp clip +n 2610.0 855.0 m 2655.0 990.0 l + 2655.0 990.0 2700.0 1125.0 3015.0 1147.5 DrawSplineSection + 3015.0 1147.5 3330.0 1170.0 3465.0 1305.0 DrawSplineSection + 3600.0 1440.0 l gs col-1 s gr + gr + +% arrowhead +n 3517 1315 m 3580 1420 l 3475 1357 l 3496 1336 l 3517 1315 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3543 330 m 3663 360 l 3543 390 l 3705 390 l 3705 330 l cp clip +n 1260.0 585.0 m 1462.5 585.0 l + 1462.5 585.0 1665.0 585.0 2070.0 472.5 DrawSplineSection + 2070.0 472.5 2475.0 360.0 3082.5 360.0 DrawSplineSection + 3690.0 360.0 l gs col-1 s gr + gr + +% arrowhead +n 3543 330 m 3663 360 l 3543 390 l 3543 360 l 3543 330 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +4022 627 m 4115 707 l 3995 681 l 4140 754 l 4167 700 l cp clip +n 3825.0 360.0 m 3847.5 472.5 l + 3847.5 472.5 3870.0 585.0 4005.0 652.5 DrawSplineSection + 4140.0 720.0 l gs col-1 s gr + gr + +% arrowhead +n 4022 627 m 4115 707 l 3995 681 l 4009 654 l 4022 627 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +2343 2402 m 2262 2495 l 2289 2375 l 2216 2520 l 2270 2547 l cp clip +n 2565.0 1800.0 m 2700.0 1800.0 l + 2700.0 1800.0 2835.0 1800.0 2835.0 2070.0 DrawSplineSection + 2835.0 2070.0 2835.0 2340.0 2587.5 2340.0 DrawSplineSection + 2587.5 2340.0 2340.0 2340.0 2295.0 2430.0 DrawSplineSection + 2250.0 2520.0 l gs col-1 s gr + gr + +% arrowhead +n 2343 2402 m 2262 2495 l 2289 2375 l 2316 2389 l 2343 2402 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3693 2402 m 3612 2495 l 3639 2375 l 3566 2520 l 3620 2547 l cp clip +n 3915.0 1800.0 m 4050.0 1800.0 l + 4050.0 1800.0 4185.0 1800.0 4185.0 2070.0 DrawSplineSection + 4185.0 2070.0 4185.0 2340.0 3937.5 2340.0 DrawSplineSection + 3937.5 2340.0 3690.0 2340.0 3645.0 2430.0 DrawSplineSection + 3600.0 2520.0 l gs col-1 s gr + gr + +% arrowhead +n 3693 2402 m 3612 2495 l 3639 2375 l 3666 2389 l 3693 2402 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +2362 3230 m 2266 3308 l 2314 3194 l 2217 3324 l 2265 3360 l cp clip +n 2565.0 2070.0 m 2767.5 2070.0 l + 2767.5 2070.0 2970.0 2070.0 2970.0 2632.5 DrawSplineSection + 2970.0 2632.5 2970.0 3195.0 2677.5 3172.5 DrawSplineSection + 2677.5 3172.5 2385.0 3150.0 2317.5 3240.0 DrawSplineSection + 2250.0 3330.0 l gs col-1 s gr + gr + +% arrowhead +n 2362 3230 m 2266 3308 l 2314 3194 l 2338 3212 l 2362 3230 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3712 3230 m 3616 3308 l 3664 3194 l 3567 3324 l 3615 3360 l cp clip +n 3915.0 2070.0 m 4117.5 2070.0 l + 4117.5 2070.0 4320.0 2070.0 4320.0 2632.5 DrawSplineSection + 4320.0 2632.5 4320.0 3195.0 4027.5 3172.5 DrawSplineSection + 4027.5 3172.5 3735.0 3150.0 3667.5 3240.0 DrawSplineSection + 3600.0 3330.0 l gs col-1 s gr + gr + +% arrowhead +n 3712 3230 m 3616 3308 l 3664 3194 l 3688 3212 l 3712 3230 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3693 4292 m 3612 4385 l 3639 4265 l 3566 4410 l 3620 4437 l cp clip +n 4005.0 3960.0 m 3982.5 4072.5 l + 3982.5 4072.5 3960.0 4185.0 3825.0 4207.5 DrawSplineSection + 3825.0 4207.5 3690.0 4230.0 3645.0 4320.0 DrawSplineSection + 3600.0 4410.0 l gs col-1 s gr + gr + +% arrowhead +n 3693 4292 m 3612 4385 l 3639 4265 l 3666 4279 l 3693 4292 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +305 4028 m 383 4123 l 269 4076 l 399 4173 l 435 4125 l cp clip +n 1260.0 1395.0 m 1395.0 1395.0 l + 1395.0 1395.0 1530.0 1395.0 1507.5 2047.5 DrawSplineSection + 1507.5 2047.5 1485.0 2700.0 877.5 2767.5 DrawSplineSection + 877.5 2767.5 270.0 2835.0 247.5 3420.0 DrawSplineSection + 247.5 3420.0 225.0 4005.0 315.0 4072.5 DrawSplineSection + 405.0 4140.0 l gs col-1 s gr + gr + +% arrowhead +n 305 4028 m 383 4123 l 269 4076 l 287 4052 l 305 4028 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +636 4535 m 662 4655 l 582 4562 l 655 4707 l 709 4680 l cp clip +n 540.0 4140.0 m 540.0 4275.0 l + 540.0 4275.0 540.0 4410.0 607.5 4545.0 DrawSplineSection + 675.0 4680.0 l gs col-1 s gr + gr + +% arrowhead +n 636 4535 m 662 4655 l 582 4562 l 609 4549 l 636 4535 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +1675 1883 m 1780 1819 l 1717 1925 l 1832 1811 l 1789 1768 l cp clip +n 990.0 5040.0 m 1305.0 4972.5 l + 1305.0 4972.5 1620.0 4905.0 1620.0 3825.0 DrawSplineSection + 1620.0 3825.0 1620.0 2745.0 1620.0 2362.5 DrawSplineSection + 1620.0 2362.5 1620.0 1980.0 1710.0 1890.0 DrawSplineSection + 1800.0 1800.0 l gs col-1 s gr + gr + +% arrowhead +n 1675 1883 m 1780 1819 l 1717 1925 l 1696 1904 l 1675 1883 l cp gs 0.00 setgray ef gr col-1 s +/Times-Roman ff 150.00 scf sf +540 405 m +gs 1 -1 sc (Query) col-1 sh gr +/Times-Roman ff 150.00 scf sf +270 630 m +gs 1 -1 sc (rtable) col-1 sh gr +/Times-Roman ff 150.00 scf sf +270 900 m +gs 1 -1 sc (targetlist) col-1 sh gr +/Times-Roman ff 150.00 scf sf +270 1170 m +gs 1 -1 sc (qual) col-1 sh gr +/Times-Roman ff 150.00 scf sf +270 1440 m +gs 1 -1 sc (groupClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +270 1710 m +gs 1 -1 sc (hasAggs: true) col-1 sh gr +/Times-Roman ff 150.00 scf sf +630 1935 m +gs 1 -1 sc 270.0 rot (. . . ) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3375 2700 m +gs 1 -1 sc (Resdom) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3150 2925 m +gs 1 -1 sc (resname: count) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1845 2925 m +gs 1 -1 sc (resname: sno) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2025 2700 m +gs 1 -1 sc (Resdom) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3240 4815 m +gs 1 -1 sc (varno: 1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3240 5085 m +gs 1 -1 sc (varattno: 2) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3420 4590 m +gs 1 -1 sc (VAR) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3375 3510 m +gs 1 -1 sc (Aggreg) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3105 4005 m +gs 1 -1 sc (target) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3105 3735 m +gs 1 -1 sc (aggname: count) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1890 3735 m +gs 1 -1 sc (varno: 1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1890 4005 m +gs 1 -1 sc (varattno: 1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2070 3510 m +gs 1 -1 sc (VAR) col-1 sh gr +/Times-Roman ff 150.00 scf sf +315 5085 m +gs 1 -1 sc (entry) col-1 sh gr +/Times-Roman ff 150.00 scf sf +270 4860 m +gs 1 -1 sc (GroupClause) col-1 sh gr +showpage +$F2psEnd +rs +%%EndDocument + @endspecial 509 1864 a(Figure)11 b(3.7:)16 b Fp(Querytr)n(ee)e +Ft(b)o(uilt)d(up)i(for)e(the)h(query)g(of)g(e)o(xample)h(3.2)198 +2091 y Fn(The)f(Rewrite)h(System)198 2200 y Ft(The)19 +b(re)o(writing)d(system)j(does)g(not)f(make)f(an)o(y)i(changes)f(to)h +(the)f Fp(querytr)n(ee)h Ft(as)g(long)f(as)g(the)h(query)198 +2260 y(in)n(v)o(olv)o(es)12 b(just)g Fp(base)g(tables)p +Ft(.)j(If)c(an)o(y)h Fp(vie)o(ws)h Ft(are)f(present)f(the)h(query)f(is) +h(re)o(written)f(to)g(access)i(the)f(tables)198 2320 +y(speci\002ed)h(in)f(the)g Fp(vie)o(w)h(de\002nition)p +Ft(.)198 2499 y Fn(Planner/Optimizer)198 2608 y Ft(Whene)o(v)o(er)d(an) +f Fp(aggr)n(e)n(gate)g(function)g Ft(is)i(in)n(v)o(olv)o(ed)e(in)h(a)g +(query)f(\(which)g(is)h(indicated)f(by)h(the)g Fr(hasAggs)198 +2668 y Ft(\003ag)18 b(set)i(to)e Fr(true)p Ft(\))g(the)h(planner)f +(creates)h(a)g Fp(plantr)n(ee)g Ft(whose)g(top)f(node)h(is)g(an)f +Fr(AGG)h Ft(node.)35 b(The)198 2728 y Fp(tar)n(getlist)12 +b Ft(is)g(searched)h(for)e Fp(aggr)n(e)n(gate)h(functions)g +Ft(and)g(for)g(e)o(v)o(ery)f(function)h(that)g(is)g(found,)g(a)h +(pointer)198 2788 y(to)h(the)g(corresponding)g Fr(Aggreg)f +Ft(node)h(is)h(added)f(to)g(a)h(list)f(which)g(is)g(\002nally)g +(attached)g(to)g(the)g(\002eld)198 2847 y Fr(aggs)19 +b Ft(of)g(the)g Fr(AGG)g Ft(node.)36 b(This)20 b(list)g(is)f(needed)h +(by)f(the)g Fp(e)o(xecutor)h Ft(to)f(kno)o(w)g(which)g +Fp(aggr)n(e)n(gate)198 2907 y(functions)12 b Ft(are)g(present)h(and)f +(ha)o(v)o(e)h(to)f(be)h(handled.)273 2975 y(The)i Fr(AGG)f +Ft(node)g(is)h(follo)o(wed)e(by)h(a)h Fr(GRP)f Ft(node.)21 +b(The)15 b(implementation)e(of)h(the)h Fp(gr)n(ouping)e +Ft(logic)198 3035 y(needs)j(a)g(sorted)f(table)g(for)g(its)h(operation) +e(so)i(the)g Fr(GRP)f Ft(node)g(is)h(follo)o(wed)e(by)i(a)f +Fr(SORT)h Ft(node.)25 b(The)198 3095 y Fr(SORT)11 b Ft(operation)f +(gets)h(its)g(tuples)g(from)f(a)i(kind)e(of)h Fr(Scan)f +Ft(node)h(\(if)f(no)h(indices)h(are)e(present)h(this)g(will)198 +3155 y(be)16 b(a)f(simple)g Fr(SeqScan)g Ft(node\).)25 +b(An)o(y)15 b(quali\002cations)g(present)g(are)h(attached)f(to)g(the)h +Fr(Scan)f Ft(node.)198 3214 y(Figure)d(3.8)g(sho)o(ws)h(the)f +Fp(plan)g Ft(created)h(for)e(the)h(query)g(gi)o(v)o(en)g(in)h(e)o +(xample)f(3.2.)273 3283 y(Note)i(that)g(e)o(v)o(ery)f(node)h(has)h(its) +f(o)o(wn)g Fp(tar)n(getlist)g Ft(which)g(may)g(dif)o(fer)e(from)h(the)h +(one)g(of)g(the)g(node)198 3342 y(abo)o(v)o(e)g(or)f(belo)o(w)m(.)18 +b(The)c(\002eld)f Fr(varattno)g Ft(of)g(e)o(v)o(ery)g +Fr(VAR)g Ft(node)g(included)g(in)g(a)h Fp(tar)n(getlist)f +Ft(contains)198 3402 y(a)g(number)e(representing)h(the)g(position)g(of) +g(the)g(attrib)o(ute')m(s)g(v)o(alue)g(in)g(the)h(tuple)f(of)g(the)g +(current)g(node.)p eop +%%Page: 64 64 +64 63 bop 270 60 a Ft(64)82 b Fm(CHAPTER)14 b(3.)28 b(POSTGRESQL)13 +b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW)385 +2841 y @beginspecial 149 @llx 169 @lly 463 @urx 622 @ury +3140 @rwi @setspecial +%%BeginDocument: figures/plan_having.ps +%Magnification: 1.05 +/$F2psDict 200 dict def +$F2psDict begin +$F2psDict /mtrx matrix put +/col-1 {0 setgray} bind def +/col0 {0.000 0.000 0.000 srgb} bind def +/col1 {0.000 0.000 1.000 srgb} bind def +/col2 {0.000 1.000 0.000 srgb} bind def +/col3 {0.000 1.000 1.000 srgb} bind def +/col4 {1.000 0.000 0.000 srgb} bind def +/col5 {1.000 0.000 1.000 srgb} bind def +/col6 {1.000 1.000 0.000 srgb} bind def +/col7 {1.000 1.000 1.000 srgb} bind def +/col8 {0.000 0.000 0.560 srgb} bind def +/col9 {0.000 0.000 0.690 srgb} bind def +/col10 {0.000 0.000 0.820 srgb} bind def +/col11 {0.530 0.810 1.000 srgb} bind def +/col12 {0.000 0.560 0.000 srgb} bind def +/col13 {0.000 0.690 0.000 srgb} bind def +/col14 {0.000 0.820 0.000 srgb} bind def +/col15 {0.000 0.560 0.560 srgb} bind def +/col16 {0.000 0.690 0.690 srgb} bind def +/col17 {0.000 0.820 0.820 srgb} bind def +/col18 {0.560 0.000 0.000 srgb} bind def +/col19 {0.690 0.000 0.000 srgb} bind def +/col20 {0.820 0.000 0.000 srgb} bind def +/col21 {0.560 0.000 0.560 srgb} bind def +/col22 {0.690 0.000 0.690 srgb} bind def +/col23 {0.820 0.000 0.820 srgb} bind def +/col24 {0.500 0.190 0.000 srgb} bind def +/col25 {0.630 0.250 0.000 srgb} bind def +/col26 {0.750 0.380 0.000 srgb} bind def +/col27 {1.000 0.500 0.500 srgb} bind def +/col28 {1.000 0.630 0.630 srgb} bind def +/col29 {1.000 0.750 0.750 srgb} bind def +/col30 {1.000 0.880 0.880 srgb} bind def +/col31 {1.000 0.840 0.000 srgb} bind def + +end +save +130.0 635.5 translate +1 -1 scale + +/cp {closepath} bind def +/ef {eofill} bind def +/gr {grestore} bind def +/gs {gsave} bind def +/sa {save} bind def +/rs {restore} bind def +/l {lineto} bind def +/m {moveto} bind def +/rm {rmoveto} bind def +/n {newpath} bind def +/s {stroke} bind def +/sh {show} bind def +/slc {setlinecap} bind def +/slj {setlinejoin} bind def +/slw {setlinewidth} bind def +/srgb {setrgbcolor} bind def +/rot {rotate} bind def +/sc {scale} bind def +/sd {setdash} bind def +/ff {findfont} bind def +/sf {setfont} bind def +/scf {scalefont} bind def +/sw {stringwidth} bind def +/tr {translate} bind def +/tnt {dup dup currentrgbcolor + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add srgb} + bind def +/shd {dup dup currentrgbcolor 4 -2 roll mul 4 -2 roll mul + 4 -2 roll mul srgb} bind def + /DrawSplineSection { + /y3 exch def + /x3 exch def + /y2 exch def + /x2 exch def + /y1 exch def + /x1 exch def + /xa x1 x2 x1 sub 0.666667 mul add def + /ya y1 y2 y1 sub 0.666667 mul add def + /xb x3 x2 x3 sub 0.666667 mul add def + /yb y3 y2 y3 sub 0.666667 mul add def + x1 y1 lineto + xa ya xb yb x3 y3 curveto + } def + +/$F2psBegin {$F2psDict begin /$F2psEnteredState save def} def +/$F2psEnd {$F2psEnteredState restore end} def + +$F2psBegin +10 setmiterlimit +n 0 792 m 0 0 l 612 0 l 612 792 l cp clip + 0.06299 0.06299 sc +7.500 slw +% Polyline +n 1665 720 m 2205 720 l 2205 990 l 1665 990 l cp gs col-1 s gr +% Polyline +n 1935 720 m 1935 990 l gs col-1 s gr +% Polyline +n 2475 720 m 3015 720 l 3015 990 l 2475 990 l cp gs col-1 s gr +% Polyline +n 2745 720 m 2745 990 l gs col-1 s gr +% Polyline +n 3015 990 m 2745 720 l gs col-1 s gr +% Polyline +n 3015 720 m 2745 990 l gs col-1 s gr +% Polyline +n 1800 1440 m 2700 1440 l 2700 2205 l 1800 2205 l cp gs col-1 s gr +% Polyline +n 1800 1665 m 2700 1665 l gs col-1 s gr +% Polyline +n 1800 1935 m 2700 1935 l gs col-1 s gr +% Polyline +n 2430 1665 m 2430 2205 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +2115 1620 m +gs 1 -1 sc (TLE) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1890 2115 m +gs 1 -1 sc (expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1890 1845 m +gs 1 -1 sc (resdom) col-1 sh gr +% Polyline +n 3150 1440 m 4050 1440 l 4050 2205 l 3150 2205 l cp gs col-1 s gr +% Polyline +n 3150 1665 m 4050 1665 l gs col-1 s gr +% Polyline +n 3150 1935 m 4050 1935 l gs col-1 s gr +% Polyline +n 3780 1665 m 3780 2205 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +3465 1620 m +gs 1 -1 sc (TLE) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3240 2115 m +gs 1 -1 sc (expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3240 1845 m +gs 1 -1 sc (resdom) col-1 sh gr +% Polyline +n 3510 225 m 4050 225 l 4050 495 l 3510 495 l cp gs col-1 s gr +% Polyline +n 3780 225 m 3780 495 l gs col-1 s gr +% Polyline +n 3780 225 m 4050 495 l gs col-1 s gr +% Polyline +n 4050 225 m 3780 495 l gs col-1 s gr +% Polyline +gs clippath +1518 825 m 1638 855 l 1518 885 l 1680 885 l 1680 825 l cp clip +n 1260 855 m 1665 855 l gs col-1 s gr gr + +% arrowhead +n 1518 825 m 1638 855 l 1518 885 l 1518 855 l 1518 825 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +2328 825 m 2448 855 l 2328 885 l 2490 885 l 2490 825 l cp clip +n 2070 855 m 2475 855 l gs col-1 s gr gr + +% arrowhead +n 2328 825 m 2448 855 l 2328 885 l 2328 855 l 2328 825 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 3105 2745 m 4095 2745 l gs col-1 s gr +% Polyline +n 3105 2520 m 4095 2520 l 4095 3015 l 3105 3015 l cp gs col-1 s gr +% Polyline +n 1755 2745 m 2745 2745 l gs col-1 s gr +% Polyline +n 1755 2520 m 2745 2520 l 2745 3015 l 1755 3015 l cp gs col-1 s gr +% Polyline +n 3060 3555 m 4140 3555 l gs col-1 s gr +% Polyline +n 3060 3825 m 4140 3825 l gs col-1 s gr +% Polyline +n 3150 4410 m 4050 4410 l 4050 5175 l 3150 5175 l cp gs col-1 s gr +% Polyline +n 3150 4635 m 4050 4635 l gs col-1 s gr +% Polyline +n 3150 4905 m 4050 4905 l gs col-1 s gr +% Polyline +n 3060 3330 m 4140 3330 l 4140 4095 l 3060 4095 l cp gs col-1 s gr +% Polyline +n 3870 3825 m 3870 4095 l gs col-1 s gr +% Polyline +n 1800 3330 m 2700 3330 l 2700 4095 l 1800 4095 l cp gs col-1 s gr +% Polyline +n 1800 3555 m 2700 3555 l gs col-1 s gr +% Polyline +n 1800 3825 m 2700 3825 l gs col-1 s gr +% Polyline +n 315 450 m 1395 450 l gs col-1 s gr +% Polyline +n 315 720 m 1395 720 l gs col-1 s gr +% Polyline +n 315 990 m 1395 990 l gs col-1 s gr +% Polyline +n 315 1260 m 1395 1260 l gs col-1 s gr +% Polyline +n 1125 450 m 1125 1620 l gs col-1 s gr +% Polyline +n 1125 450 m 1125 1530 l gs col-1 s gr +% Polyline +n 720 4995 m 1800 4995 l gs col-1 s gr +% Polyline +n 720 5265 m 1800 5265 l gs col-1 s gr +% Polyline +n 1530 4725 m 1530 5625 l gs col-1 s gr +% Polyline +n 720 4725 m 1800 4725 l gs col-1 s gr +% Polyline +n 720 4500 m 1800 4500 l 1800 5625 l 720 5625 l cp gs col-1 s gr +% Polyline +n 2160 5895 m 3240 5895 l gs col-1 s gr +% Polyline +n 2160 6165 m 3240 6165 l gs col-1 s gr +% Polyline +n 2970 5625 m 2970 6525 l gs col-1 s gr +% Polyline +n 2160 5625 m 3240 5625 l gs col-1 s gr +% Polyline +n 3600 6795 m 4680 6795 l gs col-1 s gr +% Polyline +n 3600 7065 m 4680 7065 l gs col-1 s gr +% Polyline +n 3600 6525 m 4680 6525 l gs col-1 s gr +% Polyline +n 2160 5400 m 3240 5400 l 3240 6525 l 2160 6525 l cp gs col-1 s gr +% Polyline +n 4410 6525 m 4410 7380 l gs col-1 s gr +% Polyline +n 3600 6300 m 4680 6300 l 4680 7380 l 3600 7380 l cp gs col-1 s gr +% Polyline +n 315 225 m 1395 225 l 1395 1620 l 315 1620 l cp gs col-1 s gr +% Open spline +gs clippath +2167 1315 m 2230 1420 l 2125 1357 l 2239 1472 l 2282 1429 l cp clip +n 1800.0 855.0 m 1867.5 990.0 l + 1867.5 990.0 1935.0 1125.0 2092.5 1282.5 DrawSplineSection + 2250.0 1440.0 l gs col-1 s gr + gr + +% arrowhead +n 2167 1315 m 2230 1420 l 2125 1357 l 2146 1336 l 2167 1315 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3517 1315 m 3580 1420 l 3475 1357 l 3589 1472 l 3632 1429 l cp clip +n 2610.0 855.0 m 2655.0 990.0 l + 2655.0 990.0 2700.0 1125.0 3015.0 1147.5 DrawSplineSection + 3015.0 1147.5 3330.0 1170.0 3465.0 1305.0 DrawSplineSection + 3600.0 1440.0 l gs col-1 s gr + gr + +% arrowhead +n 3517 1315 m 3580 1420 l 3475 1357 l 3496 1336 l 3517 1315 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +2343 2402 m 2262 2495 l 2289 2375 l 2216 2520 l 2270 2547 l cp clip +n 2565.0 1800.0 m 2700.0 1800.0 l + 2700.0 1800.0 2835.0 1800.0 2835.0 2070.0 DrawSplineSection + 2835.0 2070.0 2835.0 2340.0 2587.5 2340.0 DrawSplineSection + 2587.5 2340.0 2340.0 2340.0 2295.0 2430.0 DrawSplineSection + 2250.0 2520.0 l gs col-1 s gr + gr + +% arrowhead +n 2343 2402 m 2262 2495 l 2289 2375 l 2316 2389 l 2343 2402 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3693 2402 m 3612 2495 l 3639 2375 l 3566 2520 l 3620 2547 l cp clip +n 3915.0 1800.0 m 4050.0 1800.0 l + 4050.0 1800.0 4185.0 1800.0 4185.0 2070.0 DrawSplineSection + 4185.0 2070.0 4185.0 2340.0 3937.5 2340.0 DrawSplineSection + 3937.5 2340.0 3690.0 2340.0 3645.0 2430.0 DrawSplineSection + 3600.0 2520.0 l gs col-1 s gr + gr + +% arrowhead +n 3693 2402 m 3612 2495 l 3639 2375 l 3666 2389 l 3693 2402 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3712 3230 m 3616 3308 l 3664 3194 l 3567 3324 l 3615 3360 l cp clip +n 3915.0 2070.0 m 4117.5 2070.0 l + 4117.5 2070.0 4320.0 2070.0 4320.0 2632.5 DrawSplineSection + 4320.0 2632.5 4320.0 3195.0 4027.5 3172.5 DrawSplineSection + 4027.5 3172.5 3735.0 3150.0 3667.5 3240.0 DrawSplineSection + 3600.0 3330.0 l gs col-1 s gr + gr + +% arrowhead +n 3712 3230 m 3616 3308 l 3664 3194 l 3688 3212 l 3712 3230 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3693 4292 m 3612 4385 l 3639 4265 l 3566 4410 l 3620 4437 l cp clip +n 4005.0 3960.0 m 3982.5 4072.5 l + 3982.5 4072.5 3960.0 4185.0 3825.0 4207.5 DrawSplineSection + 3825.0 4207.5 3690.0 4230.0 3645.0 4320.0 DrawSplineSection + 3600.0 4410.0 l gs col-1 s gr + gr + +% arrowhead +n 3693 4292 m 3612 4385 l 3639 4265 l 3666 4279 l 3693 4292 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +2362 3230 m 2266 3308 l 2314 3194 l 2217 3324 l 2265 3360 l cp clip +n 2565.0 2070.0 m 2767.5 2070.0 l + 2767.5 2070.0 2970.0 2070.0 2970.0 2632.5 DrawSplineSection + 2970.0 2632.5 2970.0 3195.0 2677.5 3172.5 DrawSplineSection + 2677.5 3172.5 2385.0 3150.0 2317.5 3240.0 DrawSplineSection + 2250.0 3330.0 l gs col-1 s gr + gr + +% arrowhead +n 2362 3230 m 2266 3308 l 2314 3194 l 2338 3212 l 2362 3230 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3363 330 m 3483 360 l 3363 390 l 3525 390 l 3525 330 l cp clip +n 1260.0 585.0 m 1687.5 585.0 l + 1687.5 585.0 2115.0 585.0 2407.5 472.5 DrawSplineSection + 2407.5 472.5 2700.0 360.0 3105.0 360.0 DrawSplineSection + 3510.0 360.0 l gs col-1 s gr + gr + +% arrowhead +n 3363 330 m 3483 360 l 3363 390 l 3363 360 l 3363 330 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +4277 3628 m 4161 3674 l 4241 3579 l 4110 3675 l 4146 3723 l cp clip +n 3645.0 360.0 m 3645.0 585.0 l + 3645.0 585.0 3645.0 810.0 4140.0 1102.5 DrawSplineSection + 4140.0 1102.5 4635.0 1395.0 4635.0 2362.5 DrawSplineSection + 4635.0 2362.5 4635.0 3330.0 4387.5 3510.0 DrawSplineSection + 4140.0 3690.0 l gs col-1 s gr + gr + +% arrowhead +n 4277 3628 m 4161 3674 l 4241 3579 l 4259 3604 l 4277 3628 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +2608 5282 m 2679 5382 l 2569 5327 l 2692 5433 l 2731 5387 l cp clip +n 1665.0 5130.0 m 2025.0 5130.0 l + 2025.0 5130.0 2385.0 5130.0 2542.5 5265.0 DrawSplineSection + 2700.0 5400.0 l gs col-1 s gr + gr + +% arrowhead +n 2608 5282 m 2679 5382 l 2569 5327 l 2588 5304 l 2608 5282 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +1290 4353 m 1260 4473 l 1230 4353 l 1230 4515 l 1290 4515 l cp clip +n 1260.0 1125.0 m 1417.5 1125.0 l + 1417.5 1125.0 1575.0 1125.0 1552.5 1935.0 DrawSplineSection + 1552.5 1935.0 1530.0 2745.0 1395.0 3127.5 DrawSplineSection + 1395.0 3127.5 1260.0 3510.0 1260.0 4005.0 DrawSplineSection + 1260.0 4500.0 l gs col-1 s gr + gr + +% arrowhead +n 1290 4353 m 1260 4473 l 1230 4353 l 1260 4353 l 1290 4353 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +2238 4695 m 2358 4725 l 2238 4755 l 2400 4755 l 2400 4695 l cp clip +n 1665.0 4860.0 m 1845.0 4860.0 l + 1845.0 4860.0 2025.0 4860.0 2092.5 4792.5 DrawSplineSection + 2092.5 4792.5 2160.0 4725.0 2272.5 4725.0 DrawSplineSection + 2385.0 4725.0 l gs col-1 s gr + gr + +% arrowhead +n 2238 4695 m 2358 4725 l 2238 4755 l 2238 4725 l 2238 4695 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3678 5595 m 3798 5625 l 3678 5655 l 3840 5655 l 3840 5595 l cp clip +n 3105.0 5760.0 m 3285.0 5760.0 l + 3285.0 5760.0 3465.0 5760.0 3532.5 5692.5 DrawSplineSection + 3532.5 5692.5 3600.0 5625.0 3712.5 5625.0 DrawSplineSection + 3825.0 5625.0 l gs col-1 s gr + gr + +% arrowhead +n 3678 5595 m 3798 5625 l 3678 5655 l 3678 5625 l 3678 5595 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +5118 6495 m 5238 6525 l 5118 6555 l 5280 6555 l 5280 6495 l cp clip +n 4545.0 6660.0 m 4725.0 6660.0 l + 4725.0 6660.0 4905.0 6660.0 4972.5 6592.5 DrawSplineSection + 4972.5 6592.5 5040.0 6525.0 5152.5 6525.0 DrawSplineSection + 5265.0 6525.0 l gs col-1 s gr + gr + +% arrowhead +n 5118 6495 m 5238 6525 l 5118 6555 l 5118 6525 l 5118 6495 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +4048 6182 m 4119 6282 l 4009 6227 l 4132 6333 l 4171 6287 l cp clip +n 3105.0 6030.0 m 3465.0 6030.0 l + 3465.0 6030.0 3825.0 6030.0 3982.5 6165.0 DrawSplineSection + 4140.0 6300.0 l gs col-1 s gr + gr + +% arrowhead +n 4048 6182 m 4119 6282 l 4009 6227 l 4028 6204 l 4048 6182 l cp gs 0.00 setgray ef gr col-1 s +/Times-Roman ff 150.00 scf sf +3375 2700 m +gs 1 -1 sc (Resdom) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3150 2925 m +gs 1 -1 sc (resname: count) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1845 2925 m +gs 1 -1 sc (resname: sno) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2025 2700 m +gs 1 -1 sc (Resdom) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3240 4815 m +gs 1 -1 sc (varno: 1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3240 5085 m +gs 1 -1 sc (varattno: 2) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3375 3510 m +gs 1 -1 sc (Aggreg) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3105 4005 m +gs 1 -1 sc (target) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3105 3735 m +gs 1 -1 sc (aggname: count) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1890 3735 m +gs 1 -1 sc (varno: 1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1890 4005 m +gs 1 -1 sc (varattno: 1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2070 3510 m +gs 1 -1 sc (VAR) col-1 sh gr +/Times-Roman ff 150.00 scf sf +810 1530 m +gs 1 -1 sc 90.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +720 405 m +gs 1 -1 sc (AGG) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3915 5445 m +gs 1 -1 sc (Pointer to ) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3915 5835 m +gs 1 -1 sc (SORT node) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3915 5640 m +gs 1 -1 sc (targetlist of) col-1 sh gr +/Times-Roman ff 150.00 scf sf +405 900 m +gs 1 -1 sc (qptargetlist) col-1 sh gr +/Times-Roman ff 150.00 scf sf +405 630 m +gs 1 -1 sc (aggs) col-1 sh gr +/Times-Roman ff 150.00 scf sf +810 4905 m +gs 1 -1 sc (qptargetlist) col-1 sh gr +/Times-Roman ff 150.00 scf sf +810 5175 m +gs 1 -1 sc (lefttree) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1170 5535 m +gs 1 -1 sc 90.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2655 6435 m +gs 1 -1 sc 90.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3690 6975 m +gs 1 -1 sc (lefttree) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2250 5805 m +gs 1 -1 sc (qptargetlist) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2250 6075 m +gs 1 -1 sc (lefttree) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3915 6480 m +gs 1 -1 sc (SeqScan) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4095 7290 m +gs 1 -1 sc 90.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +405 1170 m +gs 1 -1 sc (lefttree) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3690 6705 m +gs 1 -1 sc (qptargetlist) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1125 4680 m +gs 1 -1 sc (GRP) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3465 4590 m +gs 1 -1 sc (VAR) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2520 5580 m +gs 1 -1 sc (SORT) col-1 sh gr +showpage +$F2psEnd +rs +%%EndDocument + @endspecial 679 2950 a Ft(Figure)f(3.8:)16 b Fp(Plantr)n(ee)d +Ft(for)e(the)i(query)f(of)g(e)o(xample)g(3.2)p eop +%%Page: 65 65 +65 64 bop 198 60 a Fm(3.7.)29 b(THE)13 b(REALIZA)-6 b(TION)14 +b(OF)e(THE)h(HA)-7 b(VING)12 b(CLA)m(USE)622 b Ft(65)198 +234 y Fn(Executor)198 329 y Ft(The)13 b Fp(e)o(xecutor)f +Ft(uses)h(the)f(function)g Fr(execAgg\(\))f Ft(to)h(e)o(x)o(ecute)g +Fr(AGG)g Ft(nodes.)k(As)d(described)f(earlier)f(it)198 +389 y(uses)k(one)g(main)f(function)f Fr(ExecProcNode)h +Ft(which)g(is)h(called)f(recursi)o(v)o(ely)g(to)g(e)o(x)o(ecute)h +(subtrees.)198 449 y(The)e(follo)o(wing)e(steps)i(are)f(performed)f(by) +h Fr(execAgg\(\))p Ft(:)273 552 y Fo(\017)25 b Ft(The)15 +b(list)g(attached)h(to)f(the)g(\002eld)g Fr(aggs)f Ft(of)h(the)g +Fr(AGG)g Ft(node)g(is)h(e)o(xamined)f(and)g(for)f(e)o(v)o(ery)h +Fp(ag-)323 612 y(gr)n(e)n(gate)f(function)f Ft(included)h(the)g +Fp(tr)o(ansition)g(functions)f Ft(are)h(fetched)g(from)f(a)h +Fp(function)f(table)p Ft(.)323 671 y(Calculating)f(the)g(v)o(alue)g(of) +g(an)h Fp(aggr)n(e)n(gate)e(function)h Ft(is)h(done)f(using)g(three)g +(functions:)382 775 y Fn(\226)25 b Ft(The)18 b Fp(\002rst)g(tr)o +(ansition)g(function)f Fr(xfn1)g Ft(is)h(called)g(with)g(the)f(current) +g(v)o(alue)g(of)h(the)f(at-)432 835 y(trib)o(ute)c(the)h +Fp(aggr)n(e)n(gate)f(function)g Ft(is)h(applied)f(to)h(and)g(changes)g +(its)g(internal)f(state)h(using)432 895 y(the)e(attrib)o(ute')m(s)g(v)o +(alue)g(gi)o(v)o(en)g(as)h(an)g(ar)o(gument.)382 976 +y Fn(\226)25 b Ft(The)e Fp(second)f(tr)o(ansition)g(function)f +Fr(xfn2)h Ft(is)g(called)g(without)f(an)o(y)h(ar)o(guments)g(and)432 +1036 y(changes)13 b(its)g(internal)e(state)i(only)f(according)g(to)g +(internal)g(rules.)382 1118 y Fn(\226)25 b Ft(The)13 +b Fp(\002nal)g(function)f Fr(finalfn)g Ft(takes)h(the)g(\002nal)f +(states)h(of)g Fr(xfn1)f Ft(and)h Fr(xfn2)f Ft(as)i(ar)o(gu-)432 +1178 y(ments)f(and)f(\002nishes)h(the)f Fp(aggr)n(e)n(gation)p +Ft(.)323 1302 y Fn(Example)g(3.3)25 b Ft(Recall)19 b(the)f(functions)g +(necessary)h(to)f(implement)g(the)g Fp(aggr)n(e)n(gate)g(function)323 +1362 y Fr(avg)12 b Ft(b)o(uilding)g(the)h(a)o(v)o(erage)g(o)o(v)o(er)f +(all)h(v)o(alues)g(of)f(an)h(attrib)o(ute)f(in)g(a)h(group)f(\(see)h +(section)g(2.5.5)323 1422 y Fp(Extending)f(Aggr)n(e)n(gates)p +Ft(\):)382 1526 y Fn(\226)25 b Ft(The)10 b(\002rst)f(transition)g +(function)g Fr(xfn1)g Ft(has)h(to)f(be)g(a)h(function)f(that)g(takes)g +(the)h(actual)f(v)o(alue)432 1585 y(of)15 b(the)h(attrib)o(ute)e +Fr(avg)h Ft(is)h(applied)f(to)h(as)g(an)f(ar)o(gument)g(and)g(adds)h +(it)f(to)h(the)f(internally)432 1645 y(stored)d(sum)h(of)f(pre)o(vious) +g(calls.)382 1727 y Fn(\226)25 b Ft(The)15 b(second)h(transition)d +(function)h Fr(xfn2)h Ft(only)f(increases)h(an)g(internal)f(counter)g +(e)o(v)o(ery)432 1787 y(time)e(it)g(is)h(called.)382 +1868 y Fn(\226)25 b Ft(The)10 b(\002nal)g(function)f +Fr(finalfn)g Ft(di)o(vides)g(the)h(result)g(of)f Fr(xfn1)g +Ft(by)h(the)g(counter)f(of)g Fr(xfn2)432 1928 y Ft(to)j(calculate)h +(the)f(a)o(v)o(erage.)323 2053 y(Note)h(that)h Fr(xfn2)f +Ft(and)h Fr(finalfn)f Ft(may)h(be)f(absent)i(\(e.g.)20 +b(for)13 b(the)g Fp(aggr)n(e)n(gate)g(function)g Fr(sum)323 +2113 y Ft(which)f(simply)g(sums)h(up)f(all)g(v)o(alues)h(of)f(the)g(gi) +o(v)o(en)g(attrib)o(ute)g(within)f(a)i(group.)323 2232 +y Fr(execAgg\(\))25 b Ft(creates)i(an)g(array)f(containing)g(one)h +(entry)f(for)g(e)o(v)o(ery)h Fp(aggr)n(e)n(gate)f(func-)323 +2292 y(tion)16 b Ft(found)h(in)g(the)g(list)g(attached)g(to)g(the)g +(\002eld)g Fr(aggs)p Ft(.)30 b(The)18 b(array)e(will)h(hold)g +(information)323 2352 y(needed)25 b(for)f(the)i(e)o(x)o(ecution)f(of)g +(e)o(v)o(ery)g Fp(aggr)n(e)n(gate)g(function)g Ft(\(including)f(the)h +Fp(tr)o(ansition)323 2412 y(functions)12 b Ft(described)g(abo)o(v)o +(e\).)273 2515 y Fo(\017)25 b Ft(The)15 b(follo)o(wing)f(steps)i(are)f +(e)o(x)o(ecuted)h(in)f(a)g(loop)g(as)g(long)g(as)h(there)f(are)g(still) +g(tuples)g(returned)323 2575 y(by)e(the)h(subplan)g(\(i.e.)20 +b(as)15 b(long)e(as)i(there)e(are)h(still)g(tuples)g(left)f(in)h(the)g +(current)f(group\).)19 b(When)323 2635 y(there)12 b(are)h(no)g(tuples)g +(left)f(in)h(the)g(group)f(a)h Fr(NULL)g Ft(pointer)f(is)h(returned)f +(indicating)h(the)g(end)g(of)323 2695 y(the)f(group.)382 +2798 y Fn(\226)25 b Ft(A)15 b(ne)o(w)f(tuple)h(from)e(the)i(subplan)g +(\(i.e.)22 b(the)15 b Fp(plan)f Ft(attached)h(to)f(the)h(\002eld)f +Fr(lefttree)p Ft(\))432 2858 y(is)e(fetched)f(by)g(recursi)o(v)o(ely)f +(calling)h Fr(ExecProcNode\(\))f Ft(with)h(the)g(subplan)g(as)h(ar)o +(gu-)432 2918 y(ment.)382 3000 y Fn(\226)25 b Ft(F)o(or)14 +b(e)o(v)o(ery)g Fp(aggr)n(e)n(gate)f(function)h Ft(\(contained)f(in)h +(the)g(array)g(created)g(before\))f(apply)h(the)432 3059 +y(transition)e(functions)h Fr(xfn1)f Ft(and)h Fr(xfn2)f +Ft(to)h(the)g(v)o(alues)g(of)f(the)h(appropriate)f(attrib)o(utes)432 +3119 y(of)g(the)g(current)g(tuple.)273 3223 y Fo(\017)25 +b Ft(When)13 b(we)g(get)g(here,)g(all)g(tuples)g(of)g(the)g(current)f +(group)g(ha)o(v)o(e)i(been)f(processed)g(and)g(the)g +Fp(tr)o(an-)323 3283 y(sition)18 b(functions)h Ft(of)g(all)g +Fp(aggr)n(e)n(gate)g(functions)f Ft(ha)o(v)o(e)i(been)f(applied)g(to)g +(the)g(v)o(alues)g(of)g(the)323 3342 y(attrib)o(utes.)c(W)l(e)d(are)g +(no)o(w)g(ready)f(to)h(complete)g(the)g Fp(aggr)n(e)n(gation)f +Ft(by)h(applying)f(the)h Fp(\002nal)g(func-)323 3402 +y(tion)f Ft(\()p Fr(finalfn)p Ft(\))g(for)h(e)o(v)o(ery)g +Fp(aggr)n(e)n(gate)g(function)p Ft(.)p eop +%%Page: 66 66 +66 65 bop 270 60 a Ft(66)82 b Fm(CHAPTER)14 b(3.)28 b(POSTGRESQL)13 +b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW)345 +234 y Fo(\017)25 b Ft(Store)10 b(the)i(tuple)f(containing)g(the)h(ne)o +(w)g(v)o(alues)f(\(the)h(results)f(of)h(the)f Fp(aggr)n(e)n(gate)g +(functions)p Ft(\))g(and)395 294 y(hand)h(it)g(back.)270 +405 y(Note)j(that)g(the)g(procedure)f(described)i(abo)o(v)o(e)f(only)g +(returns)g(one)g(tuple)g(\(i.e.)24 b(it)15 b(processes)h(just)f(one)270 +465 y(group)f(and)h(when)f(the)h(end)g(of)f(the)h(group)f(is)h +(detected)g(it)f(processes)i(the)f Fp(aggr)n(e)n(gate)f(functions)g +Ft(and)270 524 y(hands)21 b(back)f(one)h(tuple\).)39 +b(T)l(o)20 b(retrie)o(v)o(e)g(all)g(tuples)h(\(i.e.)40 +b(to)20 b(process)h(all)f(groups\))g(the)g(function)270 +584 y Fr(execAgg\(\))15 b Ft(has)i(to)f(be)g(called)h(\(returning)d(a)i +(ne)o(w)h(tuple)e(e)o(v)o(ery)h(time\))g(until)f(it)h(returns)g(a)g +Fr(NULL)270 644 y Ft(pointer)c(indicating)f(that)h(there)g(are)h(no)f +(groups)g(left)g(to)g(process.)270 807 y Fh(3.7.2)59 +b(Ho)o(w)15 b(the)g(Ha)o(ving)e(Clause)i(is)g(Implemented)270 +908 y Ft(The)k(basic)g(idea)f(of)g(the)g(implementation)f(is)i(to)f +(attach)h(the)f Fp(oper)o(ator)h(tr)n(ee)g Ft(b)o(uilt)f(for)f(the)h +Fp(having)270 968 y(clause)e Ft(to)f(the)g(\002eld)g +Fr(qpqual)f Ft(of)h(node)g Fr(AGG)g Ft(\(which)g(is)h(the)f(top)g(node) +g(of)g(the)g(query)g(tree\).)23 b(No)o(w)270 1028 y(the)17 +b(e)o(x)o(ecutor)g(has)h(to)f(e)o(v)o(aluate)g(the)g(ne)o(w)g +Fp(oper)o(ator)h(tr)n(ee)g Ft(attached)f(to)g Fr(qpqual)g +Ft(for)f(e)o(v)o(ery)h(group)270 1087 y(processed.)26 +b(If)15 b(the)h(e)o(v)o(aluation)e(returns)h Fr(true)h +Ft(the)f(group)g(is)h(taken)f(into)g(account)h(otherwise)f(it)h(is)270 +1147 y(ignored)c(and)g(the)g(ne)o(xt)h(group)e(will)h(be)h(e)o +(xamined.)270 1267 y(In)21 b(order)g(to)g(implement)g(the)g +Fp(having)g(clause)h Ft(a)f(v)o(ariety)g(of)g(changes)h(ha)o(v)o(e)g +(been)f(made)h(to)f(the)270 1326 y(follo)o(wing)11 b(stages:)345 +1437 y Fo(\017)25 b Ft(The)15 b Fp(parser)h(stage)f Ft(has)h(been)f +(modi\002ed)g(slightly)g(to)g(b)o(uild)g(up)g(and)h(transform)e(an)h +Fp(oper)o(ator)395 1497 y(tr)n(ee)e Ft(for)e(the)h Fp(having)h(clause)p +Ft(.)345 1612 y Fo(\017)25 b Ft(The)12 b Fp(r)n(e)o(write)i(system)f +Ft(has)g(been)g(adapted)f(to)g(be)h(able)f(to)h(use)f +Fp(vie)o(ws)i Ft(with)e(the)g Fp(having)g(logic)p Ft(.)345 +1727 y Fo(\017)25 b Ft(The)12 b Fp(planner/optimizer)g +Ft(no)o(w)g(takes)g(the)g Fp(oper)o(ator)h(tr)n(ee)g +Ft(of)f(the)g Fp(having)g(clause)g Ft(and)h(attaches)395 +1787 y(it)f(to)g(the)g Fr(AGG)g Ft(node)h(\(which)e(is)i(the)f(top)h +(node)f(of)g(the)g Fp(queryplan)p Ft(\).)345 1901 y Fo(\017)25 +b Ft(The)13 b Fp(e)o(xecutor)g Ft(has)g(been)g(modi\002ed)e(to)i(e)o(v) +o(aluate)f(the)h Fp(oper)o(ator)g(tr)n(ee)g Ft(\(i.e.)k(the)12 +b(internal)g(repre-)395 1961 y(sentation)g(of)f(the)i +Fp(having)e(quali\002cation)p Ft(\))g(attached)h(to)g(the)h +Fr(AGG)f Ft(node)g(and)g(the)g(results)g(of)g(the)395 +2021 y Fp(aggr)n(e)n(gation)f Ft(are)h(only)g(considered)g(if)g(the)g +(e)o(v)o(aluation)g(returns)g Fr(true)p Ft(.)270 2132 +y(In)g(the)g(follo)o(wing)e(sections)j(we)f(will)g(describe)g(the)g +(changes)h(made)f(to)g(e)o(v)o(ery)g(single)g(stage)h(in)f(detail.)270 +2285 y Fn(The)g(Parser)i(Stage)270 2386 y Ft(The)g(grammar)f(rules)g +(of)g(the)h Fp(parser)g Ft(de\002ned)g(in)f Fr(gram.y)g +Ft(did)g(not)h(require)e(an)o(y)i(changes)h(\(i.e.)k(the)270 +2446 y(rules)14 b(had)g(already)g(been)g(prepared)g(for)f(the)h +Fp(having)g(clause)p Ft(\).)21 b(The)15 b Fp(oper)o(ator)f(tr)n(ee)h +Ft(b)o(uilt)f(up)g(for)f(the)270 2506 y Fp(having)f(clause)h +Ft(is)f(attached)h(to)f(the)g(\002eld)g Fr(havingClause)f +Ft(of)h(the)h Fr(SelectStmt)e Ft(node)h(handed)270 2565 +y(back)h(by)f(the)g Fp(parser)p Ft(.)270 2685 y(The)18 +b Fp(tr)o(ansformation)g Ft(procedures)f(applied)h(to)f(the)h(tree)f +(handed)h(back)g(by)f(the)h Fp(parser)g Ft(transform)270 +2745 y(the)d Fp(oper)o(ator)g(tr)n(ee)g Ft(attached)g(to)g(the)f +(\002eld)h Fr(havingClause)e Ft(using)i(e)o(xactly)g(the)f(same)i +(functions)270 2804 y(used)j(for)f(the)h(transformation)e(of)i(the)g +Fp(oper)o(ator)g(tr)n(ee)h Ft(for)e(the)h Fp(wher)n(e)g(clause)p +Ft(.)36 b(This)20 b(is)f(possible)270 2864 y(because)c(both)e(trees)h +(are)g(b)o(uilt)g(up)f(by)h(the)g(same)h(grammar)d(rules)i(of)g(the)g +Fp(parser)g Ft(and)g(are)g(therefore)270 2924 y(compatible.)h +(Additional)9 b(checks)j(which)e(make)g(sure)h(that)f(the)h +Fp(having)f(clause)h Ft(in)n(v)o(olv)o(es)f(at)h(least)g(one)270 +2984 y Fp(aggr)n(e)n(gate)f(function)g Ft(etc.)15 b(are)c(performed)e +(at)h(a)h(later)f(point)g(in)g(time)h(in)f(the)h Fp(planner/optimizer)f +Ft(stage.)270 3103 y(The)24 b(necessary)h(changes)f(ha)o(v)o(e)g(been)g +(applied)g(to)g(the)f(follo)o(wing)g(functions)g(included)g(in)h(the) +270 3163 y(\002le)19 b Fk(:)8 b(:)g(:)p Fr +(/src/backend/parser/analyze.c)o Ft(.)33 b(Note,)21 b(that)d(only)h +(the)g(rele)o(v)o(ant)f(parts)h(of)270 3223 y(the)e(af)o(fected)f(code) +g(are)h(presented)f(instead)h(of)g(the)f(whole)h(functions.)28 +b(Ev)o(ery)17 b(added)g(source)f(line)270 3283 y(will)f(be)h(marked)e +(by)h(a)h Fr('+')f Ft(at)h(the)f(be)o(ginning)g(of)g(the)g(line)h(and)f +(e)o(v)o(ery)g(changed)h(source)f(line)g(will)270 3342 +y(be)f(marked)f(by)h(a)g Fr('!')19 b Ft(throughout)13 +b(the)h(follo)o(wing)e(code)i(listings.)21 b(Whene)o(v)o(er)13 +b(a)h(part)g(of)f(the)h(code)270 3402 y(which)e(is)h(not)f(rele)o(v)o +(ant)f(at)i(the)f(moment)g(is)h(skipped,)f(three)g(v)o(ertical)h(dots)f +(are)g(inserted)g(instead.)p eop +%%Page: 67 67 +67 66 bop 198 60 a Fm(3.7.)29 b(THE)13 b(REALIZA)-6 b(TION)14 +b(OF)e(THE)h(HA)-7 b(VING)12 b(CLA)m(USE)622 b Ft(67)273 +234 y Fo(\017)25 b Fr(transformInsertStmt\(\))323 294 +y Ft(This)14 b(function)e(becomes)i(is)g(in)n(v)o(oked)e(e)o(v)o(ery)i +(time)f(a)g(SQL)h Fr(insert)f Ft(statement)g(in)n(v)o(olving)g(a)323 +354 y Fr(select)e Ft(is)i(used)g(like)e(the)i(follo)o(wing)e(e)o +(xample)h(illustrates:)382 467 y Fr(insert)30 b(into)f(t2)382 +527 y(select)h(x,)f(y)382 587 y(from)h(t1;)323 700 y +Ft(T)l(wo)10 b(statements)h(ha)o(v)o(e)h(been)f(added)f(to)h(this)g +(function.)j(The)e(\002rst)e(one)h(performs)f(the)g(transfor)o(-)323 +760 y(mation)g(of)h(the)h Fp(oper)o(ator)g(tr)n(ee)g +Ft(attached)f(to)h(the)f(\002eld)g Fr(havingClause)f +Ft(using)i(the)f(function)323 819 y Fr(transformWhereClause\(\))h +Ft(as)j(done)f(for)g(the)h Fp(wher)n(e)g(clause)p Ft(.)23 +b(It)14 b(is)h(possible)g(to)g(use)323 879 y(the)c(same)h(function)f +(for)g(both)g(clauses,)j(because)e(the)o(y)g(are)f(both)h(b)o(uilt)f +(up)h(by)f(the)h(same)g Fp(gr)o(am-)323 939 y(mar)g(rules)h +Ft(gi)o(v)o(en)f(in)h Fr(gram.y)e Ft(and)i(are)f(therefore)f +(compatible.)323 1017 y(The)h(second)h(statement)f(makes)g(sure,)h +(that)f Fp(aggr)n(e)n(gate)f(functions)h Ft(are)g(in)n(v)o(olv)o(ed)g +(in)g(the)h(query)323 1077 y(whene)o(v)o(er)h(a)h Fp(having)f(clause)h +Ft(is)g(used,)i(otherwise)d(the)h(query)f(could)g(ha)o(v)o(e)i(been)e +(formulated)323 1137 y(using)e(only)g(a)h Fp(wher)n(e)g(clause)p +Ft(.)382 1250 y Fr(static)30 b(Query)f(*)382 1310 y +(transformInsertStmt\(ParseState)e(*pstate,)980 1370 +y(InsertStmt)i(*stmt\))382 1430 y({)442 1489 y(/*)h(make)f(a)h(new)g +(query)f(tree)g(*/)442 1549 y(Query)g(*qry)h(=)g(makeNode\(Query\);) +1159 1609 y(.)1159 1669 y(.)1159 1729 y(.)442 1788 y(/*)g(fix)f(where)h +(clause)f(*/)442 1848 y(qry->qual)g(=)h(transformWhereClause\(pstate,) +1428 1908 y(stmt->whereClause\);)323 2027 y(+)89 b(/*)30 +b(The)f(havingQual)g(has)h(a)f(similar)g(meaning)h(as)f("qual")g(in)323 +2087 y(+)119 b(*)30 b(the)f(where)h(statement.)e(So)i(we)g(can)f +(easily)g(use)h(the)323 2147 y(+)119 b(*)30 b(code)f(from)h(the)f +("where)g(clause")g(with)h(some)f(additional)323 2207 +y(+)119 b(*)30 b(traversals)f(done)g(in)h(.../optimizer/plan/planner.c) +323 2267 y(+)119 b(*/)323 2326 y(+)89 b(qry->havingQual)28 +b(=)i(transformWhereClause\(pstate,)323 2386 y(+)1045 +b(stmt->havingClause\);)1159 2446 y(.)1159 2506 y(.)1159 +2565 y(.)323 2625 y(+)89 b(/*)30 b(If)f(there)h(is)f(a)h(havingQual)f +(but)g(there)h(are)f(no)323 2685 y(+)119 b(*)30 b(aggregates,)e(then)i +(there)f(is)h(something)f(wrong)g(with)323 2745 y(+)119 +b(*)30 b(the)f(query)h(because)f(having)g(must)g(contain)g(aggregates) +323 2804 y(+)119 b(*)30 b(in)f(its)h(expressions!)f(Otherwise)f(the)i +(query)f(could)323 2864 y(+)119 b(*)30 b(have)f(been)h(formulated)e +(using)i(the)f(where)h(clause.)323 2924 y(+)119 b(*/)323 +2984 y(+)89 b(if\(\(qry->hasAggs)28 b(==)i(false\))f(&&)323 +3044 y(+)179 b(\(qry->havingQual)28 b(!=)i(NULL\)\))323 +3103 y(+)89 b({)323 3163 y(+)149 b(elog\(ERROR,"This)28 +b(is)i(not)f(a)h(valid)f(having)g(query!"\);)323 3223 +y(+)149 b(return)29 b(\(Query)g(*\)NIL;)323 3283 y(+)89 +b(})442 3342 y(return)29 b(\(Query)h(*\))f(qry;)382 3402 +y(})p eop +%%Page: 68 68 +68 67 bop 270 60 a Ft(68)82 b Fm(CHAPTER)14 b(3.)28 b(POSTGRESQL)13 +b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW)345 +234 y Fo(\017)25 b Fr(transformSelectStmt\(\))395 294 +y Ft(Exactly)17 b(the)g(same)h(statements)f(added)g(to)g(the)g +(function)f Fr(transformInsertStmt\(\))395 354 y Ft(abo)o(v)o(e)c(ha)o +(v)o(e)h(been)g(added)f(here)g(as)h(well.)454 555 y Fr(static)30 +b(Query)f(*)454 614 y(transformSelectStmt\(ParseState)e(*pstate,)1052 +674 y(SelectStmt)i(*stmt\))454 734 y({)514 794 y(Query)59 +b(*qry)30 b(=)g(makeNode\(Query\);)514 913 y(qry->commandType)e(=)i +(CMD_SELECT;)1231 973 y(.)1231 1033 y(.)1231 1093 y(.)514 +1152 y(qry->qual)f(=)h(transformWhereClause\(pstate,)1500 +1212 y(stmt->whereClause\);)395 1332 y(+)89 b(/*)30 b(The)f(havingQual) +g(has)h(a)f(similar)g(meaning)h(as)f("qual")g(in)395 +1391 y(+)119 b(*)30 b(the)f(where)h(statement.)e(So)i(we)g(can)f +(easily)g(use)h(the)395 1451 y(+)119 b(*)30 b(code)f(from)h(the)f +("where)g(clause")g(with)h(some)f(additional)395 1511 +y(+)119 b(*)30 b(traversals)f(done)g(in)h(.../optimizer/plan/planner.c) +395 1571 y(+)119 b(*/)395 1631 y(+)89 b(qry->havingQual)28 +b(=)i(transformWhereClause\(pstate,)395 1690 y(+)1045 +b(stmt->havingClause\);)1231 1750 y(.)1231 1810 y(.)1231 +1870 y(.)395 1929 y(+)89 b(/*)30 b(If)f(there)h(is)f(a)h(havingQual)f +(but)g(there)h(are)f(no)395 1989 y(+)119 b(*)30 b(aggregates,)e(then)i +(there)f(is)h(something)f(wrong)g(with)395 2049 y(+)119 +b(*)30 b(the)f(query)h(because)f(having)g(must)g(contain)g(aggregates) +395 2109 y(+)119 b(*)30 b(in)f(its)h(expressions!)f(Otherwise)f(the)i +(query)f(could)395 2169 y(+)119 b(*)30 b(have)f(been)h(formulated)e +(using)i(the)f(where)h(clause.)395 2228 y(+)119 b(*/)395 +2288 y(+)89 b(if\(\(qry->hasAggs)28 b(==)i(false\))f(&&)395 +2348 y(+)179 b(\(qry->havingQual)28 b(!=)i(NULL\)\))395 +2408 y(+)89 b({)395 2467 y(+)149 b(elog\(ERROR,"This)28 +b(is)i(not)f(a)h(valid)f(having)g(query!"\);)395 2527 +y(+)149 b(return)29 b(\(Query)g(*\)NIL;)395 2587 y(+)89 +b(})514 2647 y(return)29 b(\(Query)h(*\))f(qry;)454 2707 +y(})270 2951 y Fn(The)12 b(Rewrite)h(System)270 3083 +y Ft(This)19 b(section)g(describes)g(the)g(changes)g(to)g(the)f +Fp(r)n(e)o(write)i(system)g Ft(of)e(PostgreSQL)g(that)h(ha)o(v)o(e)g +(been)270 3143 y(necessary)c(to)f(support)g(the)g(use)h(of)f +Fp(vie)o(ws)h Ft(within)f(queries)g(using)g(a)h Fp(having)f(clause)g +Ft(and)g(to)h(support)270 3203 y(the)d(de\002nition)g(of)g +Fp(vie)o(ws)h Ft(by)f(queries)h(using)f(a)h Fp(having)f(clause)p +Ft(.)345 3283 y(As)f(described)h(in)f(section)g(3.4.1)h +Fp(T)-5 b(ec)o(hniques)12 b(T)-5 b(o)11 b(Implement)g(V)l(ie)o(ws)i +Ft(a)e(query)g(re)o(write)f(technique)270 3342 y(is)i(used)h(to)f +(implement)f Fp(vie)o(ws)p Ft(.)17 b(There)12 b(are)g(two)f(cases)j(to) +e(be)g(handled)g(within)f(the)h Fp(r)n(e)o(write)i(system)f +Ft(as)270 3402 y(far)e(as)i(the)g Fp(having)f(clause)g +Ft(is)h(concerned:)p eop +%%Page: 69 69 +69 68 bop 198 60 a Fm(3.7.)29 b(THE)13 b(REALIZA)-6 b(TION)14 +b(OF)e(THE)h(HA)-7 b(VING)12 b(CLA)m(USE)622 b Ft(69)273 +234 y Fo(\017)25 b Ft(The)10 b Fp(vie)o(w)h(de\002nition)f +Ft(does)h(not)f(contain)g(a)h Fp(having)f(clause)g Ft(b)o(ut)h(the)f +(queries)g(e)o(v)o(aluated)g(against)323 294 y(this)i(vie)o(w)g(may)g +(contain)g Fp(having)g(clauses)p Ft(.)273 423 y Fo(\017)25 +b Ft(The)15 b Fp(vie)o(w)g(de\002nition)f Ft(contains)g(a)h +Fp(having)g(clause)p Ft(.)22 b(In)14 b(this)h(case)h(queries)e(e)o(v)o +(aluated)g(against)323 483 y(this)e(vie)o(w)g(must)g(meet)h(some)f +(restrictions)g(as)h(we)g(will)f(describe)g(later)m(.)198 +655 y Fn(No)h(ha)o(ving)f(clause)i(in)f(the)g(view)g(de\002nition:)47 +b Ft(First)13 b(we)h(will)f(look)g(at)g(the)g(changes)h(necessary)g(to) +198 715 y(support)e(queries)g(using)h(a)f Fp(having)g(clause)h +Ft(against)f(a)h Fp(vie)o(w)g Ft(de\002ned)f(without)g(a)g +Fp(having)g(clause)p Ft(.)198 835 y(Let)h(the)f(follo)o(wing)f(vie)o(w) +h(de\002nition)g(be)g(gi)o(v)o(en:)258 964 y Fr(create)29 +b(view)g(test_view)258 1023 y(as)g(select)h(sno,)f(pno)347 +1083 y(from)h(sells)347 1143 y(where)g(sno)f(>)h(2;)198 +1264 y Ft(and)12 b(the)h(follo)o(wing)e(query)h(made)g(against)g +Fr(test)p 1083 1264 15 2 v 18 w(view)p Ft(:)258 1393 +y Fr(select)29 b(*)258 1453 y(from)g(testview)258 1513 +y(where)g(sno)h(<>)f(5;)198 1634 y Ft(The)13 b(query)f(will)g(be)g(re)o +(written)f(to:)258 1763 y Fr(select)29 b(sno,)g(pno)258 +1823 y(from)g(sells)258 1883 y(where)g(sno)h(>)f(2)h(and)437 +1943 y(sno)g(<>)f(5;)198 2064 y Ft(The)13 b(query)g(gi)o(v)o(en)g(in)f +(the)h(de\002nition)f(of)h(the)g Fp(vie)o(w)g Fr(test)p +1221 2064 V 18 w(view)f Ft(is)h(the)g Fp(bac)o(kbone)g +Ft(of)g(the)f(re)o(written)198 2124 y(query)m(.)k(The)d +Fp(tar)n(getlist)f Ft(is)h(taken)f(from)g(the)h(user')m(s)g(query)f +(and)g(also)h(the)g Fp(wher)n(e)h(quali\002cation)24 +b Ft(of)12 b(the)198 2184 y(user')m(s)e(query)f(is)h(added)f(to)h(the)f +Fp(wher)n(e)i(quali\002cation)d Ft(of)h(the)h(ne)o(w)f(query)g(by)h +(using)f(an)h Fr(AND)f Ft(operation.)198 2303 y(No)o(w)j(consider)g +(the)h(follo)o(wing)e(query:)258 2432 y Fr(select)29 +b(sno,)g(count\(pno\))258 2492 y(from)g(testview)258 +2552 y(where)g(sno)h(<>)f(5)258 2611 y(group)g(by)h(sno)258 +2671 y(having)f(count\(pno\))g(>)h(1;)198 2793 y Ft(From)12 +b(no)o(w)g(on)h(it)g(is)g(no)f(longer)h(suf)o(\002cient)f(to)g(add)h +(just)g(the)g Fp(wher)n(e)h(clause)f Ft(and)g(the)f Fp(tar)n(getlist)h +Ft(of)f(the)198 2853 y(user')m(s)i(query)f(to)h(the)g(ne)o(w)f(query)m +(.)19 b(The)c Fp(gr)n(oup)e(clause)h Ft(and)g(the)g Fp(having)f +(quali\002cation)g Ft(also)h(ha)o(v)o(e)g(to)198 2912 +y(be)e(added)h(to)f(the)g(re)o(written)f(query:)258 3041 +y Fr(select)29 b(sno,)g(count\(pno\))258 3101 y(from)g(sells)258 +3161 y(where)g(sno)h(>)f(2)h(and)437 3221 y(sno)g(<>)f(5)258 +3280 y(group)g(by)h(sno)258 3340 y(having)f(count\(pno\))g(>)h(1;)p +eop +%%Page: 70 70 +70 69 bop 270 60 a Ft(70)82 b Fm(CHAPTER)14 b(3.)28 b(POSTGRESQL)13 +b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW)270 +234 y Ft(Se)o(v)o(eral)i(changes)g(that)h(ha)o(v)o(e)f(already)g(been)g +(applied)g(to)g(the)h Fp(tar)n(getlist)f Ft(and)g(the)g +Fp(wher)n(e)h(clause)g Ft(also)270 294 y(ha)o(v)o(e)c(to)g(be)g +(applied)f(to)h(the)g Fp(having)f(clause)p Ft(.)16 b(Here)10 +b(is)h(a)g(collection)g(of)f(all)h Fp(additional)f Ft(steps)h(that)g +(ha)o(v)o(e)270 354 y(to)g(be)g(performed)f(in)h(order)g(to)g(re)o +(write)f(a)h(query)g(using)g(a)h Fp(having)e(clause)i +Ft(against)f(a)h(simple)f Fp(vie)o(w)h Ft(\(i.e.)270 +413 y(a)h Fp(vie)o(w)g Ft(whose)f(de\002nition)g(does)h(not)f(use)g(an) +o(y)h Fp(gr)n(oup)f Ft(and)h Fp(having)f(clauses)p Ft(\):)345 +523 y Fo(\017)25 b Ft(Re)o(write)11 b(the)i(subselects)g(contained)f +(in)h(the)f Fp(having)g(clause)h Ft(if)f(an)o(y)g(are)g(present.)345 +635 y Fo(\017)25 b Ft(Adapt)12 b(the)g Fr(varno)g Ft(and)g +Fr(varattno)f Ft(\002elds)i(of)e(all)i Fr(VAR)f Ft(nodes)g(contained)g +(in)g(the)g Fp(oper)o(ator)395 695 y(tr)n(ee)i Ft(representing)g(the)f +Fp(having)h(clause)h Ft(in)e(the)h(same)h(way)e(as)i(it)f(has)g(been)g +(done)g(for)f(the)h(tree)395 755 y(representing)e(the)g +Fp(wher)n(e)i(clause)p Ft(.)j(The)d Fr(varno)e Ft(\002elds)h(are)f +(changed)h(to)g(use)g(the)g Fp(base)g(tables)395 814 +y Ft(gi)o(v)o(en)g(in)g(the)h Fp(vie)o(w)g(de\002nition)e +Ft(\(which)h(ha)o(v)o(e)h(been)g(inserted)f(into)g(the)g +Fp(r)o(ange)h(table)f(entry)h(list)395 874 y Ft(in)h(the)h(meantime\))f +(instead)i(of)e(the)h Fp(virtual)g(tables)p Ft(.)27 b(The)17 +b(positions)f(of)f(the)h(attrib)o(utes)g(used)395 934 +y(in)d(the)g Fp(vie)o(w)h Ft(may)g(dif)o(fer)e(from)g(the)h(positions)h +(of)f(the)g(corresponding)g(attrib)o(utes)g(in)g(the)h +Fp(base)395 994 y(tables)p Ft(.)h(That')m(s)e(why)f(the)h +Fr(varattno)e Ft(\002elds)i(also)f(ha)o(v)o(e)h(to)f(be)h(adapted.)345 +1106 y Fo(\017)25 b Ft(Adapt)i(the)h Fr(varno)f Ft(and)h +Fr(varattno)f Ft(\002elds)h(of)f(all)h Fr(VAR)f Ft(nodes)h(contained)g +(in)f(the)395 1166 y Fr(groupClause)11 b Ft(of)h(the)g(user')m(s)h +(query)f(in)g(the)g(way)g(and)g(for)g(the)g(reasons)h(described)f(abo)o +(v)o(e.)345 1278 y Fo(\017)25 b Ft(Attach)19 b(the)g(tree)g +(representing)g(the)h Fp(having)f(quali\002cation)f Ft(\(which)h(is)h +(currently)e(attached)395 1338 y(to)d(the)i(\002eld)e +Fr(havingClause)g Ft(of)h(the)g Fr(Query)f Ft(node)i(for)e(the)h(user') +m(s)g(query\))f(to)h(the)g(\002eld)395 1398 y Fr(havingClause)11 +b Ft(of)h(the)g Fr(Query)g Ft(node)g(for)g(the)g(ne)o(w)g(\(re)o +(written\))e(query)m(.)345 1510 y Fo(\017)25 b Ft(Attach)j(the)h(list)g +(representing)f(the)h Fp(gr)n(oup)g(clause)g Ft(\(currently)f(attached) +h(to)g(the)f(\002eld)395 1570 y Fr(groupClause)10 b Ft(of)h(the)g +Fr(Query)g Ft(node)g(for)f(the)h(user')m(s)h(query\))e(to)i(the)f +(\002eld)g Fp(gr)n(oup)g(clause)h Ft(of)395 1630 y(the)g(node)g(for)g +(the)g(ne)o(w)g(\(re)o(written\))e(query)m(.)270 1780 +y Fn(The)15 b(view)h(de\002nition)d(contains)i(a)g(ha)o(ving)f(clause:) +50 b Ft(No)o(w)15 b(we)g(will)g(look)g(at)g(the)g(problems)g(that)270 +1840 y(can)e(arise)f(using)g Fp(vie)o(ws)i Ft(that)e(are)g(de\002ned)g +(using)h(a)f(query)g(in)n(v)o(olving)g(a)g Fp(having)g(clause)p +Ft(.)270 1959 y(Let)h(the)f(follo)o(wing)f Fp(vie)o(w)i(de\002nition)f +Ft(be)g(gi)o(v)o(en:)330 2072 y Fr(create)29 b(view)g(test_view)330 +2132 y(as)g(select)h(sno,)f(count\(pno\))g(as)h(number)419 +2191 y(from)g(sells)419 2251 y(where)g(sno)f(>)h(2)419 +2311 y(group)g(by)f(sno)419 2371 y(having)h(count\(pno\))e(>)i(1;)270 +2480 y Ft(Simple)12 b(queries)g(against)g(this)h Fp(vie)o(w)g +Ft(will)f(not)g(cause)h(an)o(y)f(troubles:)330 2592 y +Fr(select)29 b(*)330 2652 y(from)g(test_view)330 2712 +y(where)g(sno)h(<>)f(5;)270 2821 y Ft(This)17 b(query)g(can)g(easily)g +(be)g(re)o(written)f(by)g(adding)h(the)g Fp(wher)n(e)g(quali\002cation) +f Ft(of)h(the)f(user')m(s)i(query)270 2881 y(\()p Fr(sno)29 +b Fk(<>)h Fr(5)p Ft(\))11 b(to)i(the)f Fp(wher)n(e)h(quali\002cation)f +Ft(of)g(the)g Fp(vie)o(w)h(de\002nition')n(s)24 b Ft(query)m(.)270 +3000 y(The)f(ne)o(xt)g(query)f(is)h(also)g(simple)g(b)o(ut)f(it)g(will) +h(cause)g(troubles)f(when)h(it)f(is)h(e)o(v)o(aluated)f(against)270 +3060 y(the)12 b(abo)o(v)o(e)h(gi)o(v)o(en)f Fp(vie)o(w)h(de\002nition)p +Ft(:)330 3173 y Fr(select)29 b(*)330 3232 y(from)g(test_view)330 +3292 y(where)g(number)g(>)h(1;)g(/*)f(count\(pno\))g(in)h(the)f(view)h +(def.)898 3352 y(*)f(is)h(called)59 b(number)29 b(here)h(*/)p +eop +%%Page: 71 71 +71 70 bop 198 60 a Fm(3.7.)29 b(THE)13 b(REALIZA)-6 b(TION)14 +b(OF)e(THE)h(HA)-7 b(VING)12 b(CLA)m(USE)622 b Ft(71)198 +234 y(The)13 b(currently)e(implemented)h(techniques)g(for)g(query)g(re) +o(writing)e(will)i(re)o(write)g(the)g(query)g(to:)258 +368 y Fr(select)29 b(*)258 428 y(from)g(sells)258 487 +y(where)g(sno)h(>)f(2)h(and)437 547 y(count\(pno\))f(>)h(1)258 +607 y(group)f(by)h(sno)258 667 y(having)f(count\(pno\))g(>)h(1;)198 +792 y Ft(which)12 b(is)h(an)f(in)n(v)o(alid)g(query)g(because)h(an)f +Fp(aggr)n(e)n(gate)g(function)g Ft(appears)g(in)h(the)f +Fp(wher)n(e)h(clause)p Ft(.)198 912 y(Also)g(the)f(ne)o(xt)g(query)g +(will)g(cause)h(troubles:)258 1045 y Fr(select)29 b(pno,)g +(count\(sno\))258 1105 y(from)g(test_view)258 1165 y(group)g(by)h(pno;) +198 1290 y Ft(As)16 b(you)f(can)h(see)g(this)g(query)f(does)h(neither)f +(in)n(v)o(olv)o(e)g(a)h Fp(wher)n(e)g(clause)g Ft(nor)f(a)h +Fp(having)f(clause)h Ft(b)o(ut)f(it)198 1350 y(contains)i(a)g +Fp(gr)n(oup)g(clause)g Ft(which)g(groups)g(by)g(the)g(attrib)o(ute)f +Fr(pno)p Ft(.)29 b(The)18 b(query)e(in)h(the)g(de\002nition)198 +1410 y(of)d(the)g Fp(vie)o(w)h Ft(also)g(contains)f(a)h +Fp(gr)n(oup)f(clause)h Ft(that)f(groups)g(by)g(the)h(attrib)o(ute)e +Fr(sno)p Ft(.)22 b(The)15 b(two)e Fp(gr)n(oup)198 1469 +y(clauses)19 b Ft(are)f(in)h(con\003ict)e(with)i(each)f(other)g(and)g +(therefore)g(the)g(query)g(cannot)g(be)h(re)o(written)e(to)h(a)198 +1529 y(form)11 b(that)h(would)g(make)g(sense.)198 1649 +y Fn(Note:)38 b Ft(There)24 b(is)g(no)g(solution)g(to)g(the)g(abo)o(v)o +(e)g(mentioned)g(problems)f(at)h(the)g(moment)f(and)h(it)198 +1709 y(does)12 b(not)f(make)g(sense)h(to)f(put)g(much)h(ef)o(fort)d +(into)i(that)h(because)g(the)f(implementation)f(of)h(the)h(support)198 +1768 y(for)g(queries)g(like:)258 1902 y Fr(select)29 +b(pno_count,)g(count\(sno\))258 1962 y(from)g(\()h(select)f(sno,)h +(count\(pno\))e(as)i(pno_count)467 2022 y(from)f(sells)467 +2081 y(where)g(sno)h(>)g(2)467 2141 y(group)f(by)h(sno)467 +2201 y(having)f(count\(pno\))g(>)h(1\))258 2261 y(group)f(by)h +(pno_count;)198 2386 y Ft(\(which)12 b(is)g(part)g(of)g(the)h(SQL92)f +(standard\))g(will)g(automatically)f(also)i(solv)o(e)g(these)g +(problems.)198 2506 y(In)26 b(the)h(ne)o(xt)g(part)f(of)h(the)g +(current)f(section)h(we)g(will)f(present)h(the)g(changes)g(applied)f +(to)h(the)198 2565 y(source)15 b(code)f(in)h(order)f(to)g(realize)h +(the)f(abo)o(v)o(e)h(described)g(items.)22 b(Note)15 +b(that)f(it)h(is)g(not)f(necessary)h(to)198 2625 y(understand)e(the)h +(meaning)g(of)f(e)o(v)o(ery)h(single)g(source)f(line)h(here)g(and)f +(therefore)g(we)h(will)g(not)f(discuss)198 2685 y(detailed)j(questions) +g(like)g(\224Why)g(has)g(the)g(v)o(ariable)g Fr(varno)f +Ft(to)h(be)g(increased)h(by)f(3?\224.)27 b(Questions)198 +2745 y(like)13 b(that)h(belong)f(to)h(a)g(chapter)f(dealing)g(with)h +(the)g(implementation)e(of)h Fp(vie)o(ws)i Ft(in)f(PostgreSQL)f(and)198 +2804 y(to)k(be)g(able)g(to)g(answer)g(them)g(it)g(would)f(be)h +(necessary)h(to)f(kno)o(w)f(all)h(the)g(functions)g(and)g(not)f(only) +198 2864 y(those)g(described)g(here.)25 b(The)17 b(fact)e(important)f +(for)h(us)h(is)g(to)g(make)f(sure,)i(that)f(whate)o(v)o(er)f(is)h +(applied)198 2924 y(to)d(the)g Fp(tar)n(getlist)g Ft(and)g(the)g(data)h +(structures)f(representing)f(the)h Fp(wher)n(e)i(clause)e +Ft(is)h(also)f(applied)g(to)g(the)198 2984 y(data)f(structures)h(for)e +(the)h Fp(having)g(clause)p Ft(.)17 b(There)12 b(are)h(three)f(\002les) +g(af)o(fected:)273 3103 y Fk(:)c(:)g(:)p Fr +(/src/backend/rewrite/rewriteHa)o(ndler.c)273 3163 y +Fk(:)g(:)g(:)p Fr(/src/backend/rewrite/rewriteMa)o(nip.c)273 +3223 y Fk(:)g(:)g(:)p Fr(/src/backend/commands/view.c)198 +3342 y Ft(Here)29 b(is)h(a)g(description)f(of)g(the)g(changes)h(made)g +(to)f(the)g(functions)g(contained)h(in)f(the)g(\002le)198 +3402 y Fk(:)8 b(:)g(:)p Fr(/src/backend/rewrite/rewriteHandl)o(er.c)p +Ft(:)p eop +%%Page: 72 72 +72 71 bop 270 60 a Ft(72)82 b Fm(CHAPTER)14 b(3.)28 b(POSTGRESQL)13 +b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW)345 +234 y Fo(\017)25 b Fr(ApplyRetrieveRule\(\))395 294 y +Ft(This)g(function)g(becomes)g(in)n(v)o(oked)f(whene)o(v)o(er)h(a)g +Fr(select)g Ft(statement)g(against)g(a)g Fp(vie)o(w)395 +354 y Ft(is)f(recognized)g(and)g(applies)g(the)g Fp(r)n(e)o(write)h +(rule)g Ft(stored)f(in)f(the)h Fp(system)h(catalogs)p +Ft(.)51 b(The)395 413 y(additional)23 b(source)h(lines)g(gi)o(v)o(en)f +(in)h(the)g(listing)f(belo)o(w)h(make)f(sure)h(that)g(the)g(functions) +395 473 y Fr(OffsetVarNodes\(\))12 b Ft(and)j Fr(ChangeVarNodes\(\))d +Ft(that)i(are)h(in)n(v)o(oked)e(for)h(the)g Fp(wher)n(e)395 +533 y(clause)g Ft(and)h(the)f Fp(tar)n(getlist)g Ft(of)g(the)g(query)g +(gi)o(v)o(en)g(in)h(the)f Fp(vie)o(w)h(de\002nition)f +Ft(are)g(also)h(called)f(for)395 593 y(the)i Fp(having)h(clause)g +Ft(and)g(the)g Fp(gr)n(oup)g(clause)g Ft(of)f(the)h(query)f(in)h(the)g +Fp(vie)o(w)g(de\002nition)p Ft(.)29 b(These)395 653 y(functions)11 +b(adapt)i(the)f Fr(varno)g Ft(and)g Fr(varattno)g Ft(\002elds)g(of)g +(the)h Fr(VAR)f Ft(nodes)g(in)n(v)o(olv)o(ed.)395 730 +y(The)g(additional)g(source)g(lines)g(at)g(the)g(end)g(of)g +Fr(ApplyRetrieveRule\(\))e Ft(attach)i(the)g(data)395 +790 y(structures)k(representing)g(the)h Fp(having)f(clause)i +Ft(and)e(the)h Fp(gr)n(oup)g(clause)g Ft(of)f(the)h(query)f(in)h(the) +395 850 y Fp(vie)o(w)h(de\002nition)g Ft(to)g(the)g(re)o(written)e +Fp(parsetr)n(ee)p Ft(.)34 b(As)19 b(mentioned)e(earlier)n(,)j(a)e +Fp(vie)o(w)h(de\002nition)395 910 y Ft(in)n(v)o(olving)8 +b(a)i Fp(gr)n(oup)g(clause)g Ft(will)g(cause)g(troubles)f(whene)o(v)o +(er)h(a)g(query)f(using)h(a)g(dif)o(ferent)e Fp(gr)n(oup)395 +969 y(clause)i Ft(against)f(this)h Fp(vie)o(w)h Ft(is)f(e)o(x)o +(ecuted.)16 b(There)10 b(is)g(no)f(mechanism)h(pre)o(v)o(enting)f +(these)i(troubles)395 1029 y(included)h(at)g(the)g(moment.)395 +1107 y(Note)30 b(that)g(the)g(functions)g Fr(OffsetVarNodes\(\))e +Ft(,)36 b Fr(ChangeVarNodes\(\))28 b Ft(and)395 1167 +y Fr(AddHavingQual\(\))14 b Ft(appearing)i(in)g Fr +(ApplyRetrieveRule\(\))e Ft(are)i(described)h(at)f(a)395 +1227 y(later)c(point)f(in)i(time.)454 1337 y Fr(static)30 +b(void)454 1397 y(ApplyRetrieveRule\(Query)e(*parsetree,)g(RewriteRule) +h(*rule,)992 1456 y(int)h(rt_index,)f(int)g(relation_level,)992 +1516 y(Relation)g(relation,)g(int)h(*modified\))454 1576 +y({)514 1636 y(Query)59 b(*rule_action)29 b(=)h(NULL;)514 +1696 y(Node)89 b(*rule_qual;)514 1755 y(List)g(*rtable,)1231 +1815 y(.)1231 1875 y(.)1231 1935 y(.)514 1994 y(OffsetVarNodes\(\(Node) +28 b(*\))h(rule_action->targetList,)962 2054 y(rt_length\);)514 +2114 y(OffsetVarNodes\(rule_qual,)e(rt_length\);)395 +2233 y(+)89 b(OffsetVarNodes\(\(Node)28 b(*\))h +(rule_action->groupClause,)395 2293 y(+)537 b(rt_length\);)395 +2353 y(+)89 b(OffsetVarNodes\(\(Node)28 b(*\))h +(rule_action->havingQual,)395 2413 y(+)537 b(rt_length\);)1231 +2473 y(.)1231 2532 y(.)1231 2592 y(.)514 2652 y +(ChangeVarNodes\(rule_qual,)962 2712 y(PRS2_CURRENT_VARNO)28 +b(+)i(rt_length,)962 2771 y(rt_index,)f(0\);)395 2891 +y(+)89 b(ChangeVarNodes\(\(Node)28 b(*\))h(rule_action->groupClause,) +395 2951 y(+)537 b(PRS2_CURRENT_VARNO)28 b(+)i(rt_length,)395 +3011 y(+)537 b(rt_index,)29 b(0\);)395 3070 y(+)89 b +(ChangeVarNodes\(\(Node)28 b(*\))h(rule_action->havingQual,)395 +3130 y(+)537 b(PRS2_CURRENT_VARNO)28 b(+)i(rt_length,)395 +3190 y(+)537 b(rt_index,)29 b(0\);)1231 3250 y(.)1231 +3309 y(.)1231 3369 y(.)p eop +%%Page: 73 73 +73 72 bop 198 60 a Fm(3.7.)29 b(THE)13 b(REALIZA)-6 b(TION)14 +b(OF)e(THE)h(HA)-7 b(VING)12 b(CLA)m(USE)622 b Ft(73)442 +234 y Fr(if)30 b(\(*modified)f(&&)g(!badsql\))442 294 +y({)502 354 y(AddQual\(parsetree,)f(rule_action->qual\);)323 +413 y(+)149 b(/*)30 b(This)f(will)g(only)h(work)f(if)h(the)f(query)h +(made)f(to)h(the)323 473 y(+)179 b(*)30 b(view)f(defined)g(by)h(the)f +(following)g(groupClause)323 533 y(+)179 b(*)30 b(groups)f(by)g(the)h +(same)f(attributes)g(or)h(does)f(not)h(use)323 593 y(+)179 +b(*)30 b(groups)f(at)g(all!)323 653 y(+)179 b(*/)323 +712 y(+)g(if)29 b(\(parsetree->groupClause)f(==)h(NULL\))323 +772 y(+)268 b(parsetree->groupClause)28 b(=)323 832 y(+)597 +b(rule_action->groupClause;)323 892 y(+)179 b +(AddHavingQual\(parsetree,)323 951 y(+)597 b +(rule_action->havingQual\);)323 1011 y(+)179 b(parsetree->hasAggs)28 +b(=)323 1071 y(+)268 b(\(rule_action->hasAggs)28 b(||)i +(parsetree->hasAggs\);)323 1131 y(+)179 b(parsetree->hasSubLinks)27 +b(=)323 1191 y(+)268 b(\(rule_action->hasSubLinks)27 +b(||)323 1250 y(+)298 b(parsetree->hasSubLinks\);)442 +1310 y(})382 1370 y(})273 1529 y Fo(\017)25 b Fr +(QueryRewriteSubLink\(\))323 1588 y Ft(This)17 b(function)e(is)i +(called)g(by)g Fr(QueryRewrite\(\))e Ft(to)h(process)h(possibly)g +(contained)f(sub-)323 1648 y(queries)d(\002rst.)k(It)c(searches)h(for)e +(nested)i(queries)f(by)g(recursi)o(v)o(ely)f(tracing)h(through)f(the)h +Fp(parse-)323 1708 y(tr)n(ee)h Ft(gi)o(v)o(en)g(as)g(ar)o(gument.)20 +b(The)15 b(additional)e(statement)h(makes)g(sure)g(that)f(the)h +Fp(having)g(clause)323 1768 y Ft(is)e(also)h(e)o(xamined.)382 +1911 y Fr(static)30 b(void)382 1970 y(QueryRewriteSubLink\(Node)e +(*node\))382 2030 y({)442 2090 y(if)i(\(node)f(==)h(NULL\))532 +2150 y(return;)442 2209 y(switch)f(\(nodeTag\(node\)\))442 +2269 y({)502 2329 y(case)g(T_SubLink:)502 2389 y({)1159 +2449 y(.)1159 2508 y(.)1159 2568 y(.)592 2628 y +(QueryRewriteSubLink\(\(Node)e(*\))i(query->qual\);)323 +2688 y(+)239 b(QueryRewriteSubLink\(\(Node)27 b(*\))323 +2747 y(+)836 b(query->havingQual\);)1159 2807 y(.)1159 +2867 y(.)1159 2927 y(.)502 2987 y(})1159 3046 y(.)1159 +3106 y(.)1159 3166 y(.)442 3226 y(})442 3285 y(return;)382 +3345 y(})p eop +%%Page: 74 74 +74 73 bop 270 60 a Ft(74)82 b Fm(CHAPTER)14 b(3.)28 b(POSTGRESQL)13 +b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW)345 +234 y Fo(\017)25 b Fr(QueryRewrite\(\))395 294 y Ft(This)c(function)g +(takes)g(the)g Fp(parsetr)n(ee)h Ft(of)f(a)h(query)f(and)g(re)o(writes) +f(it)i(using)f(PostgreSQL)-5 b(')m(s)395 354 y Fp(r)n(e)o(write)27 +b(system)p Ft(.)58 b(Before)26 b(the)g(query)g(itself)g(can)h(be)f(re)o +(written,)j(subqueries)d(that)g(are)395 413 y(possibly)33 +b(part)f(of)g(the)h(query)f(ha)o(v)o(e)i(to)e(be)h(processed.)78 +b(Therefore)32 b(the)h(function)395 473 y Fr(QueryRewriteSubLink\(\))17 +b Ft(is)k(called)f(for)g(the)g Fp(wher)n(e)h(clause)g +Ft(and)f(for)f(the)h Fp(having)395 533 y(clause)p Ft(.)454 +648 y Fr(List)30 b(*)454 708 y(QueryRewrite\(Query)e(*parsetree\))454 +768 y({)514 828 y(QueryRewriteSubLink\(parsetree->q)o(ual\);)395 +887 y(+)89 b(QueryRewriteSubLink\(parsetree->h)o(avingQual)o(\);)514 +947 y(return)29 b(QueryRewriteOne\(parsetree\);)454 1007 +y(})270 1122 y Ft(Here)c(we)h(present)f(the)g(changes)h(applied)f(to)g +(the)h(functions)e(that)i(are)f(contained)g(in)g(the)g(\002le)270 +1182 y Fk(:)8 b(:)g(:)p Fr(/src/backend/rewrite/rewriteManip)o(.c)p +Ft(:)345 1278 y Fo(\017)25 b Fr(OffsetVarNodes\(\))395 +1338 y Ft(Recursi)o(v)o(ely)15 b(steps)h(through)f(the)g +Fp(parsetr)n(ee)i Ft(gi)o(v)o(en)e(as)h(the)g(\002rst)f(ar)o(gument)g +(and)g(increments)395 1398 y(the)h Fr(varno)f Ft(and)h +Fr(varnoold)f Ft(\002elds)h(of)g(e)o(v)o(ery)g Fr(VAR)f +Ft(node)h(found)g(by)g(the)g Fp(of)o(fset)g Ft(gi)o(v)o(en)g(as)395 +1457 y(the)f(second)h(ar)o(gument.)24 b(The)16 b(additional)f +(statements)g(are)h(necessary)g(to)f(be)g(able)h(to)f(handle)395 +1517 y Fr(GroupClause)e Ft(nodes)h(and)g Fr(Sublink)g +Ft(nodes)h(that)f(may)g(appear)g(in)g(the)g Fp(parsetr)n(ee)h +Ft(from)395 1577 y(no)o(w)d(on.)454 1692 y Fr(void)454 +1752 y(OffsetVarNodes\(Node)28 b(*node,)h(int)h(offset\))454 +1812 y({)544 1871 y(if)g(\(node)f(==)h(NULL\))634 1931 +y(return;)544 1991 y(switch)f(\(nodeTag\(node\)\))544 +2051 y({)1231 2111 y(.)1231 2170 y(.)1231 2230 y(.)395 +2290 y(+)209 b(/*)29 b(This)h(has)f(to)h(be)g(done)f(to)h(make)f +(queries)g(using)395 2350 y(+)239 b(*)29 b(groupclauses)g(work)g(on)h +(views)395 2409 y(+)239 b(*/)395 2469 y(+)g(case)29 b(T_GroupClause:) +395 2529 y(+)239 b({)395 2589 y(+)298 b(GroupClause)29 +b(*group)g(=)h(\(GroupClause)e(*\))i(node;)395 2649 y(+)395 +2708 y(+)298 b(OffsetVarNodes\(\(Node)28 b(*\)\(group->entry\),)395 +2768 y(+)747 b(offset\);)395 2828 y(+)239 b(})395 2888 +y(+)g(break;)1231 2947 y(.)1231 3007 y(.)1231 3067 y(.)395 +3127 y(+)g(case)29 b(T_SubLink:)395 3187 y(+)239 b({)395 +3246 y(+)298 b(SubLink)29 b(*sublink)g(=)h(\(SubLink)f(*\))h(node;)395 +3306 y(+)298 b(List)30 b(*tmp_oper,)f(*tmp_lefthand;)395 +3366 y(+)p eop +%%Page: 75 75 +75 74 bop 198 60 a Fm(3.7.)29 b(THE)13 b(REALIZA)-6 b(TION)14 +b(OF)e(THE)h(HA)-7 b(VING)12 b(CLA)m(USE)622 b Ft(75)323 +234 y Fr(+)298 b(/*)30 b(We)g(also)f(have)h(to)f(adapt)g(the)h +(variables)f(used)323 294 y(+)328 b(*)30 b(in)g(sublink->lefthand)e +(and)h(sublink->oper)323 354 y(+)328 b(*/)323 413 y(+)298 +b(OffsetVarNodes\(\(Node)28 b(*\)\(sublink->lefthand\),)323 +473 y(+)747 b(offset\);)323 533 y(+)323 593 y(+)298 b(/*)30 +b(Make)f(sure)h(the)f(first)h(argument)f(of)323 653 y(+)328 +b(*)30 b(sublink->oper)e(points)i(to)f(the)h(same)f(var)h(as)323 +712 y(+)328 b(*)30 b(sublink->lefthand)e(does)h(otherwise)g(we)h(will) +323 772 y(+)328 b(*)30 b(run)g(into)f(troubles)g(using)g(aggregates)g +(\(aggno)323 832 y(+)328 b(*)30 b(will)f(not)h(be)g(set)f(correctly\)) +323 892 y(+)328 b(*/)323 951 y(+)298 b(tmp_lefthand)29 +b(=)h(sublink->lefthand;)323 1011 y(+)298 b(foreach\(tmp_oper,)28 +b(sublink->oper\))323 1071 y(+)298 b({)323 1131 y(+)358 +b(lfirst\(\(\(Expr)29 b(*\)lfirst\(tmp_oper\)\)->args\))d(=)323 +1191 y(+)1016 b(lfirst\(tmp_lefthand\);)323 1250 y(+)358 +b(tmp_lefthand)29 b(=)g(lnext\(tmp_lefthand\);)323 1310 +y(+)298 b(})323 1370 y(+)239 b(})323 1430 y(+)g(break;)1159 +1489 y(.)1159 1549 y(.)1159 1609 y(.)472 1669 y(})382 +1729 y(})273 1838 y Fo(\017)25 b Fr(ChangeVarNodes\(\))323 +1898 y Ft(This)d(function)f(is)h(similar)f(to)h(the)g(abo)o(v)o(e)g +(described)g(function)f Fr(OffsetVarNodes\(\))323 1958 +y Ft(b)o(ut)e(instead)h(of)f(incrementing)g(the)h(\002elds)g +Fr(varno)f Ft(and)h Fr(varnoold)f Ft(of)g Fp(all)g Fr(VAR)h +Ft(nodes)323 2017 y(found,)j(it)e(processes)h(only)f(those)g +Fr(VAR)g Ft(nodes)h(whose)f Fr(varno)g Ft(v)o(alue)g(matches)g(the)g +(pa-)323 2077 y(rameter)13 b Fr(old)p 582 2077 15 2 v +18 w(varno)h Ft(gi)o(v)o(en)g(as)h(ar)o(gument)f(and)g(whose)h +Fr(varlevelsup)f Ft(v)o(alue)g(matches)323 2137 y(the)i(parameter)g +Fr(sublevels)p 889 2137 V 17 w(up)p Ft(.)29 b(Whene)o(v)o(er)17 +b(such)g(a)g(node)g(is)g(found,)h(the)f Fr(varno)f Ft(and)323 +2197 y Fr(varnoold)10 b Ft(\002elds)h(are)g(set)g(to)g(the)g(v)o(alue)g +(gi)o(v)o(en)g(in)g(the)g(parameter)f Fr(new)p 1615 2197 +V 18 w(varno)p Ft(.)15 b(The)d(addi-)323 2257 y(tional)g(statements)i +(are)f(necessary)h(to)f(be)h(able)f(to)g(handle)g Fr(GroupClause)f +Ft(and)i Fr(Sublink)323 2316 y Ft(nodes.)382 2419 y Fr(void)382 +2479 y(ChangeVarNodes\(Node)28 b(*node,)h(int)h(old_varno,)831 +2539 y(int)f(new_varno,)g(int)g(sublevels_up\))382 2599 +y({)442 2658 y(if)h(\(node)f(==)h(NULL\))532 2718 y(return;)442 +2778 y(switch)f(\(nodeTag\(node\)\))442 2838 y({)1159 +2897 y(.)1159 2957 y(.)1159 3017 y(.)323 3077 y(+)149 +b(/*)30 b(This)f(has)h(to)f(be)h(done)f(to)h(make)f(queries)g(using)323 +3137 y(+)179 b(*)30 b(groupclauses)e(work)i(on)f(views)g(*/)323 +3196 y(+)149 b(case)29 b(T_GroupClause:)323 3256 y(+)149 +b({)323 3316 y(+)209 b(GroupClause)58 b(*group)29 b(=)h(\(GroupClause)f +(*\))g(node;)323 3376 y(+)p eop +%%Page: 76 76 +76 75 bop 270 60 a Ft(76)82 b Fm(CHAPTER)14 b(3.)28 b(POSTGRESQL)13 +b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW)395 +234 y Fr(+)209 b(ChangeVarNodes\(\(Node)27 b(*\)\(group->entry\),)395 +294 y(+)657 b(old_varno,)29 b(new_varno,)395 354 y(+)657 +b(sublevels_up\);)395 413 y(+)149 b(})395 473 y(+)g(break;)1231 +533 y(.)1231 593 y(.)1231 653 y(.)574 712 y(case)29 b(T_Var:)574 +772 y({)1231 832 y(.)1231 892 y(.)1231 951 y(.)634 1011 +y(/*)g(This)h(is)f(a)h(hack:)g(Whenever)e(an)i(attribute)664 +1071 y(*)f(from)h(the)f("outside")g(query)g(is)h(used)g(within)664 +1131 y(*)f(a)h(nested)f(subquery,)g(the)h(varlevelsup)e(will)664 +1191 y(*)h(be)h(>0.)g(Nodes)f(having)g(varlevelsup)g(>)g(0)h(are)664 +1250 y(*)f(forgotten)g(to)h(be)g(processed.)e(The)i(call)f(to)664 +1310 y(*)g(OffsetVarNodes\(\))f(should)i(really)f(be)g(done)h(at)664 +1370 y(*)f(another)g(place)h(but)f(this)h(hack)f(makes)g(sure)664 +1430 y(*)g(that)h(also)f(those)h(VAR)f(nodes)g(are)h(processed.)664 +1489 y(*/)395 1549 y(+)209 b(if)29 b(\(var->varlevelsup)f(>)i(0\))395 +1609 y(+)298 b(OffsetVarNodes\(\(Node)28 b(*\)var,3\);)574 +1669 y(})574 1729 y(break;)1231 1788 y(.)1231 1848 y(.)1231 +1908 y(.)574 1968 y(case)h(T_SubLink:)574 2027 y({)1231 +2087 y(.)1231 2147 y(.)1231 2207 y(.)395 2267 y(+)209 +b(ChangeVarNodes\(\(Node)27 b(*\))j(query->havingQual,)395 +2326 y(+)657 b(old_varno,)29 b(new_varno,)395 2386 y(+)657 +b(sublevels_up\);)395 2446 y(+)209 b(ChangeVarNodes\(\(Node)27 +b(*\))j(query->targetList,)395 2506 y(+)657 b(old_varno,)29 +b(new_varno,)395 2565 y(+)657 b(sublevels_up\);)395 2625 +y(+)395 2685 y(+)209 b(/*)29 b(We)h(also)f(have)h(to)g(adapt)f(the)g +(variables)g(used)h(in)395 2745 y(+)239 b(*)29 b(sublink->lefthand)f +(and)i(sublink->oper)395 2804 y(+)239 b(*/)395 2864 y(+)209 +b(ChangeVarNodes\(\(Node)27 b(*\))j(\(sublink->lefthand\),)395 +2924 y(+)657 b(old_varno,)29 b(new_varno,)395 2984 y(+)657 +b(sublevels_up\);)574 3044 y(})574 3103 y(break;)1231 +3163 y(.)1231 3223 y(.)1231 3283 y(.)514 3342 y(})454 +3402 y(})p eop +%%Page: 77 77 +77 76 bop 198 60 a Fm(3.7.)26 b(THE)13 b(REALIZA)-6 b(TION)14 +b(OF)e(THE)h(HA)-7 b(VING)12 b(CLA)m(USE)625 b Ft(77)273 +234 y Fo(\017)25 b Fr(AddHavingQual\(\))323 294 y Ft(This)17 +b(function)f(adds)h(the)g Fp(oper)o(ator)g(tr)n(ee)h +Ft(gi)o(v)o(en)e(by)h(the)g(parameter)f Fr(havingQual)g +Ft(to)g(the)323 354 y(one)k(attached)g(to)g(the)g(\002eld)g +Fr(havingQual)f Ft(of)h(the)g Fp(parsetr)n(ee)i Ft(gi)o(v)o(en)e(by)g +(the)g(parameter)323 413 y Fr(parsetree)p Ft(.)28 b(This)17 +b(is)g(done)g(by)g(adding)f(a)h(ne)o(w)g Fr(AND)g Ft(node)f(and)h +(attaching)g(the)g(old)f(and)323 473 y(the)d(ne)o(w)h +Fp(oper)o(ator)h(tr)n(ee)f Ft(as)h(ar)o(guments)f(to)f(it.)21 +b Fr(AddHavingQual\(\))12 b Ft(has)i(not)g(been)g(e)o(xist-)323 +533 y(ing)e(until)f(v6.3.2.)17 b(It)12 b(has)h(been)f(created)g(for)g +(the)g Fp(having)g(logic)p Ft(.)382 667 y Fr(void)382 +727 y(AddHavingQual\(Query)28 b(*parsetree,)h(Node)g(*havingQual\))382 +787 y({)442 847 y(Node)59 b(*copy,)30 b(*old;)442 966 +y(if)g(\(havingQual)e(==)i(NULL\))532 1026 y(return;)442 +1146 y(copy)g(=)f(havingQual;)442 1265 y(old)h(=)f +(parsetree->havingQual;)442 1325 y(if)h(\(old)f(==)h(NULL\))562 +1385 y(parsetree->havingQual)d(=)j(copy;)442 1445 y(else)562 +1504 y(parsetree->havingQual)d(=)681 1564 y(\(Node)j(*\))f +(make_andclause\()1010 1624 y(makeList\(parsetree->havingQual,)1279 +1684 y(copy,)g(-1\)\);)382 1743 y(})273 1878 y Fo(\017)c +Fr(AddNotHavingQual\(\))323 1938 y Ft(This)17 b(function)f(is)i +(similar)e(to)h(the)g(abo)o(v)o(e)h(described)f(function)f +Fr(AddHavingQual\(\))p Ft(.)29 b(It)323 1998 y(also)14 +b(adds)g(the)f Fp(oper)o(ator)i(tr)n(ee)f Ft(gi)o(v)o(en)g(by)f(the)h +(parameter)f Fr(havingQual)f Ft(b)o(ut)i(pre\002x)o(es)g(it)f(by)323 +2057 y(a)h Fr(NOT)g Ft(node.)22 b Fr(AddNotHavingQual\(\))13 +b Ft(has)i(also)g(not)f(been)h(e)o(xisting)f(until)g(v6.3.2)h(and)323 +2117 y(has)d(been)h(created)f(for)g(the)g Fp(having)g(logic)p +Ft(.)382 2252 y Fr(void)382 2311 y(AddNotHavingQual\(Query)28 +b(*parsetree,)890 2371 y(Node)i(*havingQual\))382 2431 +y({)442 2491 y(Node)g(*copy;)442 2610 y(if)g(\(havingQual)e(==)i +(NULL\))532 2670 y(return;)442 2790 y(copy)g(=)f(\(Node)h(*\))f +(make_notclause\(\(Expr)f(*\)havingQual\);)442 2849 y +(AddHavingQual\(parsetree,)f(copy\);)323 2909 y(})273 +3044 y Fo(\017)e Fr(nodeHandleViewRule\(\))323 3103 y +Ft(This)20 b(function)f(is)h(called)g(by)g Fr(HandleViewRule\(\))p +Ft(.)36 b(It)20 b(replaces)g(all)g Fr(VAR)f Ft(nodes)i(of)323 +3163 y(the)16 b Fp(user)i(query)f Ft(e)o(v)o(aluated)f(against)g(the)h +Fp(vie)o(w)g Ft(\(the)f(\002elds)h(of)f(these)h Fr(VAR)g +Ft(nodes)f(represent)323 3223 y(the)g(positions)h(of)f(the)g(attrib)o +(utes)g(in)h(the)f Fp(virtual)h Ft(table\))f(by)g Fr(VAR)g +Ft(nodes)h(that)f(ha)o(v)o(e)h(already)323 3283 y(been)c(prepared)g(to) +h(represent)f(the)h(positions)g(of)f(the)h(corresponding)f(attrib)o +(utes)g(in)g(the)h Fp(phys-)323 3342 y(ical)h Ft(tables)h(\(gi)o(v)o +(en)f(in)h(the)g Fp(vie)o(w)g(de\002nition)p Ft(\).)25 +b(The)16 b(additional)f(statements)h(make)f(sure)h(that)323 +3402 y Fr(GroupClause)11 b Ft(nodes)h(and)h Fr(Sublink)e +Ft(nodes)i(are)f(handled)h(correctly)m(.)p eop +%%Page: 78 78 +78 77 bop 270 60 a Ft(78)85 b Fm(CHAPTER)14 b(3.)25 b(POSTGRESQL)13 +b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW)454 +234 y Fr(static)30 b(void)454 294 y(nodeHandleViewRule\(Node)e +(**nodePtr,)g(List)i(*rtable,)1022 354 y(List)g(*targetlist,)e(int)i +(rt_index,)1022 413 y(int)g(*modified,)e(int)i(sublevels_up\))454 +473 y({)514 533 y(Node)g(*node)f(=)h(*nodePtr;)514 593 +y(if)g(\(node)f(==)h(NULL\))604 653 y(return;)514 712 +y(switch)f(\(nodeTag\(node\)\))514 772 y({)1231 832 y(.)1231 +892 y(.)1231 951 y(.)395 1011 y(+)149 b(/*)30 b(This)f(has)h(to)f(be)h +(done)f(to)h(make)f(queries)g(using)395 1071 y(+)179 +b(*)30 b(groupclauses)e(work)i(on)f(views)395 1131 y(+)179 +b(*/)395 1191 y(+)149 b(case)29 b(T_GroupClause:)395 +1250 y(+)149 b({)395 1310 y(+)209 b(GroupClause)58 b(*group)29 +b(=)h(\(GroupClause)f(*\))g(node;)395 1370 y(+)209 b +(nodeHandleViewRule\(\(Node)27 b(**\))i(\(&\(group->entry\)\),)395 +1430 y(+)777 b(rtable,)29 b(targetlist,)f(rt_index,)395 +1489 y(+)777 b(modified,)28 b(sublevels_up\);)395 1549 +y(+)149 b(})395 1609 y(+)g(break;)1231 1669 y(.)1231 +1729 y(.)1231 1788 y(.)574 1848 y(case)29 b(T_Var:)574 +1908 y({)1231 1968 y(.)1231 2027 y(.)1231 2087 y(.)634 +2147 y(if)g(\(n)h(==)g(NULL\))634 2207 y({)693 2267 y(*nodePtr)f(=)h +(make_null\(\(\(Var)e(*\)node\)->vartype\);)634 2326 +y(})634 2386 y(else)395 2446 y(+)209 b(/*)29 b(This)h(is)f(a)h(hack:)g +(The)f(varlevelsup)g(of)g(the)395 2506 y(+)239 b(*)29 +b(original)g(variable)g(and)h(the)f(new)h(one)f(should)395 +2565 y(+)239 b(*)29 b(be)h(the)g(same.)f(Normally)g(we)g(adapt)h(the)f +(node)395 2625 y(+)239 b(*)29 b(by)h(changing)f(a)h(pointer)f(to)g +(point)h(to)f(a)h(var)395 2685 y(+)239 b(*)29 b(contained)g(in)h +('targetlist'.)e(In)i(the)395 2745 y(+)239 b(*)29 b(targetlist)g(all)h +(varlevelsups)e(are)i(0)f(so)h(if)395 2804 y(+)239 b(*)29 +b(we)h(want)f(to)h(change)f(it)h(to)g(the)f(original)395 +2864 y(+)239 b(*)29 b(value)h(we)f(have)h(to)f(copy)h(the)f(node)h +(before!)395 2924 y(+)239 b(*)29 b(\(Maybe)h(this)f(will)g(cause)h +(troubles)f(with)g(some)395 2984 y(+)239 b(*)29 b(sophisticated)g +(queries)g(on)g(views?\))395 3044 y(+)239 b(*/)395 3103 +y(+)209 b({)395 3163 y(+)268 b(if\(this_varlevelsup>0\))395 +3223 y(+)g({)395 3283 y(+)358 b(*nodePtr)29 b(=)h(copyObject\(n\);)395 +3342 y(+)268 b(})395 3402 y(+)g(else)p eop +%%Page: 79 79 +79 78 bop 198 60 a Fm(3.7.)29 b(THE)13 b(REALIZA)-6 b(TION)14 +b(OF)e(THE)h(HA)-7 b(VING)12 b(CLA)m(USE)622 b Ft(79)323 +234 y Fr(+)268 b({)323 294 y(+)328 b(*nodePtr)29 b(=)h(n;)323 +354 y(+)268 b(})323 413 y(+)g(\(\(Var)30 b(*\)*nodePtr\)->varlevelsup)d +(=)323 473 y(+)836 b(this_varlevelsup;)323 533 y(+)209 +b(})562 593 y(*modified)29 b(=)g(TRUE;)502 653 y(})502 +712 y(break;)1159 772 y(.)1159 832 y(.)1159 892 y(.)502 +951 y(case)g(T_SubLink:)502 1011 y({)1159 1071 y(.)1159 +1131 y(.)1159 1191 y(.)323 1250 y(+)209 b(nodeHandleViewRule\()323 +1310 y(+)508 b(\(Node)29 b(**\))g(&\(query->havingQual\),)323 +1370 y(+)508 b(rtable,)29 b(targetlist,)f(rt_index,)323 +1430 y(+)508 b(modified,)28 b(sublevels_up\);)323 1489 +y(+)209 b(nodeHandleViewRule\()323 1549 y(+)508 b(\(Node)29 +b(**\))g(&\(query->targetList\),)323 1609 y(+)508 b(rtable,)29 +b(targetlist,)f(rt_index,)323 1669 y(+)508 b(modified,)28 +b(sublevels_up\);)323 1729 y(+)209 b(/*)29 b(We)h(also)f(have)h(to)g +(adapt)f(the)g(variables)g(used)323 1788 y(+)239 b(*)29 +b(in)h(sublink->lefthand)e(and)h(sublink->oper)323 1848 +y(+)239 b(*/)323 1908 y(+)209 b(nodeHandleViewRule\()323 +1968 y(+)508 b(\(Node)29 b(**\))g(&\(sublink->lefthand\),)323 +2027 y(+)508 b(rtable,)29 b(targetlist,)f(rt_index,)323 +2087 y(+)508 b(modified,)28 b(sublevels_up\);)323 2147 +y(+)209 b(/*)29 b(Make)h(sure)f(the)h(first)f(argument)g(of)323 +2207 y(+)239 b(*)29 b(sublink->oper)g(points)g(to)h(the)f(same)h(var)f +(as)323 2267 y(+)239 b(*)29 b(sublink->lefthand)f(does)i(otherwise)f +(we)g(will)323 2326 y(+)239 b(*)29 b(run)h(into)f(troubles)g(using)h +(aggregates)323 2386 y(+)239 b(*)29 b(\(aggno)h(will)f(not)h(be)f(set)h +(correctly!\))323 2446 y(+)239 b(*/)323 2506 y(+)209 +b(pfree\(lfirst\(\(\(Expr)27 b(*\))323 2565 y(+)597 b +(lfirst\(sublink->oper\)\)->args\)\);)323 2625 y(+)209 +b(tmp_lefthand)28 b(=)i(sublink->lefthand;)323 2685 y(+)209 +b(foreach\(tmp_oper,)28 b(sublink->oper\))323 2745 y(+)209 +b({)323 2804 y(+)298 b(lfirst\(\(\(Expr)29 b(*\))g +(lfirst\(tmp_oper\)\)->args\))f(=)323 2864 y(+)1016 b +(lfirst\(tmp_lefthand\);)323 2924 y(+)298 b(tmp_lefthand)29 +b(=)h(lnext\(tmp_lefthand\);)323 2984 y(+)209 b(})502 +3044 y(})502 3103 y(break;)1159 3163 y(.)1159 3223 y(.)1159 +3283 y(.)442 3342 y(})382 3402 y(})p eop +%%Page: 80 80 +80 79 bop 270 60 a Ft(80)82 b Fm(CHAPTER)14 b(3.)28 b(POSTGRESQL)13 +b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW)345 +234 y Fo(\017)25 b Fr(HandleViewRule\(\))395 294 y Ft(This)11 +b(function)g(calls)g Fr(nodeHandleViewRule\(\))f Ft(for)g(the)h +Fp(wher)n(e)h(clause)p Ft(,)h(the)e Fp(tar)n(getlist)p +Ft(,)395 354 y(the)h Fp(gr)n(oup)g(clause)h Ft(and)f(the)h +Fp(having)f(clause)g Ft(of)g(the)h Fp(user)g(query)g +Ft(e)o(v)o(aluated)f(against)g(the)g(gi)o(v)o(en)395 +413 y Fp(vie)o(w)p Ft(.)454 537 y Fr(void)454 597 y +(HandleViewRule\(Query)28 b(*parsetree,)h(List)g(*rtable,)903 +656 y(List)g(*targetlist,)g(int)g(rt_index,)903 716 y(int)g +(*modified\))454 776 y({)1231 836 y(.)1231 895 y(.)1231 +955 y(.)395 1015 y(+)89 b(/*)30 b(The)f(variables)g(in)h(the)f +(havingQual)g(and)395 1075 y(+)119 b(*)30 b(groupClause)e(also)i(have)f +(to)h(be)g(adapted)395 1135 y(+)119 b(*/)395 1194 y(+)89 +b(nodeHandleViewRule\(&parsetree->h)o(avingQual)o(,)27 +b(rtable,)395 1254 y(+)657 b(targetlist,)29 b(rt_index,)395 +1314 y(+)657 b(modified,)29 b(0\);)395 1374 y(+)89 b +(nodeHandleViewRule\()395 1433 y(+)328 b(\(Node)30 b +(**\)\(&\(parsetree->groupClaus)o(e\)\),)395 1493 y(+)328 +b(rtable,)29 b(targetlist,)g(rt_index,)g(modified,)g(0\);)454 +1553 y(})270 1676 y Ft(The)13 b(follo)o(wing)e(function)g(is)i +(contained)f(in)g Fk(:)c(:)g(:)p Fr(/src/backend/commands/view.c)p +Ft(:)345 1790 y Fo(\017)25 b Fr(UpdateRangeTableOfViewParse\()o(\))395 +1849 y Ft(This)f(function)f(updates)h(the)g Fp(r)o(ange)g(table)f +Ft(of)g(the)h Fp(parsetr)n(ee)h Ft(gi)o(v)o(en)e(by)h(the)g(parameter) +395 1909 y Fr(viewParse)p Ft(.)14 b(The)e(additional)e(statement)h +(makes)g(sure)g(that)g(the)g Fr(VAR)g Ft(nodes)g(of)f(the)h +Fp(having)395 1969 y(clause)h Ft(are)h(modi\002ed)e(in)h(the)h(same)f +(way)g(as)h(the)g Fr(VAR)f Ft(nodes)g(of)g(the)h Fp(wher)n(e)g(clause)g +Ft(are.)454 2092 y Fr(static)30 b(void)454 2152 y +(UpdateRangeTableOfViewParse\(char)d(*viewName,)1291 +2212 y(Query)i(*viewParse\))454 2272 y({)1231 2331 y(.)1231 +2391 y(.)1231 2451 y(.)514 2511 y(OffsetVarNodes\(viewParse->qual,)d +(2\);)395 2630 y(+)89 b(OffsetVarNodes\(viewParse->having)o(Qual,)27 +b(2\);)1231 2690 y(.)1231 2750 y(.)1231 2810 y(.)454 +2869 y(})270 3007 y Fn(Planner/Optimizer)270 3102 y Ft(The)18 +b Fp(planner)g Ft(b)o(uilds)f(a)h Fp(queryplan)g Ft(like)e(the)i(one)f +(sho)o(wn)h(in)f(\002gure)g(3.8)h(and)g(in)f(addition)g(to)g(that)270 +3162 y(it)f(takes)g(the)g Fp(oper)o(ator)h(tr)n(ee)g +Ft(attached)f(to)g(the)g(\002eld)g Fr(havingClause)f +Ft(of)g(the)h Fr(Query)g Ft(node)g(and)270 3222 y(attaches)d(is)g(to)f +(the)g Fr(qpqual)g Ft(\002eld)g(of)g(the)g Fr(AGG)g Ft(node.)345 +3283 y(Unfortunately)18 b(this)i(is)g(not)f(the)g(only)h(thing)f(to)g +(do.)38 b(Remember)19 b(from)g(section)h(3.7.1)g Fp(How)270 +3342 y(Aggr)n(e)n(gate)11 b(Functions)g(ar)n(e)g(Implemented)f +Ft(that)g(the)h Fp(tar)n(getlist)f Ft(is)h(searched)g(for)f +Fp(aggr)n(e)n(gate)f(functions)270 3402 y Ft(which)k(are)g(appended)g +(to)g(a)g(list)g(that)g(will)g(be)g(attached)g(to)g(the)g(\002eld)g +Fr(aggs)g Ft(of)g(the)g Fr(AGG)f Ft(node.)18 b(This)p +eop +%%Page: 81 81 +81 80 bop 198 60 a Fm(3.7.)29 b(THE)13 b(REALIZA)-6 b(TION)14 +b(OF)e(THE)h(HA)-7 b(VING)12 b(CLA)m(USE)622 b Ft(81)198 +234 y(was)14 b(suf)o(\002cient)f(as)i(long)e(as)i Fp(aggr)n(e)n(gate)e +(functions)h Ft(ha)o(v)o(e)g(only)g(been)g(allo)o(wed)f(to)h(appear)g +(within)f(the)198 294 y Fp(tar)n(getlist)p Ft(.)24 b(No)o(w)16 +b(the)f Fp(having)g(clause)h Ft(is)f(another)g(source)h(of)f +Fp(aggr)n(e)n(gate)f(functions)p Ft(.)25 b(Consider)15 +b(the)198 354 y(follo)o(wing)c(e)o(xample:)258 459 y +Fr(select)29 b(sno,)g(max\(pno\))258 519 y(from)g(sells)258 +579 y(group)g(by)h(sno)258 638 y(having)f(count\(pno\))g(>)h(1;)198 +742 y Ft(Here)14 b(the)g Fp(aggr)n(e)n(gate)f(functions)h +Fr(max)g Ft(and)g Fr(count)g Ft(are)g(in)g(use.)21 b(If)14 +b(only)f(the)h Fp(tar)n(getlist)g Ft(is)h(scanned)198 +802 y(\(as)f(it)g(was)g(the)f(case)i(before)e(the)h Fp(having)g(clause) +g Ft(had)g(been)g(implemented\))f(we)h(will)f(only)h(\002nd)f(and)198 +862 y(process)18 b(the)g Fp(aggr)n(e)n(gate)g(function)f +Fr(max)p Ft(.)32 b(The)19 b(second)f(function)f Fr(count)h +Ft(is)g(not)g(processed)g(and)198 922 y(therefore)f(an)o(y)i(reference) +f(to)g(the)g(result)g(of)g Fr(count)g Ft(from)g(within)f(the)i +Fp(having)f(clause)h Ft(will)f(fail.)198 981 y(The)g(solution)g(to)f +(this)h(problem)f(is)h(to)g(scan)g(the)g(whole)g Fp(oper)o(ator)g(tr)n +(ee)h Ft(representing)e(the)g Fp(having)198 1041 y(clause)12 +b Ft(for)g Fp(aggr)n(e)n(gate)f(functions)h Ft(not)f(contained)h(in)g +(the)g Fp(tar)n(getlist)g Ft(yet)g(and)g(add)g(them)g(to)f(the)h(list)h +(of)198 1101 y Fp(aggr)n(e)n(gate)g(functions)g Ft(attached)h(to)f(the) +h(\002eld)f Fr(aggs)g Ft(of)h(the)f Fr(AGG)g Ft(node.)20 +b(The)14 b(scanning)g(is)g(done)f(by)198 1161 y(the)18 +b(function)f Fr(check)p 614 1161 15 2 v 18 w(having)p +812 1161 V 17 w(qual)p 949 1161 V 17 w(for)p 1056 1161 +V 18 w(aggs\(\))h Ft(which)g(steps)g(recursi)o(v)o(ely)g(through)f(the) +198 1220 y(tree.)198 1340 y(While)25 b(scanning)h(the)g +Fp(having)f(clause)h Ft(for)f Fp(aggr)n(e)n(gate)g(functions)g +Ft(not)h(contained)f(in)h(the)f Fp(tar)o(-)198 1400 y(getlist)18 +b Ft(yet,)j(an)e(additional)f(check)h(is)g(made)g(to)g(make)f(sure)h +(that)f Fp(aggr)n(e)n(gate)g(functions)h Ft(are)g(used)198 +1460 y(within)12 b(the)g Fp(having)g(clause)g Ft(\(otherwise)g(the)g +(query)g(could)g(ha)o(v)o(e)g(been)h(formulated)e(using)h(the)g +Fp(wher)n(e)198 1519 y(clause)p Ft(\).)k(Consider)c(the)g(follo)o(wing) +f(query)h(which)g(is)h(not)f(a)h(v)o(alid)f(SQL92)g(query:)258 +1625 y Fr(testdb=>)29 b(select)g(sno,)g(max\(pno\))258 +1684 y(testdb->)g(from)g(sells)258 1744 y(testdb->)g(group)g(by)h(sno) +258 1804 y(testdb->)f(having)g(sno)h(>)f(1;)258 1864 +y(ERROR:)59 b(This)29 b(could)h(have)f(been)h(done)f(in)h(a)f(where)h +(clause!!)258 1924 y(testdb=>)198 2027 y Ft(There)19 +b(is)f(no)g(need)h(to)f(e)o(xpress)h(this)f(query)g(using)h(a)f +Fp(having)g(clause)p Ft(,)j(this)d(kind)g(of)g(quali\002cation)198 +2087 y(belongs)12 b(to)h(the)f Fp(wher)n(e)h(clause)p +Ft(:)258 2192 y Fr(select)29 b(sno,)g(max\(pno\))258 +2252 y(from)g(sells)258 2312 y(where)g(sno)h(>)f(1)258 +2372 y(group)g(by)h(sno;)198 2476 y Ft(There)17 b(is)g(still)f(an)g +(unsolv)o(ed)h(problem)f(left.)27 b(Consider)17 b(the)f(follo)o(wing)f +(query)h(where)h(we)f(want)g(to)198 2535 y(kno)o(w)c(just)g(the)h +(supplier)f(numbers)g(\()p Fr(sno)p Ft(\))f(of)h(all)g(suppliers)g +(selling)h(more)f(than)g(one)g(part:)258 2641 y Fr(select)29 +b(sno)258 2701 y(from)g(sells)258 2760 y(group)g(by)h(sno)258 +2820 y(having)f(count\(pno\))g(>)h(1;)198 2924 y Ft(The)14 +b Fp(planner)f Ft(creates)g(a)h Fp(queryplan)f Ft(\(like)f(the)h(one)g +(sho)o(wn)g(in)g(\002gure)f(3.8\))h(where)g(the)g Fp(tar)n(getlists)h +Ft(of)198 2984 y(all)e(nodes)f(in)n(v)o(olv)o(ed)h(contain)f(only)g +(entries)h(of)f(those)h(attrib)o(utes)f(listed)h(after)f(the)g +Fr(select)g Ft(ke)o(yword)198 3044 y(of)18 b(the)h(query)m(.)35 +b(Looking)19 b(at)f(the)h(e)o(xample)g(abo)o(v)o(e)h(this)f(means)g +(that)f(the)h Fp(tar)n(getlists)g Ft(of)g(the)f Fr(AGG)198 +3103 y Ft(node,)c(the)f Fr(GRP)f Ft(node)h(the)g Fr(SORT)g +Ft(node)g(and)g(the)g Fr(SeqScan)f Ft(node)h(contain)g(only)g(the)f +(entry)h(for)f(the)198 3163 y(attrib)o(ute)d Fr(sno)p +Ft(.)15 b(As)c(described)f(earlier)g(the)g Fp(aggr)n(e)n(gation)f +(logic)h Ft(operates)g(on)g(attrib)o(utes)g(of)g(the)g(tuples)198 +3223 y(returned)h(by)g(the)h(subplan)g(of)f(the)h Fr(AGG)f +Ft(node)h(\(i.e.)j(the)d(result)g(of)f(the)g Fr(GRP)h +Ft(node\).)j(Which)d(attrib)o(utes)198 3283 y(are)17 +b(contained)f(in)g(the)h(tuples)g(handed)f(back)h(by)g(a)g(subplan)f +(is)h(determined)f(by)h(the)f Fp(tar)n(getlist)p Ft(.)29 +b(In)198 3342 y(the)13 b(case)h(of)e(our)h(e)o(xample)g(the)f(attrib)o +(ute)g Fr(pno)h Ft(needed)g(for)f(the)h Fp(aggr)n(e)n(gate)f(function)h +Fr(count)f Ft(is)h(not)198 3402 y(included)f(and)g(therefore)g(the)g +Fp(aggr)n(e)n(gation)f Ft(will)h(fail.)p eop +%%Page: 82 82 +82 81 bop 270 60 a Ft(82)85 b Fm(CHAPTER)14 b(3.)25 b(POSTGRESQL)13 +b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW)270 +234 y Ft(The)h(solution)f(to)g(this)h(problem)e(is)i(gi)o(v)o(en)f(in)g +(the)g(follo)o(wing)f(steps:)345 334 y Fo(\017)25 b Ft(Make)12 +b(a)g(copy)g(of)g(the)h(actual)f Fp(tar)n(getlist)g Ft(of)g(the)g +Fr(AGG)g Ft(node.)345 433 y Fo(\017)25 b Ft(Search)17 +b(the)h Fp(oper)o(ator)h(tr)n(ee)g Ft(representing)e(the)h +Fp(having)g(clause)h Ft(for)e(attrib)o(utes)g(that)h(are)g(not)395 +493 y(contained)12 b(in)h(the)g Fp(tar)n(getlist)f Ft(of)h(the)g +Fr(AGG)f Ft(node)h(yet)g(and)g(add)g(them)f(to)h(the)g(pre)o(viously)f +(made)395 553 y(copy)m(.)345 653 y Fo(\017)25 b Ft(The)12 +b(e)o(xtended)f Fp(tar)n(getlist)g Ft(is)h(used)g(to)f(create)h(the)f +(subplan)h(attached)f(to)g(the)h Fr(lefttree)e Ft(\002eld)395 +712 y(of)18 b(the)h Fr(AGG)f Ft(node.)35 b(That)19 b(means)g(that)g +(the)f Fp(tar)n(getlists)h Ft(of)g(the)f Fr(GRP)h Ft(node,)h(of)f(the)f +Fr(SORT)395 772 y Ft(node)g(and)g(of)f(the)h Fr(SeqScan)g +Ft(node)g(will)f(no)o(w)h(contain)g(an)g(entry)f(for)h(the)g(attrib)o +(ute)f Fr(pno)p Ft(.)395 832 y(The)c Fp(tar)n(getlist)g +Ft(of)g(the)g Fr(AGG)g Ft(node)g(itself)g(will)g(not)g(be)h(changed)f +(because)h(we)f(do)h(not)f(want)f(to)395 892 y(include)g(the)g(attrib)o +(ute)f Fr(pno)i Ft(into)f(the)g(result)g(returned)f(by)i(the)f(whole)g +(query)m(.)270 991 y(Care)17 b(has)g(to)f(be)h(taken)f(that)h(the)f +Fr(varattno)g Ft(\002elds)h(of)f(the)h Fr(VAR)f Ft(nodes)h(used)g(in)f +(the)h Fp(tar)n(getlists)270 1051 y Ft(contain)e(the)h(position)f(of)g +(the)h(corresponding)e(attrib)o(ute)h(in)g(the)h Fp(tar)n(getlist)f +Ft(of)g(the)h(subplan)f(\(i.e)h(the)270 1111 y(subplan)c(deli)o(v)o +(ering)g(the)g(tuples)h(for)e(further)g(processing)i(by)f(the)g(actual) +h(node\).)270 1230 y(The)23 b(follo)o(wing)e(part)h(deals)g(with)g(the) +h(source)f(code)h(of)f(the)g(ne)o(w)g(and)g(changed)h(functions)f(in-) +270 1290 y(v)o(olv)o(ed)12 b(in)h(the)f(planner/optimizer)e(stage.)17 +b(The)c(\002les)f(af)o(fected)g(are:)345 1410 y Fk(:)c(:)g(:)p +Fr(/src/backend/optimizer/plan/se)o(trefs.c)345 1469 +y Fk(:)g(:)g(:)p Fr(/src/backend/optimizer/plan/pl)o(anner.c)270 +1589 y Ft(Since)25 b(all)f(of)h(the)g(functions)f(presented)h(here)g +(are)f(v)o(ery)h(long)g(and)g(would)f(need)h(v)o(ery)f(much)270 +1649 y(space)13 b(if)f(presented)g(as)h(a)g(whole,)f(we)h(just)f(list)h +(the)f(most)g(important)g(parts.)270 1768 y(The)23 b(follo)o(wing)e +(two)g(functions)h(are)g(ne)o(w)g(and)g(ha)o(v)o(e)h(been)f(introduced) +g(for)f(the)h Fp(having)g(logic)p Ft(.)270 1828 y(The)o(y)13 +b(are)f(contained)g(in)h(the)f(\002le)g Fk(:)c(:)g(:)p +Fr(/src/backend/optimizer/plan/setref)o(s.c)p Ft(:)345 +1928 y Fo(\017)25 b Fr(check)p 548 1928 15 2 v 17 w(having)p +745 1928 V 17 w(qual)p 882 1928 V 18 w(for)p 990 1928 +V 17 w(aggs\(\))395 1988 y Ft(This)19 b(function)g(takes)g(the)g +(representation)f(of)h(a)g Fp(having)g(clause)h Ft(gi)o(v)o(en)f(by)g +(the)g(parameter)395 2047 y Fr(clause)p Ft(,)14 b(a)h +Fp(tar)n(getlist)f Ft(gi)o(v)o(en)h(by)f(the)h(parameter)e +Fr(subplanTargetList)g Ft(and)i(a)f Fp(gr)n(oup)395 2107 +y(clause)j Ft(gi)o(v)o(en)h(by)f(the)g(parameter)g Fr(groupClause)f +Ft(as)j(ar)o(guments)e(and)g(scans)i(the)e(repre-)395 +2167 y(sentation)e(of)g(the)h Fp(having)g(clause)g Ft(recursi)o(v)o +(ely)f(for)g Fp(aggr)n(e)n(gate)g(functions)p Ft(.)25 +b(If)15 b(an)h Fp(aggr)n(e)n(gate)395 2227 y(function)i +Ft(is)h(found)f(it)g(is)h(attached)g(to)g(a)g(list)f(\(internally)g +(called)g Fr(agg)p 1682 2227 V 18 w(list)p Ft(\))g(and)h(\002nally)395 +2286 y(returned)11 b(by)h(the)h(function.)395 2366 y(Additionally)g +(the)i Fr(varno)f Ft(\002eld)g(of)g(e)o(v)o(ery)h Fr(VAR)f +Ft(node)h(found)f(is)h(set)g(to)f(the)h(position)f(of)g(the)395 +2426 y(corresponding)d(attrib)o(ute)g(in)i(the)f Fp(tar)n(getlist)g +Ft(gi)o(v)o(en)g(by)g Fr(subplanTargetList)p Ft(.)395 +2506 y(If)17 b(the)h Fp(having)f(clause)h Ft(contains)g(a)g(subquery)g +(the)g(function)f(also)h(makes)g(sure,)i(that)d(e)o(v)o(ery)395 +2565 y(attrib)o(ute)f(from)f(the)i Fp(main)g(query)g +Ft(that)g(is)g(used)g(within)g(the)f(subquery)h(also)g(appears)g(in)g +(the)395 2625 y Fp(gr)n(oup)11 b(clause)i Ft(gi)o(v)o(en)e(by)h +Fr(groupClause)p Ft(.)j(If)c(the)h(attrib)o(ute)f(cannot)h(be)g(found)f +(in)h(the)g Fp(gr)n(oup)395 2685 y(clause)g Ft(an)h(error)e(message)i +(is)g(printed)e(to)i(the)f(screen)h(and)f(the)g(query)g(processing)h +(is)f(aborted.)454 2804 y Fr(List)30 b(*)454 2864 y +(check_having_qual_for_aggs\(Node)d(*clause,)1261 2924 +y(List)j(*subplanTargetList,)1261 2984 y(List)g(*groupClause\))454 +3044 y({)514 3103 y(List)g(*t,)f(*l1;)514 3163 y(List)h(*agg_list)e(=)i +(NIL;)514 3223 y(int)60 b(contained_in_group_clause)27 +b(=)i(0;)514 3342 y(if)h(\(IsA\(clause,)e(Var\)\))514 +3402 y({)p eop +%%Page: 83 83 +83 82 bop 198 60 a Fm(3.7.)29 b(THE)13 b(REALIZA)-6 b(TION)14 +b(OF)e(THE)h(HA)-7 b(VING)12 b(CLA)m(USE)622 b Ft(83)502 +234 y Fr(TargetEntry)29 b(*subplanVar;)502 354 y(subplanVar)g(=)g +(match_varid\(\(Var)f(*\))i(clause,)1249 413 y(subplanTargetList\);)502 +473 y(/*)g(Change)f(the)g(varattno)g(fields)g(of)h(the)532 +533 y(*)g(var)f(node)h(to)f(point)h(to)f(the)h(resdom->resnofields)532 +593 y(*)g(of)f(the)h(subplan)f(\(lefttree\))532 653 y(*/)502 +712 y(\(\(Var)g(*\))h(clause\)->varattno)e(=)562 772 +y(subplanVar->resdom->resno;)502 832 y(return)h(NIL;)442 +892 y(})442 951 y(else)502 1011 y(if)h(\(is_funcclause\(clause\))d(||)j +(not_clause\(clause\))621 1071 y(||)g(or_clause\(clause\))e(||)i +(and_clause\(clause\)\))502 1131 y({)562 1191 y(int)f(new_length=0,)g +(old_length=0;)562 1310 y(/*)g(This)h(is)f(a)h(function.)f(Recursively) +g(call)g(this)592 1370 y(*)g(routine)g(for)h(its)g(arguments...)e +(\(i.e.)h(for)h(AND,)592 1430 y(*)f(OR,)h(...)f(clauses!\))592 +1489 y(*/)562 1549 y(foreach\(t,)f(\(\(Expr)i(*\))f(clause\)->args\)) +562 1609 y({)621 1669 y(old_length=length\(\(List)f(*\)agg_list\);)621 +1729 y(agg_list)h(=)h(nconc\(agg_list,)741 1788 y +(check_having_qual_for_aggs\(lfir)o(st\(t\),)1309 1848 +y(subplanTargetList,)1309 1908 y(groupClause\)\);)621 +1968 y(if\(\(\(new_length=length\(\(List)d(*\)agg_list\)\))i(==)741 +2027 y(old_length\))g(||)g(\(new_length)g(==)h(0\)\))621 +2087 y({)681 2147 y(elog\(ERROR,"This)e(could)i(have)f(been)g(done)1309 +2207 y(in)g(a)h(where)g(clause!!"\);)681 2267 y(return)f(NIL;)621 +2326 y(})562 2386 y(})562 2446 y(return)g(agg_list;)502 +2506 y(})502 2565 y(else)562 2625 y(if)g(\(IsA\(clause,)g(Aggreg\)\)) +562 2685 y({)621 2745 y(return)h(lcons\(clause,)1040 +2804 y(check_having_qual_for_aggs\()1159 2864 y(\(\(Aggreg)f +(*\)clause\)->target,)1159 2924 y(subplanTargetList,)1159 +2984 y(groupClause\)\);)562 3044 y(})562 3103 y(else)1159 +3163 y(.)1159 3223 y(.)1159 3283 y(.)382 3342 y(})p eop +%%Page: 84 84 +84 83 bop 270 60 a Ft(84)85 b Fm(CHAPTER)14 b(3.)25 b(POSTGRESQL)13 +b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW)345 +234 y Fo(\017)25 b Fr(check)p 548 234 15 2 v 17 w(having)p +745 234 V 17 w(qual)p 882 234 V 18 w(for)p 990 234 V +17 w(vars\(\))395 294 y Ft(This)19 b(function)g(takes)g(the)g +(representation)f(of)h(a)g Fp(having)g(clause)h Ft(gi)o(v)o(en)f(by)g +(the)g(parameter)395 354 y Fr(clause)11 b Ft(and)h(the)g(actual)h +Fp(tar)n(getlist)e Ft(gi)o(v)o(en)h(by)h(the)f(parameter)f +Fr(targetlist)p 1835 354 V 17 w(so)p 1912 354 V 18 w(far)h +Ft(as)395 413 y(ar)o(guments)e(and)h(recursi)o(v)o(ely)f(scans)i(the)e +(representation)g(of)h(the)f Fp(having)h(clause)g Ft(for)f(attrib)o +(utes)395 473 y(that)i(are)g(not)h(included)f(in)g(the)h(actual)f +Fp(tar)n(getlist)g Ft(yet.)k(Whene)o(v)o(er)d(such)g(an)f(attrib)o(ute) +g(is)h(found)395 533 y(it)f(is)g(added)h(to)f(the)g(actual)h +Fp(tar)n(getlist)f Ft(which)g(is)h(\002nally)e(returned)h(by)g(the)g +(function.)395 611 y(Attrib)o(utes)20 b(contained)h(in)g(the)g +Fp(having)g(clause)g Ft(b)o(ut)g(not)g(in)g(the)g Fp(tar)n(getlist)f +Ft(sho)o(w)h(up)g(with)395 671 y(queries)12 b(like:)454 +785 y Fr(select)30 b(sid)454 844 y(from)60 b(part)454 +904 y(group)30 b(by)f(sid)454 964 y(having)h(min\(pid\))f(>)g(1;)395 +1077 y Ft(In)9 b(the)g(abo)o(v)o(e)h(query)f(the)g(attrib)o(ute)g +Fr(pid)g Ft(is)h(used)f(in)h(the)f Fp(having)g(clause)h +Ft(b)o(ut)f(it)g(does)h(not)f(appear)395 1137 y(in)j(the)h +Fp(tar)n(getlist)f Ft(\(i.e.)17 b(the)c(list)f(of)h(attrib)o(utes)f +(after)g(the)g(ke)o(yword)g Fr(select)p Ft(\).)k(Unfortunately)395 +1197 y(only)f(those)g(attrib)o(utes)g(are)g(deli)o(v)o(ered)g(by)g(the) +h(subplan)f(and)h(can)f(therefore)f(be)i(used)g(within)395 +1257 y(the)e Fp(having)g(clause)p Ft(.)22 b(T)l(o)15 +b(become)f(able)h(to)f(handle)g(queries)h(like)e(that)i(correctly)m(,)f +(we)g(ha)o(v)o(e)h(to)395 1316 y(e)o(xtend)c(the)h(actual)g +Fp(tar)n(getlist)f Ft(by)g(those)h(attrib)o(utes)g(used)g(in)f(the)h +Fr(having)29 b(clause)11 b Ft(b)o(ut)g(not)395 1376 y(already)h +(appearing)f(in)i(the)f Fp(tar)n(getlist)p Ft(.)454 1489 +y Fr(List)30 b(*)454 1549 y(check_having_qual_for_vars\(Node)d +(*clause,)1261 1609 y(List)j(*targetlist_so_far\))454 +1669 y({)514 1729 y(List)149 b(*t;)514 1848 y(if)30 b(\(IsA\(clause,)e +(Var\)\))514 1908 y({)574 1968 y(Rel)269 b(tmp_rel;)574 +2087 y(tmp_rel.targetlist)28 b(=)i(targetlist_so_far;)574 +2147 y(/*)g(Check)f(if)h(the)f(VAR)h(is)f(already)g(contained)g(in)h +(the)604 2207 y(*)g(targetlist)604 2267 y(*/)574 2326 +y(if)g(\(tlist_member\(\(Var)d(*\)clause,)933 2386 y(\(List)i +(*\)targetlist_so_far\))e(==)j(NULL\))574 2446 y({)634 +2506 y(add_tl_element\(&tmp_rel,)d(\(Var)i(*\)clause\);)574 +2565 y(})574 2625 y(return)g(tmp_rel.targetlist;)514 +2685 y(})514 2745 y(else)574 2804 y(if)h(\(is_funcclause\(clause\))d +(||)j(not_clause\(clause\))693 2864 y(||)g(or_clause\(clause\))e(||)i +(and_clause\(clause\)\))574 2924 y({)634 2984 y(/*)f(This)h(is)f(a)h +(function.)f(Recursively)g(call)g(this)664 3044 y(*)g(routine)g(for)h +(its)g(arguments...)664 3103 y(*/)634 3163 y(foreach\(t,)e(\(\(Expr)i +(*\))f(clause\)->args\))634 3223 y({)693 3283 y(targetlist_so_far)f(=) +753 3342 y(check_having_qual_for_vars\(lfirst)o(\(t\),)1231 +3402 y(targetlist_so_far\);)p eop +%%Page: 85 85 +85 84 bop 198 60 a Fm(3.7.)29 b(THE)13 b(REALIZA)-6 b(TION)14 +b(OF)e(THE)h(HA)-7 b(VING)12 b(CLA)m(USE)622 b Ft(85)562 +234 y Fr(})562 294 y(return)29 b(targetlist_so_far;)502 +354 y(})502 413 y(else)562 473 y(if)g(\(IsA\(clause,)g(Aggreg\)\))562 +533 y({)621 593 y(targetlist_so_far)f(=)681 653 y +(check_having_qual_for_vars\()1159 712 y(\(\(Aggreg)h +(*\)clause\)->target,)1159 772 y(targetlist_so_far\);)621 +832 y(return)h(targetlist_so_far;)562 892 y(})1159 951 +y(.)1159 1011 y(.)1159 1071 y(.)382 1131 y(})198 1271 +y Ft(The)13 b(ne)o(xt)f(function)g(is)h(found)e(in)h +Fk(:)c(:)g(:)q Fr(/src/backend/optimizer/plan/)o(planner.c)o +Ft(:)273 1386 y Fo(\017)25 b Fr(union)p 476 1386 15 2 +v 17 w(planner\(\))323 1446 y Ft(This)14 b(function)f(creates)h(a)g +Fp(plan)f Ft(from)g(the)h Fp(parsetr)n(ee)g Ft(gi)o(v)o(en)g(to)g(it)f +(by)h(the)g(parameter)f Fr(parse)323 1505 y Ft(that)f(can)g(be)h(e)o(x) +o(ecuted)g(by)f(the)g Fp(e)o(xecutor)p Ft(.)323 1595 +y(If)g Fp(aggr)n(e)n(gate)g(functions)g Ft(are)h(present)f(\(indicated) +h(by)f Fr(parse->hasAggs)f Ft(set)j(to)e(true\))g(the)323 +1655 y(\002rst)f(step)i(is)g(to)f(e)o(xtend)g(the)g Fp(tar)n(getlist)g +Ft(by)g(those)h(attrib)o(utes)f(that)g(are)g(used)h(within)e(the)h +Fp(having)323 1715 y(clause)h Ft(\(if)e(an)o(y)i(is)h(present\))e(b)o +(ut)g(do)h(not)f(appear)h(in)g(the)f Fp(select)i(list)e +Ft(\(Refer)g(to)h(the)g(description)323 1775 y(of)e Fr(check)p +529 1775 V 18 w(having)p 727 1775 V 17 w(qual)p 864 1775 +V 18 w(for)p 972 1775 V 17 w(vars\(\))h Ft(abo)o(v)o(e\).)323 +1865 y(The)17 b(ne)o(xt)g(step)g(is)g(to)g(call)f(the)h(function)f +Fr(query)p 1224 1865 V 17 w(planner\(\))g Ft(creating)g(a)h +Fp(plan)g Ft(without)323 1924 y(taking)c(the)g Fp(gr)n(oup)h(clause)p +Ft(,)h(the)e Fp(aggr)n(e)n(gate)g(functions)g Ft(and)h(the)g +Fp(having)f(clause)h Ft(into)f(account)323 1984 y(for)e(the)h(moment.) +323 2074 y(Ne)o(xt)j(insert)h(a)f Fr(GRP)h Ft(node)f(at)h(the)f(top)h +(of)f(the)g Fp(plan)h Ft(according)f(to)g(the)h Fp(gr)n(oup)f(clause)h +Ft(of)f(the)323 2134 y Fp(parsetr)n(ee)e Ft(if)f(an)o(y)g(is)h +(present.)323 2224 y(Add)d(an)h Fr(AGG)g Ft(node)f(to)h(the)g(top)f(of) +h(the)f(current)g Fp(plan)h Ft(if)f Fp(aggr)n(e)n(gate)g(functions)h +Ft(are)f(present)h(and)323 2284 y(if)g(a)i Fp(having)f(clause)h +Ft(is)f(present)h(additionally)e(perform)g(the)h(follo)o(wing)f(steps:) +382 2404 y Fn(\226)25 b Ft(Perform)9 b(v)o(arious)i(transformations)e +(to)i(the)g(representation)f(of)g(the)h Fp(having)f(clause)h +Ft(\(e.g.)432 2463 y(transform)g(it)h(to)h(CNF)l(,)f +Fk(:)c(:)g(:)q Ft(\).)382 2553 y Fn(\226)25 b Ft(Attach)30 +b(the)f(transformed)f(representation)h(of)g(the)h Fp(having)f(clause)h +Ft(to)f(the)g(\002eld)432 2613 y Fr(plan.qual)12 b Ft(of)g(the)g(just)g +(created)h Fr(AGG)f Ft(node.)382 2703 y Fn(\226)25 b +Ft(Examine)15 b(the)g(whole)g Fp(having)f(clause)h Ft(and)g(search)g +(for)f Fp(aggr)n(e)n(gate)g(functions)p Ft(.)23 b(This)16 +b(is)432 2763 y(done)10 b(using)g(the)g(function)f Fr(check)p +1057 2763 V 17 w(having)p 1254 2763 V 18 w(qual)p 1392 +2763 V 17 w(for)p 1499 2763 V 18 w(aggs\(\))g Ft(which)h(appends)432 +2823 y(e)o(v)o(ery)i Fp(aggr)n(e)n(gate)g(function)g +Ft(found)f(to)h(a)h(list)f(that)h(is)f(\002nally)g(returned.)382 +2913 y Fn(\226)25 b Ft(Append)12 b(the)h(list)f(just)h(created)f(to)g +(the)g(list)h(already)f(attached)g(to)h(the)f(\002eld)g +Fr(aggs)g Ft(of)g(the)432 2972 y Fr(AGG)g Ft(node)h(\(this)f(list)g +(contains)g(the)h Fp(aggr)n(e)n(gate)e(functions)h Ft(found)g(in)g(the) +h Fp(tar)n(getlist)p Ft(\).)382 3062 y Fn(\226)25 b Ft(Make)10 +b(sure)h(that)f Fp(aggr)n(e)n(gate)f(functions)h Ft(do)h(appear)f(in)g +(the)g Fp(having)g(clause)p Ft(.)16 b(This)11 b(is)f(done)432 +3122 y(by)15 b(comparing)f(the)g(length)g(of)h(the)f(list)h(attached)g +(to)f Fr(aggs)h Ft(before)f(and)g(after)g(the)h(call)432 +3182 y(to)h Fr(check)p 640 3182 V 17 w(having)p 837 3182 +V 18 w(qual)p 975 3182 V 17 w(for)p 1082 3182 V 18 w(aggs\(\))p +Ft(.)26 b(If)15 b(the)h(length)g(has)h(not)e(changed,)j(we)432 +3242 y(kno)o(w)e(that)h(no)g Fp(aggr)n(e)n(gate)f(function)g +Ft(has)h(been)g(detected)g(and)g(that)f(this)h(query)f(could)432 +3302 y(ha)o(v)o(e)d(been)g(formulated)f(using)g(only)h(a)g +Fp(wher)n(e)h(clause)p Ft(.)j(In)12 b(this)h(case)h(an)f(error)e +(message)432 3361 y(is)i(printed)e(to)i(the)f(screen)h(and)f(the)g +(processing)h(is)f(aborted.)p eop +%%Page: 86 86 +86 85 bop 270 60 a Ft(86)85 b Fm(CHAPTER)14 b(3.)25 b(POSTGRESQL)13 +b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW)454 +234 y Fr(Plan)30 b(*)454 294 y(union_planner\(Query)e(*parse\))454 +354 y({)544 413 y(List)209 b(*tlist)29 b(=)h(parse->targetList;)395 +533 y(+)119 b(/*)30 b(copy)f(the)h(original)f(tlist,)g(we)g(will)h +(need)f(the)395 593 y(+)149 b(*)30 b(original)f(one)g(for)h(the)f(AGG)h +(node)f(later)h(on)f(*/)395 653 y(+)149 b(List)29 b(*new_tlist)g(=)h +(new_unsorted_tlist\(tlist\);)1231 712 y(.)1231 772 y(.)1231 +832 y(.)395 892 y(+)268 b(if)30 b(\(parse->hasAggs\))395 +951 y(+)268 b({)395 1011 y(+)328 b(/*)30 b(extend)f(targetlist)g(by)g +(variables)g(not)395 1071 y(+)358 b(*)30 b(contained)f(already)g(but)g +(used)h(in)f(the)395 1131 y(+)358 b(*)30 b(havingQual.)395 +1191 y(+)358 b(*/)395 1250 y(+)328 b(if)30 b(\(parse->havingQual)e(!=)h +(NULL\))395 1310 y(+)388 b({)395 1370 y(+)448 b(new_tlist)29 +b(=)395 1430 y(+)508 b(check_having_qual_for_vars\()395 +1489 y(+)896 b(parse->havingQual,)395 1549 y(+)g(new_tlist\);)395 +1609 y(+)388 b(})395 1669 y(+)268 b(})1231 1729 y(.)1231 +1788 y(.)1231 1848 y(.)693 1908 y(/*)30 b(Call)g(the)f(planner)g(for)h +(everything)723 1968 y(*)g(but)g(groupclauses)e(and)i(aggregate)f +(funcs.)723 2027 y(*/)693 2087 y(result_plan)g(=)h +(query_planner\(parse,)1411 2147 y(parse->commandType,)1411 +2207 y(new_tlist,)1411 2267 y(\(List)f(*\))h(parse->qual\);)1231 +2326 y(.)1231 2386 y(.)1231 2446 y(.)634 2506 y(/*)f(If)h(aggregate)f +(is)h(present,)e(insert)i(the)f(AGG)h(node)664 2565 y(*/)634 +2625 y(if)f(\(parse->hasAggs\))634 2685 y({)693 2745 +y(int)h(old_length=0,)e(new_length=0;)693 2804 y(/*)i(Create)f(the)h +(AGG)f(node)h(but)f(use)h('tlist')f(not)723 2864 y(*)h('new_tlist')f +(as)g(target)h(list)f(because)g(we)723 2924 y(*)h(don't)f(want)h(the)f +(additional)g(attributes)723 2984 y(*)h(\(only)f(used)h(for)f(the)h +(havingQual,)f(see)723 3044 y(*)h(above\))f(to)h(show)f(up)h(in)g(the)f +(result.)723 3103 y(*/)693 3163 y(result_plan)g(=)h(\(Plan)f(*\))h +(make_agg\(tlist,)1560 3223 y(result_plan\);)1231 3283 +y(.)1231 3342 y(.)1231 3402 y(.)p eop +%%Page: 87 87 +87 86 bop 198 60 a Fm(3.7.)29 b(THE)13 b(REALIZA)-6 b(TION)14 +b(OF)e(THE)h(HA)-7 b(VING)12 b(CLA)m(USE)622 b Ft(87)323 +234 y Fr(+)268 b(/*)30 b(Check)f(every)h(clause)f(of)h(the)f +(havingQual)g(for)323 294 y(+)298 b(*)30 b(aggregates)f(used)g(and)h +(append)f(them)g(to)323 354 y(+)298 b(*)30 b(the)g(list)f(in)h +(result_plan->aggs)323 413 y(+)298 b(*/)323 473 y(+)268 +b(foreach\(clause,)323 533 y(+)508 b(\(\(Agg)29 b(*\))h +(result_plan\)->plan.qual\))323 593 y(+)268 b({)323 653 +y(+)328 b(/*)30 b(Make)f(sure)h(there)f(are)h(aggregates)e(in)i(the)323 +712 y(+)358 b(*)30 b(havingQual)f(if)g(so,)h(the)f(list)h(must)f(be)323 +772 y(+)358 b(*)30 b(longer)f(after)g(check_having_qual_for_aggs)323 +832 y(+)358 b(*/)323 892 y(+)328 b(old_length)29 b(=)323 +951 y(+)388 b(length\(\(\(Agg)29 b(*\))g(result_plan\)->aggs\);)323 +1011 y(+)323 1071 y(+)328 b(\(\(Agg)30 b(*\))f(result_plan\)->aggs)f(=) +323 1131 y(+)418 b(nconc\(\(\(Agg)29 b(*\))g(result_plan\)->aggs,)323 +1191 y(+)597 b(check_having_qual_for_aggs\()323 1250 +y(+)657 b(\(Node)29 b(*\))h(lfirst\(clause\),)323 1310 +y(+)657 b(\(\(Agg)29 b(*\)result_plan\)->)323 1370 y(+)777 +b(plan.lefttree->targetlist,)323 1430 y(+)657 b(\(\(List)29 +b(*\))h(parse->groupClause\)\)\);)323 1489 y(+)328 b(/*)30 +b(Have)f(a)h(look)g(at)f(the)h(length)f(of)h(the)f(returned)323 +1549 y(+)358 b(*)30 b(list.)f(If)h(there)f(is)h(no)f(difference,)g(no) +323 1609 y(+)358 b(*)30 b(aggregates)f(have)g(been)g(found)h(and)f +(that)h(means)323 1669 y(+)358 b(*)30 b(that)f(the)h(Qual)f(belongs)g +(to)h(the)g(where)f(clause)323 1729 y(+)358 b(*/)323 +1788 y(+)328 b(if)30 b(\(\(\(new_length)e(=)323 1848 +y(+)508 b(length\(\(\(Agg)28 b(*\))i(result_plan\)->aggs\)\)==)323 +1908 y(+)508 b(old_length\))28 b(||)i(\(new_length)e(==)i(0\)\))323 +1968 y(+)328 b({)323 2027 y(+)388 b(elog\(ERROR,"This)28 +b(could)h(have)h(been)f(done)h(in)f(a)323 2087 y(+)1135 +b(where)29 b(clause!!"\);)323 2147 y(+)388 b(return)29 +b(\(Plan)h(*\)NIL;)323 2207 y(+)328 b(})323 2267 y(+)268 +b(})1159 2326 y(.)1159 2386 y(.)1159 2446 y(.)382 2506 +y(})198 2647 y Fn(Executor)198 2743 y Ft(The)17 b Fp(e)o(xecutor)g +Ft(takes)g(the)f Fp(queryplan)h Ft(produced)f(by)g(the)h +Fp(planner/optimizer)g Ft(in)f(the)h(way)f(just)g(de-)198 +2803 y(scribed)c(and)g(processes)h(all)e Fp(aggr)n(e)n(gate)g +(functions)h Ft(in)g(the)g(way)f(described)h(in)g(section)g(3.7.1)g +Fp(The)g(Im-)198 2863 y(plementation)g(of)g(Aggr)n(e)n(gate)g +(Functions)h Ft(b)o(ut)f(before)g(the)g(tuple)g(deri)o(v)o(ed)g(is)h +(handed)f(back)h(the)f Fp(oper)o(-)198 2922 y(ator)h(tr)n(ee)g +Ft(attached)f(to)g(the)h(\002eld)f Fr(qpqual)g Ft(is)g(e)o(v)o(aluated) +g(by)h(calling)f(the)g(function)g Fr(ExecQual\(\))p Ft(.)198 +2982 y(This)i(function)e(recursi)o(v)o(ely)g(steps)i(through)e(the)h +Fp(oper)o(ator)h(tr)n(ee)f Ft(\(i.e.)18 b(the)13 b Fp(having)g(clause)p +Ft(\))g(and)g(e)o(v)o(al-)198 3042 y(uates)k(the)g(predicates)f +(appearing)g(there.)29 b(Thanks)17 b(to)g(our)f(changes)h(that)f(ha)o +(v)o(e)h(been)g(made)g(to)f(the)198 3102 y Fp(planner)i +Ft(the)g(v)o(alues)f(of)h(all)g(operands)f(needed)h(to)g(e)o(v)o +(aluate)f(the)h(predicates)g(\(e.g.)32 b(the)18 b(v)o(alues)g(of)198 +3162 y(all)13 b Fp(aggr)n(e)n(gate)f(functions)p Ft(\))g(are)h(already) +f(present)h(and)g(can)g(be)g(accessed)i(throughout)c(the)i(e)o(v)o +(aluation)198 3221 y(without)f(an)o(y)g(problems.)273 +3283 y(If)i(the)h(e)o(v)o(aluation)e(of)i(the)f Fp(having)h +(quali\002cation)f Ft(returns)g Fr(true)g Ft(the)h(tuple)g(is)g +(returned)e(by)i(the)198 3342 y(function)c Fr(execAgg\(\))h +Ft(otherwise)g(it)g(is)h(ignored)f(and)g(the)g(ne)o(xt)h(group)e(is)i +(processed.)p eop +%%Page: 88 88 +88 87 bop 270 60 a Ft(88)82 b Fm(CHAPTER)14 b(3.)28 b(POSTGRESQL)13 +b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW)270 +234 y Ft(The)26 b(necessary)h(changes)f(and)g(enhancements)g(ha)o(v)o +(e)g(been)g(applied)f(to)h(the)g(follo)o(wing)e(func-)270 +294 y(tion)12 b(in)g(the)g(\002le)h Fk(:)8 b(:)g(:)p +Fr(/src/backend/executor/nodeAgg)o(.c)p Ft(:)345 391 +y Fo(\017)25 b Fr(execAgg\(\))17 b Ft(Whene)o(v)o(er)g(the)h +Fp(e)o(xecutor)h Ft(gets)f(to)g(an)g Fr(AGG)g Ft(node)g(this)g +(function)f(is)i(called.)395 451 y(Before)d(the)g Fp(having)g(logic)g +Ft(had)g(been)h(implemented,)g(all)g(the)f Fp(tuples)h +Ft(of)f(the)g(current)g(group)395 511 y(were)j(fetched)f(from)g(the)h +Fp(subplan)g Ft(and)h(all)f Fp(aggr)n(e)n(gate)f(functions)h +Ft(were)g(applied)g(to)g(these)395 571 y(tuples.)c(After)d(that,)h(the) +f(results)g(were)h(handed)f(back)h(to)f(the)g(calling)g(function.)395 +650 y(Since)i(the)g Fp(having)h(logic)f Ft(has)h(been)f(implemented)g +(there)h(is)f(one)h(additional)f(step)h(e)o(x)o(ecuted.)395 +710 y(Before)d(the)h(results)g(of)f(applying)g(the)h +Fp(aggr)n(e)n(gate)f(functions)g Ft(are)h(handed)g(back,)g(the)g +(function)395 769 y Fr(ExecQual\(\))d Ft(is)i(called)f(with)h(the)f +(representation)g(of)g(the)g Fp(having)h(clause)g Ft(as)g(an)f(ar)o +(gument.)395 829 y(If)h Fr(true)h Ft(is)h(returned,)f(the)g(results)g +(are)g(handed)h(back,)g(otherwise)f(the)o(y)g(are)g(ignored)g(and)g(we) +395 889 y(start)18 b(from)f(the)i(be)o(ginning)f(for)f(the)i(ne)o(xt)f +(group)g(until)g(a)g(group)g(meeting)g(the)h(restrictions)395 +949 y(gi)o(v)o(en)12 b(in)g(the)g Fp(having)g(clause)h +Ft(is)g(found.)454 1066 y Fr(TupleTableSlot)29 b(*)454 +1125 y(ExecAgg\(Agg)g(*node\))454 1185 y({)1231 1245 +y(.)1231 1305 y(.)1231 1364 y(.)634 1424 y(/*)g(We)h(loop)f(retrieving) +g(groups)g(until)h(we)f(find)h(one)664 1484 y(*)f(matching)g +(node->plan.qual)664 1544 y(*/)395 1603 y(+)209 b(do)395 +1663 y(+)g({)1231 1723 y(.)1231 1783 y(.)1231 1843 y(.)693 +1902 y(/*)30 b(Apply)f(*all*)h(aggregate)f(function)g(to)g(the)723 +1962 y(*)h(tuples)f(of)h(the)g(*current*)e(group)723 +2022 y(*/)1231 2082 y(.)1231 2141 y(.)1231 2201 y(.)693 +2261 y(econtext->ecxt_scantuple)g(=)962 2321 y +(aggstate->csstate.css_ScanTupleSlot)o(;)693 2381 y(resultSlot)h(=)h +(ExecProject\(projInfo,)d(&isDone\);)395 2500 y(+)268 +b(/*)30 b(As)g(long)f(as)h(the)f(retrieved)g(group)h(does)f(not)395 +2560 y(+)298 b(*)30 b(match)f(the)h(qualifications)e(it)i(is)g(ignored) +f(and)395 2620 y(+)298 b(*)30 b(the)g(next)f(group)g(is)h(fetched)395 +2679 y(+)298 b(*/)395 2739 y(+)268 b(if\(node->plan.qual)28 +b(!=)i(NULL\))395 2799 y(+)268 b({)395 2859 y(+)328 b(qual_result)29 +b(=)395 2919 y(+)448 b(ExecQual\(fix_opids\(node->plan)o(.qual\),)395 +2978 y(+)717 b(econtext\);)395 3038 y(+)268 b(})395 3098 +y(+)g(if)30 b(\(oneTuple\))f(pfree\(oneTuple\);)395 3158 +y(+)209 b(})395 3217 y(+)g(while\(\(node->plan.qual!=NULL)o(\))27 +b(&&)395 3277 y(+)926 b(\(qual_result!=true\)\);)634 +3337 y(return)29 b(resultSlot;)454 3397 y(})p eop +%%Page: 89 89 +89 88 bop 198 60 a Fm(3.8.)29 b(THE)13 b(REALIZA)-6 b(TION)14 +b(OF)e(UNION,)g(INTERSECT)i(AND)f(EXCEPT)349 b Ft(89)198 +234 y Fi(3.8)71 b(The)18 b(Realization)f(of)g(Union,)g(Intersect)g(and) +h(Except)198 352 y Ft(SQL92)12 b(supports)g(the)h(well)f(kno)o(wn)g +(set)g(theoretic)g(operations)g Fp(union)p Ft(,)g Fp(intersect)h +Ft(and)f Fp(set)h(dif)o(fer)n(ence)198 411 y Ft(\(the)j +Fp(set)h(dif)o(fer)n(ence)f Ft(is)h(called)f Fp(e)o(xcept)h +Ft(in)f(SQL92\).)27 b(The)17 b(operators)f(are)g(used)h(to)f(connect)g +(two)g(or)198 471 y(more)c Fr(select)g Ft(statements.)18 +b(Ev)o(ery)13 b Fr(select)f Ft(statement)h(returns)f(a)h(set)g(of)f +(tuples)h(and)g(the)g(opera-)198 531 y(tors)f(between)h(the)f +Fr(select)g Ft(statements)g(tell)h(ho)o(w)f(to)g(mer)o(ge)g(the)g +(returned)g(sets)h(of)f(tuples)g(into)g(one)198 591 y(result)g +(relation.)198 729 y Fn(Example)h(3.4)25 b Ft(Let)13 +b(the)f(follo)o(wing)f(tables)i(be)f(gi)o(v)o(en:)616 +842 y Fr(A)60 b(C1|C2|C3)268 b(B)60 b(C1|C2|C3)706 902 +y(--+--+--)358 b(--+--+--)736 961 y(1|)30 b(a|)f(b)389 +b(1|)29 b(a|)h(b)736 1021 y(2|)g(a|)f(b)389 b(5|)29 b(a|)h(b)736 +1081 y(3|)g(c|)f(d)389 b(3|)29 b(c|)h(d)736 1141 y(4|)g(e|)f(f)389 +b(8|)29 b(e|)h(f)945 1260 y(C)60 b(C1|C2|C3)1035 1320 +y(--+--+--)1065 1380 y(4|)29 b(e|)h(f)1065 1440 y(8|)f(e|)h(f)198 +1549 y Ft(No)o(w)12 b(let')m(s)h(ha)o(v)o(e)f(a)h(look)f(at)g(the)h +(results)f(of)g(the)g(follo)o(wing)f(queries:)258 1661 +y Fr(select)29 b(*)h(from)f(A)258 1721 y(union)258 1781 +y(select)g(*)h(from)f(B;)198 1890 y Ft(deri)o(v)o(es)12 +b(the)h(set)f(theoretic)g Fp(union)g Ft(of)g(the)g(two)g(tables:)1035 +2002 y Fr(C1|C2|C3)1035 2062 y(--+--+--)1065 2122 y(1|)29 +b(a|)h(b)1065 2182 y(2|)f(a|)h(b)1065 2242 y(3|)f(c|)h(d)1065 +2301 y(4|)f(e|)h(f)1065 2361 y(5|)f(a|)h(b)1065 2421 +y(8|)f(e|)h(f)198 2530 y Ft(The)13 b Fr(select)f Ft(statements)g(used)h +(may)f(be)h(more)f(comple)o(x:)258 2643 y Fr(select)29 +b(C1,)h(C3)f(from)h(A)318 2702 y(where)f(C2)h(=)f('a')258 +2762 y(union)258 2822 y(select)g(C1,)h(C2)f(from)h(B)318 +2882 y(where)f(C3)h(=)f('b';)198 2991 y Ft(will)12 b(return)f(the)i +(follo)o(wing)e(table:)1065 3103 y Fr(C1|C3)1065 3163 +y(--+--)1095 3223 y(1|)29 b(b)1095 3283 y(2|)g(b)1095 +3342 y(1|)g(a)1095 3402 y(5|)g(a)p eop +%%Page: 90 90 +90 89 bop 270 60 a Ft(90)85 b Fm(CHAPTER)14 b(3.)25 b(POSTGRESQL)13 +b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW)270 +234 y Ft(Note)j(that)f(the)h(selected)g(columns)f(do)h(not)f(need)h(to) +g(ha)o(v)o(e)g(identical)f(names,)i(the)o(y)f(only)f(ha)o(v)o(e)h(to)g +(be)270 294 y(of)e(the)g(same)h(type.)k(In)13 b(the)g(pre)o(vious)g(e)o +(xample)g(we)h(selected)g(for)e Fr(C1)h Ft(and)g Fr(C3)g +Ft(in)h(the)f(\002rst)g Fr(select)270 354 y Ft(statement)i(and)h(for)e +Fr(C1)h Ft(and)g Fr(C2)g Ft(in)h(the)f(second)g(one.)25 +b(The)16 b(names)f(of)g(the)g(resulting)g(columns)g(are)270 +413 y(taken)d(from)f(the)h(\002rst)g Fr(select)g Ft(statement.)270 +533 y(Let')m(s)h(ha)o(v)o(e)g(a)f(look)g(at)h(a)f(query)g(using)h +Fr(intersect)p Ft(:)330 634 y Fr(select)29 b(*)h(from)f(A)330 +694 y(intersect)330 754 y(select)g(*)h(from)f(B;)270 +855 y Ft(will)12 b(return:)1107 956 y Fr(C1|C2|C3)1107 +1016 y(--+--+--)1137 1076 y(1|)29 b(a|)h(b)1137 1136 +y(3|)f(c|)h(d)270 1236 y Ft(Here)12 b(is)h(an)f(e)o(xample)h(using)f +Fr(except)p Ft(:)330 1338 y Fr(select)29 b(*)h(from)f(A)330 +1398 y(except)330 1457 y(select)g(*)h(from)f(B;)270 1558 +y Ft(will)12 b(return:)1107 1660 y Fr(C1|C2|C3)1107 1719 +y(--+--+--)1137 1779 y(2|)29 b(a|)h(b)1137 1839 y(4|)f(e|)h(f)270 +1940 y Ft(The)11 b(last)g(e)o(xamples)g(were)f(rather)g(simple)g +(because)h(the)o(y)g(only)f(used)h(one)g(set)g(operator)e(at)i(a)f +(time)g(with)270 2000 y(only)h(two)f(operands.)15 b(No)o(w)c(we)g(look) +g(at)g(some)g(more)f(comple)o(x)h(queries)g(in)n(v)o(olving)f(more)h +Fp(oper)o(ators)p Ft(:)330 2101 y Fr(select)29 b(*)h(from)f(A)330 +2161 y(union)330 2221 y(select)g(*)h(from)f(B)330 2280 +y(intersect)330 2340 y(select)g(*)h(from)f(C;)270 2441 +y Ft(will)12 b(return:)1107 2542 y Fr(C1|C2|C3)1107 2602 +y(--+--+--)1137 2662 y(4|)29 b(e|)h(f)1137 2722 y(8|)f(e|)h(f)270 +2823 y Ft(The)11 b(abo)o(v)o(e)g(query)f(performs)f(the)i(set)g +(theoretic)f(computation)f Fl(\()p Fk(A)t Fo([)t Fk(B)r +Fl(\))t Fo(\\)t Fk(C)t Ft(.)17 b(When)10 b(no)h(parentheses)270 +2882 y(are)j(used,)h(the)f(operations)g(are)g(considered)g(to)g(be)g +(left)f(associati)o(v)o(e,)j(i.e.)21 b Fk(A)13 b Fo([)f +Fk(B)j Fo([)e Fk(C)i Fo([)e Fk(D)i Ft(will)f(be)270 2942 +y(treated)e(as)h Fl(\(\()p Fk(A)f Fo([)f Fk(B)r Fl(\))h +Fo([)f Fk(C)t Fl(\))g Fo([)g Fk(D)q Ft(.)270 3062 y(The)i(same)g(query) +f(using)g(parenthesis)h(can)f(lead)h(to)f(a)g(completely)g(dif)o +(ferent)f(result:)330 3163 y Fr(select)29 b(*)h(from)f(A)330 +3223 y(union)330 3283 y(\(select)g(*)h(from)f(B)360 3342 +y(intersect)360 3402 y(select)g(*)h(from)f(C\);)p eop +%%Page: 91 91 +91 90 bop 198 60 a Fm(3.8.)29 b(THE)13 b(REALIZA)-6 b(TION)14 +b(OF)e(UNION,)g(INTERSECT)i(AND)f(EXCEPT)349 b Ft(91)198 +234 y(performs)11 b Fk(A)h Fo([)f Fl(\()p Fk(B)j Fo(\\)d +Fk(C)t Fl(\))h Ft(and)g(will)g(return:)1035 333 y Fr(C1|C2|C3)1035 +393 y(--+--+--)1065 453 y(1|)29 b(a|)h(b)1065 513 y(2|)f(a|)h(b)1065 +572 y(3|)f(c|)h(d)1065 632 y(4|)f(e|)h(f)1065 692 y(8|)f(e|)h(f)198 +835 y Fh(3.8.1)59 b(Ho)o(w)15 b(Unions)h(ha)o(v)o(e)e(been)g(Realized)g +(Until)g(V)-6 b(ersion)14 b(6.3.2)198 928 y Ft(First)d(we)h(gi)o(v)o(e) +g(a)g(description)f(of)h(the)f(implementation)g(of)g +Fp(union)h Ft(and)f Fp(union)h(all)f Ft(until)h(v)o(ersion)f(6.3.2)198 +988 y(because)g(we)f(need)g(it)g(to)g(understand)g(the)g +(implementation)f(of)g Fp(intersect)h Ft(and)g Fp(e)o(xcept)h +Ft(described)f(later)m(.)198 1107 y(A)i Fp(union)g Ft(query)g(is)h +(passed)g(through)f(the)g(usual)h(stages:)273 1206 y +Fo(\017)25 b Ft(parser)273 1306 y Fo(\017)g Ft(re)o(write)11 +b(system)273 1405 y Fo(\017)25 b Ft(planner/optimizer)273 +1505 y Fo(\017)g Ft(e)o(x)o(ecutor)198 1604 y(and)11 +b(we)g(will)f(no)o(w)g(describe)h(what)g(e)o(v)o(ery)f(single)h(stage)g +(does)g(to)g(the)f(query)m(.)15 b(F)o(or)10 b(our)g(e)o(xplanation)h +(we)198 1664 y(assume)j(to)f(process)g(a)h(simple)f(query)f(\(i.e.)19 +b(a)13 b(query)g(without)f Fp(subselects)p Ft(,)j Fp(aggr)n(e)n(gates)e +Ft(and)g(without)198 1724 y(in)n(v)o(olving)e Fp(vie)o(ws)p +Ft(\))198 1856 y Fn(The)h(Parser)i(Stage)198 1949 y Ft(As)f(described)f +(earlier)g(the)g Fp(parser)h(stage)f Ft(can)g(be)h(di)o(vided)e(into)h +(two)g(parts:)273 2049 y Fo(\017)25 b Ft(the)12 b Fp(parser)h +Ft(b)o(uilt)f(up)g(by)g(the)h(grammar)e(rules)h(gi)o(v)o(en)g(in)g +Fr(gram.y)g Ft(and)273 2148 y Fo(\017)25 b Ft(the)12 +b Fp(tr)o(ansformation)g(r)n(outines)g Ft(performing)e(a)i(lot)g(of)g +(changes)g(and)g(analysis)h(to)f(the)g(tree)g(b)o(uilt)323 +2208 y(up)g(by)g(the)g(parser)m(.)k(Most)d(of)f(these)h(routines)f +(reside)g(in)g Fr(analyze.c)p Ft(.)198 2307 y(A)18 b +Fp(union)f Ft(statement)h(consists)h(of)e(two)h(or)f(more)g +Fp(select)i Ft(statements)f(connected)g(by)g(the)f(ke)o(yword)198 +2367 y Fr(union)12 b Ft(as)h(the)f(follo)o(wing)f(e)o(xample)i(sho)o +(ws:)258 2466 y Fr(select)29 b(*)h(from)f(A)318 2526 +y(where)g(C1=1)258 2586 y(union)258 2645 y(select)g(*)h(from)f(B)318 +2705 y(where)g(C2)h(=)f('a')258 2765 y(union)258 2825 +y(select)g(*)h(from)f(C)318 2885 y(where)g(C3)h(=)f('f')198 +2984 y Ft(The)17 b(abo)o(v)o(e)f Fp(union)g Ft(statement)g(consists)g +(of)g(three)g Fp(select)g Ft(statements)h(connected)f(by)f(the)h(ke)o +(yword)198 3044 y Fr(union)p Ft(.)i(W)l(e)13 b(will)g(refer)f(to)h(the) +h(\002rst)e Fp(select)i Ft(statement)f(by)g(A,)h(to)f(the)g(second)h +(one)f(by)g(B)h(and)f(to)g(the)198 3103 y(third)i(one)g(by)h(C)g(for)e +(our)h(further)g(e)o(xplanation)g(\(in)g(the)g(ne)o(w)h(notation)f(our) +g(query)g(looks)g(like)g(this:)198 3163 y Fr(A)30 b(union)f(B)h(union)f +(C)p Ft(\).)198 3283 y(The)g Fp(parser)g Ft(\(gi)o(v)o(en)f(by)h +Fr(gram.y)p Ft(\))e(processes)j(all)e(three)h Fr(select)e +Ft(statements,)34 b(creates)29 b(a)198 3342 y Fr(SelectStmt)13 +b Ft(node)g(for)g(e)o(v)o(ery)g Fr(select)g Ft(and)h(attaches)g(the)g +Fr(where)f Ft(quali\002cations,)h Fp(tar)n(getlists)198 +3402 y Ft(etc.)48 b(to)23 b(the)g(corresponding)g(nodes.)48 +b(Then)23 b(it)g(creates)h(a)f(list)g(of)g(the)g(second)h(and)f(the)g +(third)p eop +%%Page: 92 92 +92 91 bop 270 60 a Ft(92)82 b Fm(CHAPTER)14 b(3.)28 b(POSTGRESQL)13 +b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW)275 +1049 y @beginspecial 127 @llx 309 @lly 485 @urx 482 @ury +3580 @rwi @setspecial +%%BeginDocument: figures/parser_union_back.ps +%Magnification: 1.05 +/$F2psDict 200 dict def +$F2psDict begin +$F2psDict /mtrx matrix put +/col-1 {0 setgray} bind def +/col0 {0.000 0.000 0.000 srgb} bind def +/col1 {0.000 0.000 1.000 srgb} bind def +/col2 {0.000 1.000 0.000 srgb} bind def +/col3 {0.000 1.000 1.000 srgb} bind def +/col4 {1.000 0.000 0.000 srgb} bind def +/col5 {1.000 0.000 1.000 srgb} bind def +/col6 {1.000 1.000 0.000 srgb} bind def +/col7 {1.000 1.000 1.000 srgb} bind def +/col8 {0.000 0.000 0.560 srgb} bind def +/col9 {0.000 0.000 0.690 srgb} bind def +/col10 {0.000 0.000 0.820 srgb} bind def +/col11 {0.530 0.810 1.000 srgb} bind def +/col12 {0.000 0.560 0.000 srgb} bind def +/col13 {0.000 0.690 0.000 srgb} bind def +/col14 {0.000 0.820 0.000 srgb} bind def +/col15 {0.000 0.560 0.560 srgb} bind def +/col16 {0.000 0.690 0.690 srgb} bind def +/col17 {0.000 0.820 0.820 srgb} bind def +/col18 {0.560 0.000 0.000 srgb} bind def +/col19 {0.690 0.000 0.000 srgb} bind def +/col20 {0.820 0.000 0.000 srgb} bind def +/col21 {0.560 0.000 0.560 srgb} bind def +/col22 {0.690 0.000 0.690 srgb} bind def +/col23 {0.820 0.000 0.820 srgb} bind def +/col24 {0.500 0.190 0.000 srgb} bind def +/col25 {0.630 0.250 0.000 srgb} bind def +/col26 {0.750 0.380 0.000 srgb} bind def +/col27 {1.000 0.500 0.500 srgb} bind def +/col28 {1.000 0.630 0.630 srgb} bind def +/col29 {1.000 0.750 0.750 srgb} bind def +/col30 {1.000 0.880 0.880 srgb} bind def +/col31 {1.000 0.840 0.000 srgb} bind def + +end +save +100.0 495.5 translate +1 -1 scale + +/cp {closepath} bind def +/ef {eofill} bind def +/gr {grestore} bind def +/gs {gsave} bind def +/sa {save} bind def +/rs {restore} bind def +/l {lineto} bind def +/m {moveto} bind def +/rm {rmoveto} bind def +/n {newpath} bind def +/s {stroke} bind def +/sh {show} bind def +/slc {setlinecap} bind def +/slj {setlinejoin} bind def +/slw {setlinewidth} bind def +/srgb {setrgbcolor} bind def +/rot {rotate} bind def +/sc {scale} bind def +/sd {setdash} bind def +/ff {findfont} bind def +/sf {setfont} bind def +/scf {scalefont} bind def +/sw {stringwidth} bind def +/tr {translate} bind def +/tnt {dup dup currentrgbcolor + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add srgb} + bind def +/shd {dup dup currentrgbcolor 4 -2 roll mul 4 -2 roll mul + 4 -2 roll mul srgb} bind def +/$F2psBegin {$F2psDict begin /$F2psEnteredState save def} def +/$F2psEnd {$F2psEnteredState restore end} def + +$F2psBegin +10 setmiterlimit +n 0 792 m 0 0 l 612 0 l 612 792 l cp clip + 0.06299 0.06299 sc +7.500 slw +% Polyline +n 450 450 m 1800 450 l gs col-1 s gr +% Polyline +n 450 225 m 1800 225 l 1800 1350 l 450 1350 l cp gs col-1 s gr +% Polyline +n 450 1080 m 1800 1080 l gs col-1 s gr +% Polyline +n 450 810 m 1800 810 l gs col-1 s gr +% Polyline +n 1530 450 m 1530 1350 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +540 405 m +gs 1 -1 sc (SelectStmt node \(A\)) col-1 sh gr +/Times-Roman ff 150.00 scf sf +900 720 m +gs 1 -1 sc 90.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 990 m +gs 1 -1 sc (qual) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 1260 m +gs 1 -1 sc (unionclause) col-1 sh gr +% Polyline +n 4365 2655 m 4635 2925 l gs col-1 s gr +% Polyline +n 4635 2655 m 4365 2925 l gs col-1 s gr +% Polyline +n 3285 2025 m 4635 2025 l gs col-1 s gr +% Polyline +n 3285 1800 m 4635 1800 l 4635 2925 l 3285 2925 l cp gs col-1 s gr +% Polyline +n 3285 2655 m 4635 2655 l gs col-1 s gr +% Polyline +n 3285 2385 m 4635 2385 l gs col-1 s gr +% Polyline +n 4365 2025 m 4365 2925 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +3375 1980 m +gs 1 -1 sc (SelectStmt node \(C\)) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3735 2295 m +gs 1 -1 sc 90.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3375 2565 m +gs 1 -1 sc (qual) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3375 2835 m +gs 1 -1 sc (unionclause) col-1 sh gr +% Polyline +gs clippath +2103 1185 m 2223 1215 l 2103 1245 l 2265 1245 l 2265 1185 l cp clip +n 1665 1215 m 2250 1215 l gs col-1 s gr gr + +% arrowhead +n 2103 1185 m 2223 1215 l 2103 1245 l 2103 1215 l 2103 1185 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +3453 1185 m 3573 1215 l 3453 1245 l 3615 1245 l 3615 1185 l cp clip +n 2655 1215 m 3600 1215 l gs col-1 s gr gr + +% arrowhead +n 3453 1185 m 3573 1215 l 3453 1245 l 3453 1215 l 3453 1185 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 2250 1080 m 2790 1080 l 2790 1350 l 2250 1350 l cp gs col-1 s gr +% Polyline +n 3600 1080 m 4140 1080 l 4140 1350 l 3600 1350 l cp gs col-1 s gr +% Polyline +n 2520 1080 m 2520 1350 l gs col-1 s gr +% Polyline +n 3870 1080 m 3870 1350 l gs col-1 s gr +% Polyline +n 3870 1080 m 4140 1350 l gs col-1 s gr +% Polyline +n 3870 1350 m 4140 1080 l gs col-1 s gr +% Polyline +gs clippath +3935 1652 m 3950 1774 l 3879 1674 l 3937 1825 l 3993 1803 l cp clip +n 3735 1215 m 3960 1800 l gs col-1 s gr gr + +% arrowhead +n 3935 1652 m 3950 1774 l 3879 1674 l 3907 1663 l 3935 1652 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +1878 2490 m 1998 2520 l 1878 2550 l 2040 2550 l 2040 2490 l cp clip +n 1665 2520 m 2025 2520 l gs col-1 s gr gr + +% arrowhead +n 1878 2490 m 1998 2520 l 1878 2550 l 1878 2520 l 1878 2490 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 1530 2655 m 1800 2925 l gs col-1 s gr +% Polyline +n 1800 2655 m 1530 2925 l gs col-1 s gr +% Polyline +n 450 2025 m 1800 2025 l gs col-1 s gr +% Polyline +n 450 1800 m 1800 1800 l 1800 2925 l 450 2925 l cp gs col-1 s gr +% Polyline +n 450 2655 m 1800 2655 l gs col-1 s gr +% Polyline +n 450 2385 m 1800 2385 l gs col-1 s gr +% Polyline +n 1530 2025 m 1530 2925 l gs col-1 s gr +% Polyline +gs clippath +4713 2490 m 4833 2520 l 4713 2550 l 4875 2550 l 4875 2490 l cp clip +n 4500 2520 m 4860 2520 l gs col-1 s gr gr + +% arrowhead +n 4713 2490 m 4833 2520 l 4713 2550 l 4713 2520 l 4713 2490 l cp gs 0.00 setgray ef gr col-1 s +% Interp Spline +gs clippath +2114 874 m 2228 826 l 2150 922 l 2280 825 l 2244 777 l cp clip +n 1665 945 m + 1820.9 950.7 1888.4 950.7 1935 945 curveto + 1977.7 939.7 2075.0 917.7 2115 900 curveto + 2141.2 888.4 2175.0 865.9 2250 810 curveto + gs col-1 s gr + gr + +% arrowhead +n 2114 874 m 2228 826 l 2150 922 l 2132 898 l 2114 874 l cp gs 0.00 setgray ef gr col-1 s +% Interp Spline +gs clippath +1259 1733 m 1146 1783 l 1222 1686 l 1095 1786 l 1132 1833 l cp clip +n 2385 1215 m + 2315.4 1408.3 2270.4 1487.0 2205 1530 curveto + 2009.1 1658.7 1581.4 1552.1 1395 1620 curveto + 1339.3 1640.3 1271.8 1685.3 1125 1800 curveto + gs col-1 s gr + gr + +% arrowhead +n 1259 1733 m 1146 1783 l 1222 1686 l 1241 1709 l 1259 1733 l cp gs 0.00 setgray ef gr col-1 s +/Times-Roman ff 150.00 scf sf +2340 720 m +gs 1 -1 sc (Pointer to qualtree) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2340 915 m +gs 1 -1 sc (of 1st Select) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2070 2475 m +gs 1 -1 sc (Pointer to qualtree) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2070 2670 m +gs 1 -1 sc (of 2nd Select) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 1980 m +gs 1 -1 sc (SelectStmt node \(B\)) col-1 sh gr +/Times-Roman ff 150.00 scf sf +900 2295 m +gs 1 -1 sc 90.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 2565 m +gs 1 -1 sc (qual) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 2835 m +gs 1 -1 sc (unionclause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4905 2670 m +gs 1 -1 sc (of 3rd Select) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4905 2475 m +gs 1 -1 sc (Pointer to qualtree) col-1 sh gr +showpage +$F2psEnd +rs +%%EndDocument + @endspecial 642 1159 a Ft(Figure)g(3.9:)j(Data)e(structure)f(handed)g +(back)g(by)h(the)f Fp(parser)270 1401 y Fr(SelectStmt)j +Ft(node)g(\(of)g(B)h(and)f(C\))g(and)h(attaches)g(it)f(to)h(the)f +(\002eld)g Fr(unionClause)g Ft(of)g(the)g(\002rst)270 +1460 y(node)i(\(of)e(A\).)i(Finally)f(it)h(hands)g(back)f(the)h +(\002rst)f(node)h(\(node)f(A\))g(with)h(the)f(list)h(of)f(the)h +(remaining)270 1520 y(nodes)c(attached)f(as)h(sho)o(wn)f(in)h(\002gure) +e(3.9.)270 1640 y(The)24 b(follo)o(wing)d Fp(tr)o(ansformation)j(r)n +(outines)f Ft(process)g(the)g(data)g(structure)g(handed)g(back)g(by)g +(the)270 1700 y Fp(parser)p Ft(.)45 b(First)21 b(the)h(top)g(node)g +(\(node)f(A\))h(is)g(transformed)f(from)f(a)i Fr(SelectStmt)f +Ft(node)h(to)g(a)270 1759 y Fr(Query)15 b Ft(node.)26 +b(The)16 b Fp(tar)n(getlist)p Ft(,)h(the)f Fr(where)f +Ft(quali\002cation)g(etc.)26 b(attached)16 b(to)f(it)h(are)f +(transformed)270 1819 y(as)h(well.)26 b(Ne)o(xt)16 b(the)g(list)g(of)f +(the)h(remaining)f(nodes)h(\(attached)f(to)h Fr(unionClause)e +Ft(of)i(node)f(A\))h(is)270 1879 y(transformed)c(and)h(in)g(this)g +(step)h(also)f(a)h(check)f(is)h(made)f(if)f(the)h(types)h(and)f +(lengths)g(of)g(the)g Fp(tar)n(getlists)270 1939 y Ft(of)g(the)g(in)n +(v)o(olv)o(ed)g(nodes)h(are)f(equal.)19 b(The)14 b(ne)o(w)f +Fr(Query)g Ft(nodes)g(are)h(no)o(w)e(handed)i(back)f(in)g(the)h(same) +270 1998 y(way)e(as)h(the)g Fr(SelectStmt)e Ft(nodes)i(were)g(before)e +(\(i.e.)17 b(the)12 b Fr(Query)h Ft(nodes)f(B)h(and)g(C)g(are)f +(collected)270 2058 y(in)g(a)h(list)f(which)g(is)h(attached)f(to)h +Fr(unionClause)e Ft(of)h Fr(Query)g Ft(node)g(A\).)270 +2278 y Fn(The)g(Rewrite)h(System)270 2401 y Ft(If)18 +b(an)o(y)g Fp(r)n(e)o(write)i(rules)f Ft(are)f(present)g(for)f(the)i +Fr(Query)e Ft(nodes)i(\(i.e.)34 b(one)18 b(of)g(the)g +Fp(select)h Ft(statements)270 2461 y(uses)d(a)g Fp(vie)o(w)p +Ft(\))f(the)g(necessary)i(changes)e(to)g(the)h Fr(Query)f +Ft(nodes)g(are)g(performed)f(\(see)i(section)f(3.4.1)270 +2521 y Fp(T)-5 b(ec)o(hniques)11 b(T)-5 b(o)11 b(Implement)e(V)l(ie)o +(ws)p Ft(\).)17 b(Otherwise)10 b(no)g(changes)h(are)g(made)f(to)g(the)h +(nodes)f(in)h(this)f(stage.)270 2741 y Fn(Planner/Optimizer)270 +2864 y Ft(This)15 b(stage)g(has)g(to)f(create)g(a)h Fp(plan)f +Ft(out)g(of)g(the)g Fp(querytr)n(ee)i Ft(produced)d(by)i(the)f +Fp(parser)h(stage)f Ft(that)g(can)270 2924 y(be)j(e)o(x)o(ecuted)g(by)f +(the)g Fp(e)o(xecutor)p Ft(.)29 b(In)16 b(most)g(cases)i(there)e(are)g +(se)o(v)o(eral)h(ways)f(\(paths\))g(with)g(dif)o(ferent)270 +2984 y(cost)d(to)f(get)h(to)f(the)h(same)g(result.)j(It')m(s)c(the)g +Fp(planner/optimizer')n(s)h Ft(task)g(to)f(\002nd)g(out)h(which)f(path) +g(is)h(the)270 3044 y(cheapest)f(and)f(to)g(create)h(a)f +Fp(plan)g Ft(using)h(this)f(path.)k(The)d(implementation)e(of)h +Fp(unions)g Ft(in)g(PostgreSQL)270 3103 y(is)i(based)g(on)f(the)g +(follo)o(wing)f(idea:)270 3223 y(The)26 b(set)g(deri)o(v)o(ed)e(by)h(e) +o(v)o(aluating)g Fk(A)c Fo([)g Fk(B)27 b Ft(must)f(contain)f(e)o(v)o +(ery)g(member)f(of)h Fk(A)h Fn(and)e Ft(e)o(v)o(ery)270 +3283 y(member)16 b(of)h Fk(B)r Ft(.)30 b(So)17 b(if)f(we)h(append)g +(the)g(members)g(of)f Fk(B)k Ft(to)c(the)h(members)g(of)g +Fk(A)g Ft(we)g(are)g(almost)270 3342 y(done.)f(If)11 +b(there)h(e)o(xist)h(members)f(common)f(to)h Fk(A)h Ft(and)f +Fk(B)j Ft(these)d(members)g(are)g(no)o(w)g(contained)g(twice)270 +3402 y(in)g(our)g(ne)o(w)g(set,)i(so)e(the)h(only)f(thing)f(left)h(to)h +(do)f(is)g(to)h(remo)o(v)o(e)f(these)h(duplicates.)p +eop +%%Page: 93 93 +93 92 bop 198 60 a Fm(3.8.)29 b(THE)13 b(REALIZA)-6 b(TION)14 +b(OF)e(UNION,)g(INTERSECT)i(AND)f(EXCEPT)349 b Ft(93)198 +234 y(In)11 b(the)h(case)h(of)e(our)h(e)o(xample)g(the)g +Fp(planner)g Ft(would)f(b)o(uild)g(up)h(the)g Fp(tr)n(ee)g +Ft(sho)o(wn)g(in)g(\002gure)f(3.10.)16 b(Ev)o(ery)198 +294 y Fr(Query)f Ft(node)h(is)g(planned)f(separately)h(and)f(results)h +(in)f(a)h Fr(SeqScan)f Ft(node)g(in)h(our)f(e)o(xample.)26 +b(The)198 354 y(three)12 b Fr(SeqScan)f Ft(nodes)h(are)g(put)f +(together)h(into)f(a)h(list)g(which)g(is)g(attached)g(to)g +Fr(unionplans)f Ft(of)g(an)198 413 y Fr(Append)h Ft(node.)283 +1835 y @beginspecial 143 @llx 261 @lly 469 @urx 530 @ury +3260 @rwi @setspecial +%%BeginDocument: figures/union_plan.ps +%Magnification: 1.05 +/$F2psDict 200 dict def +$F2psDict begin +$F2psDict /mtrx matrix put +/col-1 {0 setgray} bind def +/col0 {0.000 0.000 0.000 srgb} bind def +/col1 {0.000 0.000 1.000 srgb} bind def +/col2 {0.000 1.000 0.000 srgb} bind def +/col3 {0.000 1.000 1.000 srgb} bind def +/col4 {1.000 0.000 0.000 srgb} bind def +/col5 {1.000 0.000 1.000 srgb} bind def +/col6 {1.000 1.000 0.000 srgb} bind def +/col7 {1.000 1.000 1.000 srgb} bind def +/col8 {0.000 0.000 0.560 srgb} bind def +/col9 {0.000 0.000 0.690 srgb} bind def +/col10 {0.000 0.000 0.820 srgb} bind def +/col11 {0.530 0.810 1.000 srgb} bind def +/col12 {0.000 0.560 0.000 srgb} bind def +/col13 {0.000 0.690 0.000 srgb} bind def +/col14 {0.000 0.820 0.000 srgb} bind def +/col15 {0.000 0.560 0.560 srgb} bind def +/col16 {0.000 0.690 0.690 srgb} bind def +/col17 {0.000 0.820 0.820 srgb} bind def +/col18 {0.560 0.000 0.000 srgb} bind def +/col19 {0.690 0.000 0.000 srgb} bind def +/col20 {0.820 0.000 0.000 srgb} bind def +/col21 {0.560 0.000 0.560 srgb} bind def +/col22 {0.690 0.000 0.690 srgb} bind def +/col23 {0.820 0.000 0.820 srgb} bind def +/col24 {0.500 0.190 0.000 srgb} bind def +/col25 {0.630 0.250 0.000 srgb} bind def +/col26 {0.750 0.380 0.000 srgb} bind def +/col27 {1.000 0.500 0.500 srgb} bind def +/col28 {1.000 0.630 0.630 srgb} bind def +/col29 {1.000 0.750 0.750 srgb} bind def +/col30 {1.000 0.880 0.880 srgb} bind def +/col31 {1.000 0.840 0.000 srgb} bind def + +end +save +130.0 543.5 translate +1 -1 scale + +/cp {closepath} bind def +/ef {eofill} bind def +/gr {grestore} bind def +/gs {gsave} bind def +/sa {save} bind def +/rs {restore} bind def +/l {lineto} bind def +/m {moveto} bind def +/rm {rmoveto} bind def +/n {newpath} bind def +/s {stroke} bind def +/sh {show} bind def +/slc {setlinecap} bind def +/slj {setlinejoin} bind def +/slw {setlinewidth} bind def +/srgb {setrgbcolor} bind def +/rot {rotate} bind def +/sc {scale} bind def +/sd {setdash} bind def +/ff {findfont} bind def +/sf {setfont} bind def +/scf {scalefont} bind def +/sw {stringwidth} bind def +/tr {translate} bind def +/tnt {dup dup currentrgbcolor + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add srgb} + bind def +/shd {dup dup currentrgbcolor 4 -2 roll mul 4 -2 roll mul + 4 -2 roll mul srgb} bind def +/$F2psBegin {$F2psDict begin /$F2psEnteredState save def} def +/$F2psEnd {$F2psEnteredState restore end} def + +$F2psBegin +10 setmiterlimit +n 0 792 m 0 0 l 612 0 l 612 792 l cp clip + 0.06299 0.06299 sc +7.500 slw +% Polyline +n 225 450 m 1575 450 l gs col-1 s gr +% Polyline +n 1305 450 m 1305 1080 l gs col-1 s gr +% Polyline +n 225 225 m 1575 225 l 1575 1080 l 225 1080 l cp gs col-1 s gr +% Polyline +n 225 810 m 1575 810 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +675 720 m +gs 1 -1 sc 90.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +315 405 m +gs 1 -1 sc (Unique node) col-1 sh gr +/Times-Roman ff 150.00 scf sf +315 990 m +gs 1 -1 sc (lefttree) col-1 sh gr +% Polyline +n 225 4095 m 1575 4095 l gs col-1 s gr +% Polyline +n 1305 4095 m 1305 4455 l gs col-1 s gr +% Polyline +n 225 3870 m 1575 3870 l 1575 4455 l 225 4455 l cp gs col-1 s gr +/Times-Roman ff 150.00 scf sf +675 4365 m +gs 1 -1 sc 90.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +315 4050 m +gs 1 -1 sc (SeqScan node \(A\)) col-1 sh gr +% Polyline +n 2115 4095 m 3465 4095 l gs col-1 s gr +% Polyline +n 3195 4095 m 3195 4455 l gs col-1 s gr +% Polyline +n 2115 3870 m 3465 3870 l 3465 4455 l 2115 4455 l cp gs col-1 s gr +/Times-Roman ff 150.00 scf sf +2565 4365 m +gs 1 -1 sc 90.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2205 4050 m +gs 1 -1 sc (SeqScan node \(B\)) col-1 sh gr +% Polyline +n 4005 4095 m 5355 4095 l gs col-1 s gr +% Polyline +n 5085 4095 m 5085 4455 l gs col-1 s gr +% Polyline +n 4005 3870 m 5355 3870 l 5355 4455 l 4005 4455 l cp gs col-1 s gr +/Times-Roman ff 150.00 scf sf +4455 4365 m +gs 1 -1 sc 90.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4095 4050 m +gs 1 -1 sc (SeqScan node \(C\)) col-1 sh gr +% Polyline +n 765 3285 m 1305 3285 l 1305 3555 l 765 3555 l cp gs col-1 s gr +% Polyline +n 1035 3285 m 1035 3555 l gs col-1 s gr +% Polyline +n 2655 3285 m 3195 3285 l 3195 3555 l 2655 3555 l cp gs col-1 s gr +% Polyline +n 2925 3285 m 2925 3555 l gs col-1 s gr +% Polyline +n 4545 3285 m 5085 3285 l 5085 3555 l 4545 3555 l cp gs col-1 s gr +% Polyline +n 4815 3285 m 4815 3555 l gs col-1 s gr +% Polyline +n 4815 3285 m 5085 3555 l gs col-1 s gr +% Polyline +n 4815 3555 m 5085 3285 l gs col-1 s gr +% Polyline +gs clippath +930 3723 m 900 3843 l 870 3723 l 870 3885 l 930 3885 l cp clip +n 900 3870 m 900 3420 l gs col-1 s gr gr + +% arrowhead +n 930 3723 m 900 3843 l 870 3723 l 900 3723 l 930 3723 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +2820 3723 m 2790 3843 l 2760 3723 l 2760 3885 l 2820 3885 l cp clip +n 2790 3870 m 2790 3420 l gs col-1 s gr gr + +% arrowhead +n 2820 3723 m 2790 3843 l 2760 3723 l 2790 3723 l 2820 3723 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +2508 3390 m 2628 3420 l 2508 3450 l 2670 3450 l 2670 3390 l cp clip +n 1170 3420 m 2655 3420 l gs col-1 s gr gr + +% arrowhead +n 2508 3390 m 2628 3420 l 2508 3450 l 2508 3420 l 2508 3390 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +4710 3723 m 4680 3843 l 4650 3723 l 4650 3885 l 4710 3885 l cp clip +n 4680 3870 m 4680 3420 l gs col-1 s gr gr + +% arrowhead +n 4710 3723 m 4680 3843 l 4650 3723 l 4680 3723 l 4710 3723 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +4398 3390 m 4518 3420 l 4398 3450 l 4560 3450 l 4560 3390 l cp clip +n 3060 3420 m 4545 3420 l gs col-1 s gr gr + +% arrowhead +n 4398 3390 m 4518 3420 l 4398 3450 l 4398 3420 l 4398 3390 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 4005 2250 m 5355 2250 l gs col-1 s gr +% Polyline +n 5085 2250 m 5085 2880 l gs col-1 s gr +% Polyline +n 4005 2025 m 5355 2025 l 5355 2880 l 4005 2880 l cp gs col-1 s gr +% Polyline +n 4005 2610 m 5355 2610 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +4455 2520 m +gs 1 -1 sc 90.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4095 2790 m +gs 1 -1 sc (unionplans) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4095 2205 m +gs 1 -1 sc (Append node) col-1 sh gr +% Polyline +n 2115 1350 m 3465 1350 l gs col-1 s gr +% Polyline +n 3195 1350 m 3195 1980 l gs col-1 s gr +% Polyline +n 2115 1125 m 3465 1125 l 3465 1980 l 2115 1980 l cp gs col-1 s gr +% Polyline +n 2115 1710 m 3465 1710 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +2565 1620 m +gs 1 -1 sc 90.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2205 1305 m +gs 1 -1 sc (Sort node) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2205 1890 m +gs 1 -1 sc (lefttree) col-1 sh gr +% Interp Spline +gs clippath +2702 1004 m 2770 1106 l 2661 1048 l 2781 1157 l 2821 1113 l cp clip +n 1440 945 m + 1674.5 943.0 1775.8 943.0 1845 945 curveto + 2019.7 950.1 2429.3 923.8 2610 990 curveto + 2649.8 1004.6 2694.8 1038.3 2790 1125 curveto + gs col-1 s gr + gr + +% arrowhead +n 2702 1004 m 2770 1106 l 2661 1048 l 2682 1026 l 2702 1004 l cp gs 0.00 setgray ef gr col-1 s +% Interp Spline +gs clippath +4592 1904 m 4660 2006 l 4551 1948 l 4671 2057 l 4711 2013 l cp clip +n 3330 1845 m + 3564.5 1843.0 3665.8 1843.0 3735 1845 curveto + 3909.7 1850.1 4319.3 1823.8 4500 1890 curveto + 4539.8 1904.6 4584.8 1938.3 4680 2025 curveto + gs col-1 s gr + gr + +% arrowhead +n 4592 1904 m 4660 2006 l 4551 1948 l 4572 1926 l 4592 1904 l cp gs 0.00 setgray ef gr col-1 s +% Interp Spline +gs clippath +617 3396 m 738 3421 l 619 3456 l 781 3449 l 779 3389 l cp clip +n 5220 2745 m + 5223.4 2874.8 5212.2 2931.0 5175 2970 curveto + 5094.8 3054.1 4900.0 3048.4 4815 3060 curveto + 4423.3 3113.5 3494.7 3099.9 3105 3105 curveto + 2694.9 3110.4 1715.1 3105.0 1305 3105 curveto + 1202.5 3105.0 957.7 3100.3 855 3105 curveto + 741.6 3110.1 477.3 3095.1 360 3150 curveto + 330.0 3164.1 274.4 3195.4 270 3240 curveto + 264.4 3296.9 324.9 3350.2 360 3375 curveto + 400.2 3403.3 497.3 3414.7 540 3420 curveto + 578.9 3424.8 635.1 3424.8 765 3420 curveto + gs col-1 s gr + gr + +% arrowhead +n 617 3396 m 738 3421 l 619 3456 l 618 3426 l 617 3396 l cp gs 0.00 setgray ef gr col-1 s +showpage +$F2psEnd +rs +%%EndDocument + @endspecial 743 1945 a(Figure)g(3.10:)j Fp(Plan)e Ft(for)e(a)i(union)f +(query)198 2225 y Fn(Executor)198 2327 y Ft(The)k Fp(e)o(xecutor)h +Ft(will)e(process)h(all)g(the)f Fr(SeqScan)g Ft(nodes)i(and)e(append)h +(all)g(the)f(deli)o(v)o(ered)g(tuples)h(to)198 2387 y(a)e(single)g +Fp(r)n(esult)h(r)n(elation)p Ft(.)21 b(No)o(w)13 b(it)h(is)g(possible)h +(that)e(duplicate)h(tuples)g(are)g(contained)g(in)f(the)h +Fp(r)n(esult)198 2447 y(r)n(elation)e Ft(which)g(ha)o(v)o(e)g(to)g(be)g +(remo)o(v)o(ed.)j(The)e(remo)o(v)o(al)e(is)i(done)e(by)h(the)g +Fr(Unique)g Ft(node)f(and)h(the)g(sort)198 2506 y(is)h(just)f +(performed)f(to)h(make)g(its)h(work)e(easier)m(.)198 +2674 y Fh(3.8.2)59 b(Ho)o(w)15 b(Intersect,)f(Except)g(and)h(Union)g(W) +l(ork)f(T)-5 b(ogether)198 2777 y Ft(The)20 b(last)f(section)g(sho)o +(wed)h(that)f(e)o(v)o(ery)f(stage)i(\()p Fp(parser)f(stage)p +Ft(,)i Fp(planner/optimizer)p Ft(,)g Fp(e)o(xecutor)p +Ft(\))f(of)198 2836 y(PostgreSQL)15 b(has)h(to)g(pro)o(vide)f(features) +h(in)f(order)g(to)h(support)f Fp(union)g Ft(statements.)26 +b(F)o(or)15 b(the)h(imple-)198 2896 y(mentation)f(of)h +Fp(intersect)h Ft(and)f Fp(e)o(xcept)g Ft(statements)h(\(and)f +(statements)g(in)n(v)o(olving)f(all)h Fp(set)h(oper)o(ators)p +Ft(\))198 2956 y(we)c(choose)f(a)h(dif)o(ferent)e(approach)h(based)g +(on)h Fp(query)g(r)n(e)o(writing)p Ft(.)198 3076 y(The)26 +b(idea)f(is)h(based)g(on)f(the)g(fact)f(that)i Fp(intersect)f +Ft(and)g Fp(e)o(xcept)h Ft(statements)g(are)f(redundant)f(in)198 +3135 y(SQL,)15 b(i.e.)21 b(for)14 b(e)o(v)o(ery)g Fp(intersect)g +Ft(or)g Fp(e)o(xcept)g Ft(statement)g(it)g(is)g(possible)h(to)f +(formulate)f(a)h(semantically)198 3195 y(equi)o(v)o(alent)d(statement)i +(without)f(using)g Fp(intersect)g Ft(or)g Fp(e)o(xcept)p +Ft(.)198 3342 y Fn(Example)h(3.5)25 b Ft(This)18 b(e)o(xample)g(sho)o +(ws)h(ho)o(w)e(a)h(query)g(using)f Fp(intersect)h Ft(can)h(be)f +(transformed)e(to)i(a)198 3402 y(semantically)12 b(equi)o(v)o(alent)g +(query)g(without)f(an)i Fp(intersect)p Ft(:)p eop +%%Page: 94 94 +94 93 bop 270 60 a Ft(94)82 b Fm(CHAPTER)14 b(3.)28 b(POSTGRESQL)13 +b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW)330 +234 y Fr(select)29 b(C1,)h(C3)f(from)h(A)330 294 y(where)f(C1)h(=)g(1) +330 354 y(intersect)330 413 y(select)f(C1,)h(C2)f(from)h(B)330 +473 y(where)f(C2)h(=)g('c';)270 564 y Ft(is)13 b(equi)o(v)o(alent)e +(to:)330 656 y Fr(select)29 b(C1,)h(C3)330 715 y(from)f(A)330 +775 y(where)g(C1)h(=)g(1)f(and)509 835 y(\(C1,)h(C3\))f(in)h(\(select)f +(C1,)g(C2)898 895 y(from)g(B)898 955 y(where)g(C2)h(=)f('c'\);)270 +1046 y Ft(This)13 b(e)o(xample)f(sho)o(ws)h(ho)o(w)f(an)h +Fp(e)o(xcept)f Ft(query)g(can)h(be)f(transformed)f(to)i(an)f +Fp(e)o(xcept)p Ft(-less)h(form:)330 1137 y Fr(select)29 +b(C1,)h(C2)f(from)h(A)330 1197 y(where)f(C2)h(=)g('c')330 +1257 y(except)330 1316 y(select)f(C1,)h(C3)f(from)h(B)330 +1376 y(where)f(C3)h(=)g('f';)270 1467 y Ft(is)13 b(equi)o(v)o(alent)e +(to:)330 1558 y Fr(select)29 b(C1,)h(C2)330 1618 y(from)f(A)330 +1678 y(where)g(C2)h(=)g('c')f(and)509 1738 y(\(C1,)h(C2\))f(not)h(in)f +(\(select)g(C1,)h(C3)1017 1798 y(from)g(B)1017 1857 y(where)g(C3)f(=)h +('f'\);)270 1949 y Ft(The)13 b(transformations)e(used)i(in)g(e)o +(xample)f(3.5)h(are)g(always)f(v)o(alid)g(because)h(the)o(y)g(just)f +(implement)g(the)270 2008 y(set)h(theoretic)f(de\002nition)f(of)h +Fp(intersect)g Ft(and)h Fp(e)o(xcept)p Ft(:)270 2122 +y Fn(De\002nition)e(3.1)270 2181 y Ft(The)i Fp(intersection)f +Ft(of)g(two)g(sets)h Fk(A)g Ft(and)f Fk(B)j Ft(is)d(de\002ned)h(as:)828 +2280 y Fl(\()p Fk(A)f Fo(\\)f Fk(B)r Fl(\))k(:=)e Fo(f)p +Fk(x)h Fo(j)g Fk(x)g Fo(2)g Fk(A)e Fo(^)f Fk(x)k Fo(2)f +Fk(B)r Fo(g)270 2380 y Ft(The)f Fp(intersection)f Ft(of)g +Fk(n)g Ft(sets)i Fk(A)828 2387 y Fg(1)850 2380 y Fk(;)8 +b(:)g(:)g(:)h(;)f(A)998 2387 y Ff(n)1038 2380 y Ft(is)13 +b(de\002ned)f(as:)918 2453 y Ff(n)903 2468 y Fb(\\)899 +2575 y Ff(i)p Fg(=1)971 2516 y Fk(A)1008 2523 y Ff(i)1039 +2516 y Fl(:=)i Fo(f)p Fk(x)g Fo(j)1220 2453 y Ff(n)1205 +2468 y Fb(^)1200 2575 y Ff(i)p Fg(=1)1273 2516 y Fk(x)h +Fo(2)f Fk(A)1400 2523 y Ff(i)1417 2516 y Fo(g)270 2672 +y Fn(De\002nition)d(3.2)270 2732 y Ft(The)i Fp(dif)o(fer)n(ence)g +Ft(of)f(two)f(sets)j Fk(A)e Ft(and)h Fk(B)i Ft(is)d(de\002ned)g(as:)843 +2831 y Fl(\()p Fk(A)p Fo(n)p Fk(B)r Fl(\))k(:=)d Fo(f)p +Fk(x)h Fo(j)g Fk(x)g Fo(2)g Fk(A)e Fo(^)f Fk(x)j Fo(62)g +Fk(B)r Fo(g)270 2944 y Fn(De\002nition)d(3.3)270 3004 +y Ft(The)i Fp(union)f Ft(of)g(two)f(sets)j Fk(A)e Ft(and)h +Fk(B)i Ft(is)d(de\002ned)g(as:)828 3103 y Fl(\()p Fk(A)g +Fo([)f Fk(B)r Fl(\))k(:=)e Fo(f)p Fk(x)h Fo(j)g Fk(x)g +Fo(2)g Fk(A)e Fo(_)f Fk(x)k Fo(2)f Fk(B)r Fo(g)270 3202 +y Ft(The)f Fp(union)f Ft(of)g Fk(n)g Ft(sets)h Fk(A)706 +3209 y Fg(1)729 3202 y Fk(;)8 b(:)g(:)g(:)h(;)f(A)877 +3209 y Ff(n)917 3202 y Ft(is)k(de\002ned)g(as:)918 3276 +y Ff(n)903 3291 y Fb([)899 3397 y Ff(i)p Fg(=1)971 3338 +y Fk(A)1008 3345 y Ff(i)1039 3338 y Fl(:=)i Fo(f)p Fk(x)g +Fo(j)1220 3276 y Ff(n)1205 3291 y Fb(_)1200 3397 y Ff(i)p +Fg(=1)1273 3338 y Fk(x)h Fo(2)f Fk(A)1400 3345 y Ff(i)1417 +3338 y Fo(g)p eop +%%Page: 95 95 +95 94 bop 198 60 a Fm(3.8.)29 b(THE)13 b(REALIZA)-6 b(TION)14 +b(OF)e(UNION,)g(INTERSECT)i(AND)f(EXCEPT)349 b Ft(95)198 +234 y Fn(De\002nition)11 b(3.4)25 b Ft(Disjuncti)o(v)o(e)12 +b(Normal)g(F)o(orm)f(\(DNF\))198 294 y(Let)k Fk(F)24 +b Fl(=)17 b Fk(C)427 301 y Fg(1)461 294 y Fo(_)c Fk(:)8 +b(:)g(:)13 b Fo(_)f Fk(C)659 301 y Ff(n)700 294 y Ft(be)j(gi)o(v)o(en)f +(where)g(e)o(v)o(ery)g Fk(C)1180 301 y Ff(i)1210 294 +y Ft(is)h(of)f(the)g(form)f Fl(\()p Fk(L)1553 276 y Fg(1)1553 +307 y Ff(i)1588 294 y Fo(^)g Fk(:)8 b(:)g(:)k Fo(^)h +Fk(L)1784 272 y Ff(k)1805 277 y Fa(i)1784 308 y Ff(i)1823 +294 y Fl(\))i Ft(and)f Fk(L)1977 270 y Ff(j)1977 308 +y(i)198 354 y Ft(is)g(a)f(propositional)g(v)o(ariable)f(or)h(the)h(ne)o +(gation)f(of)g(a)g(propositional)g(v)o(ariable.)18 b(No)o(w)13 +b(we)g(say)h Fk(F)21 b Ft(is)13 b(in)198 413 y(DNF)l(.)198 +549 y Fn(Example)g(3.6)25 b Ft(In)12 b(the)g(follo)o(wing)f(e)o(xample) +h(the)h Fk(L)1106 525 y Ff(j)1106 563 y(i)1139 549 y +Ft(are)f(of)g(the)h(form)e Fk(x)j Fo(2)g Fk(X)j Ft(or)12 +b Fo(:)p Fl(\()p Fk(x)j Fo(2)f Fk(X)t Fl(\))p Ft(:)273 +609 y Fl(\(\()p Fk(x)h Fo(2)f Fk(A)d Fo(^)h(:)p Fl(\()p +Fk(x)i Fo(2)g Fk(B)r Fl(\))e Fo(^)f Fk(x)k Fo(2)f Fk(C)t +Fl(\))c Fo(_)i Fl(\()p Fk(x)i Fo(2)g Fk(D)f Fo(^)e Fk(x)k +Fo(2)f Fk(E)s Fl(\)\))f Ft(is)f(a)h(formula)e(in)h(DNF)273 +669 y Fl(\(\()p Fk(x)j Fo(2)f Fk(A)d Fo(_)h Fk(x)i Fo(2)g +Fk(B)r Fl(\))e Fo(^)f Fl(\()p Fk(x)k Fo(2)f Fk(C)g Fo(_)d(:)p +Fl(\()p Fk(x)k Fo(2)f Fk(D)q Fl(\)\)\))g Ft(is)f(not)f(in)g(DNF)l(.)198 +779 y(The)g(transformation)e(of)i(an)o(y)g(formula)e(in)i +(propositional)e(logic)i(into)f(DNF)h(is)g(done)f(by)h(successi)o(v)o +(ely)198 839 y(applying)g(the)g(follo)o(wing)f(rules:)273 +959 y Fl(\()p Fk(R)p Fl(1\))25 b Fo(:)p Fl(\()p Fk(F)483 +966 y Fg(1)518 959 y Fo(_)11 b Fk(F)594 966 y Fg(2)616 +959 y Fl(\))j Fo(\))g Fl(\()p Fo(:)p Fk(F)797 966 y Fg(1)831 +959 y Fo(^)d(:)p Fk(F)940 966 y Fg(2)963 959 y Fl(\))273 +1018 y(\()p Fk(R)p Fl(2\))25 b Fo(:)p Fl(\()p Fk(F)483 +1025 y Fg(1)518 1018 y Fo(^)11 b Fk(F)594 1025 y Fg(2)616 +1018 y Fl(\))j Fo(\))g Fl(\()p Fo(:)p Fk(F)797 1025 y +Fg(1)831 1018 y Fo(_)d(:)p Fk(F)940 1025 y Fg(2)963 1018 +y Fl(\))273 1078 y(\()p Fk(R)p Fl(3\))25 b Fk(F)431 1085 +y Fg(1)465 1078 y Fo(^)11 b Fl(\()p Fk(F)560 1085 y Fg(2)594 +1078 y Fo(_)g Fk(F)670 1085 y Fg(3)693 1078 y Fl(\))j +Fo(\))g Fl(\()p Fk(F)841 1085 y Fg(1)874 1078 y Fo(^)e +Fk(F)951 1085 y Fg(2)973 1078 y Fl(\))f Fo(_)h Fl(\()p +Fk(F)1099 1085 y Fg(1)1133 1078 y Fo(^)f Fk(F)1209 1085 +y Fg(3)1231 1078 y Fl(\))273 1138 y(\()p Fk(R)p Fl(4\))25 +b(\()p Fk(F)450 1145 y Fg(1)484 1138 y Fo(_)12 b Fk(F)561 +1145 y Fg(2)583 1138 y Fl(\))f Fo(^)h Fk(F)690 1145 y +Fg(3)726 1138 y Fo(\))i Fl(\()p Fk(F)841 1145 y Fg(1)874 +1138 y Fo(^)e Fk(F)951 1145 y Fg(3)973 1138 y Fl(\))f +Fo(_)h Fl(\()p Fk(F)1099 1145 y Fg(2)1133 1138 y Fo(^)f +Fk(F)1209 1145 y Fg(3)1231 1138 y Fl(\))198 1257 y Ft(It)24 +b(can)i(be)f(sho)o(wn)f(that)h(the)g(transformation)e(using)i(the)g +(rules)g(\(R1\))f(to)h(\(R4\))f(always)g(termi-)198 1317 +y(nates)13 b(after)f(a)g(\002nite)g(number)g(of)g(steps.)198 +1465 y Fn(Set)g(Operations)f(as)i(Pr)o(opositional)f(Logic)g(F)o +(ormulas)198 1563 y Ft(Using)j(the)f(de\002nitions)h(from)e(abo)o(v)o +(e)i(we)g(can)g(treat)g(formulas)e(in)n(v)o(olving)h(set)h(theoretic)f +(operations)198 1623 y(as)d(formulas)f(of)h Fp(pr)n(opositional)f +(logic)p Ft(.)k(As)d(we)g(will)f(see)i(later)e(these)h(formulas)f(can)h +(easily)g(be)g(used)g(in)198 1683 y(the)h Fr(where-)g +Ft(and)g Fr(having)g Ft(quali\002cations)g(of)g(the)g +Fr(select)g Ft(statements)h(in)n(v)o(olv)o(ed)f(in)g(the)h(query)m(.) +198 1819 y Fn(Example)g(3.7)25 b Ft(Here)12 b(are)g(some)h(e)o +(xamples:)273 1938 y Fl(\(\()p Fk(A)f Fo([)f Fk(B)r Fl(\))h +Fo(\\)f Fk(C)t Fl(\))j(:=)f Fo(f)p Fk(x)h Fo(j)g Fl(\()p +Fk(x)h Fo(2)f Fk(A)d Fo(_)g Fk(x)k Fo(2)f Fk(B)r Fl(\))d +Fo(^)h Fk(x)i Fo(2)g Fk(C)t Fo(g)273 1998 y Fl(\(\()p +Fk(A)e Fo([)f Fk(B)r Fl(\))h Fo(\\)f Fl(\()p Fk(C)k Fo([)c +Fk(D)q Fl(\)\))k(:=)f Fo(f)p Fk(x)g Fo(j)g Fl(\()p Fk(x)g +Fo(2)g Fk(A)e Fo(_)f Fk(x)j Fo(2)g Fk(B)r Fl(\))e Fo(^)f +Fl(\()p Fk(x)k Fo(2)f Fk(C)g Fo(_)e Fk(x)i Fo(2)g Fk(D)q +Fl(\))p Fo(g)273 2058 y Fl(\(\()p Fk(A)e Fo(\\)f Fk(B)r +Fl(\))p Fo(n)p Fk(C)t Fl(\))j(:=)g Fo(f)p Fk(x)g Fo(j)f +Fl(\()p Fk(x)i Fo(2)f Fk(A)e Fo(^)f Fk(x)j Fo(2)g Fk(B)r +Fl(\))e Fo(^)f Fk(x)k Fo(62)f Fk(C)t Fo(g)273 2117 y +Fl(\()p Fk(A)p Fo(n)p Fl(\()p Fk(B)g Fo([)d Fk(C)t Fl(\)\))j(:=)g +Fo(f)p Fk(x)g Fo(j)f Fk(x)i Fo(2)f Fk(A)d Fo(^)g(:)p +Fl(\()p Fk(x)k Fo(2)f Fk(B)g Fo(_)d Fk(x)j Fo(2)g Fk(C)t +Fl(\))p Fo(g)273 2177 y Fl(\(\(\()p Fk(A)e Fo(\\)g Fk(B)r +Fl(\))f Fo([)h Fl(\()p Fk(C)t Fo(n)p Fk(D)q Fl(\)\))f +Fo(\\)h Fk(E)s Fl(\))i(:=)f Fo(f)p Fl(\(\()p Fk(x)i Fo(2)f +Fk(A)d Fo(^)h Fk(x)i Fo(2)g Fk(B)r Fl(\))e Fo(_)f Fl(\()p +Fk(x)k Fo(2)f Fk(C)g Fo(^)d Fk(x)k Fo(62)f Fk(D)q Fl(\)\))e +Fo(^)f Fk(x)k Fo(2)f Fk(E)s Fo(g)198 2335 y Fh(3.8.3)59 +b(Implementing)19 b(Intersect)h(and)g(Except)g(Using)g(the)g(Union)h +(Capabili-)377 2404 y(ties)198 2503 y Ft(W)l(e)14 b(want)g(to)g(be)g +(able)g(to)g(use)h(queries)f(in)n(v)o(olving)f(more)h(than)g(just)g +(one)g(type)g(of)g(set)g(operation)f(\(e.g.)198 2563 +y(only)18 b Fp(union)g Ft(or)g(only)g Fp(intersect)p +Ft(\))g(at)g(a)h(time,)h(so)f(we)f(ha)o(v)o(e)h(to)f(look)g(for)g(a)g +(solution)g(that)g(supports)198 2622 y(correct)12 b(handling)h(of)g +(queries)g(like)f(that.)18 b(As)13 b(described)g(abo)o(v)o(e)h(there)e +(is)i(a)f(solution)g(for)f(pure)h Fp(union)198 2682 y +Ft(statements)19 b(implemented)f(already)m(,)i(so)f(we)g(ha)o(v)o(e)g +(to)g(de)o(v)o(elop)f(an)h(approach)f(that)h(makes)f(use)i(of)198 +2742 y(these)13 b Fp(union)f Ft(capabilities.)198 2862 +y(As)27 b(\002gure)g(3.9)g(illustrates,)k(the)c(operands)g(of)f(a)i +Fp(union)e Ft(operation)g(are)h(just)g Fr(Query)g Ft(nodes)198 +2921 y(\(the)14 b(\002rst)h(operand)f(is)h(the)g(top)g(node)f(and)h +(all)g(further)e(operands)i(form)f(a)h(list)g(which)f(is)h(attached)g +(to)198 2981 y(the)h(\002eld)f Fr(unionClause)g Ft(of)g(the)g(top)h +(node\).)25 b(So)15 b(our)h(goal)f(will)g(be)h(to)g(transform)e(e)o(v)o +(ery)i(query)198 3041 y(in)n(v)o(olving)11 b(set)i(operations)f(into)f +(this)i(form.)h(\(Note)e(that)g(the)g(operands)g(to)g(the)g +Fp(union)g Ft(operation)f(may)198 3101 y(be)h(comple)o(x,)h(i.e.)k +Fp(subselects)p Ft(,)c Fp(gr)n(ouping)p Ft(,)g Fp(aggr)n(e)n(gates)f +Ft(etc.)k(are)c(allo)o(wed.\))273 3163 y(The)k(transformation)e(of)i(a) +g(query)f(in)n(v)o(olving)g(set)i(operations)e(in)h(an)o(y)g(order)f +(into)h(a)g(query)f(that)198 3223 y(can)g(be)f(accepted)h(by)g(the)f +Fp(union)g Ft(logic)g(is)h(equi)o(v)o(alent)f(to)g(transforming)f(the)i +Fp(membership)f(formula)198 3283 y Ft(\(see)d(de\002nitions)g(3.1,)h +(3.2)f(and)g(3.3\))g(in)g(propositional)f(logic)g(into)h +Fp(disjunctive)g(normal)g(form)g Ft(\(DNF\).)198 3342 +y(The)j(transformation)d(of)i(an)o(y)g(formula)f(in)h(propositional)g +(logic)g(into)f(DNF)h(is)h(always)e(possible)i(in)f(a)198 +3402 y(\002nite)f(number)g(of)f(steps.)p eop +%%Page: 96 96 +96 95 bop 270 60 a Ft(96)82 b Fm(CHAPTER)14 b(3.)28 b(POSTGRESQL)13 +b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW)270 +234 y Ft(The)18 b(adv)o(antage)f(of)g(this)g Fp(tr)o(ansformation)h +(tec)o(hnique)f Ft(is)g(the)h(little)e(impact)h(on)g(the)h(whole)f +(system)270 294 y(and)12 b(the)f(implicit)g(in)n(v)o(ocation)g(of)g +(the)h Fp(planner/optimizer)p Ft(.)k(The)c(only)f(changes)h(necessary)h +(are)e(made)270 354 y(to)h(the)h Fp(parser)g(stage)e +Ft(and)i(the)f Fp(r)n(e)o(write)i(system)p Ft(.)270 473 +y(Here)24 b(are)f(some)h(changes)g(that)g(had)f(to)h(be)g(applied)f(to) +h(the)f(source)h(code)g(before)f(the)g Fp(parser)270 +533 y(stage)12 b Ft(and)g(the)g Fp(r)n(e)o(write)i(system)f +Ft(could)f(be)h(adapted:)345 636 y Fo(\017)25 b Ft(Add)19 +b(the)g(additional)g(\002eld)g Fr(intersectClause)f Ft(to)h(the)g(data) +h(structures)f Fr(Query)g Ft(and)395 695 y Fr(InsertStmt)11 +b Ft(de\002ned)h(in)g(the)g(\002le)h Fk(:)8 b(:)g(:)p +Fr(/src/include/nodes/parsenodes)o(.h)p Ft(:)454 819 +y Fr(typedef)29 b(struct)h(Query)454 878 y({)514 938 +y(NodeTag)119 b(type;)514 998 y(CmdType)g(commandType;)753 +1058 y(.)753 1118 y(.)753 1177 y(.)514 1237 y(Node)209 +b(*havingQual;)395 1297 y(+)89 b(List)209 b(*intersectClause;)514 +1357 y(List)g(*unionClause;)514 1416 y(List)g(*base_relation_list_;)514 +1476 y(List)g(*join_relation_list_;)454 1536 y(})30 b(Query;)454 +1656 y(typedef)f(struct)h(InsertStmt)454 1715 y({)514 +1775 y(NodeTag)119 b(type;)753 1835 y(.)753 1895 y(.)753 +1954 y(.)514 2014 y(bool)209 b(unionall;)395 2074 y(+)89 +b(List)209 b(*intersectClause;)454 2134 y(})30 b(InsertStmt;)345 +2257 y Fo(\017)25 b Ft(Add)63 b(the)g(ne)o(w)g(ke)o(ywords)g +Fr(EXCEPT)g Ft(and)g Fr(INTERSECT)g Ft(to)g(the)g(\002le)395 +2317 y Fk(:)8 b(:)g(:)p Fr(/src/backend/parser/keywords.)o(c)p +Ft(:)454 2440 y Fr(static)30 b(ScanKeyword)e(ScanKeywords[])g(=)i({)514 +2500 y({"abort",)f(ABORT_TRANS},)514 2560 y({"action",)g(ACTION},)813 +2620 y(.)813 2679 y(.)813 2739 y(.)514 2799 y({"end",)g(END_TRANS},)395 +2859 y(+)89 b({"except",)29 b(EXCEPT},)813 2919 y(.)813 +2978 y(.)813 3038 y(.)514 3098 y({"instead",)g(INSTEAD},)395 +3158 y(+)89 b({"intersect",)29 b(INTERSECT},)813 3217 +y(.)813 3277 y(.)813 3337 y(.)454 3397 y(};)p eop +%%Page: 97 97 +97 96 bop 198 60 a Fm(3.8.)29 b(THE)13 b(REALIZA)-6 b(TION)14 +b(OF)e(UNION,)g(INTERSECT)i(AND)f(EXCEPT)349 b Ft(97)273 +234 y Fo(\017)25 b Ft(PostgreSQL)14 b(contains)h(functions)g(to)f(con)n +(v)o(ert)h(the)g(internal)f(representation)g(of)h(a)g +Fp(parsetr)n(ee)323 294 y Ft(or)j Fp(plantr)n(ee)g Ft(into)g(an)h +(ASCII)f(representation)f(\(that)h(can)h(easily)g(be)f(printed)g(to)g +(the)h(screen)323 354 y(\(for)f(deb)o(ugging)g(purposes\))i(or)f(be)g +(stored)g(in)h(a)f(\002le\))g(and)g(vice)h(v)o(ersa.)37 +b(These)21 b(functions)323 413 y(ha)o(v)o(e)g(to)g(be)h(adapted)f(to)g +(be)g(able)g(to)g(deal)h(with)f Fp(intersects)g Ft(and)h +Fp(e)o(xcepts)p Ft(.)43 b(These)22 b(func-)323 473 y(tions)e(can)h(be)g +(found)f(in)h(the)f(\002les)h Fk(:)8 b(:)g(:)p Fr +(/src/backend/nodes/outfuncs.c)18 b Ft(and)323 533 y +Fk(:)8 b(:)g(:)p Fr(/src/backend/nodes/readfuncs.)o(c)p +Ft(:)382 675 y Fr(static)30 b(void)382 735 y(_outQuery\(StringInfo)e +(str,)h(Query)h(*node\))382 795 y({)1159 854 y(.)1159 +914 y(.)1159 974 y(.)442 1034 y(appendStringInfo\(str,)e(")h +(:unionClause)g("\);)442 1094 y(_outNode\(str,)g(node->unionClause\);) +323 1153 y(+)89 b(appendStringInfo\(str,)28 b(")h(:intersectClause)f +("\);)323 1213 y(+)89 b(_outNode\(str,)29 b(node->intersectClause\);) +382 1273 y(})382 1392 y(static)h(Query)f(*)382 1452 y(_readQuery\(\)) +382 1512 y({)1159 1572 y(.)1159 1632 y(.)1159 1691 y(.)442 +1751 y(token)g(=)h(lsptok\(NULL,)f(&length\);)442 1811 +y(local_node->unionClause)e(=)j(nodeRead\(true\);)323 +1871 y(+)89 b(token)29 b(=)h(lsptok\(NULL,)f(&length\);)323 +1930 y(+)89 b(local_node->intersectClause)27 b(=)j(nodeRead\(true\);) +442 2050 y(return)f(\(local_node\);)382 2110 y(})273 +2252 y Fo(\017)c Ft(The)14 b(function)g Fr(ExecReScan\(\))f +Ft(is)h(called)h(whene)o(v)o(er)f(a)g(ne)o(w)g(e)o(x)o(ecution)h(of)f +(a)g(gi)o(v)o(en)g Fp(plan)323 2312 y Ft(has)j(to)f(be)h(started)g +(\(i.e.)29 b(whene)o(v)o(er)16 b(we)h(ha)o(v)o(e)g(to)f(start)h(from)f +(the)g(be)o(ginning)g(with)h(the)f(\002rst)323 2371 y(tuple)k(again\).) +41 b(The)21 b(call)g(to)f(this)h(function)f(happens)h(implicitly)m(.)40 +b(F)o(or)20 b(the)h(special)g(kind)323 2431 y(of)16 b(subqueries)h(we)g +(are)g(using)f(for)g(the)h(re)o(written)f(queries)g(\(see)h(e)o(xample) +g(3.5\))g(we)g(ha)o(v)o(e)g(to)323 2491 y(take)g(that)g(also)i +Fr(Group)e Ft(nodes)h(are)g(processed.)32 b(The)18 b(function)f(can)h +(be)g(found)f(in)h(the)f(\002le)323 2551 y Fk(l)q(dots)p +Fr(/backend/executor/execAmi.c)p Ft(.)382 2693 y Fr(void)382 +2753 y(ExecReScan\(Plan)29 b(*node,)g(ExprContext)f(*exprCtxt,)711 +2812 y(Plan)i(*parent\))382 2872 y({)1159 2932 y(.)1159 +2992 y(.)1159 3052 y(.)472 3111 y(switch)f(\(nodeTag\(node\)\))472 +3171 y({)1159 3231 y(.)1159 3291 y(.)1159 3350 y(.)p +eop +%%Page: 98 98 +98 97 bop 270 60 a Ft(98)82 b Fm(CHAPTER)14 b(3.)28 b(POSTGRESQL)13 +b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW)395 +234 y Fr(+)179 b(case)29 b(T_Group:)395 294 y(+)388 b +(ExecReScanGroup\(\(Group)27 b(*\))j(node,)395 354 y(+)896 +b(exprCtxt,)29 b(parent\);)395 413 y(+)388 b(break;)1231 +473 y(.)1231 533 y(.)1231 593 y(.)544 653 y(})454 712 +y(})345 933 y Fo(\017)25 b Ft(The)g(function)e Fr(ExecReScanGroup\(\))g +Ft(is)i(called)f(by)h Fr(ExecReScan\(\))e Ft(described)395 +993 y(abo)o(v)o(e)33 b(whene)o(v)o(er)g(a)g Fr(Group)g +Ft(node)g(is)g(detected)g(and)g(can)h(be)f(found)f(in)h(the)g(\002le) +395 1053 y Fk(:)8 b(:)g(:)p Fr(/src/backend/executor/nodeGro)o(up.c)i +Ft(.)18 b(It)13 b(has)g(been)g(created)g(for)g(the)g +Fp(in-)395 1112 y(tersect)e Ft(and)f Fp(e)o(xcept)h Ft(logic)f +(although)g(it)h(is)g(actually)f(needed)h(by)f(the)h(special)g(kind)f +(of)g(subselect)395 1172 y(\(see)i(abo)o(v)o(e\).)454 +1365 y Fr(void)454 1424 y(ExecReScanGroup\(Group)28 b(*node,)h +(ExprContext)g(*exprCtxt,)933 1484 y(Plan)g(*parent\))454 +1544 y({)514 1604 y(GroupState)g(*grpstate)g(=)h(node->grpstate;)514 +1723 y(grpstate->grp_useFirstTuple)d(=)j(FALSE;)514 1783 +y(grpstate->grp_done)e(=)i(FALSE;)514 1843 y(grpstate->grp_firstTuple)d +(=)j(\(HeapTupleData)e(*\)NIL;)514 1962 y(/*)544 2022 +y(*)i(if)f(chgParam)g(of)h(subnode)f(is)h(not)f(null)h(then)f(plan)544 +2082 y(*)h(will)f(be)h(re-scanned)f(by)g(first)h(ExecProcNode.)544 +2142 y(*/)514 2201 y(if)g(\(\(\(Plan)f(*\))h +(node\)->lefttree->chgParam)d(==)i(NULL\))574 2261 y +(ExecReScan\(\(\(Plan)f(*\))i(node\)->lefttree,)903 2321 +y(exprCtxt,)f(\(Plan)g(*\))g(node\);)454 2381 y(})270 +2614 y Fn(Parser)270 2742 y Ft(The)12 b Fp(parser)g Ft(de\002ned)f(in)g +(the)g(\002le)g Fk(:)d(:)g(:)p Fr(/src/backend/parser/gram.y)g +Ft(had)j(to)h(be)f(modi\002ed)270 2801 y(in)h(two)g(ways:)345 +2956 y Fo(\017)25 b Ft(The)17 b(grammar)f(had)g(to)h(be)g(adapted)g(to) +f(support)h(the)g(usage)g(of)f(parenthesis)h(\(to)f(be)h(able)g(to)395 +3016 y(specify)12 b(the)g(order)g(of)g(e)o(x)o(ecution)g(of)g(the)h +(set)f(operators\).)345 3188 y Fo(\017)25 b Ft(The)10 +b(code)f(b)o(uilding)g(up)h(the)f(data)h(structures)f(handed)h(back)g +(by)f(the)h Fp(parser)g Ft(had)g(to)f(be)h(inserted.)270 +3342 y(Here)h(is)h(a)f(part)g(of)f(the)i(grammar)e(which)h(is)g +(responsible)g(for)g Fr(select)f Ft(statements)i(ha)o(ving)f(the)g +(code)270 3402 y(b)o(uilding)h(up)g(the)g(data)h(structures)f +(inserted:)p eop +%%Page: 99 99 +99 98 bop 198 60 a Fm(3.8.)29 b(THE)13 b(REALIZA)-6 b(TION)14 +b(OF)e(UNION,)g(INTERSECT)i(AND)f(EXCEPT)349 b Ft(99)258 +234 y Fr(SelectStmt)29 b(:)59 b(select_w_o_sort)28 b(sort_clause)377 +294 y({)1035 354 y(.)1035 413 y(.)1035 473 y(.)467 533 +y(/*)i($1)f(holds)h(the)f(tree)h(built)f(up)h(by)f(the)497 +593 y(*)h(rule)f('select_w_o_sort')497 653 y(*/)467 712 +y(Node)g(*op)h(=)g(\(Node)f(*\))h($1;)467 832 y(if)g(IsA\($1,)f +(SelectStmt\))467 892 y({)527 951 y(SelectStmt)g(*n)g(=)h(\(SelectStmt) +f(*\)$1;)527 1011 y(n->sortClause)f(=)i($2;)527 1071 +y($$)f(=)h(\(Node)g(*\)n;)467 1131 y(})467 1191 y(else)467 +1250 y({)527 1310 y(/*)f(Create)h(a)f("flat)h(list")f(of)h(the)f +(operator)557 1370 y(*)g(tree)h(built)f(up)h(by)g('select_w_o_sort')e +(and)557 1430 y(*)h(let)h(select_list)f(point)g(to)h(it)557 +1489 y(*/)527 1549 y(create_select_list\(\(Node)d(*\)op,)1095 +1609 y(&select_list,)1095 1669 y(&unionall_present\);)527 +1729 y(/*)i(Replace)h(all)f(the)h(A_Expr)f(nodes)g(in)h(the)557 +1788 y(*)f(operator)g(tree)h(by)g(Expr)f(nodes.)557 1848 +y(*/)557 1908 y(op)g(=)h(A_Expr_to_Expr\(op,)e(&intersect_present\);) +1035 1968 y(.)1035 2027 y(.)1035 2087 y(.)557 2147 y(/*)h(Get)h(the)f +(leftmost)g(SelectStmt)g(node)h(\(which)587 2207 y(*)f(automatically)g +(represents)g(the)g(first)g(Select)587 2267 y(*)g(Statement)g(of)h(the) +f(query!\))h(*/)557 2326 y(first_select)e(=)766 2386 +y(\(SelectStmt)h(*\)lfirst\(select_list\);)557 2446 y(/*)g(Attach)h +(the)f(list)h(of)f(all)h(SelectStmt)f(nodes)587 2506 +y(*)g(to)h(unionClause)587 2565 y(*/)557 2625 y +(first_select->unionClause)d(=)j(select_list;)557 2745 +y(/*)f(Attach)h(the)f(whole)g(operator)g(tree)h(to)587 +2804 y(*)f(intersectClause)g(*/)557 2864 y +(first_select->intersectClause)d(=)1423 2924 y(\(List)k(*\))f(op;)557 +2984 y(/*)g(finally)g(attach)h(the)f(sort)h(clause)f(*/)557 +3044 y(first_select->sortClause)e(=)j($2;)557 3163 y(/*)f(Now)h(hand)f +(it)h(back!)f(*/)557 3223 y($$)g(=)h(\(Node)f(*\)first_select;)497 +3283 y(})377 3342 y(})258 3402 y(;)p eop +%%Page: 100 100 +100 99 bop 270 60 a Ft(100)57 b Fm(CHAPTER)14 b(3.)28 +b(POSTGRESQL)13 b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW) +330 234 y Fr(select_w_o_sort)28 b(:)60 b('\(')29 b(select_w_o_sort)f +('\)')449 294 y({)509 354 y($$)i(=)g($2;)449 413 y(})330 +473 y(|)59 b(SubSelect)449 533 y({)509 593 y($$)30 b(=)g($1;)449 +653 y(})330 712 y(|)59 b(select_w_o_sort)29 b(EXCEPT)g(select_w_o_sort) +449 772 y({)509 832 y($$)h(=)g(\(Node)f(*\)makeA_Expr\(AND,NULL,$1,) +1017 892 y(makeA_Expr\(NOT,NULL,NULL,$3\)\);)449 951 +y(})330 1011 y(|)59 b(select_w_o_sort)29 b(UNION)g(opt_union)g +(select_w_o_sort)449 1071 y({)509 1131 y(if)h(\(IsA\($4,)f +(SelectStmt\)\))509 1191 y({)569 1250 y(SelectStmt)g(*n)g(=)h +(\(SelectStmt)f(*\)$4;)569 1310 y(n->unionall)g(=)g($3;)509 +1370 y(})509 1430 y($$)h(=)g(\(Node)f(*\)makeA_Expr\(OR,NULL,$1,$4\);) +449 1489 y(})330 1549 y(|)59 b(select_w_o_sort)29 b(INTERSECT)g +(select_w_o_sort)449 1609 y({)509 1669 y($$)h(=)g(\(Node)f +(*\)makeA_Expr\(AND,NULL,$1,$3\);)449 1729 y(})330 1788 +y(;)330 1896 y(SubSelect)g(:)59 b(SELECT)30 b(opt_unique)e +(res_target_list2)718 1956 y(result)i(from_clause)e(where_clause)718 +2016 y(group_clause)h(having_clause)390 2076 y({)449 +2135 y(SelectStmt)g(*n)h(=)g(makeNode\(SelectStmt\);)449 +2195 y(n->unique)f(=)h($2;)688 2255 y(.)688 2315 y(.)688 +2375 y(.)449 2434 y(n->havingClause)f(=)g($8;)449 2494 +y($$)h(=)g(\(Node)f(*\)n;)390 2554 y(})330 2614 y(;)270 +2722 y Ft(The)e(ke)o(ywords)f Fr(SELECT)p Ft(,)h Fr(EXCEPT)p +Ft(,)g Fr(UNION)p Ft(,)g Fr(INTERSECT)p Ft(,)f Fr('\(')h +Ft(and)g Fr('\)')f Ft(are)h Fp(termi-)270 2782 y(nal)f(symbols)h +Ft(and)f Fr(SelectStmt)p Ft(,)k Fr(select)p 1170 2782 +15 2 v 17 w(w)p 1217 2782 V 18 w(o)p 1265 2782 V 17 w(sort)p +Ft(,)g Fr(sort)p 1564 2782 V 18 w(clause)p Ft(,)g Fr(opt)p +1894 2782 V 17 w(union)p Ft(,)270 2841 y Fr(SubSelect)p +Ft(,)57 b Fr(opt)p 702 2841 V 18 w(unique)p Ft(,)h Fr(res)p +1060 2841 V 17 w(target)p 1257 2841 V 17 w(list2)p Ft(,)g +Fr(result)p Ft(,)g Fr(from)p 1864 2841 V 17 w(clause)p +Ft(,)270 2901 y Fr(where)p 423 2901 V 17 w(clause)p Ft(,)23 +b Fr(group)p 805 2901 V 18 w(clause)p Ft(,)g Fr(having)p +1218 2901 V 17 w(clause)d Ft(are)h Fp(nonterminal)g(symbols)p +Ft(.)42 b(The)270 2961 y(symbols)13 b Fr(EXCEPT)p Ft(,)h +Fr(UNION)e Ft(and)i Fr(INTERSECT)e Ft(are)h Fp(left)g(associative)h +Ft(meaning)f(that)g(a)g(statement)270 3021 y(like:)330 +3119 y Fr(select)29 b(*)h(from)f(A)330 3179 y(union)330 +3239 y(select)g(*)h(from)f(B)330 3298 y(union)330 3358 +y(select)g(*)h(from)f(C;)p eop +%%Page: 101 101 +101 100 bop 198 60 a Fm(3.8.)29 b(THE)13 b(REALIZA)-6 +b(TION)14 b(OF)e(UNION,)g(INTERSECT)i(AND)f(EXCEPT)324 +b Ft(101)198 234 y(will)12 b(be)g(treated)g(as:)258 343 +y Fr(\(\(select)29 b(*)h(from)f(A)318 403 y(union)318 +463 y(select)g(*)h(from)f(B\))318 523 y(union)318 583 +y(select)g(*)h(from)f(C\))198 689 y Ft(The)13 b Fr(select)p +471 689 15 2 v 17 w(w)p 518 689 V 18 w(o)p 566 689 V +18 w(sort)f Ft(rule)g(b)o(uilds)g(up)h(an)f Fp(oper)o(ator)h(tr)n(ee)g +Ft(using)g(nodes)g(of)f(type)g Fr(A)p 1767 689 V 18 w(Expr)p +Ft(.)k(F)o(or)198 749 y(e)o(v)o(ery)f Fp(union)g Ft(an)h +Fr(OR)f Ft(node)g(is)h(created,)g(for)f(e)o(v)o(ery)g +Fp(intersect)h Ft(an)f Fr(AND)g Ft(node)h(and)f(for)g(e)o(v)o(ery)g +Fp(e)o(xcept)198 809 y Ft(and)d Fr(AND)30 b(NOT)12 b +Ft(node)g(b)o(uilding)f(up)h(a)g(representation)f(of)h(a)g(formula)f +(in)h(propositional)f(logic.)16 b(If)11 b(the)198 869 +y(query)h(parsed)h(did)g(not)g(contain)f(an)o(y)i(set)f(operations)g +(the)f(rule)h(hands)g(back)g(a)g Fr(SelectStmt)f Ft(node)198 +929 y(representing)g(the)h(query)f(otherwise)h(the)f(top)h(node)g(of)f +(the)h Fp(oper)o(ator)g(tr)n(ee)h Ft(is)f(returned.)j(Figure)c(3.11)198 +988 y(sho)o(ws)h(a)f(typical)g Fp(oper)o(ator)h(tr)n(ee)g +Ft(returned)f(by)g(the)g Fr(select)p 1287 988 V 18 w(w)p +1335 988 V 18 w(o)p 1383 988 V 17 w(sort)g Ft(rule.)388 +2579 y @beginspecial 145 @llx 244 @lly 467 @urx 547 @ury +3220 @rwi @setspecial +%%BeginDocument: figures/union_intersect_select_w_o_sort.ps +%Magnification: 1.05 +/$F2psDict 200 dict def +$F2psDict begin +$F2psDict /mtrx matrix put +/col-1 {0 setgray} bind def +/col0 {0.000 0.000 0.000 srgb} bind def +/col1 {0.000 0.000 1.000 srgb} bind def +/col2 {0.000 1.000 0.000 srgb} bind def +/col3 {0.000 1.000 1.000 srgb} bind def +/col4 {1.000 0.000 0.000 srgb} bind def +/col5 {1.000 0.000 1.000 srgb} bind def +/col6 {1.000 1.000 0.000 srgb} bind def +/col7 {1.000 1.000 1.000 srgb} bind def +/col8 {0.000 0.000 0.560 srgb} bind def +/col9 {0.000 0.000 0.690 srgb} bind def +/col10 {0.000 0.000 0.820 srgb} bind def +/col11 {0.530 0.810 1.000 srgb} bind def +/col12 {0.000 0.560 0.000 srgb} bind def +/col13 {0.000 0.690 0.000 srgb} bind def +/col14 {0.000 0.820 0.000 srgb} bind def +/col15 {0.000 0.560 0.560 srgb} bind def +/col16 {0.000 0.690 0.690 srgb} bind def +/col17 {0.000 0.820 0.820 srgb} bind def +/col18 {0.560 0.000 0.000 srgb} bind def +/col19 {0.690 0.000 0.000 srgb} bind def +/col20 {0.820 0.000 0.000 srgb} bind def +/col21 {0.560 0.000 0.560 srgb} bind def +/col22 {0.690 0.000 0.690 srgb} bind def +/col23 {0.820 0.000 0.820 srgb} bind def +/col24 {0.500 0.190 0.000 srgb} bind def +/col25 {0.630 0.250 0.000 srgb} bind def +/col26 {0.750 0.380 0.000 srgb} bind def +/col27 {1.000 0.500 0.500 srgb} bind def +/col28 {1.000 0.630 0.630 srgb} bind def +/col29 {1.000 0.750 0.750 srgb} bind def +/col30 {1.000 0.880 0.880 srgb} bind def +/col31 {1.000 0.840 0.000 srgb} bind def + +end +save +143.0 574.5 translate +1 -1 scale + +/cp {closepath} bind def +/ef {eofill} bind def +/gr {grestore} bind def +/gs {gsave} bind def +/sa {save} bind def +/rs {restore} bind def +/l {lineto} bind def +/m {moveto} bind def +/rm {rmoveto} bind def +/n {newpath} bind def +/s {stroke} bind def +/sh {show} bind def +/slc {setlinecap} bind def +/slj {setlinejoin} bind def +/slw {setlinewidth} bind def +/srgb {setrgbcolor} bind def +/rot {rotate} bind def +/sc {scale} bind def +/sd {setdash} bind def +/ff {findfont} bind def +/sf {setfont} bind def +/scf {scalefont} bind def +/sw {stringwidth} bind def +/tr {translate} bind def +/tnt {dup dup currentrgbcolor + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add srgb} + bind def +/shd {dup dup currentrgbcolor 4 -2 roll mul 4 -2 roll mul + 4 -2 roll mul srgb} bind def +/$F2psBegin {$F2psDict begin /$F2psEnteredState save def} def +/$F2psEnd {$F2psEnteredState restore end} def + +$F2psBegin +10 setmiterlimit +n 0 792 m 0 0 l 612 0 l 612 792 l cp clip + 0.06299 0.06299 sc +7.500 slw +% Polyline +n 990 1575 m 1890 1575 l 1890 2295 l 990 2295 l cp gs col-1 s gr +% Polyline +n 990 2025 m 1890 2025 l gs col-1 s gr +% Polyline +n 1440 2025 m 1440 2295 l gs col-1 s gr +% Polyline +n 990 1800 m 1890 1800 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +1215 1755 m +gs 1 -1 sc (A_Expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1350 1980 m +gs 1 -1 sc (OR) col-1 sh gr +% Polyline +n 2025 450 m 2925 450 l 2925 1170 l 2025 1170 l cp gs col-1 s gr +% Polyline +n 2025 900 m 2925 900 l gs col-1 s gr +% Polyline +n 2475 900 m 2475 1170 l gs col-1 s gr +% Polyline +n 2025 675 m 2925 675 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +2250 630 m +gs 1 -1 sc (A_Expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2340 855 m +gs 1 -1 sc (AND) col-1 sh gr +% Polyline +n 3060 1575 m 3960 1575 l 3960 2295 l 3060 2295 l cp gs col-1 s gr +% Polyline +n 3060 2025 m 3960 2025 l gs col-1 s gr +% Polyline +n 3510 2025 m 3510 2295 l gs col-1 s gr +% Polyline +n 3060 1800 m 3960 1800 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +3285 1755 m +gs 1 -1 sc (A_Expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3375 1980 m +gs 1 -1 sc (NOT) col-1 sh gr +% Polyline +n 3060 2025 m 3510 2295 l gs col-1 s gr +% Polyline +n 3510 2025 m 3060 2295 l gs col-1 s gr +% Polyline +n 3285 2970 m 4185 2970 l 4185 3690 l 3285 3690 l cp gs col-1 s gr +% Polyline +n 3285 3420 m 4185 3420 l gs col-1 s gr +% Polyline +n 3735 3420 m 3735 3690 l gs col-1 s gr +% Polyline +n 3285 3195 m 4185 3195 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +3510 3150 m +gs 1 -1 sc (A_Expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3600 3375 m +gs 1 -1 sc (AND) col-1 sh gr +% Polyline +gs clippath +800 2617 m 694 2680 l 758 2575 l 643 2689 l 686 2732 l cp clip +n 1215 2160 m 675 2700 l gs col-1 s gr gr + +% arrowhead +n 800 2617 m 694 2680 l 758 2575 l 779 2596 l 800 2617 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +2122 2575 m 2185 2680 l 2080 2617 l 2194 2732 l 2237 2689 l cp clip +n 1665 2160 m 2205 2700 l gs col-1 s gr gr + +% arrowhead +n 2122 2575 m 2185 2680 l 2080 2617 l 2101 2596 l 2122 2575 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +1579 1518 m 1462 1560 l 1546 1468 l 1411 1558 l 1444 1608 l cp clip +n 2250 1035 m 1440 1575 l gs col-1 s gr gr + +% arrowhead +n 1579 1518 m 1462 1560 l 1546 1468 l 1562 1493 l 1579 1518 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +3411 1458 m 3494 1550 l 3378 1508 l 3513 1598 l 3546 1548 l cp clip +n 2707 1025 m 3517 1565 l gs col-1 s gr gr + +% arrowhead +n 3411 1458 m 3494 1550 l 3378 1508 l 3395 1483 l 3411 1458 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +3765 2823 m 3735 2943 l 3705 2823 l 3705 2985 l 3765 2985 l cp clip +n 3735 2160 m 3735 2970 l gs col-1 s gr gr + +% arrowhead +n 3765 2823 m 3735 2943 l 3705 2823 l 3735 2823 l 3765 2823 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +3095 4012 m 2989 4075 l 3053 3970 l 2938 4084 l 2981 4127 l cp clip +n 3510 3555 m 2970 4095 l gs col-1 s gr gr + +% arrowhead +n 3095 4012 m 2989 4075 l 3053 3970 l 3074 3991 l 3095 4012 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +4417 3970 m 4480 4075 l 4375 4012 l 4489 4127 l 4532 4084 l cp clip +n 3960 3555 m 4500 4095 l gs col-1 s gr gr + +% arrowhead +n 4417 3970 m 4480 4075 l 4375 4012 l 4396 3991 l 4417 3970 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 45 3555 m 1305 3555 l gs col-1 s gr +% Polyline +n 45 3285 m 1305 3285 l gs col-1 s gr +% Polyline +n 45 2700 m 1305 2700 l 1305 3825 l 45 3825 l cp gs col-1 s gr +% Polyline +n 1035 2925 m 1035 3825 l gs col-1 s gr +% Polyline +n 45 2925 m 1305 2925 l gs col-1 s gr +% Polyline +n 1035 3285 m 1305 3555 l gs col-1 s gr +% Polyline +n 1035 3555 m 1305 3285 l gs col-1 s gr +% Polyline +n 1305 3555 m 1035 3825 l gs col-1 s gr +% Polyline +n 1035 3555 m 1305 3825 l gs col-1 s gr +% Polyline +n 1575 3555 m 2835 3555 l gs col-1 s gr +% Polyline +n 1575 3285 m 2835 3285 l gs col-1 s gr +% Polyline +n 1575 2700 m 2835 2700 l 2835 3825 l 1575 3825 l cp gs col-1 s gr +% Polyline +n 2565 2925 m 2565 3825 l gs col-1 s gr +% Polyline +n 1575 2925 m 2835 2925 l gs col-1 s gr +% Polyline +n 2565 3285 m 2835 3555 l gs col-1 s gr +% Polyline +n 2565 3555 m 2835 3285 l gs col-1 s gr +% Polyline +n 2835 3555 m 2565 3825 l gs col-1 s gr +% Polyline +n 2565 3555 m 2835 3825 l gs col-1 s gr +% Polyline +n 2340 4950 m 3600 4950 l gs col-1 s gr +% Polyline +n 2340 4680 m 3600 4680 l gs col-1 s gr +% Polyline +n 2340 4095 m 3600 4095 l 3600 5220 l 2340 5220 l cp gs col-1 s gr +% Polyline +n 3330 4320 m 3330 5220 l gs col-1 s gr +% Polyline +n 2340 4320 m 3600 4320 l gs col-1 s gr +% Polyline +n 3330 4680 m 3600 4950 l gs col-1 s gr +% Polyline +n 3330 4950 m 3600 4680 l gs col-1 s gr +% Polyline +n 3600 4950 m 3330 5220 l gs col-1 s gr +% Polyline +n 3330 4950 m 3600 5220 l gs col-1 s gr +% Polyline +n 3870 4950 m 5130 4950 l gs col-1 s gr +% Polyline +n 3870 4680 m 5130 4680 l gs col-1 s gr +% Polyline +n 3870 4095 m 5130 4095 l 5130 5220 l 3870 5220 l cp gs col-1 s gr +% Polyline +n 4860 4320 m 4860 5220 l gs col-1 s gr +% Polyline +n 3870 4320 m 5130 4320 l gs col-1 s gr +% Polyline +n 4860 4680 m 5130 4950 l gs col-1 s gr +% Polyline +n 4860 4950 m 5130 4680 l gs col-1 s gr +% Polyline +n 5130 4950 m 4860 5220 l gs col-1 s gr +% Polyline +n 4860 4950 m 5130 5220 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +585 3150 m +gs 1 -1 sc 90.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +315 2880 m +gs 1 -1 sc (SeqScan \(A\)) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2115 3150 m +gs 1 -1 sc 90.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1845 2880 m +gs 1 -1 sc (SeqScan \(B\)) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2880 4545 m +gs 1 -1 sc 90.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2610 4275 m +gs 1 -1 sc (SeqScan \(C\)) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4410 4545 m +gs 1 -1 sc 90.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4140 4275 m +gs 1 -1 sc (SeqScan \(D\)) col-1 sh gr +/Times-Roman ff 150.00 scf sf +90 3465 m +gs 1 -1 sc (unionClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +90 3735 m +gs 1 -1 sc (intersectClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1620 3465 m +gs 1 -1 sc (unionClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1620 3735 m +gs 1 -1 sc (intersectClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2385 4860 m +gs 1 -1 sc (unionClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2385 5130 m +gs 1 -1 sc (intersectClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3915 4860 m +gs 1 -1 sc (unionClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3915 5130 m +gs 1 -1 sc (intersectClause) col-1 sh gr +showpage +$F2psEnd +rs +%%EndDocument + @endspecial 604 2688 a(Figure)g(3.11:)j Fp(Oper)o(ator)e(tr)n(ee)h +Ft(for)d Fl(\()p Fk(A)h Fo([)f Fk(B)r Fl(\))p Fo(n)p +Fl(\()p Fk(C)k Fo(\\)d Fk(D)q Fl(\))198 2864 y Ft(The)24 +b(rule)f Fr(SelectStmt)g Ft(transforms)f(the)i Fp(oper)o(ator)g(tr)n +(ee)g Ft(b)o(uilt)f(of)g Fr(A)p 1552 2864 V 18 w(Expr)g +Ft(nodes)h(into)f(an)198 2924 y Fp(oper)o(ator)d(tr)n(ee)g +Ft(using)g Fr(Expr)f Ft(nodes)g(by)g(a)h(call)f(to)h(the)f(function)f +Fr(A)p 1447 2924 V 18 w(Expr)p 1585 2924 V 18 w(to)p +1663 2924 V 17 w(Expr\(\))h Ft(which)198 2984 y(additionally)13 +b(replaces)h(e)o(v)o(ery)f Fr(OR)g Ft(node)h(by)f(an)h +Fr(AND)f Ft(node)h(and)f(vice)h(v)o(ersa.)20 b(This)14 +b(is)g(performed)e(in)198 3044 y(order)g(to)g(be)g(able)h(to)f(use)h +(the)f(function)g Fr(cnfify\(\))f Ft(later)h(on.)198 +3163 y(The)j Fp(tr)o(ansformations)g Ft(follo)o(wing)e(the)h +Fp(parser)h Ft(e)o(xpect)g(a)f Fr(SelectStmt)g Ft(node)g(to)g(be)h +(returned)e(by)198 3223 y(the)g(rule)f Fr(SelectStmt)f +Ft(and)i(not)f(an)h Fp(oper)o(ator)g(tr)n(ee)p Ft(.)18 +b(So)12 b(if)g(the)g(rule)h Fr(select)p 1640 3223 V 17 +w(w)p 1687 3223 V 18 w(o)p 1735 3223 V 18 w(sort)f Ft(hands)198 +3283 y(back)h(such)h(a)f(node)g(\(meaning)g(that)g(the)g(query)f(did)h +(not)g(contain)g(an)o(y)g(set)h(operations\))e(we)h(just)h(ha)o(v)o(e) +198 3342 y(to)f(attach)h(the)g(data)f(structure)g(b)o(uilt)g(up)h(by)f +(the)h Fr(sort)p 1171 3342 V 17 w(clause)f Ft(rule)g(and)h(are)g +(\002nished,)g(b)o(ut)f(when)198 3402 y(we)g(get)f(an)g +Fp(oper)o(ator)h(tr)n(ee)g Ft(we)g(ha)o(v)o(e)g(to)f(perform)f(the)h +(follo)o(wing)f(steps:)p eop +%%Page: 102 102 +102 101 bop 270 60 a Ft(102)57 b Fm(CHAPTER)14 b(3.)28 +b(POSTGRESQL)13 b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW) +345 234 y Fo(\017)25 b Ft(Create)17 b(a)h(\003at)f(list)g(of)g(all)h +Fr(SelectStmt)e Ft(nodes)i(of)f(the)g Fp(oper)o(ator)i(tr)n(ee)f +Ft(\(by)f(a)g(call)h(to)f(the)395 294 y(function)8 b +Fr(create)p 753 294 15 2 v 18 w(select)p 951 294 V 17 +w(list\(\))p Ft(\))h(and)h(attach)g(the)f(list)h(to)g(the)g(\002eld)f +Fr(unionClause)395 354 y Ft(of)i(the)i(leftmost)f Fr(SelectStmt)f +Ft(\(see)i(ne)o(xt)f(step\).)345 463 y Fo(\017)25 b Ft(Find)d(the)i +(leftmost)e(leaf)h(\()p Fr(SelectStmt)f Ft(node\))h(of)g(the)g +Fp(oper)o(ator)h(tr)n(ee)g Ft(\(this)f(is)h(auto-)395 +523 y(matically)h(the)h(\002rst)f(member)g(of)g(the)h(abo)o(v)o(e)g +(created)g(list)g(because)g(of)g(the)f(technique)395 +583 y Fr(create)p 578 583 V 17 w(select)p 775 583 V 17 +w(list\(\))12 b Ft(uses)h(to)f(create)h(the)f(list\).)345 +692 y Fo(\017)25 b Ft(Attach)e(the)g(whole)g Fp(oper)o(ator)h(tr)n(ee)g +Ft(\(including)e(the)i(leftmost)e(node)h(itself\))g(to)g(the)g(\002eld) +395 752 y Fr(intersectClause)10 b Ft(of)i(the)h(leftmost)e +Fr(SelectStmt)h Ft(node.)345 861 y Fo(\017)25 b Ft(Attach)32 +b(the)g(data)h(structure)f(b)o(uilt)g(up)g(by)h(the)f +Fr(sort)p 1480 861 V 18 w(clause)g Ft(rule)g(to)g(the)g(\002eld)395 +921 y Fr(sortClause)11 b Ft(of)h(the)g(leftmost)g Fr(SelectStmt)f +Ft(node.)345 1030 y Fo(\017)25 b Ft(Hand)16 b(back)g(the)g(leftmost)g +Fr(SelectStmt)f Ft(node)h(\(with)g(the)g Fp(oper)o(ator)h(tr)n(ee)p +Ft(,)h(the)e(list)g(of)g(all)395 1090 y Fr(SelectStmt)11 +b Ft(nodes)i(and)f(the)g Fr(sortClause)g Ft(attached)g(to)g(it\).)270 +1197 y(Figure)i(3.12)i(sho)o(ws)g(the)f(\002nal)g(data)g(structure)g +(deri)o(v)o(ed)f(from)g(the)i Fp(oper)o(ator)g(tr)n(ee)g +Ft(sho)o(wn)f(in)g(\002gure)270 1257 y(3.11)e(handed)f(back)g(by)h(the) +f Fr(SelectStmt)f Ft(rule:)465 3167 y @beginspecial 145 +@llx 212 @lly 466 @urx 579 @ury 3210 @rwi @setspecial +%%BeginDocument: figures/union_intersect_select.ps +%Magnification: 1.05 +/$F2psDict 200 dict def +$F2psDict begin +$F2psDict /mtrx matrix put +/col-1 {0 setgray} bind def +/col0 {0.000 0.000 0.000 srgb} bind def +/col1 {0.000 0.000 1.000 srgb} bind def +/col2 {0.000 1.000 0.000 srgb} bind def +/col3 {0.000 1.000 1.000 srgb} bind def +/col4 {1.000 0.000 0.000 srgb} bind def +/col5 {1.000 0.000 1.000 srgb} bind def +/col6 {1.000 1.000 0.000 srgb} bind def +/col7 {1.000 1.000 1.000 srgb} bind def +/col8 {0.000 0.000 0.560 srgb} bind def +/col9 {0.000 0.000 0.690 srgb} bind def +/col10 {0.000 0.000 0.820 srgb} bind def +/col11 {0.530 0.810 1.000 srgb} bind def +/col12 {0.000 0.560 0.000 srgb} bind def +/col13 {0.000 0.690 0.000 srgb} bind def +/col14 {0.000 0.820 0.000 srgb} bind def +/col15 {0.000 0.560 0.560 srgb} bind def +/col16 {0.000 0.690 0.690 srgb} bind def +/col17 {0.000 0.820 0.820 srgb} bind def +/col18 {0.560 0.000 0.000 srgb} bind def +/col19 {0.690 0.000 0.000 srgb} bind def +/col20 {0.820 0.000 0.000 srgb} bind def +/col21 {0.560 0.000 0.560 srgb} bind def +/col22 {0.690 0.000 0.690 srgb} bind def +/col23 {0.820 0.000 0.820 srgb} bind def +/col24 {0.500 0.190 0.000 srgb} bind def +/col25 {0.630 0.250 0.000 srgb} bind def +/col26 {0.750 0.380 0.000 srgb} bind def +/col27 {1.000 0.500 0.500 srgb} bind def +/col28 {1.000 0.630 0.630 srgb} bind def +/col29 {1.000 0.750 0.750 srgb} bind def +/col30 {1.000 0.880 0.880 srgb} bind def +/col31 {1.000 0.840 0.000 srgb} bind def + +end +save +132.5 582.5 translate +1 -1 scale + +/cp {closepath} bind def +/ef {eofill} bind def +/gr {grestore} bind def +/gs {gsave} bind def +/sa {save} bind def +/rs {restore} bind def +/l {lineto} bind def +/m {moveto} bind def +/rm {rmoveto} bind def +/n {newpath} bind def +/s {stroke} bind def +/sh {show} bind def +/slc {setlinecap} bind def +/slj {setlinejoin} bind def +/slw {setlinewidth} bind def +/srgb {setrgbcolor} bind def +/rot {rotate} bind def +/sc {scale} bind def +/sd {setdash} bind def +/ff {findfont} bind def +/sf {setfont} bind def +/scf {scalefont} bind def +/sw {stringwidth} bind def +/tr {translate} bind def +/tnt {dup dup currentrgbcolor + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add srgb} + bind def +/shd {dup dup currentrgbcolor 4 -2 roll mul 4 -2 roll mul + 4 -2 roll mul srgb} bind def + /DrawSplineSection { + /y3 exch def + /x3 exch def + /y2 exch def + /x2 exch def + /y1 exch def + /x1 exch def + /xa x1 x2 x1 sub 0.666667 mul add def + /ya y1 y2 y1 sub 0.666667 mul add def + /xb x3 x2 x3 sub 0.666667 mul add def + /yb y3 y2 y3 sub 0.666667 mul add def + x1 y1 lineto + xa ya xb yb x3 y3 curveto + } def + +/$F2psBegin {$F2psDict begin /$F2psEnteredState save def} def +/$F2psEnd {$F2psEnteredState restore end} def + +$F2psBegin +10 setmiterlimit +n 0 792 m 0 0 l 612 0 l 612 792 l cp clip + 0.06299 0.06299 sc +7.500 slw +% Polyline +n 1800 1350 m 2700 1350 l 2700 2070 l 1800 2070 l cp gs col-1 s gr +% Polyline +n 1800 1800 m 2700 1800 l gs col-1 s gr +% Polyline +n 1800 1575 m 2700 1575 l gs col-1 s gr +% Polyline +n 2430 1800 m 2430 2070 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +2160 1755 m +gs 1 -1 sc (OR) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2115 1530 m +gs 1 -1 sc (Expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1980 1980 m +gs 1 -1 sc (args) col-1 sh gr +% Polyline +n 225 2475 m 1125 2475 l 1125 3195 l 225 3195 l cp gs col-1 s gr +% Polyline +n 225 2925 m 1125 2925 l gs col-1 s gr +% Polyline +n 225 2700 m 1125 2700 l gs col-1 s gr +% Polyline +n 855 2925 m 855 3195 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +540 2880 m +gs 1 -1 sc (AND) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 2655 m +gs 1 -1 sc (Expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +360 3105 m +gs 1 -1 sc (args) col-1 sh gr +% Polyline +n 1350 2925 m 1890 2925 l 1890 3195 l 1350 3195 l cp gs col-1 s gr +% Polyline +n 1620 2925 m 1620 3195 l gs col-1 s gr +% Polyline +n 2115 2925 m 2655 2925 l 2655 3195 l 2115 3195 l cp gs col-1 s gr +% Polyline +n 2385 2925 m 2385 3195 l gs col-1 s gr +% Polyline +n 2385 2925 m 2655 3195 l gs col-1 s gr +% Polyline +n 2655 2925 m 2385 3195 l gs col-1 s gr +% Polyline +n 2925 1800 m 3465 1800 l 3465 2070 l 2925 2070 l cp gs col-1 s gr +% Polyline +n 3195 1800 m 3195 2070 l gs col-1 s gr +% Polyline +n 3690 1800 m 4230 1800 l 4230 2070 l 3690 2070 l cp gs col-1 s gr +% Polyline +n 3960 1800 m 3960 2070 l gs col-1 s gr +% Polyline +n 3960 1800 m 4230 2070 l gs col-1 s gr +% Polyline +n 4230 1800 m 3960 2070 l gs col-1 s gr +% Polyline +gs clippath +3543 1905 m 3663 1935 l 3543 1965 l 3705 1965 l 3705 1905 l cp clip +n 3330 1935 m 3690 1935 l gs col-1 s gr gr + +% arrowhead +n 3543 1905 m 3663 1935 l 3543 1965 l 3543 1935 l 3543 1905 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 1710 810 m 2250 810 l 2250 1080 l 1710 1080 l cp gs col-1 s gr +% Polyline +n 1980 810 m 1980 1080 l gs col-1 s gr +% Polyline +n 3240 810 m 3780 810 l 3780 1080 l 3240 1080 l cp gs col-1 s gr +% Polyline +n 3510 810 m 3510 1080 l gs col-1 s gr +% Polyline +n 4005 810 m 4545 810 l 4545 1080 l 4005 1080 l cp gs col-1 s gr +% Polyline +n 4275 810 m 4275 1080 l gs col-1 s gr +% Polyline +n 4275 810 m 4545 1080 l gs col-1 s gr +% Polyline +n 4545 810 m 4275 1080 l gs col-1 s gr +% Polyline +n 2475 810 m 3015 810 l 3015 1080 l 2475 1080 l cp gs col-1 s gr +% Polyline +n 2745 810 m 2745 1080 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +2340 420 m +gs 1 -1 sc (SelectStmt \(B\)) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2430 225 m +gs 1 -1 sc (Pointer to) col-1 sh gr +% Polyline +n 2925 2475 m 3825 2475 l 3825 3195 l 2925 3195 l cp gs col-1 s gr +% Polyline +n 2925 2925 m 3825 2925 l gs col-1 s gr +% Polyline +n 2925 2700 m 3825 2700 l gs col-1 s gr +% Polyline +n 3555 2925 m 3555 3195 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +3240 2880 m +gs 1 -1 sc (NOT) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3240 2655 m +gs 1 -1 sc (Expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3105 3105 m +gs 1 -1 sc (args) col-1 sh gr +% Polyline +n 4050 2925 m 4590 2925 l 4590 3195 l 4050 3195 l cp gs col-1 s gr +% Polyline +n 4320 2925 m 4320 3195 l gs col-1 s gr +% Polyline +n 4320 2925 m 4590 3195 l gs col-1 s gr +% Polyline +n 4590 2925 m 4320 3195 l gs col-1 s gr +% Polyline +n 2340 3600 m 3240 3600 l 3240 4320 l 2340 4320 l cp gs col-1 s gr +% Polyline +n 2340 4050 m 3240 4050 l gs col-1 s gr +% Polyline +n 2340 3825 m 3240 3825 l gs col-1 s gr +% Polyline +n 2970 4050 m 2970 4320 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +2700 4005 m +gs 1 -1 sc (OR) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2655 3780 m +gs 1 -1 sc (Expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2520 4230 m +gs 1 -1 sc (args) col-1 sh gr +% Polyline +n 3465 4050 m 4005 4050 l 4005 4320 l 3465 4320 l cp gs col-1 s gr +% Polyline +n 3735 4050 m 3735 4320 l gs col-1 s gr +% Polyline +n 4230 4050 m 4770 4050 l 4770 4320 l 4230 4320 l cp gs col-1 s gr +% Polyline +n 4500 4050 m 4500 4320 l gs col-1 s gr +% Polyline +n 4500 4050 m 4770 4320 l gs col-1 s gr +% Polyline +n 4770 4050 m 4500 4320 l gs col-1 s gr +% Polyline +gs clippath +3318 4155 m 3438 4185 l 3318 4215 l 3480 4215 l 3480 4155 l cp clip +n 3105 4185 m 3465 4185 l gs col-1 s gr gr + +% arrowhead +n 3318 4155 m 3438 4185 l 3318 4215 l 3318 4185 l 3318 4155 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +4083 4155 m 4203 4185 l 4083 4215 l 4245 4215 l 4245 4155 l cp clip +n 3870 4185 m 4230 4185 l gs col-1 s gr gr + +% arrowhead +n 4083 4155 m 4203 4185 l 4083 4215 l 4083 4185 l 4083 4155 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +1203 3030 m 1323 3060 l 1203 3090 l 1365 3090 l 1365 3030 l cp clip +n 990 3060 m 1350 3060 l gs col-1 s gr gr + +% arrowhead +n 1203 3030 m 1323 3060 l 1203 3090 l 1203 3060 l 1203 3030 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +2778 1905 m 2898 1935 l 2778 1965 l 2940 1965 l 2940 1905 l cp clip +n 2565 1935 m 2925 1935 l gs col-1 s gr gr + +% arrowhead +n 2778 1905 m 2898 1935 l 2778 1965 l 2778 1935 l 2778 1905 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +1968 3030 m 2088 3060 l 1968 3090 l 2130 3090 l 2130 3030 l cp clip +n 1755 3060 m 2115 3060 l gs col-1 s gr gr + +% arrowhead +n 1968 3030 m 2088 3060 l 1968 3090 l 1968 3060 l 1968 3030 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +2328 915 m 2448 945 l 2328 975 l 2490 975 l 2490 915 l cp clip +n 2115 945 m 2475 945 l gs col-1 s gr gr + +% arrowhead +n 2328 915 m 2448 945 l 2328 975 l 2328 945 l 2328 915 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +3858 915 m 3978 945 l 3858 975 l 4020 975 l 4020 915 l cp clip +n 3645 945 m 4005 945 l gs col-1 s gr gr + +% arrowhead +n 3858 915 m 3978 945 l 3858 975 l 3858 945 l 3858 915 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +3093 915 m 3213 945 l 3093 975 l 3255 975 l 3255 915 l cp clip +n 2880 945 m 3240 945 l gs col-1 s gr gr + +% arrowhead +n 3093 915 m 3213 945 l 3093 975 l 3093 945 l 3093 915 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +1563 915 m 1683 945 l 1563 975 l 1725 975 l 1725 915 l cp clip +n 1350 945 m 1710 945 l gs col-1 s gr gr + +% arrowhead +n 1563 915 m 1683 945 l 1563 975 l 1563 945 l 1563 915 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +3903 3030 m 4023 3060 l 3903 3090 l 4065 3090 l 4065 3030 l cp clip +n 3690 3060 m 4050 3060 l gs col-1 s gr gr + +% arrowhead +n 3903 3030 m 4023 3060 l 3903 3090 l 3903 3060 l 3903 3030 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 225 4455 m 1485 4455 l gs col-1 s gr +% Polyline +n 225 4185 m 1485 4185 l gs col-1 s gr +% Polyline +n 225 3600 m 1485 3600 l 1485 4725 l 225 4725 l cp gs col-1 s gr +% Polyline +n 1215 3825 m 1215 4725 l gs col-1 s gr +% Polyline +n 225 3825 m 1485 3825 l gs col-1 s gr +% Polyline +n 1215 4185 m 1485 4455 l gs col-1 s gr +% Polyline +n 1215 4455 m 1485 4185 l gs col-1 s gr +% Polyline +n 1215 4455 m 1485 4725 l gs col-1 s gr +% Polyline +n 1485 4455 m 1215 4725 l gs col-1 s gr +% Polyline +n 2025 5580 m 3285 5580 l gs col-1 s gr +% Polyline +n 2025 5310 m 3285 5310 l gs col-1 s gr +% Polyline +n 2025 4725 m 3285 4725 l 3285 5850 l 2025 5850 l cp gs col-1 s gr +% Polyline +n 3015 4950 m 3015 5850 l gs col-1 s gr +% Polyline +n 2025 4950 m 3285 4950 l gs col-1 s gr +% Polyline +n 3015 5310 m 3285 5580 l gs col-1 s gr +% Polyline +n 3015 5580 m 3285 5310 l gs col-1 s gr +% Polyline +n 3015 5580 m 3285 5850 l gs col-1 s gr +% Polyline +n 3285 5580 m 3015 5850 l gs col-1 s gr +% Polyline +n 3825 5580 m 5085 5580 l gs col-1 s gr +% Polyline +n 3825 5310 m 5085 5310 l gs col-1 s gr +% Polyline +n 3825 4725 m 5085 4725 l 5085 5850 l 3825 5850 l cp gs col-1 s gr +% Polyline +n 4815 4950 m 4815 5850 l gs col-1 s gr +% Polyline +n 3825 4950 m 5085 4950 l gs col-1 s gr +% Polyline +n 4815 5310 m 5085 5580 l gs col-1 s gr +% Polyline +n 4815 5580 m 5085 5310 l gs col-1 s gr +% Polyline +n 4815 5580 m 5085 5850 l gs col-1 s gr +% Polyline +n 5085 5580 m 4815 5850 l gs col-1 s gr +% Polyline +n 225 1080 m 1485 1080 l gs col-1 s gr +% Polyline +n 225 810 m 1485 810 l gs col-1 s gr +% Polyline +n 225 225 m 1485 225 l 1485 1350 l 225 1350 l cp gs col-1 s gr +% Polyline +n 1215 450 m 1215 1350 l gs col-1 s gr +% Polyline +n 225 450 m 1485 450 l gs col-1 s gr +% Open spline +gs clippath +2150 1238 m 2228 1333 l 2114 1286 l 2244 1383 l 2280 1335 l cp clip +n 1350.0 1215.0 m 1710.0 1215.0 l + 1710.0 1215.0 2070.0 1215.0 2160.0 1282.5 DrawSplineSection + 2250.0 1350.0 l gs col-1 s gr + gr + +% arrowhead +n 2150 1238 m 2228 1333 l 2114 1286 l 2132 1262 l 2150 1238 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +996 3548 m 877 3585 l 964 3497 l 826 3583 l 858 3633 l cp clip +n 2250.0 3060.0 m 2205.0 3195.0 l + 2205.0 3195.0 2160.0 3330.0 1687.5 3352.5 DrawSplineSection + 1687.5 3352.5 1215.0 3375.0 1035.0 3487.5 DrawSplineSection + 855.0 3600.0 l gs col-1 s gr + gr + +% arrowhead +n 996 3548 m 877 3585 l 964 3497 l 980 3522 l 996 3548 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +840 1499 m 857 1376 l 899 1493 l 883 1332 l 824 1338 l cp clip +n 1485.0 3060.0 m 1462.5 2722.5 l + 1462.5 2722.5 1440.0 2385.0 1170.0 2092.5 DrawSplineSection + 1170.0 2092.5 900.0 1800.0 877.5 1575.0 DrawSplineSection + 855.0 1350.0 l gs col-1 s gr + gr + +% arrowhead +n 840 1499 m 857 1376 l 899 1493 l 870 1496 l 840 1499 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +807 2404 m 695 2457 l 769 2358 l 644 2462 l 683 2508 l cp clip +n 3060.0 1935.0 m 3037.5 2070.0 l + 3037.5 2070.0 3015.0 2205.0 1980.0 2227.5 DrawSplineSection + 1980.0 2227.5 945.0 2250.0 810.0 2362.5 DrawSplineSection + 675.0 2475.0 l gs col-1 s gr + gr + +% arrowhead +n 807 2404 m 695 2457 l 769 2358 l 788 2381 l 807 2404 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3487 2375 m 3391 2453 l 3439 2339 l 3342 2469 l 3390 2505 l cp clip +n 3825.0 1935.0 m 3802.5 2070.0 l + 3802.5 2070.0 3780.0 2205.0 3645.0 2250.0 DrawSplineSection + 3645.0 2250.0 3510.0 2295.0 3442.5 2385.0 DrawSplineSection + 3375.0 2475.0 l gs col-1 s gr + gr + +% arrowhead +n 3487 2375 m 3391 2453 l 3439 2339 l 3463 2357 l 3487 2375 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +989 157 m 876 208 l 951 110 l 825 211 l 862 258 l cp clip +n 1845.0 945.0 m 1845.0 630.0 l + 1845.0 630.0 1845.0 315.0 1755.0 202.5 DrawSplineSection + 1755.0 202.5 1665.0 90.0 1372.5 67.5 DrawSplineSection + 1372.5 67.5 1080.0 45.0 967.5 135.0 DrawSplineSection + 855.0 225.0 l gs col-1 s gr + gr + +% arrowhead +n 989 157 m 876 208 l 951 110 l 970 133 l 989 157 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +2644 606 m 2731 518 l 2695 636 l 2778 498 l 2727 467 l cp clip +n 2610.0 945.0 m 2610.0 832.5 l + 2610.0 832.5 2610.0 720.0 2677.5 607.5 DrawSplineSection + 2745.0 495.0 l gs col-1 s gr + gr + +% arrowhead +n 2644 606 m 2731 518 l 2695 636 l 2669 621 l 2644 606 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3511 563 m 3623 511 l 3549 610 l 3675 509 l 3638 462 l cp clip +n 3375.0 945.0 m 3397.5 810.0 l + 3397.5 810.0 3420.0 675.0 3532.5 585.0 DrawSplineSection + 3645.0 495.0 l gs col-1 s gr + gr + +% arrowhead +n 3511 563 m 3623 511 l 3549 610 l 3530 587 l 3511 563 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +4488 527 m 4610 505 l 4513 582 l 4661 516 l 4637 461 l cp clip +n 4140.0 945.0 m 4185.0 810.0 l + 4185.0 810.0 4230.0 675.0 4432.5 585.0 DrawSplineSection + 4635.0 495.0 l gs col-1 s gr + gr + +% arrowhead +n 4488 527 m 4610 505 l 4513 582 l 4501 555 l 4488 527 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +2927 3539 m 2811 3584 l 2892 3490 l 2760 3584 l 2795 3633 l cp clip +n 4185.0 3060.0 m 4162.5 3195.0 l + 4162.5 3195.0 4140.0 3330.0 3622.5 3352.5 DrawSplineSection + 3622.5 3352.5 3105.0 3375.0 2947.5 3487.5 DrawSplineSection + 2790.0 3600.0 l gs col-1 s gr + gr + +% arrowhead +n 2927 3539 m 2811 3584 l 2892 3490 l 2910 3515 l 2927 3539 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +2780 4642 m 2674 4705 l 2738 4600 l 2623 4714 l 2666 4757 l cp clip +n 3600.0 4185.0 m 3555.0 4297.5 l + 3555.0 4297.5 3510.0 4410.0 3195.0 4455.0 DrawSplineSection + 3195.0 4455.0 2880.0 4500.0 2767.5 4612.5 DrawSplineSection + 2655.0 4725.0 l gs col-1 s gr + gr + +% arrowhead +n 2780 4642 m 2674 4705 l 2738 4600 l 2759 4621 l 2780 4642 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +4437 4576 m 4446 4699 l 4380 4595 l 4431 4749 l 4488 4730 l cp clip +n 4365.0 4185.0 m 4365.0 4320.0 l + 4365.0 4320.0 4365.0 4455.0 4410.0 4590.0 DrawSplineSection + 4455.0 4725.0 l gs col-1 s gr + gr + +% arrowhead +n 4437 4576 m 4446 4699 l 4380 4595 l 4409 4586 l 4437 4576 l cp gs 0.00 setgray ef gr col-1 s +/Times-Roman ff 150.00 scf sf +3330 420 m +gs 1 -1 sc (SelectStmt \(C\)) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3420 225 m +gs 1 -1 sc (Pointer to) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4320 420 m +gs 1 -1 sc (SelectStmt \(D\)) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4410 225 m +gs 1 -1 sc (Pointer to) col-1 sh gr +/Times-Roman ff 150.00 scf sf +765 4050 m +gs 1 -1 sc 90.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +405 3780 m +gs 1 -1 sc (SelectStmt \(B\)) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2565 5175 m +gs 1 -1 sc 90.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2205 4905 m +gs 1 -1 sc (SelectStmt \(C\)) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4365 5175 m +gs 1 -1 sc 90.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +4005 4905 m +gs 1 -1 sc (SelectStmt \(D\)) col-1 sh gr +/Times-Roman ff 150.00 scf sf +765 675 m +gs 1 -1 sc 90.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +405 405 m +gs 1 -1 sc (SelectStmt \(A\)) col-1 sh gr +/Times-Roman ff 150.00 scf sf +270 990 m +gs 1 -1 sc (unionClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +270 1260 m +gs 1 -1 sc (intersectClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +270 4365 m +gs 1 -1 sc (unionClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +270 4635 m +gs 1 -1 sc (intersectClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2070 5490 m +gs 1 -1 sc (unionClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2070 5760 m +gs 1 -1 sc (intersectClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3870 5490 m +gs 1 -1 sc (unionClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3870 5760 m +gs 1 -1 sc (intersectClause) col-1 sh gr +showpage +$F2psEnd +rs +%%EndDocument + @endspecial 537 3277 a(Figure)g(3.12:)16 b(Data)c(structure)g(handed)g +(back)h(by)f Fr(SelectStmt)g Ft(rule)p eop +%%Page: 103 103 +103 102 bop 198 60 a Fm(3.8.)26 b(THE)13 b(REALIZA)-6 +b(TION)14 b(OF)e(UNION,)g(INTERSECT)i(AND)f(EXCEPT)327 +b Ft(103)198 234 y(Here)26 b(is)g(a)g(description)g(of)f(the)h(abo)o(v) +o(e)g(used)h(functions.)56 b(The)o(y)26 b(can)g(be)g(found)g(in)f(the)h +(\002le)198 294 y Fk(:)8 b(:)g(:)p Fr(/src/backend/parser/anlayze.c)p +Ft(.)273 398 y Fo(\017)25 b Fr(create)p 506 398 15 2 +v 17 w(select)p 703 398 V 17 w(list\(\))p Ft(:)323 457 +y(This)15 b(function)f(steps)i(through)e(the)h Fp(tr)n(ee)g +Ft(handed)g(to)g(it)f(by)h(the)g(parameter)f Fr(ptr)h +Ft(and)g(creates)323 517 y(a)h(list)g(of)g(all)g Fr(SelectStmt)f +Ft(nodes)h(found.)27 b(The)17 b(list)f(is)g(handed)g(back)h(by)f(the)g +(parameter)323 577 y Fr(select)p 506 577 V 17 w(list)p +Ft(.)f(The)e(function)f(uses)h(a)g(recursi)o(v)o(e)f +Fp(depth)g(\002rst)g(sear)n(c)o(h)i Ft(algorithm)d(to)h(e)o(xam-)323 +637 y(ine)g(the)g Fp(tr)n(ee)h Ft(leading)g(to)f(the)g(fact)g(that)g +(the)h(leftmost)e Fr(SelectStmt)h Ft(node)g(will)g(appear)g(\002rst)323 +696 y(in)g(the)g(created)g(list.)382 821 y Fr(void)382 +881 y(create_select_list\(Node)28 b(*ptr,)h(List)g(**select_list,)950 +941 y(bool)h(*unionall_present\))382 1001 y({)442 1060 +y(if\(IsA\(ptr,)f(SelectStmt\)\))442 1120 y({)502 1180 +y(*select_list)f(=)i(lappend\(*select_list,)e(ptr\);)502 +1240 y(if\(\(\(SelectStmt)g(*\)ptr\)->unionall)g(==)i(TRUE\))562 +1299 y(*unionall_present)e(=)h(TRUE;)502 1359 y(return;)442 +1419 y(})442 1539 y(/*)h(Recursively)e(call)i(for)f(all)h(arguments.) +472 1598 y(*)g(A)g(NOT)f(expr)h(has)f(no)h(lexpr!)472 +1658 y(*/)442 1718 y(if)g(\(\(\(A_Expr)f(*\)ptr\)->lexpr)f(!=)i(NULL\)) +502 1778 y(create_select_list\(\(\(A_Expr)d(*\)ptr\)->lexpr,)1010 +1837 y(select_list,)h(unionall_present\);)442 1897 y +(create_select_list\(\(\(A_Expr)f(*\)ptr\)->rexpr,)1010 +1957 y(select_list,)h(unionall_present\);)323 2017 y(})273 +2142 y Fo(\017)d Fr(A)p 356 2142 V 17 w(Expr)p 493 2142 +V 18 w(to)p 571 2142 V 18 w(Expr\(\))p Ft(:)323 2201 +y(This)14 b(function)e(recursi)o(v)o(ely)h(steps)h(through)e(the)i +Fp(oper)o(ator)g(tr)n(ee)g Ft(handed)f(to)g(it)g(by)h(the)f(param-)323 +2261 y(eter)k Fr(ptr)g Ft(and)h(replaces)g Fr(A)p 826 +2261 V 18 w(Expr)f Ft(nodes)h(by)f Fr(Expr)h Ft(nodes.)31 +b(Additionally)17 b(it)g(e)o(xchanges)323 2321 y Fr(AND)e +Ft(nodes)h(with)g Fr(OR)f Ft(nodes)h(and)g(vice)g(v)o(ersa.)27 +b(The)16 b(reason)g(for)f(this)h(e)o(xchange)g(is)g(easy)g(to)323 +2381 y(understand.)27 b(W)l(e)17 b(implement)e Fp(intersect)i +Ft(and)f Fp(e)o(xcept)h Ft(clauses)g(by)f(re)o(writing)f(these)i +(queries)323 2441 y(to)d(semantically)h(equi)o(v)o(alent)f(queries)h +(that)g(use)g Fr(IN)g Ft(and)g Fr(NOT)29 b(IN)15 b Ft(subselects.)25 +b(T)l(o)15 b(be)g(able)323 2500 y(to)d(use)h(all)f(three)h(operations)f +(\()p Fp(unions)p Ft(,)h Fp(intersects)g Ft(and)f Fp(e)o(xcepts)p +Ft(\))h(in)f(one)h(comple)o(x)g(query)m(,)f(we)323 2560 +y(ha)o(v)o(e)18 b(to)g(translate)h(the)f(queries)g(into)g +Fp(Disjunctive)g(Normal)h(F)-5 b(orm)19 b Ft(\(DNF\).)f(Unfortunately) +323 2620 y(there)12 b(is)g(no)h(function)e Fr(dnfify\(\))p +Ft(,)i(b)o(ut)f(there)g(is)h(a)g(function)e Fr(cnfify\(\))h +Ft(which)g(produces)323 2680 y(DNF)17 b(when)g(we)h(e)o(xchange)g +Fr(AND)g Ft(nodes)g(with)f Fr(OR)g Ft(nodes)h(and)g(vice)f(v)o(ersa)h +(before)f(calling)323 2739 y Fr(cnfify\(\))11 b Ft(and)h(e)o(xchange)h +(them)f(again)g(in)h(the)f(result.)382 2864 y Fr(Node)30 +b(*)382 2924 y(A_Expr_to_Expr\(Node)e(*ptr,)831 2984 +y(bool)h(*intersect_present\))382 3044 y({)442 3103 y(Node)h(*result;) +442 3223 y(switch\(nodeTag\(ptr\)\))442 3283 y({)502 +3342 y(case)f(T_A_Expr:)502 3402 y({)p eop +%%Page: 104 104 +104 103 bop 270 60 a Ft(104)60 b Fm(CHAPTER)14 b(3.)25 +b(POSTGRESQL)13 b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW) +634 234 y Fr(A_Expr)29 b(*a)h(=)f(\(A_Expr)g(*\)ptr;)634 +354 y(switch)g(\(a->oper\))634 413 y({)693 473 y(case)h(AND:)693 +533 y({)753 593 y(Expr)g(*expr)f(=)h(makeNode\(Expr\);)753 +653 y(Node)g(*lexpr)f(=)843 712 y(A_Expr_to_Expr\(\(\(A_Expr)e +(*\)ptr\)->lexpr,)1291 772 y(intersect_present\);)753 +832 y(Node)j(*rexpr)f(=)843 892 y(A_Expr_to_Expr\(\(\(A_Expr)e +(*\)ptr\)->rexpr,)1291 951 y(intersect_present\);)753 +1071 y(*intersect_present)h(=)i(TRUE;)753 1191 y(expr->typeOid)f(=)g +(BOOLOID;)753 1250 y(expr->opType)g(=)h(OR_EXPR;)753 +1310 y(expr->args)f(=)h(makeList\(lexpr,)e(rexpr,)h(-1\);)753 +1370 y(result)g(=)h(\(Node)g(*\))f(expr;)753 1430 y(break;)693 +1489 y(})693 1549 y(case)h(OR:)693 1609 y({)753 1669 +y(Expr)g(*expr)f(=)h(makeNode\(Expr\);)753 1729 y(Node)g(*lexpr)f(=)843 +1788 y(A_Expr_to_Expr\(\(\(A_Expr)e(*\)ptr\)->lexpr,)1291 +1848 y(intersect_present\);)753 1908 y(Node)j(*rexpr)f(=)843 +1968 y(A_Expr_to_Expr\(\(\(A_Expr)e(*\)ptr\)->rexpr,)1291 +2027 y(intersect_present\);)753 2147 y(expr->typeOid)i(=)g(BOOLOID;)753 +2207 y(expr->opType)g(=)h(AND_EXPR;)753 2267 y(expr->args)f(=)h +(makeList\(lexpr,)e(rexpr,)h(-1\);)753 2326 y(result)g(=)h(\(Node)g +(*\))f(expr;)753 2386 y(break;)693 2446 y(})693 2506 +y(case)h(NOT:)693 2565 y({)753 2625 y(Expr)g(*expr)f(=)h +(makeNode\(Expr\);)753 2685 y(Node)g(*rexpr)f(=)843 2745 +y(A_Expr_to_Expr\(\(\(A_Expr)e(*\)ptr\)->rexpr,)1291 +2804 y(intersect_present\);)753 2924 y(expr->typeOid)i(=)g(BOOLOID;)753 +2984 y(expr->opType)g(=)h(NOT_EXPR;)753 3044 y(expr->args)f(=)h +(makeList\(rexpr,)e(-1\);)753 3103 y(result)h(=)h(\(Node)g(*\))f(expr;) +753 3163 y(break;)693 3223 y(})634 3283 y(})634 3342 +y(break;)574 3402 y(})p eop +%%Page: 105 105 +105 104 bop 198 60 a Fm(3.8.)29 b(THE)13 b(REALIZA)-6 +b(TION)14 b(OF)e(UNION,)g(INTERSECT)i(AND)f(EXCEPT)324 +b Ft(105)502 234 y Fr(default:)502 294 y({)562 354 y(result)29 +b(=)h(ptr;)502 413 y(})442 473 y(})382 533 y(})382 593 +y(return)g(result;)323 653 y(})198 787 y Ft(Note)11 b(that)g(the)g +Fr(stmtmulti)f Ft(and)h Fr(OptStmtMulti)f Ft(rules)h(had)g(to)g(be)g +(changed)g(in)g(order)f(to)h(a)o(v)o(oid)198 847 y Fp(shift/r)n(educe) +16 b Ft(con\003icts.)26 b(The)17 b(old)e(rules)h(allo)o(wed)g(an)g(in)n +(v)o(alid)f(syntax)h(\(e.g.)26 b(the)16 b(concatenation)g(of)198 +907 y(two)c(statements)i(without)e(a)i(';')e(inbetween\))h(which)g +(will)g(be)g(pre)o(v)o(ented)g(no)o(w)m(.)k(The)d(ne)o(w)f(rules)g(ha)o +(v)o(e)198 967 y(the)f(second)h(line)f(commented)g(out)g(as)h(sho)o(wn) +f(belo)o(w:)258 1082 y Fr(stmtmulti)208 b(:)60 b(stmtmulti)29 +b(stmt)g(';')646 1142 y(/*)h(|)60 b(stmtmulti)29 b(stmt)g(*/)736 +1201 y(|)60 b(stmt)29 b(';')736 1261 y(;)258 1381 y(OptStmtMulti)118 +b(:)60 b(OptStmtMulti)28 b(OptimizableStmt)g(';')646 +1440 y(/*)i(|)60 b(OptStmtMulti)28 b(OptimizableStmt)g(*/)736 +1500 y(|)60 b(OptimizableStmt)28 b(';')736 1560 y(;)198 +1714 y Fn(T)l(ransf)o(ormations)198 1814 y Ft(This)17 +b(step)g(normally)f(transforms)f(e)o(v)o(ery)i Fr(SelectStmt)e +Ft(node)i(found)f(into)g(a)g Fr(Query)h Ft(node)f(and)198 +1874 y(does)f(a)f(lot)g(of)g(transformations)f(to)h(the)h +Fp(tar)n(getlist)p Ft(,)g(the)f Fr(where)g Ft(quali\002cation)f(etc.)22 +b(As)15 b(mentioned)198 1934 y(abo)o(v)o(e)d(this)g(stage)g(e)o(xpects) +g(a)g Fr(SelectStmt)f Ft(node)g(and)h(cannot)g(handle)f(an)h +Fr(A)p 1603 1934 15 2 v 18 w(Expr)f Ft(node.)k(That')m(s)198 +1994 y(why)d(we)h(did)f(the)g(changes)h(to)f(the)g Fp(oper)o(ator)h(tr) +n(ee)h Ft(sho)o(wn)e(in)g(\002gure)g(3.12.)198 2113 y(In)g(this)g +(stage)h(only)f(v)o(ery)g(fe)o(w)g(changes)h(ha)o(v)o(e)g(been)f +(necessary:)273 2224 y Fo(\017)25 b Ft(The)13 b(transformation)e(of)h +(the)g(list)h(attached)g(to)f Fr(unionClause)f Ft(is)i(pre)o(v)o +(ented.)j(The)d(ra)o(w)g(list)323 2284 y(is)g(no)o(w)h(passed)g +(through)f(instead)g(and)h(the)f(necessary)i(transformations)d(are)h +(performed)f(at)i(a)323 2344 y(later)e(point)f(in)i(time.)273 +2459 y Fo(\017)25 b Ft(The)20 b(additionally)e(introduced)h(\002eld)g +Fr(intersectClause)f Ft(is)h(also)h(passed)g(untouched)323 +2519 y(through)11 b(this)h(stage.)198 2630 y(The)29 b(changes)f +(described)g(in)g(the)g(abo)o(v)o(e)g(paragraph)g(ha)o(v)o(e)g(been)g +(applied)g(to)g(the)g(functions)198 2690 y Fr(transformInsertStmt\(\)) +17 b Ft(and)i Fr(transformSelectStmt\(\))e Ft(which)i(are)g(contained) +198 2749 y(in)12 b(the)h(\002le)f Fk(:)c(:)g(:)p Fr +(/src/backend/parser/analyze.c)p Ft(:)273 2861 y Fo(\017)25 +b Fr(transformInsertStmt\(\))p Ft(:)382 2995 y Fr(static)30 +b(Query)f(*)382 3055 y(transformInsertStmt\(ParseState)e(*pstate,)980 +3115 y(InsertStmt)i(*stmt\))382 3175 y({)1159 3235 y(.)1159 +3294 y(.)1159 3354 y(.)p eop +%%Page: 106 106 +106 105 bop 270 60 a Ft(106)57 b Fm(CHAPTER)14 b(3.)28 +b(POSTGRESQL)13 b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW) +514 234 y Fr(/*)30 b(Just)f(pass)h(through)f(the)g(unionClause)g(and) +544 294 y(*)h(intersectClause.)e(We)i(will)f(process)g(it)h(in)544 +354 y(*)g(the)f(function)g(Except_Intersect_Rewrite\(\))544 +413 y(*/)514 473 y(qry->unionClause)f(=)i(stmt->unionClause;)514 +533 y(qry->intersectClause)e(=)i(stmt->intersectClause;)1231 +593 y(.)1231 653 y(.)1231 712 y(.)514 832 y(return)f(\(Query)h(*\))f +(qry;)454 892 y(})345 1043 y Fo(\017)c Fr(transformSelectStmt\(\))p +Ft(:)454 1180 y Fr(static)30 b(Query)f(*)454 1240 y +(transformSelectStmt\(ParseState)e(*pstate,)1052 1300 +y(SelectStmt)i(*stmt\))454 1360 y({)1231 1419 y(.)1231 +1479 y(.)1231 1539 y(.)514 1599 y(/*)h(Just)f(pass)h(through)f(the)g +(unionClause)g(and)544 1658 y(*)h(intersectClause.)e(We)i(will)f +(process)g(it)h(in)544 1718 y(*)g(the)f(function)g +(Except_Intersect_Rewrite\(\))544 1778 y(*/)514 1838 +y(qry->unionClause)f(=)i(stmt->unionClause;)514 1898 +y(qry->intersectClause)e(=)i(stmt->intersectClause;)1231 +1957 y(.)1231 2017 y(.)1231 2077 y(.)514 2137 y(return)f(\(Query)h(*\)) +f(qry;)454 2196 y(})270 2353 y Fn(The)12 b(Rewrite)h(System)270 +2455 y Ft(In)24 b(this)h(stage)g(the)f(information)f(contained)h(in)g +(the)h Fp(oper)o(ator)g(tr)n(ee)g Ft(attached)g(to)f(the)g(topmost)270 +2515 y Fr(SelectStmt)18 b Ft(node)i(is)g(used)g(to)f(form)f(a)i(tree)f +(of)g Fr(Query)g Ft(nodes)h(representing)f(the)g(re)o(written)270 +2574 y(query)c(\(i.e.)25 b(the)15 b(semantically)g(equi)o(v)o(alent)g +(query)g(that)g(contains)h(only)f Fp(union)g Ft(b)o(ut)g(no)g +Fp(intersect)h Ft(or)270 2634 y Fp(e)o(xcept)d Ft(operations\).)270 +2754 y(The)g(follo)o(wing)e(steps)i(ha)o(v)o(e)g(to)f(be)g(performed:) +345 2867 y Fo(\017)25 b Ft(Sa)o(v)o(e)16 b(the)g Fr(sortClause)p +Ft(,)g Fr(uniqueFlag)p Ft(,)g Fr(targetList)f Ft(\002elds)h(etc.)27 +b(of)16 b(the)f(topmost)395 2926 y Fr(Query)f Ft(node)g(because)h(the)f +(topmost)h(node)f(may)g(change)h(during)e(the)i(re)o(write)e(process)i +(\(re-)395 2986 y(member)f(\(only\))f(the)i(topmost)g +Fr(SelectStmt)f Ft(node)h(has)g(already)f(been)h(transformed)f(to)h(a) +395 3046 y Fr(Query)c Ft(node\).)345 3163 y Fo(\017)25 +b Ft(Recursi)o(v)o(ely)12 b(step)h(through)e(the)h Fp(oper)o(ator)h(tr) +n(ee)g Ft(and)g(transform)e(e)o(v)o(ery)h Fr(SelectStmt)f +Ft(node)395 3223 y(to)18 b(a)h Fr(Query)f Ft(node)g(using)h(the)f +(function)g Fr(intersect)p 1440 3223 15 2 v 17 w(tree)p +1577 3223 V 17 w(analyze\(\))g Ft(described)395 3283 +y(belo)o(w)m(.)d(The)d(one)g(node)g(already)f(transformed)g(\(the)h +(topmost)f(node\))h(is)g(still)g(contained)f(in)h(the)395 +3342 y Fp(oper)o(ator)j(tr)n(ee)g Ft(and)f(must)g(not)h(be)f +(transformed)f(again)h(because)h(this)g(would)e(cause)j(troubles)395 +3402 y(in)c(the)g Fp(tr)o(ansforming)h(logic)p Ft(.)p +eop +%%Page: 107 107 +107 106 bop 198 60 a Fm(3.8.)26 b(THE)13 b(REALIZA)-6 +b(TION)14 b(OF)e(UNION,)g(INTERSECT)i(AND)f(EXCEPT)327 +b Ft(107)433 2199 y @beginspecial 173 @llx 194 @lly 439 +@urx 597 @ury 2660 @rwi @setspecial +%%BeginDocument: figures/union_intersect_dnf.ps +%Magnification: 1.05 +/$F2psDict 200 dict def +$F2psDict begin +$F2psDict /mtrx matrix put +/col-1 {0 setgray} bind def +/col0 {0.000 0.000 0.000 srgb} bind def +/col1 {0.000 0.000 1.000 srgb} bind def +/col2 {0.000 1.000 0.000 srgb} bind def +/col3 {0.000 1.000 1.000 srgb} bind def +/col4 {1.000 0.000 0.000 srgb} bind def +/col5 {1.000 0.000 1.000 srgb} bind def +/col6 {1.000 1.000 0.000 srgb} bind def +/col7 {1.000 1.000 1.000 srgb} bind def +/col8 {0.000 0.000 0.560 srgb} bind def +/col9 {0.000 0.000 0.690 srgb} bind def +/col10 {0.000 0.000 0.820 srgb} bind def +/col11 {0.530 0.810 1.000 srgb} bind def +/col12 {0.000 0.560 0.000 srgb} bind def +/col13 {0.000 0.690 0.000 srgb} bind def +/col14 {0.000 0.820 0.000 srgb} bind def +/col15 {0.000 0.560 0.560 srgb} bind def +/col16 {0.000 0.690 0.690 srgb} bind def +/col17 {0.000 0.820 0.820 srgb} bind def +/col18 {0.560 0.000 0.000 srgb} bind def +/col19 {0.690 0.000 0.000 srgb} bind def +/col20 {0.820 0.000 0.000 srgb} bind def +/col21 {0.560 0.000 0.560 srgb} bind def +/col22 {0.690 0.000 0.690 srgb} bind def +/col23 {0.820 0.000 0.820 srgb} bind def +/col24 {0.500 0.190 0.000 srgb} bind def +/col25 {0.630 0.250 0.000 srgb} bind def +/col26 {0.750 0.380 0.000 srgb} bind def +/col27 {1.000 0.500 0.500 srgb} bind def +/col28 {1.000 0.630 0.630 srgb} bind def +/col29 {1.000 0.750 0.750 srgb} bind def +/col30 {1.000 0.880 0.880 srgb} bind def +/col31 {1.000 0.840 0.000 srgb} bind def + +end +save +149.0 635.5 translate +1 -1 scale + +/cp {closepath} bind def +/ef {eofill} bind def +/gr {grestore} bind def +/gs {gsave} bind def +/sa {save} bind def +/rs {restore} bind def +/l {lineto} bind def +/m {moveto} bind def +/rm {rmoveto} bind def +/n {newpath} bind def +/s {stroke} bind def +/sh {show} bind def +/slc {setlinecap} bind def +/slj {setlinejoin} bind def +/slw {setlinewidth} bind def +/srgb {setrgbcolor} bind def +/rot {rotate} bind def +/sc {scale} bind def +/sd {setdash} bind def +/ff {findfont} bind def +/sf {setfont} bind def +/scf {scalefont} bind def +/sw {stringwidth} bind def +/tr {translate} bind def +/tnt {dup dup currentrgbcolor + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add srgb} + bind def +/shd {dup dup currentrgbcolor 4 -2 roll mul 4 -2 roll mul + 4 -2 roll mul srgb} bind def + /DrawSplineSection { + /y3 exch def + /x3 exch def + /y2 exch def + /x2 exch def + /y1 exch def + /x1 exch def + /xa x1 x2 x1 sub 0.666667 mul add def + /ya y1 y2 y1 sub 0.666667 mul add def + /xb x3 x2 x3 sub 0.666667 mul add def + /yb y3 y2 y3 sub 0.666667 mul add def + x1 y1 lineto + xa ya xb yb x3 y3 curveto + } def + +/$F2psBegin {$F2psDict begin /$F2psEnteredState save def} def +/$F2psEnd {$F2psEnteredState restore end} def + +$F2psBegin +10 setmiterlimit +n 0 792 m 0 0 l 612 0 l 612 792 l cp clip + 0.06299 0.06299 sc +7.500 slw +% Polyline +n 675 810 m 675 1350 l 405 1350 l 405 810 l cp gs col-1 s gr +% Polyline +n 675 1080 m 405 1080 l gs col-1 s gr +% Polyline +n 675 4095 m 675 4635 l 405 4635 l 405 4095 l cp gs col-1 s gr +% Polyline +n 675 4365 m 405 4365 l gs col-1 s gr +% Polyline +n 675 4365 m 405 4635 l gs col-1 s gr +% Polyline +n 675 4635 m 405 4365 l gs col-1 s gr +% Polyline +gs clippath +888 4200 m 1008 4230 l 888 4260 l 1050 4260 l 1050 4200 l cp clip +n 1035 4230 m 540 4230 l gs col-1 s gr gr + +% arrowhead +n 888 4200 m 1008 4230 l 888 4260 l 888 4230 l 888 4200 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 2925 4905 m 3825 4905 l 3825 5625 l 2925 5625 l cp gs col-1 s gr +% Polyline +n 2925 5355 m 3825 5355 l gs col-1 s gr +% Polyline +n 2925 5130 m 3825 5130 l gs col-1 s gr +% Polyline +n 3555 5355 m 3555 5625 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +3240 5310 m +gs 1 -1 sc (NOT) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3240 5085 m +gs 1 -1 sc (Expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3105 5535 m +gs 1 -1 sc (args) col-1 sh gr +% Polyline +n 4050 5355 m 4590 5355 l 4590 5625 l 4050 5625 l cp gs col-1 s gr +% Polyline +n 4320 5355 m 4320 5625 l gs col-1 s gr +% Polyline +n 4320 5355 m 4590 5625 l gs col-1 s gr +% Polyline +n 4590 5355 m 4320 5625 l gs col-1 s gr +% Polyline +gs clippath +3903 5460 m 4023 5490 l 3903 5520 l 4065 5520 l 4065 5460 l cp clip +n 3690 5490 m 4050 5490 l gs col-1 s gr gr + +% arrowhead +n 3903 5460 m 4023 5490 l 3903 5520 l 3903 5490 l 3903 5460 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 2160 4365 m 2700 4365 l 2700 4635 l 2160 4635 l cp gs col-1 s gr +% Polyline +n 2430 4365 m 2430 4635 l gs col-1 s gr +% Polyline +n 2925 4365 m 3465 4365 l 3465 4635 l 2925 4635 l cp gs col-1 s gr +% Polyline +n 3195 4365 m 3195 4635 l gs col-1 s gr +% Polyline +n 3195 4365 m 3465 4635 l gs col-1 s gr +% Polyline +n 3465 4365 m 3195 4635 l gs col-1 s gr +% Polyline +gs clippath +2778 4470 m 2898 4500 l 2778 4530 l 2940 4530 l 2940 4470 l cp clip +n 2565 4500 m 2925 4500 l gs col-1 s gr gr + +% arrowhead +n 2778 4470 m 2898 4500 l 2778 4530 l 2778 4500 l 2778 4470 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 1035 3915 m 1935 3915 l 1935 4635 l 1035 4635 l cp gs col-1 s gr +% Polyline +n 1035 4365 m 1935 4365 l gs col-1 s gr +% Polyline +n 1035 4140 m 1935 4140 l gs col-1 s gr +% Polyline +n 1665 4365 m 1665 4635 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +1395 4320 m +gs 1 -1 sc (OR) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1350 4095 m +gs 1 -1 sc (Expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1215 4545 m +gs 1 -1 sc (args) col-1 sh gr +% Polyline +n 2925 1620 m 3825 1620 l 3825 2340 l 2925 2340 l cp gs col-1 s gr +% Polyline +n 2925 2070 m 3825 2070 l gs col-1 s gr +% Polyline +n 2925 1845 m 3825 1845 l gs col-1 s gr +% Polyline +n 3555 2070 m 3555 2340 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +3240 2025 m +gs 1 -1 sc (NOT) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3240 1800 m +gs 1 -1 sc (Expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3105 2250 m +gs 1 -1 sc (args) col-1 sh gr +% Polyline +n 4050 2070 m 4590 2070 l 4590 2340 l 4050 2340 l cp gs col-1 s gr +% Polyline +n 4320 2070 m 4320 2340 l gs col-1 s gr +% Polyline +n 4320 2070 m 4590 2340 l gs col-1 s gr +% Polyline +n 4590 2070 m 4320 2340 l gs col-1 s gr +% Polyline +gs clippath +3903 2175 m 4023 2205 l 3903 2235 l 4065 2235 l 4065 2175 l cp clip +n 3690 2205 m 4050 2205 l gs col-1 s gr gr + +% arrowhead +n 3903 2175 m 4023 2205 l 3903 2235 l 3903 2205 l 3903 2175 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 2160 1080 m 2700 1080 l 2700 1350 l 2160 1350 l cp gs col-1 s gr +% Polyline +n 2430 1080 m 2430 1350 l gs col-1 s gr +% Polyline +n 2925 1080 m 3465 1080 l 3465 1350 l 2925 1350 l cp gs col-1 s gr +% Polyline +n 3195 1080 m 3195 1350 l gs col-1 s gr +% Polyline +n 3195 1080 m 3465 1350 l gs col-1 s gr +% Polyline +n 3465 1080 m 3195 1350 l gs col-1 s gr +% Polyline +gs clippath +2778 1185 m 2898 1215 l 2778 1245 l 2940 1245 l 2940 1185 l cp clip +n 2565 1215 m 2925 1215 l gs col-1 s gr gr + +% arrowhead +n 2778 1185 m 2898 1215 l 2778 1245 l 2778 1215 l 2778 1185 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 1035 630 m 1935 630 l 1935 1350 l 1035 1350 l cp gs col-1 s gr +% Polyline +n 1035 1080 m 1935 1080 l gs col-1 s gr +% Polyline +n 1035 855 m 1935 855 l gs col-1 s gr +% Polyline +n 1665 1080 m 1665 1350 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +1395 1035 m +gs 1 -1 sc (OR) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1350 810 m +gs 1 -1 sc (Expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1215 1260 m +gs 1 -1 sc (args) col-1 sh gr +% Polyline +gs clippath +570 3948 m 540 4068 l 510 3948 l 510 4110 l 570 4110 l cp clip +n 540 1215 m 540 4095 l gs col-1 s gr gr + +% arrowhead +n 570 3948 m 540 4068 l 510 3948 l 540 3948 l 570 3948 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +888 915 m 1008 945 l 888 975 l 1050 975 l 1050 915 l cp clip +n 540 945 m 1035 945 l gs col-1 s gr gr + +% arrowhead +n 888 915 m 1008 945 l 888 975 l 888 945 l 888 915 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +2013 4470 m 2133 4500 l 2013 4530 l 2175 4530 l 2175 4470 l cp clip +n 1800 4500 m 2160 4500 l gs col-1 s gr gr + +% arrowhead +n 2013 4470 m 2133 4500 l 2013 4530 l 2013 4500 l 2013 4470 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +2325 5703 m 2295 5823 l 2265 5703 l 2265 5865 l 2325 5865 l cp clip +n 2295 4500 m 2295 5850 l gs col-1 s gr gr + +% arrowhead +n 2325 5703 m 2295 5823 l 2265 5703 l 2295 5703 l 2325 5703 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 1665 6705 m 2925 6705 l gs col-1 s gr +% Polyline +n 1665 6435 m 2925 6435 l gs col-1 s gr +% Polyline +n 1665 5850 m 2925 5850 l 2925 6975 l 1665 6975 l cp gs col-1 s gr +% Polyline +n 2655 6075 m 2655 6975 l gs col-1 s gr +% Polyline +n 1665 6075 m 2925 6075 l gs col-1 s gr +% Polyline +n 2655 6435 m 2925 6705 l gs col-1 s gr +% Polyline +n 2655 6705 m 2925 6435 l gs col-1 s gr +% Polyline +n 2655 6705 m 2925 6975 l gs col-1 s gr +% Polyline +n 2925 6705 m 2655 6975 l gs col-1 s gr +% Polyline +n 3330 6705 m 4590 6705 l gs col-1 s gr +% Polyline +n 3330 6435 m 4590 6435 l gs col-1 s gr +% Polyline +n 3330 5850 m 4590 5850 l 4590 6975 l 3330 6975 l cp gs col-1 s gr +% Polyline +n 4320 6075 m 4320 6975 l gs col-1 s gr +% Polyline +n 3330 6075 m 4590 6075 l gs col-1 s gr +% Polyline +n 4320 6435 m 4590 6705 l gs col-1 s gr +% Polyline +n 4320 6705 m 4590 6435 l gs col-1 s gr +% Polyline +n 4320 6705 m 4590 6975 l gs col-1 s gr +% Polyline +n 4590 6705 m 4320 6975 l gs col-1 s gr +% Polyline +gs clippath +2013 1185 m 2133 1215 l 2013 1245 l 2175 1245 l 2175 1185 l cp clip +n 1800 1215 m 2160 1215 l gs col-1 s gr gr + +% arrowhead +n 2013 1185 m 2133 1215 l 2013 1245 l 2013 1215 l 2013 1185 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +2325 2418 m 2295 2538 l 2265 2418 l 2265 2580 l 2325 2580 l cp clip +n 2295 1215 m 2295 2565 l gs col-1 s gr gr + +% arrowhead +n 2325 2418 m 2295 2538 l 2265 2418 l 2295 2418 l 2325 2418 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 1665 3420 m 2925 3420 l gs col-1 s gr +% Polyline +n 1665 3150 m 2925 3150 l gs col-1 s gr +% Polyline +n 1665 2565 m 2925 2565 l 2925 3690 l 1665 3690 l cp gs col-1 s gr +% Polyline +n 2655 2790 m 2655 3690 l gs col-1 s gr +% Polyline +n 1665 2790 m 2925 2790 l gs col-1 s gr +% Polyline +n 2655 3150 m 2925 3420 l gs col-1 s gr +% Polyline +n 2655 3420 m 2925 3150 l gs col-1 s gr +% Polyline +n 2655 3420 m 2925 3690 l gs col-1 s gr +% Polyline +n 2925 3420 m 2655 3690 l gs col-1 s gr +% Polyline +n 3330 3420 m 4590 3420 l gs col-1 s gr +% Polyline +n 3330 3150 m 4590 3150 l gs col-1 s gr +% Polyline +n 3330 2565 m 4590 2565 l 4590 3690 l 3330 3690 l cp gs col-1 s gr +% Polyline +n 4320 2790 m 4320 3690 l gs col-1 s gr +% Polyline +n 3330 2790 m 4590 2790 l gs col-1 s gr +% Polyline +n 4320 3150 m 4590 3420 l gs col-1 s gr +% Polyline +n 4320 3420 m 4590 3150 l gs col-1 s gr +% Polyline +n 4320 3420 m 4590 3690 l gs col-1 s gr +% Polyline +n 4590 3420 m 4320 3690 l gs col-1 s gr +% Open spline +gs clippath +3269 4798 m 3352 4890 l 3236 4848 l 3371 4938 l 3404 4888 l cp clip +n 3060.0 4500.0 m 3082.5 4612.5 l + 3082.5 4612.5 3105.0 4725.0 3240.0 4815.0 DrawSplineSection + 3375.0 4905.0 l gs col-1 s gr + gr + +% arrowhead +n 3269 4798 m 3352 4890 l 3236 4848 l 3253 4823 l 3269 4798 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +4096 5786 m 3981 5833 l 4060 5738 l 3930 5835 l 3966 5883 l cp clip +n 4185.0 5490.0 m 4162.5 5602.5 l + 4162.5 5602.5 4140.0 5715.0 4050.0 5782.5 DrawSplineSection + 3960.0 5850.0 l gs col-1 s gr + gr + +% arrowhead +n 4096 5786 m 3981 5833 l 4060 5738 l 4078 5762 l 4096 5786 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3269 1513 m 3352 1605 l 3236 1563 l 3371 1653 l 3404 1603 l cp clip +n 3060.0 1215.0 m 3082.5 1327.5 l + 3082.5 1327.5 3105.0 1440.0 3240.0 1530.0 DrawSplineSection + 3375.0 1620.0 l gs col-1 s gr + gr + +% arrowhead +n 3269 1513 m 3352 1605 l 3236 1563 l 3253 1538 l 3269 1513 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +4096 2501 m 3981 2548 l 4060 2453 l 3930 2550 l 3966 2598 l cp clip +n 4185.0 2205.0 m 4162.5 2317.5 l + 4162.5 2317.5 4140.0 2430.0 4050.0 2497.5 DrawSplineSection + 3960.0 2565.0 l gs col-1 s gr + gr + +% arrowhead +n 4096 2501 m 3981 2548 l 4060 2453 l 4078 2477 l 4096 2501 l cp gs 0.00 setgray ef gr col-1 s +/Times-Roman ff 150.00 scf sf +2205 6300 m +gs 1 -1 sc 90.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1980 6030 m +gs 1 -1 sc (Query \(B\)) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3870 6300 m +gs 1 -1 sc 90.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3690 6030 m +gs 1 -1 sc (Query \(C\)) col-1 sh gr +/Times-Roman ff 150.00 scf sf +2205 3015 m +gs 1 -1 sc 90.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1980 2745 m +gs 1 -1 sc (Query \(A\)) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3870 3015 m +gs 1 -1 sc 90.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3690 2745 m +gs 1 -1 sc (Query \(C\)) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1710 3330 m +gs 1 -1 sc (unionClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1710 3600 m +gs 1 -1 sc (intersectClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3375 3330 m +gs 1 -1 sc (unionClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3375 3600 m +gs 1 -1 sc (intersectClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3375 6615 m +gs 1 -1 sc (unionClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3375 6885 m +gs 1 -1 sc (intersectClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1710 6615 m +gs 1 -1 sc (unionClause) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1710 6885 m +gs 1 -1 sc (intersectClause) col-1 sh gr +showpage +$F2psEnd +rs +%%EndDocument + @endspecial 391 2309 a(Figure)11 b(3.13:)16 b(Data)c(structure)g(of)g +Fl(\()p Fk(A)g Fo([)f Fk(B)r Fl(\))p Fo(n)p Fk(C)16 b +Ft(after)c(transformation)f(to)h(DNF)273 2542 y Fo(\017)25 +b Ft(T)n(ransform)14 b(the)g(ne)o(w)h Fp(oper)o(ator)g(tr)n(ee)g +Ft(into)f(DNF)h(\(disjuncti)o(v)o(e)f(normal)f(form\).)21 +b(PostgreSQL)323 2602 y(does)f(not)f(pro)o(vide)h(an)o(y)g(function)f +(for)g(the)h(transformation)e(into)h(DNF)h(b)o(ut)g(it)f(pro)o(vides)h +(a)323 2662 y(function)14 b Fr(cnfify\(\))g Ft(that)h(performs)f(a)i +(transformation)e(into)g(CNF)i(\(conjuncti)o(v)o(e)e(normal)323 +2721 y(form\).)g(So)e(we)g(can)h(easily)g(make)f(use)g(of)g(this)h +(function)e(when)i(we)f(e)o(xchange)h(e)o(v)o(ery)f Fr(OR)g +Ft(with)323 2781 y(an)17 b Fr(AND)f Ft(and)h(vice)g(v)o(ersa)h(before)e +(calling)h Fr(cnfify\(\))f Ft(as)h(we)g(did)g(already)g(in)g(the)f +Fp(parser)323 2841 y Ft(\(compare)11 b(\002gure)h(3.11)h(to)f(\002gure) +g(3.12\).)k(When)c Fr(cnfify\(\))g Ft(is)h(called)f(with)g(a)h(special) +g(\003ag,)323 2901 y(the)f Fr(removeAndFlag)g Ft(set)h(to)f +Fr(true)h Ft(it)f(returns)g(a)h(list)g(where)g(the)f(entries)h(can)g +(be)g(thought)323 2961 y(of)e(being)i(connected)f(together)g(by)g +Fr(ANDs)p Ft(,)g(so)h(the)f(e)o(xplicit)h Fr(AND)f Ft(nodes)g(are)h +(remo)o(v)o(ed.)323 3062 y(After)d Fr(cnfify\(\))h Ft(has)h(been)f +(called)h(we)f(normally)g(would)f(ha)o(v)o(e)i(to)g(e)o(xchange)g +Fr(OR)f Ft(and)g Fr(AND)323 3122 y Ft(nodes)16 b(again.)28 +b(W)l(e)17 b(skip)g(this)g(step)f(by)h(simply)f(treating)g(e)o(v)o(ery) +g Fr(OR)h Ft(node)f(as)h(an)g Fr(AND)f Ft(node)323 3181 +y(throughout)10 b(the)h(follo)o(wing)f(steps)i(\(remember)n(,)f(that)g +(there)h(are)f(no)g Fr(AND)h Ft(nodes)f(left)g(that)h(ha)o(v)o(e)323 +3241 y(to)g(be)g(treated)g(as)h Fr(OR)f Ft(nodes)h(because)g(of)f(the)g +Fr(removeAndFlag)p Ft(\).)323 3342 y(Figure)e(3.13)i(sho)o(ws)h(what)e +(the)h(data)g(structure)f(looks)h(like)f(after)g(the)h(transformation)e +(to)h(DNF)323 3402 y(has)h(taken)g(place)h(for)e(the)i(follo)o(wing)e +(query:)p eop +%%Page: 108 108 +108 107 bop 270 60 a Ft(108)57 b Fm(CHAPTER)14 b(3.)28 +b(POSTGRESQL)13 b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW) +454 234 y Fr(\(select)29 b(*)h(from)g(A)484 294 y(union)484 +354 y(select)f(*)h(from)g(B\))484 413 y(except)484 473 +y(select)f(*)h(from)g(C;)345 589 y Fo(\017)25 b Ft(F)o(or)10 +b(e)o(v)o(ery)h(entry)g(of)g(the)g(list)g(returned)g(by)g +Fr(cnfify\(\))f Ft(\(i.e.)16 b(for)10 b(e)o(v)o(ery)h +Fp(oper)o(ator)h(tr)n(ee)g Ft(which)395 648 y(may)e(only)g(contain)h +Fr(OR)f Ft(and)h Fr(NOT)f Ft(operator)g(nodes)h(and)f +Fr(Query)g Ft(nodes)h(as)g(lea)o(v)o(es\))g(contained)395 +708 y(in)h(the)g Fr(union)p 672 708 15 2 v 17 w(list)g +Ft(perform)f(the)i(follo)o(wing)e(steps:)454 806 y Fn(\226)25 +b Ft(Check)15 b(if)g(the)g Fp(tar)n(getlists)f Ft(of)h(all)g +Fr(Query)f Ft(nodes)h(appearing)g(are)f(compatible)h(\(i.e.)23 +b(all)504 866 y Fp(tar)n(getlists)13 b Ft(ha)o(v)o(e)h(the)f(same)h +(number)e(of)h(attrib)o(utes)g(and)g(the)g(corresponding)g(attrib)o +(utes)504 926 y(are)f(of)g(the)h(same)f(type\))454 1004 +y Fn(\226)25 b Ft(There)13 b(must)f(be)h(at)g(least)g(one)f(positi)o(v) +o(e)h Fr(OR)f Ft(node)h(\(i.e.)j(at)d(least)g(one)f Fr(OR)h +Ft(node)f(which)h(is)504 1064 y(not)h(preceded)g(by)f(a)h +Fr(NOT)g Ft(node\).)20 b(Create)14 b(a)g(list)g(of)g(all)f +Fr(Query)h Ft(nodes)g(\(or)f(of)h Fr(Query)504 1123 y +Ft(nodes)f(preceded)f(by)h Fr(NOT)f Ft(nodes)h(if)f Fr(OR)29 +b(NOT)13 b Ft(is)f(found\))g(with)g(the)g(non)h(ne)o(gated)f(node)504 +1183 y(\002rst)g(using)g(the)h(function)e Fr(create)p +1149 1183 V 18 w(list\(\))g Ft(described)i(belo)o(w)m(.)454 +1261 y Fn(\226)25 b Ft(The)19 b(\002rst)f(\(non)f(ne)o(gated\))h(node)g +(of)g(the)g(list)g(will)g(be)g(the)g(topmost)g Fr(Query)f +Ft(node)i(of)504 1321 y(the)g(current)f Fp(union)h Ft(operand.)36 +b(F)o(or)18 b(all)h(other)g(nodes)g(found)g(in)g(the)g(list)g(add)g(an) +g Fr(IN)504 1381 y Ft(subselect)14 b(\()p Fr(NOT)29 b(IN)14 +b Ft(subselect)g(if)f(the)g Fr(Query)g Ft(node)h(is)g(preceded)f(by)g +(a)h Fr(NOT)p Ft(\))f(to)g(the)504 1440 y Fr(where)j +Ft(quali\002cation)g(of)f(the)i(topmost)f(node.)28 b(Adding)15 +b(a)i(subselect)g(to)f(the)h Fr(where)504 1500 y Ft(quali\002cation)12 +b(is)g(done)h(by)f(logically)g Fr(AND)p Ft(ing)f(it)i(to)f(the)g +(original)g(quali\002cation.)454 1578 y Fn(\226)25 b +Ft(Append)16 b(the)f Fr(Query)g Ft(node)h(setup)g(in)f(the)h(last)g +(steps)g(to)f(a)h(list)g(which)f(is)h(hold)g(by)f(the)504 +1638 y(pointer)d Fr(union)p 811 1638 V 17 w(list)p Ft(.)345 +1736 y Fo(\017)25 b Ft(T)l(ake)17 b(the)f(\002rst)h(node)g(of)f +Fr(union)p 1004 1736 V 18 w(list)g Ft(as)i(the)e(ne)o(w)h(topmost)g +(node)g(of)f(the)h(whole)g(query)395 1796 y(and)11 b(attach)h(the)f +(rest)h(of)f(the)g(list)h(to)f(the)h(\002eld)f Fr(unionClause)f +Ft(of)h(this)h(topmost)f(node.)k(Since)395 1856 y(the)f(ne)o(w)g +(topmost)g(node)h(might)f(dif)o(fer)f(from)g(the)i(original)e(one)i +(\(i.e.)22 b(from)13 b(the)i(node)f(which)395 1915 y(was)h(topmost)g +(when)g(we)g(entered)g(the)g Fp(r)n(e)o(write)i(stage)p +Ft(\))d(we)h(ha)o(v)o(e)h(to)f(attach)g(the)g(\002elds)g(sa)o(v)o(ed) +395 1975 y(in)h(the)h(\002rst)g(step)g(to)g(the)g(ne)o(w)g(topmost)f +(node)h(\(i.e.)30 b(the)17 b Fr(sortClause)p Ft(,)h Fr(targetList)p +Ft(,)395 2035 y Fr(unionFlag)p Ft(,)11 b(etc.\).)345 +2133 y Fo(\017)25 b Ft(Hand)16 b(the)h(ne)o(w)g(topmost)g +Fr(Query)f Ft(node)h(back.)29 b(No)o(w)17 b(the)g(normal)f +Fp(query)h(r)n(e)o(writing)h Ft(takes)395 2193 y(place)12 +b(\(in)f(order)g(to)h(handle)g(vie)o(ws)g(if)f(present\))h(and)f(then)h +(the)g Fp(planner/optimizer)g Ft(and)g Fp(e)o(xecu-)395 +2252 y(tor)g Ft(functions)f(are)g(called)h(to)g(get)g(a)g(result.)j +(There)d(ha)o(v)o(e)g(no)g(changes)g(been)g(made)g(to)f(the)h(code)395 +2312 y(of)f(these)i(stages.)270 2408 y(Figure)f(3.14)g(sho)o(ws)h(the)f +(re)o(written)f(data)i(structure)e(of)h(the)h(query:)360 +2505 y Fr(select)29 b(C1,)g(C2)h(from)g(A)360 2565 y(intersect)360 +2624 y(select)f(C1,)g(C3)h(from)g(C;)270 2721 y Ft(against)11 +b(the)g(tables)h(de\002ned)f(in)g(e)o(xample)g(3.4.)16 +b(The)c(re)o(written)d(data)j(structure)e(represents)i(the)f(query:)330 +2817 y Fr(select)29 b(C1,)h(C2)f(form)h(A)330 2877 y(where)f(\(C1,)h +(C2\))f(in)509 2936 y(\(select)g(C1,C3)h(from)f(C\);)270 +3033 y Ft(The)15 b(\002eld)e Fr(lefttree)h Ft(of)g(the)g +Fr(Sublink)f Ft(node)h(points)g(to)g(a)g(list)h(where)e(e)o(v)o(ery)h +(entry)g(points)g(to)g(a)270 3093 y Fr(VAR)e Ft(node)g(of)g(the)g +Fp(tar)n(getlist)g Ft(of)g(the)h(topmost)e(node)i(\(node)f(A\).)g(The)h +(\002eld)f Fr(oper)g Ft(of)g(the)g Fr(Sublink)270 3152 +y Ft(node)i(points)h(to)f(a)h(list)f(holding)g(a)h(pointer)e(to)i(an)f +Fr(Expr)g Ft(node)h(for)e(e)o(v)o(ery)h(attrib)o(ute)g(of)g(the)g +(topmost)270 3212 y Fp(tar)n(getlist)p Ft(.)k(Ev)o(ery)13 +b Fr(Expr)g Ft(node)g(is)h(used)f(to)g(compare)g(a)g +Fr(VAR)g Ft(node)g(of)g(the)g(topmost)g Fp(tar)n(getlist)f +Ft(with)270 3272 y(the)17 b(corresponding)f Fr(VAR)g +Ft(node)h(of)f(the)h(subselect')m(s)h Fp(tar)n(getlist)p +Ft(.)28 b(So)17 b(the)g(\002rst)f(ar)o(gument)g(of)g(e)o(v)o(ery)270 +3332 y Fr(Expr)c Ft(node)h(points)g(to)g(a)g Fr(VAR)f +Ft(node)h(of)f(the)h(topmost)g Fp(tar)n(getlist)f Ft(and)h(the)g +(second)g(ar)o(gument)f(points)270 3391 y(to)g(the)h(corresponding)e +Fr(VAR)h Ft(node)g(of)g(the)h(subselect')m(s)g Fp(tar)n(getlist)p +Ft(.)p eop +%%Page: 109 109 +109 108 bop 198 60 a Fm(3.8.)29 b(THE)13 b(REALIZA)-6 +b(TION)14 b(OF)e(UNION,)g(INTERSECT)i(AND)f(EXCEPT)324 +b Ft(109)298 3216 y @beginspecial 136 @llx 94 @lly 476 +@urx 697 @ury 3400 @rwi @setspecial +%%BeginDocument: figures/union_operand.ps +%Magnification: 1.05 +/$F2psDict 200 dict def +$F2psDict begin +$F2psDict /mtrx matrix put +/col-1 {0 setgray} bind def +/col0 {0.000 0.000 0.000 srgb} bind def +/col1 {0.000 0.000 1.000 srgb} bind def +/col2 {0.000 1.000 0.000 srgb} bind def +/col3 {0.000 1.000 1.000 srgb} bind def +/col4 {1.000 0.000 0.000 srgb} bind def +/col5 {1.000 0.000 1.000 srgb} bind def +/col6 {1.000 1.000 0.000 srgb} bind def +/col7 {1.000 1.000 1.000 srgb} bind def +/col8 {0.000 0.000 0.560 srgb} bind def +/col9 {0.000 0.000 0.690 srgb} bind def +/col10 {0.000 0.000 0.820 srgb} bind def +/col11 {0.530 0.810 1.000 srgb} bind def +/col12 {0.000 0.560 0.000 srgb} bind def +/col13 {0.000 0.690 0.000 srgb} bind def +/col14 {0.000 0.820 0.000 srgb} bind def +/col15 {0.000 0.560 0.560 srgb} bind def +/col16 {0.000 0.690 0.690 srgb} bind def +/col17 {0.000 0.820 0.820 srgb} bind def +/col18 {0.560 0.000 0.000 srgb} bind def +/col19 {0.690 0.000 0.000 srgb} bind def +/col20 {0.820 0.000 0.000 srgb} bind def +/col21 {0.560 0.000 0.560 srgb} bind def +/col22 {0.690 0.000 0.690 srgb} bind def +/col23 {0.820 0.000 0.820 srgb} bind def +/col24 {0.500 0.190 0.000 srgb} bind def +/col25 {0.630 0.250 0.000 srgb} bind def +/col26 {0.750 0.380 0.000 srgb} bind def +/col27 {1.000 0.500 0.500 srgb} bind def +/col28 {1.000 0.630 0.630 srgb} bind def +/col29 {1.000 0.750 0.750 srgb} bind def +/col30 {1.000 0.880 0.880 srgb} bind def +/col31 {1.000 0.840 0.000 srgb} bind def + +end +save +126.0 696.5 translate +1 -1 scale + +/cp {closepath} bind def +/ef {eofill} bind def +/gr {grestore} bind def +/gs {gsave} bind def +/sa {save} bind def +/rs {restore} bind def +/l {lineto} bind def +/m {moveto} bind def +/rm {rmoveto} bind def +/n {newpath} bind def +/s {stroke} bind def +/sh {show} bind def +/slc {setlinecap} bind def +/slj {setlinejoin} bind def +/slw {setlinewidth} bind def +/srgb {setrgbcolor} bind def +/rot {rotate} bind def +/sc {scale} bind def +/sd {setdash} bind def +/ff {findfont} bind def +/sf {setfont} bind def +/scf {scalefont} bind def +/sw {stringwidth} bind def +/tr {translate} bind def +/tnt {dup dup currentrgbcolor + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add + 4 -2 roll dup 1 exch sub 3 -1 roll mul add srgb} + bind def +/shd {dup dup currentrgbcolor 4 -2 roll mul 4 -2 roll mul + 4 -2 roll mul srgb} bind def + /DrawSplineSection { + /y3 exch def + /x3 exch def + /y2 exch def + /x2 exch def + /y1 exch def + /x1 exch def + /xa x1 x2 x1 sub 0.666667 mul add def + /ya y1 y2 y1 sub 0.666667 mul add def + /xb x3 x2 x3 sub 0.666667 mul add def + /yb y3 y2 y3 sub 0.666667 mul add def + x1 y1 lineto + xa ya xb yb x3 y3 curveto + } def + +/$F2psBegin {$F2psDict begin /$F2psEnteredState save def} def +/$F2psEnd {$F2psEnteredState restore end} def + +$F2psBegin +10 setmiterlimit +n 0 792 m 0 0 l 612 0 l 612 792 l cp clip + 0.06299 0.06299 sc +7.500 slw +% Polyline +n 180 3780 m 1170 3780 l gs col-1 s gr +% Polyline +n 180 4050 m 1170 4050 l gs col-1 s gr +% Polyline +n 180 4320 m 1170 4320 l gs col-1 s gr +% Polyline +n 180 4590 m 1170 4590 l gs col-1 s gr +% Polyline +n 900 3780 m 900 5040 l gs col-1 s gr +% Polyline +n 180 3555 m 1170 3555 l 1170 5040 l 180 5040 l cp gs col-1 s gr +/Times-Roman ff 150.00 scf sf +450 3735 m +gs 1 -1 sc (Sublink) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 4725 m +gs 1 -1 sc 270.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +270 4500 m +gs 1 -1 sc (subselect) col-1 sh gr +/Times-Roman ff 150.00 scf sf +270 4230 m +gs 1 -1 sc (oper) col-1 sh gr +/Times-Roman ff 150.00 scf sf +270 3960 m +gs 1 -1 sc (lefthand) col-1 sh gr +% Polyline +n 3195 3780 m 3735 3780 l 3735 4050 l 3195 4050 l cp gs col-1 s gr +% Polyline +n 3465 3780 m 3465 4050 l gs col-1 s gr +% Polyline +n 3465 3780 m 3735 4050 l gs col-1 s gr +% Polyline +n 3735 3780 m 3465 4050 l gs col-1 s gr +% Polyline +n 1710 3780 m 2250 3780 l 2250 4050 l 1710 4050 l cp gs col-1 s gr +% Polyline +n 1980 3780 m 1980 4050 l gs col-1 s gr +% Polyline +gs clippath +3048 3885 m 3168 3915 l 3048 3945 l 3210 3945 l 3210 3885 l cp clip +n 2115 3915 m 3195 3915 l gs col-1 s gr gr + +% arrowhead +n 3048 3885 m 3168 3915 l 3048 3945 l 3048 3915 l 3048 3885 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 3195 4140 m 3735 4140 l 3735 4410 l 3195 4410 l cp gs col-1 s gr +% Polyline +n 3465 4140 m 3465 4410 l gs col-1 s gr +% Polyline +n 3465 4140 m 3735 4410 l gs col-1 s gr +% Polyline +n 3735 4140 m 3465 4410 l gs col-1 s gr +% Polyline +n 1710 4140 m 2250 4140 l 2250 4410 l 1710 4410 l cp gs col-1 s gr +% Polyline +n 1980 4140 m 1980 4410 l gs col-1 s gr +% Polyline +gs clippath +3048 4245 m 3168 4275 l 3048 4305 l 3210 4305 l 3210 4245 l cp clip +n 2115 4275 m 3195 4275 l gs col-1 s gr gr + +% arrowhead +n 3048 4245 m 3168 4275 l 3048 4305 l 3048 4275 l 3048 4245 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 1395 5265 m 2295 5265 l gs col-1 s gr +% Polyline +n 1395 5535 m 2295 5535 l gs col-1 s gr +% Polyline +n 1395 5040 m 2295 5040 l 2295 5805 l 1395 5805 l cp gs col-1 s gr +% Polyline +n 2025 5535 m 2025 5805 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +1710 5220 m +gs 1 -1 sc (Expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1485 5445 m +gs 1 -1 sc (opType: '=') col-1 sh gr +/Times-Roman ff 150.00 scf sf +1485 5715 m +gs 1 -1 sc (args) col-1 sh gr +% Polyline +n 2520 5535 m 3060 5535 l 3060 5805 l 2520 5805 l cp gs col-1 s gr +% Polyline +n 2790 5535 m 2790 5805 l gs col-1 s gr +% Polyline +n 3285 5535 m 3825 5535 l 3825 5805 l 3285 5805 l cp gs col-1 s gr +% Polyline +n 3555 5535 m 3555 5805 l gs col-1 s gr +% Polyline +n 3555 5535 m 3825 5805 l gs col-1 s gr +% Polyline +n 3825 5535 m 3555 5805 l gs col-1 s gr +% Polyline +gs clippath +3138 5640 m 3258 5670 l 3138 5700 l 3300 5700 l 3300 5640 l cp clip +n 2925 5670 m 3285 5670 l gs col-1 s gr gr + +% arrowhead +n 3138 5640 m 3258 5670 l 3138 5700 l 3138 5670 l 3138 5640 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +2373 5640 m 2493 5670 l 2373 5700 l 2535 5700 l 2535 5640 l cp clip +n 2160 5670 m 2520 5670 l gs col-1 s gr gr + +% arrowhead +n 2373 5640 m 2493 5670 l 2373 5700 l 2373 5670 l 2373 5640 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 3105 4815 m 4005 4815 l gs col-1 s gr +% Polyline +n 3105 5085 m 4005 5085 l gs col-1 s gr +% Polyline +n 3105 4590 m 4005 4590 l 4005 5355 l 3105 5355 l cp gs col-1 s gr +% Polyline +n 3735 5085 m 3735 5355 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +3420 4770 m +gs 1 -1 sc (Expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3195 4995 m +gs 1 -1 sc (opType: '=') col-1 sh gr +/Times-Roman ff 150.00 scf sf +3195 5265 m +gs 1 -1 sc (args) col-1 sh gr +% Polyline +n 4230 5085 m 4770 5085 l 4770 5355 l 4230 5355 l cp gs col-1 s gr +% Polyline +n 4500 5085 m 4500 5355 l gs col-1 s gr +% Polyline +n 4995 5085 m 5535 5085 l 5535 5355 l 4995 5355 l cp gs col-1 s gr +% Polyline +n 5265 5085 m 5265 5355 l gs col-1 s gr +% Polyline +n 5265 5085 m 5535 5355 l gs col-1 s gr +% Polyline +n 5535 5085 m 5265 5355 l gs col-1 s gr +% Polyline +n 3600 0 m 4140 0 l 4140 270 l 3600 270 l cp gs col-1 s gr +% Polyline +n 3870 0 m 3870 270 l gs col-1 s gr +% Polyline +n 3870 0 m 4140 270 l gs col-1 s gr +% Polyline +n 4140 0 m 3870 270 l gs col-1 s gr +% Polyline +n 3285 495 m 4185 495 l 4185 990 l 3285 990 l cp gs col-1 s gr +% Polyline +n 3285 720 m 4185 720 l gs col-1 s gr +/Times-Roman ff 150.00 scf sf +3375 900 m +gs 1 -1 sc (relname: "A") col-1 sh gr +/Times-Roman ff 150.00 scf sf +3600 675 m +gs 1 -1 sc (RTE) col-1 sh gr +% Polyline +n 1395 315 m 1935 315 l 1935 585 l 1395 585 l cp gs col-1 s gr +% Polyline +n 1665 315 m 1665 585 l gs col-1 s gr +% Polyline +n 2160 315 m 2700 315 l 2700 585 l 2160 585 l cp gs col-1 s gr +% Polyline +n 2430 315 m 2430 585 l gs col-1 s gr +% Polyline +n 2430 315 m 2700 585 l gs col-1 s gr +% Polyline +n 2700 315 m 2430 585 l gs col-1 s gr +% Polyline +gs clippath +2013 420 m 2133 450 l 2013 480 l 2175 480 l 2175 420 l cp clip +n 1800 450 m 2160 450 l gs col-1 s gr gr + +% arrowhead +n 2013 420 m 2133 450 l 2013 480 l 2013 450 l 2013 420 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 1440 2340 m 2340 2340 l gs col-1 s gr +% Polyline +n 1440 2115 m 2340 2115 l 2340 2610 l 1440 2610 l cp gs col-1 s gr +/Times-Roman ff 150.00 scf sf +1665 2295 m +gs 1 -1 sc (Resdom) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1530 2520 m +gs 1 -1 sc (resname: C1) col-1 sh gr +% Polyline +n 2925 2340 m 3825 2340 l gs col-1 s gr +% Polyline +n 2925 2115 m 3825 2115 l 3825 2610 l 2925 2610 l cp gs col-1 s gr +/Times-Roman ff 150.00 scf sf +3150 2295 m +gs 1 -1 sc (Resdom) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3015 2520 m +gs 1 -1 sc (resname: C2) col-1 sh gr +% Polyline +n 3600 5985 m 4140 5985 l 4140 6255 l 3600 6255 l cp gs col-1 s gr +% Polyline +n 3870 5985 m 3870 6255 l gs col-1 s gr +% Polyline +n 3870 5985 m 4140 6255 l gs col-1 s gr +% Polyline +n 4140 5985 m 3870 6255 l gs col-1 s gr +% Polyline +n 1395 6300 m 1935 6300 l 1935 6570 l 1395 6570 l cp gs col-1 s gr +% Polyline +n 1665 6300 m 1665 6570 l gs col-1 s gr +% Polyline +n 2160 6300 m 2700 6300 l 2700 6570 l 2160 6570 l cp gs col-1 s gr +% Polyline +n 2430 6300 m 2430 6570 l gs col-1 s gr +% Polyline +n 2430 6300 m 2700 6570 l gs col-1 s gr +% Polyline +n 2700 6300 m 2430 6570 l gs col-1 s gr +% Polyline +gs clippath +2013 6405 m 2133 6435 l 2013 6465 l 2175 6465 l 2175 6405 l cp clip +n 1800 6435 m 2160 6435 l gs col-1 s gr gr + +% arrowhead +n 2013 6405 m 2133 6435 l 2013 6465 l 2013 6435 l 2013 6405 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 1440 8325 m 2340 8325 l gs col-1 s gr +% Polyline +n 1440 8100 m 2340 8100 l 2340 8595 l 1440 8595 l cp gs col-1 s gr +/Times-Roman ff 150.00 scf sf +1665 8280 m +gs 1 -1 sc (Resdom) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1530 8505 m +gs 1 -1 sc (resname: C1) col-1 sh gr +% Polyline +n 180 225 m 1170 225 l gs col-1 s gr +% Polyline +n 180 495 m 1170 495 l gs col-1 s gr +% Polyline +n 180 765 m 1170 765 l gs col-1 s gr +% Polyline +n 180 1035 m 1170 1035 l gs col-1 s gr +% Polyline +n 900 225 m 900 1440 l gs col-1 s gr +% Polyline +n 180 0 m 1170 0 l 1170 1440 l 180 1440 l cp gs col-1 s gr +% Polyline +gs clippath +3300 3702 m 3330 3582 l 3360 3702 l 3360 3540 l 3300 3540 l cp clip +n 3330 3915 m 3330 3555 l gs col-1 s gr gr + +% arrowhead +n 3300 3702 m 3330 3582 l 3360 3702 l 3330 3702 l 3300 3702 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +1815 3702 m 1845 3582 l 1875 3702 l 1875 3540 l 1815 3540 l cp clip +n 1845 3915 m 1845 3555 l gs col-1 s gr gr + +% arrowhead +n 1815 3702 m 1845 3582 l 1875 3702 l 1845 3702 l 1815 3702 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +1875 4893 m 1845 5013 l 1815 4893 l 1815 5055 l 1875 5055 l cp clip +n 1845 4275 m 1845 5040 l gs col-1 s gr gr + +% arrowhead +n 1875 4893 m 1845 5013 l 1815 4893 l 1845 4893 l 1875 4893 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +1563 3885 m 1683 3915 l 1563 3945 l 1725 3945 l 1725 3885 l cp clip +n 1035 3915 m 1710 3915 l gs col-1 s gr gr + +% arrowhead +n 1563 3885 m 1683 3915 l 1563 3945 l 1563 3915 l 1563 3885 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +4848 5190 m 4968 5220 l 4848 5250 l 5010 5250 l 5010 5190 l cp clip +n 4635 5220 m 4995 5220 l gs col-1 s gr gr + +% arrowhead +n 4848 5190 m 4968 5220 l 4848 5250 l 4848 5220 l 4848 5190 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +4083 5190 m 4203 5220 l 4083 5250 l 4245 5250 l 4245 5190 l cp clip +n 3870 5220 m 4230 5220 l gs col-1 s gr gr + +% arrowhead +n 4083 5190 m 4203 5220 l 4083 5250 l 4083 5220 l 4083 5190 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +gs clippath +3765 348 m 3735 468 l 3705 348 l 3705 510 l 3765 510 l cp clip +n 3735 135 m 3735 495 l gs col-1 s gr gr + +% arrowhead +n 3765 348 m 3735 468 l 3705 348 l 3735 348 l 3765 348 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 3555 1395 m 3555 1935 l gs col-1 s gr +% Polyline +n 2925 1395 m 3825 1395 l gs col-1 s gr +% Polyline +n 2925 1665 m 3825 1665 l gs col-1 s gr +% Polyline +n 2925 1170 m 3825 1170 l 3825 1935 l 2925 1935 l cp gs col-1 s gr +% Polyline +n 2070 1395 m 2070 1935 l gs col-1 s gr +% Polyline +n 1440 1395 m 2340 1395 l gs col-1 s gr +% Polyline +n 1440 1665 m 2340 1665 l gs col-1 s gr +% Polyline +n 1440 1170 m 2340 1170 l 2340 1935 l 1440 1935 l cp gs col-1 s gr +% Polyline +n 180 6210 m 1170 6210 l gs col-1 s gr +% Polyline +n 180 6480 m 1170 6480 l gs col-1 s gr +% Polyline +n 180 6750 m 1170 6750 l gs col-1 s gr +% Polyline +n 180 7020 m 1170 7020 l gs col-1 s gr +% Polyline +n 900 6210 m 900 7425 l gs col-1 s gr +% Polyline +n 180 5985 m 1170 5985 l 1170 7425 l 180 7425 l cp gs col-1 s gr +% Polyline +gs clippath +3765 6333 m 3735 6453 l 3705 6333 l 3705 6495 l 3765 6495 l cp clip +n 3735 6120 m 3735 6480 l gs col-1 s gr gr + +% arrowhead +n 3765 6333 m 3735 6453 l 3705 6333 l 3735 6333 l 3765 6333 l cp gs 0.00 setgray ef gr col-1 s +% Polyline +n 3555 7380 m 3555 7920 l gs col-1 s gr +% Polyline +n 2925 7380 m 3825 7380 l gs col-1 s gr +% Polyline +n 2925 7650 m 3825 7650 l gs col-1 s gr +% Polyline +n 2925 7155 m 3825 7155 l 3825 7920 l 2925 7920 l cp gs col-1 s gr +% Polyline +n 2070 7380 m 2070 7920 l gs col-1 s gr +% Polyline +n 1440 7380 m 2340 7380 l gs col-1 s gr +% Polyline +n 1440 7650 m 2340 7650 l gs col-1 s gr +% Polyline +n 1440 7155 m 2340 7155 l 2340 7920 l 1440 7920 l cp gs col-1 s gr +% Polyline +n 2925 8325 m 3825 8325 l gs col-1 s gr +% Polyline +n 2925 8100 m 3825 8100 l 3825 8595 l 2925 8595 l cp gs col-1 s gr +% Polyline +n 3285 6480 m 4185 6480 l 4185 6975 l 3285 6975 l cp gs col-1 s gr +% Polyline +n 3285 6705 m 4185 6705 l gs col-1 s gr +% Polyline +n 1485 3015 m 2295 3015 l gs col-1 s gr +% Polyline +n 1485 3285 m 2295 3285 l gs col-1 s gr +% Polyline +n 1485 2790 m 2295 2790 l 2295 3555 l 1485 3555 l cp gs col-1 s gr +% Polyline +n 2970 3015 m 3780 3015 l gs col-1 s gr +% Polyline +n 2970 3285 m 3780 3285 l gs col-1 s gr +% Polyline +n 2970 2790 m 3780 2790 l 3780 3555 l 2970 3555 l cp gs col-1 s gr +% Polyline +n 1485 9000 m 2295 9000 l gs col-1 s gr +% Polyline +n 1485 9270 m 2295 9270 l gs col-1 s gr +% Polyline +n 1485 8775 m 2295 8775 l 2295 9540 l 1485 9540 l cp gs col-1 s gr +% Polyline +n 2970 9000 m 3780 9000 l gs col-1 s gr +% Polyline +n 2970 9270 m 3780 9270 l gs col-1 s gr +% Polyline +n 2970 8775 m 3780 8775 l 3780 9540 l 2970 9540 l cp gs col-1 s gr +% Open spline +gs clippath +2363 3284 m 2311 3171 l 2410 3246 l 2309 3120 l 2262 3157 l cp clip +n 2655.0 5670.0 m 2655.0 4635.0 l + 2655.0 4635.0 2655.0 3600.0 2475.0 3375.0 DrawSplineSection + 2295.0 3150.0 l gs col-1 s gr + gr + +% arrowhead +n 2363 3284 m 2311 3171 l 2410 3246 l 2387 3265 l 2363 3284 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3878 3263 m 3801 3166 l 3915 3216 l 3786 3117 l 3750 3165 l cp clip +n 4365.0 5220.0 m 4365.0 4410.0 l + 4365.0 4410.0 4365.0 3600.0 4072.5 3375.0 DrawSplineSection + 3780.0 3150.0 l gs col-1 s gr + gr + +% arrowhead +n 3878 3263 m 3801 3166 l 3915 3216 l 3897 3240 l 3878 3263 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +1577 4206 m 1684 4267 l 1560 4263 l 1716 4308 l 1733 4250 l cp clip +n 1035.0 4185.0 m 1215.0 4185.0 l + 1215.0 4185.0 1395.0 4185.0 1552.5 4230.0 DrawSplineSection + 1710.0 4275.0 l gs col-1 s gr + gr + +% arrowhead +n 1577 4206 m 1684 4267 l 1560 4263 l 1569 4235 l 1577 4206 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3455 4478 m 3533 4573 l 3419 4526 l 3549 4623 l 3585 4575 l cp clip +n 3330.0 4275.0 m 3352.5 4365.0 l + 3352.5 4365.0 3375.0 4455.0 3465.0 4522.5 DrawSplineSection + 3555.0 4590.0 l gs col-1 s gr + gr + +% arrowhead +n 3455 4478 m 3533 4573 l 3419 4526 l 3437 4502 l 3455 4478 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +711 3409 m 676 3528 l 651 3407 l 644 3569 l 704 3571 l cp clip +n 1016.0 890.0 m 1151.0 912.5 l + 1151.0 912.5 1286.0 935.0 1286.0 1407.5 DrawSplineSection + 1286.0 1407.5 1286.0 1880.0 993.5 2420.0 DrawSplineSection + 993.5 2420.0 701.0 2960.0 688.0 3257.5 DrawSplineSection + 675.0 3555.0 l gs col-1 s gr + gr + +% arrowhead +n 711 3409 m 676 3528 l 651 3407 l 681 3408 l 711 3409 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3453 105 m 3573 135 l 3453 165 l 3615 165 l 3615 105 l cp clip +n 1035.0 360.0 m 1215.0 270.0 l + 1215.0 270.0 1395.0 180.0 1912.5 157.5 DrawSplineSection + 1912.5 157.5 2430.0 135.0 3015.0 135.0 DrawSplineSection + 3600.0 135.0 l gs col-1 s gr + gr + +% arrowhead +n 3453 105 m 3573 135 l 3453 165 l 3453 135 l 3453 105 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +1270 533 m 1375 469 l 1312 575 l 1427 461 l 1384 418 l cp clip +n 1035.0 630.0 m 1147.5 607.5 l + 1147.5 607.5 1260.0 585.0 1327.5 517.5 DrawSplineSection + 1395.0 450.0 l gs col-1 s gr + gr + +% arrowhead +n 1270 533 m 1375 469 l 1312 575 l 1291 554 l 1270 533 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +1807 1045 m 1870 1150 l 1765 1087 l 1879 1202 l 1922 1159 l cp clip +n 1530.0 450.0 m 1552.5 652.5 l + 1552.5 652.5 1575.0 855.0 1732.5 1012.5 DrawSplineSection + 1890.0 1170.0 l gs col-1 s gr + gr + +% arrowhead +n 1807 1045 m 1870 1150 l 1765 1087 l 1786 1066 l 1807 1045 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3262 1071 m 3351 1156 l 3232 1123 l 3373 1203 l 3403 1151 l cp clip +n 2295.0 450.0 m 2362.5 697.5 l + 2362.5 697.5 2430.0 945.0 2745.0 967.5 DrawSplineSection + 2745.0 967.5 3060.0 990.0 3217.5 1080.0 DrawSplineSection + 3375.0 1170.0 l gs col-1 s gr + gr + +% arrowhead +n 3262 1071 m 3351 1156 l 3232 1123 l 3247 1097 l 3262 1071 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +2035 2076 m 1914 2102 l 2008 2022 l 1863 2095 l 1890 2149 l cp clip +n 2205.0 1530.0 m 2362.5 1530.0 l + 2362.5 1530.0 2520.0 1530.0 2520.0 1777.5 DrawSplineSection + 2520.0 1777.5 2520.0 2025.0 2295.0 2025.0 DrawSplineSection + 2295.0 2025.0 2070.0 2025.0 1980.0 2070.0 DrawSplineSection + 1890.0 2115.0 l gs col-1 s gr + gr + +% arrowhead +n 2035 2076 m 1914 2102 l 2008 2022 l 2021 2049 l 2035 2076 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +2029 2733 m 1912 2775 l 1996 2683 l 1861 2773 l 1894 2823 l cp clip +n 2205.0 1800.0 m 2407.5 1800.0 l + 2407.5 1800.0 2610.0 1800.0 2610.0 2047.5 DrawSplineSection + 2610.0 2047.5 2610.0 2295.0 2610.0 2497.5 DrawSplineSection + 2610.0 2497.5 2610.0 2700.0 2317.5 2700.0 DrawSplineSection + 2317.5 2700.0 2025.0 2700.0 1957.5 2745.0 DrawSplineSection + 1890.0 2790.0 l gs col-1 s gr + gr + +% arrowhead +n 2029 2733 m 1912 2775 l 1996 2683 l 2012 2708 l 2029 2733 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3520 2751 m 3399 2777 l 3493 2697 l 3348 2770 l 3375 2824 l cp clip +n 3690.0 1800.0 m 3892.5 1800.0 l + 3892.5 1800.0 4095.0 1800.0 4095.0 2047.5 DrawSplineSection + 4095.0 2047.5 4095.0 2295.0 4095.0 2497.5 DrawSplineSection + 4095.0 2497.5 4095.0 2700.0 3825.0 2700.0 DrawSplineSection + 3825.0 2700.0 3555.0 2700.0 3465.0 2745.0 DrawSplineSection + 3375.0 2790.0 l gs col-1 s gr + gr + +% arrowhead +n 3520 2751 m 3399 2777 l 3493 2697 l 3506 2724 l 3520 2751 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3520 2076 m 3399 2102 l 3493 2022 l 3348 2095 l 3375 2149 l cp clip +n 3690.0 1530.0 m 3847.5 1530.0 l + 3847.5 1530.0 4005.0 1530.0 4005.0 1777.5 DrawSplineSection + 4005.0 1777.5 4005.0 2025.0 3780.0 2025.0 DrawSplineSection + 3780.0 2025.0 3555.0 2025.0 3465.0 2070.0 DrawSplineSection + 3375.0 2115.0 l gs col-1 s gr + gr + +% arrowhead +n 3520 2076 m 3399 2102 l 3493 2022 l 3506 2049 l 3520 2076 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3453 6090 m 3573 6120 l 3453 6150 l 3615 6150 l 3615 6090 l cp clip +n 1035.0 6345.0 m 1215.0 6255.0 l + 1215.0 6255.0 1395.0 6165.0 1912.5 6142.5 DrawSplineSection + 1912.5 6142.5 2430.0 6120.0 3015.0 6120.0 DrawSplineSection + 3600.0 6120.0 l gs col-1 s gr + gr + +% arrowhead +n 3453 6090 m 3573 6120 l 3453 6150 l 3453 6120 l 3453 6090 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +1270 6518 m 1375 6454 l 1312 6560 l 1427 6446 l 1384 6403 l cp clip +n 1035.0 6615.0 m 1147.5 6592.5 l + 1147.5 6592.5 1260.0 6570.0 1327.5 6502.5 DrawSplineSection + 1395.0 6435.0 l gs col-1 s gr + gr + +% arrowhead +n 1270 6518 m 1375 6454 l 1312 6560 l 1291 6539 l 1270 6518 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +1807 7030 m 1870 7135 l 1765 7072 l 1879 7187 l 1922 7144 l cp clip +n 1530.0 6435.0 m 1552.5 6637.5 l + 1552.5 6637.5 1575.0 6840.0 1732.5 6997.5 DrawSplineSection + 1890.0 7155.0 l gs col-1 s gr + gr + +% arrowhead +n 1807 7030 m 1870 7135 l 1765 7072 l 1786 7051 l 1807 7030 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3262 7056 m 3351 7141 l 3232 7108 l 3373 7188 l 3403 7136 l cp clip +n 2295.0 6435.0 m 2362.5 6682.5 l + 2362.5 6682.5 2430.0 6930.0 2745.0 6952.5 DrawSplineSection + 2745.0 6952.5 3060.0 6975.0 3217.5 7065.0 DrawSplineSection + 3375.0 7155.0 l gs col-1 s gr + gr + +% arrowhead +n 3262 7056 m 3351 7141 l 3232 7108 l 3247 7082 l 3262 7056 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +2035 8061 m 1914 8087 l 2008 8007 l 1863 8080 l 1890 8134 l cp clip +n 2205.0 7515.0 m 2362.5 7515.0 l + 2362.5 7515.0 2520.0 7515.0 2520.0 7762.5 DrawSplineSection + 2520.0 7762.5 2520.0 8010.0 2295.0 8010.0 DrawSplineSection + 2295.0 8010.0 2070.0 8010.0 1980.0 8055.0 DrawSplineSection + 1890.0 8100.0 l gs col-1 s gr + gr + +% arrowhead +n 2035 8061 m 1914 8087 l 2008 8007 l 2021 8034 l 2035 8061 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +2029 8718 m 1912 8760 l 1996 8668 l 1861 8758 l 1894 8808 l cp clip +n 2205.0 7785.0 m 2407.5 7785.0 l + 2407.5 7785.0 2610.0 7785.0 2610.0 8032.5 DrawSplineSection + 2610.0 8032.5 2610.0 8280.0 2610.0 8482.5 DrawSplineSection + 2610.0 8482.5 2610.0 8685.0 2317.5 8685.0 DrawSplineSection + 2317.5 8685.0 2025.0 8685.0 1957.5 8730.0 DrawSplineSection + 1890.0 8775.0 l gs col-1 s gr + gr + +% arrowhead +n 2029 8718 m 1912 8760 l 1996 8668 l 2012 8693 l 2029 8718 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3520 8736 m 3399 8762 l 3493 8682 l 3348 8755 l 3375 8809 l cp clip +n 3690.0 7785.0 m 3892.5 7785.0 l + 3892.5 7785.0 4095.0 7785.0 4095.0 8032.5 DrawSplineSection + 4095.0 8032.5 4095.0 8280.0 4095.0 8482.5 DrawSplineSection + 4095.0 8482.5 4095.0 8685.0 3825.0 8685.0 DrawSplineSection + 3825.0 8685.0 3555.0 8685.0 3465.0 8730.0 DrawSplineSection + 3375.0 8775.0 l gs col-1 s gr + gr + +% arrowhead +n 3520 8736 m 3399 8762 l 3493 8682 l 3506 8709 l 3520 8736 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3520 8061 m 3399 8087 l 3493 8007 l 3348 8080 l 3375 8134 l cp clip +n 3690.0 7515.0 m 3847.5 7515.0 l + 3847.5 7515.0 4005.0 7515.0 4005.0 7762.5 DrawSplineSection + 4005.0 7762.5 4005.0 8010.0 3780.0 8010.0 DrawSplineSection + 3780.0 8010.0 3555.0 8010.0 3465.0 8055.0 DrawSplineSection + 3375.0 8100.0 l gs col-1 s gr + gr + +% arrowhead +n 3520 8061 m 3399 8087 l 3493 8007 l 3506 8034 l 3520 8061 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +3930 9145 m 3806 9131 l 3922 9085 l 3761 9107 l 3769 9167 l cp clip +n 5130.0 5220.0 m 5130.0 6930.0 l + 5130.0 6930.0 5130.0 8640.0 4950.0 8820.0 DrawSplineSection + 4950.0 8820.0 4770.0 9000.0 4275.0 9067.5 DrawSplineSection + 3780.0 9135.0 l gs col-1 s gr + gr + +% arrowhead +n 3930 9145 m 3806 9131 l 3922 9085 l 3926 9115 l 3930 9145 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +2444 9150 m 2321 9132 l 2438 9091 l 2277 9107 l 2283 9166 l cp clip +n 3420.0 5670.0 m 3217.5 6030.0 l + 3217.5 6030.0 3015.0 6390.0 2880.0 6750.0 DrawSplineSection + 2880.0 6750.0 2745.0 7110.0 2745.0 8100.0 DrawSplineSection + 2745.0 8100.0 2745.0 9090.0 2520.0 9112.5 DrawSplineSection + 2295.0 9135.0 l gs col-1 s gr + gr + +% arrowhead +n 2444 9150 m 2321 9132 l 2438 9091 l 2441 9120 l 2444 9150 l cp gs 0.00 setgray ef gr col-1 s +% Open spline +gs clippath +740 5850 m 681 5958 l 682 5835 l 642 5992 l 700 6007 l cp clip +n 1035.0 4455.0 m 1170.0 4455.0 l + 1170.0 4455.0 1305.0 4455.0 1282.5 4972.5 DrawSplineSection + 1282.5 4972.5 1260.0 5490.0 1012.5 5557.5 DrawSplineSection + 1012.5 5557.5 765.0 5625.0 720.0 5805.0 DrawSplineSection + 675.0 5985.0 l gs col-1 s gr + gr + +% arrowhead +n 740 5850 m 681 5958 l 682 5835 l 711 5842 l 740 5850 l cp gs 0.00 setgray ef gr col-1 s +/Times-Roman ff 150.00 scf sf +495 180 m +gs 1 -1 sc (Query) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 1170 m +gs 1 -1 sc 270.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +270 945 m +gs 1 -1 sc (qual) col-1 sh gr +/Times-Roman ff 150.00 scf sf +270 675 m +gs 1 -1 sc (targetlist) col-1 sh gr +/Times-Roman ff 150.00 scf sf +270 405 m +gs 1 -1 sc (rtable) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3240 1350 m +gs 1 -1 sc (TLE) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3015 1575 m +gs 1 -1 sc (resdom) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3015 1845 m +gs 1 -1 sc (expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1755 1350 m +gs 1 -1 sc (TLE) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1530 1575 m +gs 1 -1 sc (resdom) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1530 1845 m +gs 1 -1 sc (expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +495 6165 m +gs 1 -1 sc (Query) col-1 sh gr +/Times-Roman ff 150.00 scf sf +540 7155 m +gs 1 -1 sc 270.0 rot (. . .) col-1 sh gr +/Times-Roman ff 150.00 scf sf +270 6390 m +gs 1 -1 sc (rtable) col-1 sh gr +/Times-Roman ff 150.00 scf sf +270 6660 m +gs 1 -1 sc (targetlist) col-1 sh gr +/Times-Roman ff 150.00 scf sf +270 6930 m +gs 1 -1 sc (qual) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3240 7335 m +gs 1 -1 sc (TLE) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3015 7560 m +gs 1 -1 sc (resdom) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3015 7830 m +gs 1 -1 sc (expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1755 7335 m +gs 1 -1 sc (TLE) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1530 7560 m +gs 1 -1 sc (resdom) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1530 7830 m +gs 1 -1 sc (expr) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3150 8280 m +gs 1 -1 sc (Resdom) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3015 8505 m +gs 1 -1 sc (resname: C3) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3375 6885 m +gs 1 -1 sc (relname: "C") col-1 sh gr +/Times-Roman ff 150.00 scf sf +3600 6660 m +gs 1 -1 sc (RTE) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1620 2970 m +gs 1 -1 sc (VAR) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1575 3195 m +gs 1 -1 sc (varno: 1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1575 3480 m +gs 1 -1 sc (varattno: 1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3105 2970 m +gs 1 -1 sc (VAR) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3060 3195 m +gs 1 -1 sc (varno: 1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3060 3480 m +gs 1 -1 sc (varattno: 2) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1620 8955 m +gs 1 -1 sc (VAR) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1575 9180 m +gs 1 -1 sc (varno: 1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3105 8955 m +gs 1 -1 sc (VAR) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3060 9180 m +gs 1 -1 sc (varno: 1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +1575 9465 m +gs 1 -1 sc (varattno: 1) col-1 sh gr +/Times-Roman ff 150.00 scf sf +3060 9465 m +gs 1 -1 sc (varattno: 2) col-1 sh gr +showpage +$F2psEnd +rs +%%EndDocument + @endspecial 517 3325 a(Figure)12 b(3.14:)j(Data)e(structure)e(of)h +Fk(A)g Fo(\\)f Fk(C)16 b Ft(after)11 b(query)h(re)o(writing)p +eop +%%Page: 110 110 +110 109 bop 270 60 a Ft(110)57 b Fm(CHAPTER)14 b(3.)28 +b(POSTGRESQL)13 b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW) +270 234 y Ft(If)h(the)g(user')m(s)g(query)g(in)n(v)o(olv)o(es)h +Fp(union)f Ft(as)g(well)h(as)g Fp(intersect)f Ft(or)g +Fp(e)o(xcept)h Ft(there)e(will)h(be)h(more)f Fr(Query)270 +294 y Ft(nodes)f(of)f(the)h(form)f(sho)o(wn)g(in)h(\002gure)f(3.14.)16 +b(One)c(will)f(be)h(the)f(topmost)h(node)f(\(as)h(described)g(abo)o(v)o +(e\))270 354 y(and)j(the)g(others)g(will)f(be)h(collected)g(in)g(a)g +(list)g(which)f(is)i(attached)f(to)f(the)h(\002eld)g +Fr(unionClause)f Ft(of)270 413 y(the)k(topmost)f(node.)32 +b(\(The)18 b Fp(intersectClause)g Ft(\002elds)g(of)f(all)g +Fr(Query)h Ft(nodes)g(will)f(be)h(set)g(to)f Fr(NULL)270 +473 y Ft(because)c(the)o(y)g(are)f(no)g(longer)g(needed.\))270 +593 y(The)28 b(function)f Fr(pg)p 632 593 15 2 v 17 w(parse)p +799 593 V 18 w(and)p 907 593 V 17 w(plan\(\))g Ft(is)h(responsible)g +(for)e(in)n(v)o(oking)h(the)h(re)o(write)e(pro-)270 653 +y(cedure.)16 b(It)c(can)g(be)h(found)e(in)h(the)h(\002le)f +Fk(:)c(:)g(:)p Fr(/src/backend/tcop/postgres.c)p Ft(.)330 +845 y Fr(List)29 b(*)330 905 y(pg_parse_and_plan\(char)e +(*query_string,)i(Oid)g(*typev,)868 965 y(int)g(nargs,)868 +1024 y(QueryTreeList)f(**queryListP,)868 1084 y(CommandDest)g(dest\)) +330 1144 y({)1107 1204 y(.)1107 1264 y(.)1107 1323 y(.)390 +1383 y(/*)h(Rewrite)g(Union,)h(Intersect)e(and)i(Except)f(Queries)419 +1443 y(*)h(to)g(normal)f(Union)g(Queries)h(using)f(IN)h(and)f(NOT)419 +1503 y(*)h(IN)g(subselects)f(*/)390 1562 y +(if\(querytree->intersectClaus)o(e)e(!=)j(NIL\))390 1622 +y({)449 1682 y(querytree)f(=)h(Except_Intersect_Rewrite\(querytr)o +(ee\);)390 1742 y(})1107 1802 y(.)1107 1861 y(.)1107 +1921 y(.)330 1981 y(})270 2150 y Ft(Here)14 b(are)f(the)h(functions)f +(that)h(ha)o(v)o(e)g(been)g(added)g(to)g(perform)e(the)i(functionality) +e(described)i(abo)o(v)o(e.)270 2210 y(The)o(y)f(can)g(be)f(found)g(in)g +(the)g(\002le)g Fk(:)c(:)g(:)q Fr(/src/backend/rewrite/rewrite)o +(Handler.c)o Ft(.)345 2379 y Fo(\017)25 b Fr(Except)p +578 2379 V 17 w(Intersect)p 865 2379 V 17 w(Rewrite\(\))395 +2439 y Ft(Re)o(writes)19 b(queries)g(in)n(v)o(olving)f +Fp(union)h(clauses)p Ft(,)j Fp(intersect)d(clauses)h +Ft(and)f Fp(e)o(xcept)g(clauses)h Ft(to)395 2499 y(semantiacally)12 +b(equi)o(v)o(alent)f(queries)i(that)f(use)h Fr(IN)f Ft(and)g +Fr(NOT)30 b(IN)12 b Ft(subselects)i(instead.)395 2625 +y(The)23 b Fp(oper)o(ator)g(tr)n(ee)h Ft(is)f(attached)g(to)f +Fr(intersectClause)g Ft(\(see)h(rule)f Fr(SelectStmt)395 +2685 y Ft(abo)o(v)o(e\))f(of)f(the)h Fp(parsetr)n(ee)h +Ft(gi)o(v)o(en)f(as)g(an)g(ar)o(gument.)41 b(First)21 +b(we)g(sa)o(v)o(e)g(some)h(clauses)g(\(the)395 2745 y +Fr(sortClause)p Ft(,)j(the)e Fr(unique)29 b(flag)23 b +Ft(etc.\).)48 b(Then)23 b(we)h(translate)f(the)g Fp(oper)o(ator)g(tr)n +(ee)395 2804 y Ft(to)d(DNF)g(\()p Fp(Disjunctive)g(Normal)h(F)-5 +b(orm)p Ft(\))20 b(by)h Fr(cnfify\(\))p Ft(.)39 b(Note)20 +b(that)g Fr(cnfify\(\))g Ft(pro-)395 2864 y(duces)27 +b(CNF)g(b)o(ut)g(as)h(we)f(e)o(xchanged)h Fr(AND)f Ft(nodes)g(with)g +Fr(OR)g Ft(nodes)g(within)g(function)395 2924 y Fr(A)p +428 2924 V 17 w(Expr)p 565 2924 V 18 w(to)p 643 2924 +V 18 w(Expr\(\))17 b Ft(earlier)g(we)h(get)f(DNF)h(when)g(we)g(e)o +(xchange)g Fr(AND)f Ft(nodes)h(and)g Fr(OR)395 2984 y +Ft(nodes)c(again)g(in)g(the)g(result.)21 b(No)o(w)14 +b(we)h(create)f(a)g(ne)o(w)g(\(re)o(written\))e(query)i(by)g(e)o +(xamining)g(the)395 3044 y(ne)o(w)f Fp(oper)o(ator)i(tr)n(ee)f +Ft(which)g(is)g(in)g(DNF)f(no)o(w)m(.)20 b(F)o(or)13 +b(e)o(v)o(ery)h Fr(AND)f Ft(node)h(we)g(create)g(an)g(entry)f(in)395 +3103 y(the)e Fp(union)g(list)h Ft(and)g(for)f(e)o(v)o(ery)g +Fr(OR)h Ft(node)f(we)h(create)g(an)g Fr(IN)f Ft(subselect.)16 +b(\()p Fr(NOT)29 b(IN)12 b Ft(subselects)395 3163 y(are)i(created)g +(for)f Fr(OR)30 b(NOT)14 b Ft(nodes\).)21 b(The)14 b(\002rst)g(entry)g +(of)f(the)i Fp(union)e(list)h Ft(is)h(handed)f(back)g(b)o(ut)395 +3223 y(before)e(that)h(the)h(sa)o(v)o(ed)g(clauses)g(\()p +Fr(sortClause)e Ft(etc.\))18 b(are)13 b(restored)g(to)g(the)h(ne)o(w)f +(top)g(node.)395 3283 y(Note)d(that)g(the)g(ne)o(w)g(top)h(node)f(can)g +(dif)o(fer)f(from)h(the)g(one)g(of)g(the)g Fp(parsetr)n(ee)i +Ft(gi)o(v)o(en)e(as)h(ar)o(gument)395 3342 y(because)k(of)g(the)f +(translation)h(into)f(DNF)l(.)h(That')m(s)h(why)e(we)h(had)g(to)g(sa)o +(v)o(e)g(the)g Fr(sortClause)395 3402 y Ft(etc.)p eop +%%Page: 111 111 +111 110 bop 198 60 a Fm(3.8.)26 b(THE)13 b(REALIZA)-6 +b(TION)14 b(OF)e(UNION,)g(INTERSECT)i(AND)f(EXCEPT)327 +b Ft(111)382 234 y Fr(Query)30 b(*)382 294 y(Except_Intersect_Rewrite)e +(\(Query)h(*parsetree\))382 354 y({)1219 413 y(.)1219 +473 y(.)1219 533 y(.)442 593 y(/*)h(Save)f(some)h(fields,)f(to)g(be)h +(able)f(to)h(restore)f(them)472 653 y(*)h(to)f(the)h(resulting)f(top)g +(node)h(at)f(the)h(end)g(of)f(the)472 712 y(*)h(function)472 +772 y(*/)442 832 y(sortClause)f(=)h(parsetree->sortClause;)442 +892 y(uniqueFlag)f(=)h(parsetree->uniqueFlag;)442 951 +y(into)g(=)f(parsetree->into;)442 1011 y(isBinary)g(=)h +(parsetree->isBinary;)442 1071 y(isPortal)f(=)h(parsetree->isPortal;) +442 1191 y(/*)g(Transform)f(the)g(SelectStmt)g(nodes)g(into)h(Query)f +(nodes)472 1250 y(*)h(as)f(usually)h(done)f(by)h +(transformSelectStmt\(\))d(earlier.)472 1310 y(*)j(/)442 +1370 y(intersectClause)e(=)502 1430 y(\(List)h +(*\)intersect_tree_analyze\()741 1489 y(\(Node)g +(*\)parsetree->intersectClause,)741 1549 y(\(Node)g +(*\)lfirst\(parsetree->unionClause\),)741 1609 y(\(Node)g +(*\)parsetree\);)1219 1669 y(.)1219 1729 y(.)1219 1788 +y(.)442 1848 y(/*)h(Transform)f(the)g(operator)g(tree)h(to)f(DNF)h(*/) +442 1908 y(intersectClause)e(=)801 1968 y(cnfify\(\(Expr)g +(*\)intersectClause,)g(true\);)442 2027 y(/*)i(For)f(every)h(entry)f +(of)h(the)f(intersectClause)f(list)i(we)472 2087 y(*)g(generate)f(one)g +(entry)h(in)f(the)h(union_list)472 2147 y(*/)442 2207 +y(foreach\(intersect,)e(intersectClause\))442 2267 y({)502 +2326 y(/*)i(For)f(every)g(OR)h(we)g(create)f(an)h(IN)f(subselect)g(and) +532 2386 y(*)h(for)f(every)g(OR)h(NOT)g(we)f(create)g(a)h(NOT)g(IN)f +(subselect,)532 2446 y(*/)502 2506 y(intersect_list)f(=)i(NIL;)502 +2565 y(create_list\(\(Node)e(*\)lfirst\(intersect\),)861 +2625 y(&intersect_list\);)502 2685 y(/*)i(The)f(first)g(node)h(will)f +(become)g(the)h(Select)f(Query)532 2745 y(*)h(node,)f(all)g(other)h +(nodes)f(are)h(transformed)e(into)532 2804 y(*)i(subselects)e(under)i +(this)f(node!)532 2864 y(*/)502 2924 y(intersect_node)f(=)i(\(Query)f +(*\)lfirst\(intersect_list\);)502 2984 y(intersect_list)f(=)i +(lnext\(intersect_list\);)1219 3044 y(.)1219 3103 y(.)1219 +3163 y(.)502 3223 y(/*)g(Transform)e(all)i(remaining)f(nodes)g(into)h +(subselects)532 3283 y(*)g(and)f(add)h(them)f(to)h(the)f +(qualifications)g(of)g(the)532 3342 y(*)h(Select)f(Query)g(node)532 +3402 y(*/)p eop +%%Page: 112 112 +112 111 bop 270 60 a Ft(112)60 b Fm(CHAPTER)14 b(3.)25 +b(POSTGRESQL)13 b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW) +574 234 y Fr(while\(intersect_list)28 b(!=)h(NIL\))574 +294 y({)634 354 y(n)g(=)h(makeNode\(SubLink\);)634 473 +y(/*)f(Here)h(we)f(got)h(an)g(OR)f(so)h(transform)f(it)g(to)h(an)664 +533 y(*)f(IN)h(subselect)664 593 y(*/)634 653 y +(if\(IsA\(lfirst\(intersect_list)o(\),)d(Query\)\))634 +712 y({)1291 772 y(.)1291 832 y(.)1291 892 y(.)693 951 +y(n->subselect)i(=)h(lfirst\(intersect_list\);)693 1011 +y(op)g(=)g("=";)693 1071 y(n->subLinkType)f(=)h(ANY_SUBLINK;)693 +1131 y(n->useor)f(=)h(false;)634 1191 y(})634 1310 y(/*)f(Here)h(we)f +(got)h(an)g(OR)f(NOT)h(node)f(so)h(transform)664 1370 +y(*)f(it)h(to)g(a)f(NOT)h(IN)60 b(subselect)664 1430 +y(*/)634 1489 y(else)634 1549 y({)1291 1609 y(.)1291 +1669 y(.)1291 1729 y(.)693 1788 y(n->subselect)29 b(=)783 +1848 y(\(Node)g(*\)lfirst\(\(\(Expr)g(*\))962 1908 y +(lfirst\(intersect_list\)\)->args\);)693 1968 y(op)h(=)g("<>";)693 +2027 y(n->subLinkType)f(=)h(ALL_SUBLINK;)693 2087 y(n->useor)f(=)h +(true;)634 2147 y(})634 2267 y(/*)f(Prepare)g(the)h(lefthand)f(side)g +(of)h(the)g(Sublinks:)664 2326 y(*)f(All)h(the)f(entries)h(of)f(the)h +(targetlist)e(must)i(be)664 2386 y(*)f(\(IN\))h(or)f(must)h(not)f(be)h +(\(NOT)f(IN\))h(the)g(subselect)664 2446 y(*/)634 2506 +y(foreach\(elist,)e(intersect_node->targetList\))634 +2565 y({)693 2625 y(Node)239 b(*expr)29 b(=)h(lfirst\(elist\);)693 +2685 y(TargetEntry)f(*tent)g(=)h(\(TargetEntry)f(*\)expr;)693 +2804 y(n->lefthand)g(=)903 2864 y(lappend\(n->lefthand,)e +(tent->expr\);)634 2924 y(})634 3044 y(/*)i(The)h(first)f(arguments)g +(of)h(oper)f(also)h(have)f(to)h(be)664 3103 y(*)f(created)g(for)h(the)g +(sublink)f(\(they)g(are)g(the)h(same)664 3163 y(*)f(as)h(the)g +(lefthand)f(side!\))664 3223 y(*/)634 3283 y(left_expr)g(=)g +(n->lefthand;)634 3342 y(right_expr)f(=)783 3402 y(\(\(Query)h +(*\)\(n->subselect\)\)->targetList;)p eop +%%Page: 113 113 +113 112 bop 198 60 a Fm(3.8.)29 b(THE)13 b(REALIZA)-6 +b(TION)14 b(OF)e(UNION,)g(INTERSECT)i(AND)f(EXCEPT)324 +b Ft(113)562 234 y Fr(foreach\(elist,)28 b(left_expr\))562 +294 y({)621 354 y(Node)269 b(*lexpr)29 b(=)h(lfirst\(elist\);)621 +413 y(Node)269 b(*rexpr)29 b(=)h(lfirst\(right_expr\);)621 +473 y(TargetEntry)f(*tent)g(=)h(\(TargetEntry)f(*\))g(rexpr;)621 +533 y(Expr)269 b(*op_expr;)621 653 y(op_expr)30 b(=)f(make_op\(op,)g +(lexpr,)g(tent->expr\);)621 712 y(n->oper)h(=)f(lappend\(n->oper,)f +(op_expr\);)621 772 y(right_expr)h(=)h(lnext\(right_expr\);)562 +832 y(})562 951 y(/*)f(If)h(the)g(Select)f(Query)g(node)g(has)h +(aggregates)592 1011 y(*)f(in)h(use)g(add)f(all)h(the)f(subselects)g +(to)h(the)592 1071 y(*)f(HAVING)h(qual)f(else)g(to)h(the)g(WHERE)f +(qual)592 1131 y(*/)562 1191 y(if\(intersect_node->hasAggs)e(==)i +(false\))562 1250 y({)621 1310 y(AddQual\(intersect_node,)f(\(Node)h +(*\)n\);)562 1370 y(})562 1430 y(else)562 1489 y({)621 +1549 y(AddHavingQual\(intersect_node,)e(\(Node)i(*\)n\);)562 +1609 y(})562 1729 y(/*)g(Now)h(we)g(got)f(sublinks)g(*/)562 +1788 y(intersect_node->hasSubLinks)d(=)k(true;)562 1848 +y(intersect_list)e(=)i(lnext\(intersect_list\);)502 1908 +y(})502 1968 y(intersect_node->intersectClaus)o(e)d(=)j(NIL;)502 +2027 y(union_list)f(=)g(lappend\(union_list,)f(intersect_node\);)442 +2087 y(})442 2207 y(/*)i(The)f(first)h(entry)f(to)h(union_list)e(is)i +(our)472 2267 y(*)g(new)f(top)h(node)472 2326 y(*/)442 +2386 y(result)f(=)h(\(Query)f(*\)lfirst\(union_list\);)442 +2506 y(/*)h(attach)f(the)h(rest)f(to)h(unionClause)e(*/)442 +2565 y(result->unionClause)g(=)i(lnext\(union_list\);)442 +2685 y(/*)g(Attach)f(all)h(the)f(items)g(saved)h(in)f(the)472 +2745 y(*)h(beginning)f(of)g(the)h(function)f(*/)442 2804 +y(result->sortClause)f(=)i(sortClause;)442 2864 y(result->uniqueFlag)e +(=)i(uniqueFlag;)442 2924 y(result->into)f(=)g(into;)442 +2984 y(result->isPortal)f(=)i(isPortal;)442 3044 y(result->isBinary)e +(=)i(isBinary;)1219 3103 y(.)1219 3163 y(.)1219 3223 +y(.)442 3283 y(return)59 b(result;)382 3342 y(})p eop +%%Page: 114 114 +114 113 bop 270 60 a Ft(114)60 b Fm(CHAPTER)14 b(3.)25 +b(POSTGRESQL)13 b(FR)n(OM)f(THE)i(PR)n(OGRAMMER'S)f(POINT)f(OF)g(VIEW) +345 234 y Fo(\017)25 b Fr(create)p 578 234 15 2 v 17 +w(list\(\))395 294 y Ft(Create)19 b(a)h(list)g(of)f(nodes)h(that)f(are) +g(either)h Fr(Query)f Ft(nodes)h(or)f Fr(NOT)g Ft(nodes)h(follo)o(wed)e +(by)i(a)395 354 y Fr(Query)11 b Ft(node.)16 b(The)c Fp(tr)n(ee)h +Ft(gi)o(v)o(en)f(in)f Fr(ptr)h Ft(contains)g(at)g(least)h(one)f +Fp(non)f(ne)n(gated)h Fr(Query)g Ft(node.)395 413 y(This)h(node)f(is)h +(put)f(to)g(the)g(be)o(ginning)g(of)g(the)g(list.)454 +533 y Fr(void)30 b(create_list\(Node)e(*ptr,)962 593 +y(List)i(**intersect_list\))454 653 y({)514 712 y(List)g(*arg;)514 +832 y(if\(IsA\(ptr,Query\)\))514 892 y({)574 951 y(/*)g(The)f(non)h +(negated)f(node)g(is)h(attached)f(at)g(the)604 1011 y(*)h(beginning)e +(\(lcons\))i(*/)574 1071 y(*intersect_list)e(=)i(lcons\(ptr,)f +(*intersect_list\);)574 1131 y(return;)514 1191 y(})514 +1250 y(if\(IsA\(ptr,Expr\)\))514 1310 y({)574 1370 y(if\(\(\(Expr)g +(*\)ptr\)->opType)f(==)i(NOT_EXPR\))574 1430 y({)634 +1489 y(/*)f(negated)g(nodes)h(are)f(appended)g(to)h(the)664 +1549 y(*)f(end)h(\(lappend\))664 1609 y(*/)634 1669 y(*intersect_list)e +(=)843 1729 y(lappend\(*intersect_list,)f(ptr\);)634 +1788 y(return;)574 1848 y(})574 1908 y(else)574 1968 +y({)634 2027 y(foreach\(arg,)h(\(\(Expr)h(*\)ptr\)->args\))634 +2087 y({)693 2147 y(create_list\(lfirst\(arg\),)f(intersect_list\);)634 +2207 y(})634 2267 y(return;)574 2326 y(})574 2386 y(return;)514 +2446 y(})454 2506 y(})345 2625 y Fo(\017)d Fr(intersect)p +668 2625 V 16 w(tree)p 804 2625 V 18 w(analyze\(\))395 +2685 y Ft(The)32 b(nodes)h(gi)o(v)o(en)f(in)g Fr(tree)g +Ft(are)g(not)g(transformed)f(yet)h(so)g(process)h(them)f(using)395 +2745 y Fr(parse)p 548 2745 V 17 w(analyze\(\))p Ft(.)d(The)18 +b(node)f(gi)o(v)o(en)g(in)g Fr(first)p 1417 2745 V 18 +w(select)f Ft(has)i(already)f(been)g(pro-)395 2804 y(cessed,)e(so)f +(don')o(t)e(transform)h(it)g(again)g(b)o(ut)g(return)g(a)g(pointer)g +(to)g(the)h(already)f(processed)h(v)o(er)o(-)395 2864 +y(sion)e(gi)o(v)o(en)g(in)g Fr(parsetree)g Ft(instead.)454 +2984 y Fr(Node)30 b(*intersect_tree_analyze\(Node)c(*tree,)873 +3044 y(Node)j(*first_select,)f(Node)i(*parsetree\))454 +3103 y({)514 3163 y(Node)g(*result;)514 3223 y(List)g(*arg;)514 +3342 y(if\(IsA\(tree,)f(SelectStmt\)\))514 3402 y({)p +eop +%%Page: 115 115 +115 114 bop 198 60 a Fm(3.8.)29 b(THE)13 b(REALIZA)-6 +b(TION)14 b(OF)e(UNION,)g(INTERSECT)i(AND)f(EXCEPT)324 +b Ft(115)502 234 y Fr(QueryTreeList)28 b(*qtree;)502 +354 y(/*)i(If)f(we)h(get)f(to)h(the)g(tree)f(given)g(in)h(first_select) +532 413 y(*)g(return)f(parsetree)g(instead)g(of)g(performing)532 +473 y(*)h(parse_analyze\(\))e(*/)502 533 y(if\(tree)h(==)h +(first_select\))502 593 y({)562 653 y(result)f(=)h(parsetree;)502 +712 y(})502 772 y(else)502 832 y({)562 892 y(/*)f(transform)g(the)h +(unprocessed)e(Query)i(nodes)f(*/)562 951 y(qtree)g(=)711 +1011 y(parse_analyze\(lcons\(tree,)e(NIL\),)i(NULL\);)562 +1071 y(result)g(=)h(\(Node)f(*\)qtree->qtrees[0];)502 +1131 y(})442 1191 y(})442 1250 y(if\(IsA\(tree,Expr\)\))442 +1310 y({)502 1370 y(/*)h(Call)f(recursively)g(for)g(every)g(argument)g +(*/)532 1430 y(foreach\(arg,)f(\(\(Expr)i(*\)tree\)->args\))532 +1489 y({)592 1549 y(lfirst\(arg\))e(=)711 1609 y +(intersect_tree_analyze\(lfirst\(ar)o(g\),)1100 1669 +y(first_select,)g(parsetree\);)532 1729 y(})532 1788 +y(result)h(=)h(tree;)442 1848 y(})442 1908 y(return)f(result;)382 +1968 y(})p eop +%%Page: 116 116 +116 115 bop 270 633 a Fq(Summary)270 892 y Ft(PostgreSQL)14 +b(has)g(become)g(one)g(of)g(the)g(most)g(popular)f(non)h(commercial)g +(RDBMSs)h(in)e(the)i(UNIX)270 951 y(world.)27 b(It)16 +b(pro)o(vides)h(an)f(e)o(xtended)h(subset)g(of)f(the)h(SQL92)g +(standard)f(as)h(query)f(language,)i(allo)o(ws)270 1011 +y(concurrent)c(database)i(access,)h(pro)o(vides)e(a)h(huge)f(amount)f +(of)h(datatypes,)h(etc.)25 b(At)15 b(the)g(the)g(time)g(of)270 +1071 y(writing)9 b(this)i(document)e(the)i(implemented)e(part)h(of)g +(SQL92)g(in)g(PostgreSQL)g(lacked)g(two)f(important)270 +1131 y(features:)345 1230 y Fo(\017)25 b Ft(The)12 b +Fp(having)g(clause)h Ft(was)g(not)f(implemented.)345 +1330 y Fo(\017)25 b Ft(The)12 b(use)h(of)f Fp(e)o(xcept)h +Ft(and)f Fp(intersect)h Ft(statements)g(was)f(not)g(possible.)270 +1430 y(The)19 b(implementation)f(of)g(these)h(two)f(items)g(was)h(the)g +(moti)o(v)o(ation)e(for)h(the)g(whole)h(work.)33 b(When)270 +1489 y(I)22 b(started)g(to)g(implement)g(the)g(abo)o(v)o(e)h(mentioned) +e(features,)k(I)d(noticed)g(that)g(there)g(was)g(almost)270 +1549 y(no)g(documentation)e(on)i(the)g(internal)f(structure)g(of)g +(PostgreSQL)g(a)o(v)o(ailable)g(that)h(could)f(help)h(a)270 +1609 y(programmer)c(to)h(\002nd)g(his)h(way)f(in.)37 +b(So)20 b(I)f(decided)g(to)h(include)f(all)h(the)f(kno)o(wledge)g(I)g +(collected)270 1669 y(while)14 b(working)e(with)i(the)g(source)g(code)g +(into)f(this)h(document,)h(hoping)e(that)h(it)f(will)h(be)g(a)g(useful) +g(for)270 1729 y(an)o(y)19 b(ne)o(wcomer)f(who)h(wants)g(to)f(enhance)i +(PostgreSQL)e(etc.)35 b(Additionally)18 b(I)h(included)f(a)h(short)270 +1788 y(discussion)13 b(on)g(SQL)g(and)g(a)g(description)f(of)g +(PostgreSQL)-5 b(')m(s)14 b(features)e(\(like)g Fp(triggers)g +Ft(etc.\))17 b(and)12 b(ho)o(w)270 1848 y(the)o(y)g(can)h(be)g(used.) +270 1968 y(Chapter)24 b(1)h(discusses)h(the)f(theoretical)f +(\(mathematical\))f(background)h(of)h(relational)e(database)270 +2027 y(management)12 b(systems)h(\(RDBMSs\))g(ending)f(in)g(a)g(short)h +(description)e(of)h(SQL.)270 2147 y(Chapter)30 b(2)g(\002rst)g(gi)o(v)o +(es)g(an)h(o)o(v)o(ervie)o(w)e(of)h(ho)o(w)g(to)g(setup)g(and)g +(administrate)g(PostgreSQL.)270 2207 y(Ne)o(xt)15 b(some)g(of)f +(PostgreSQL)-5 b(')m(s)15 b(special)g(features)g(are)g(presented)f +(\(i.e.)23 b Fp(multiple)14 b(inheritance)p Ft(,)i Fp(user)270 +2267 y(de\002ned)c(data)g(types)p Ft(,)i Fp(rules)p Ft(,)f +Fp(triggers)p Ft(,)f(etc.\))k(using)c(a)h(lot)f(of)g(e)o(xamples.)270 +2386 y(Chapter)19 b(3)g(\002rst)g(gi)o(v)o(es)g(an)g(o)o(v)o(ervie)o(w) +g(on)g(the)g(internal)g(structure)f(of)h(PostgreSQL)g(and)g(presents) +270 2446 y(the)k(stages)g(and)g(data)f(structures)g(that)h(are)f(in)n +(v)o(olv)o(ed)h(whene)o(v)o(er)f(a)h(SQL)f(query)g(arri)o(v)o(es.)47 +b(The)270 2506 y Fp(parser)15 b(stage)p Ft(,)g(the)f +Fp(rule)h(system)h Ft(\(which)e(is)g(mainly)g(used)h(for)f(the)h +(implementation)e(of)h Fp(vie)o(ws)p Ft(\),)i(the)270 +2565 y Fp(planner/optimizer)f Ft(and)f(the)h Fp(e)o(xecutor)g +Ft(are)f(described)h(and)f(illustrated)g(by)h(a)f(lot)h(of)f +(\002gures.)22 b(After)270 2625 y(that)15 b(the)g(changes)h(necessary)g +(for)e(the)i(implementation)e(of)h(the)g(missing)g(features)g(\()p +Fp(having)g(clause)270 2685 y Ft(and)d Fp(e)o(xcept/intersect)p +Ft(\))h(are)f(presented)g(including)g(parts)g(of)g(the)g(added)h +(source)f(code.)1133 3552 y(116)p eop +%%Page: 117 117 +117 116 bop 198 633 a Fq(Bibliograph)n(y)198 892 y Ft([D)n(A)-6 +b(TE96])99 b(C.)15 b(J.)g(Date)f(with)g(H.)g(Darwen:)k +Fp(A)d(Guide)f(to)f(the)h(SQL)g(Standar)n(d)p Ft(,)h(F)o(ourth)e +(Edition,)505 951 y(Addison-W)l(esle)o(y)g(1996)198 1051 +y([ULL88])127 b(Jef)o(fre)o(y)12 b(D.)h(Ullman:)i Fp(Principles)e(of)f +(Database)h(and)f(Knowledge)g(-)g(Base)i(Systems)p Ft(,)505 +1111 y(V)-6 b(olume)12 b(1,)g(Computer)g(Science)h(Press)f(1988)198 +1210 y([D)n(A)-6 b(TE94])99 b(C.)23 b(J.)g(Date:)36 b +Fp(An)23 b(Intr)n(oduction)e(to)h(Database)g(Systems)p +Ft(,)k(V)-6 b(ol.)23 b(1,)i(6th)d(Edition,)505 1270 y(Addison-W)l(esle) +o(y)13 b(1994)198 1370 y([LOCK98])88 b(Thomas)23 b(Lockhart:)36 +b Fp(P)l(ostgr)n(eSQL)23 b(Pr)n(ogr)o(ammer')n(s)h(Guide)p +Ft(,)h(part)d(of)g(the)h(Post-)505 1430 y(greSQL)12 b(documentation.) +198 1529 y([ST)o(ON89])94 b(Michael)16 b(Stonebraker)d(et.)j(al.:)21 +b Fp(On)16 b(Rules,)h(Pr)n(ocedur)n(es,)h(Cac)o(hing)d(and)g(V)l(ie)o +(ws)i(in)505 1589 y(Data)12 b(Base)i(Systems)p Ft(.)1061 +3552 y(117)p eop +%%Trailer +end +userdict /end-hook known{end-hook}if +%%EOF