संबंधपरक बीजगणित में, हम पहले बाएं (बाहरी) जुड़ने की एक अनौपचारिक परिभाषा प्रदान करेंगे, और यह साबित करने के लिए आगे बढ़ेंगे कि इसका नाम बदलने, चयन, शामिल होने और प्रक्षेपण से अंतर पैदा हो सकता है, साथ ही साथ अंतर, चयन और संघ का निर्माण करने के लिए उपयोग किया जा सकता है। बाईं ओर का बाहरी जोड़। वास्तव में, हम इसे उल्टे क्रम में करते हुए समाप्त करेंगे: हम यह दिखाएंगे कि अंतरों का उपयोग करके बाएं जोड़ों का निर्माण कैसे किया जाता है, और फिर हम दिखाएँगे कि बाएँ जोड़ों का उपयोग करके अंतरों का निर्माण कैसे किया जाए।
चलो आरR और एसS स्कीमेता है ( आर ' , टी )(R′,T) और ( टी , एस ' )(T,S′) , क्रमशः, जहां आर 'R′ और एस 'S′ एक स्कीमा में विशेषताओं के सेट नहीं बल्कि अन्य हैं, और टीT सामान्य विशेषताएं का सेट है।
चलो डब्ल्यू = ( ε , ε , । । । , Ε )w=(ϵ,ϵ,...,ϵ) हो स्कीमा के लिए अशक्त टपल एस 'S′ । है यही कारण है, इसके बारे में प्रत्येक विशेषता के लिए सभी शून्य मान से मिलकर टपल है एस 'S′ । फिर, हम के रूप में इस प्रकार में शामिल होने के बाहरी छोड़ दिया परिभाषित करें: R LEFT JOIN Sसभी tuples के सेट है ( आर , टी , एस )(r,t,s) स्कीमा से संबंधित ( आर ' , टी , एस ' )(R′,T,S′) जहां ...
- ( आर , टी ) आर(r,t) में एक ट्यूपल है;R
- (ए) ( टी , एस ) एस या (बी) एस = डब्ल्यू की(t,s) एक उलझन है ;Ss=w
- अगर ( आर , टी , एस )(r,t,s) के लिए सेट में है रों ≠ डब्ल्यूs≠w , तो ( आर , टी , डब्ल्यू )(r,t,w) नहीं सेट में है।
उदाहरण: आरR का स्कीमा है ( ए 1 , ए 2 , ए 3 )(A1,A2,A3) , एसS का स्कीमा है ( ए 2 , ए 3 , ए 4 )(A2,A3,A4) , और हमारे पास आर = { ( 1 , 2 , 3 ) , ( 4 , 5 , 6 ) }R={(1,2,3),(4,5,6)} और एस = { ( 2 , 3 , 4 ), ( 2 , 3 , 6 ) } । द्वारा (1) और (2) हम मध्यवर्ती परिणाम { ( 1 , 2 , 3 , 4 ) , ( 1 , 2 , 3 , 6 ) , ( 1 , 2 , 3 , ϵ ) , ( 4 , 5 , 6) प्राप्त करते हैं। , ε ) } । द्वारा (3) हमें ( 1 , 2 ) निकालना होगाS={(2,3,4),(2,3,6)}{(1,2,3,4),(1,2,3,6),(1,2,3,ϵ),(4,5,6,ϵ)}, 3 , ε ) , हम (उदाहरण के लिए) के बाद से ( 1 , 2 , 3 , 4 ) और एस = 4 ≠ ε = डब्ल्यू । हम इस प्रकार के साथ छोड़ दिया जाता है { ( 1 , 2 , 3 , 4 ) , ( 1 , 2 , 3 , 6 ) , ( 4 , 5 , 6 , ε ) }(1,2,3,ϵ)(1,2,3,4)s=4≠ϵ=w{(1,2,3,4),(1,2,3,6),(4,5,6,ϵ)}बाईं ओर के लिए अपेक्षित परिणाम।
प्रमेय: R LEFT JOIN Sके बराबर है (R EQUIJOIN S) UNION ((((PROJECT_T R) DIFFERENCE (PROJECT_T S)) EQUIJOIN R) JOIN w)।
प्रमाण: (R EQUIJOIN S)हमें (1) और (2a) द्वारा आवश्यक सब कुछ देता है। हम दावा करते हैं कि ((((PROJECT_T R) DIFFERENCE (PROJECT_T S)) EQUIJOIN R) JOIN w)हमें (r, t, w)(2b) और (3) द्वारा आवश्यक फॉर्म का सब कुछ दिया गया है।
यह देखने के लिए, पहले ध्यान दें कि R(((PROJECT_T R) DIFFERENCE (PROJECT_T S)) EQUIJOIN R) में सभी tuples का सेट है , जिसके लिए S में संबंधित tuple नहीं है । यह देखने के लिए, यह ध्यान रखना चाहिए कि R और S (विशेषता सेट T ) में से सामान्य विशेषताओं को प्रोजेक्ट करके और अंतर लेते हुए, सभी को केवल और केवल उन ट्यूपल्स (स्कीमा टी के साथ ) के साथ छोड़ दिया जाता है जिन्हें R में दर्शाया गया है लेकिन एस नहीं । तक के साथ आर , हम सभी और केवल उन tuples की वसूली आर जिसमें विशेषताओं के लिए मान हैं टी जो में मौजूद हैं आर लेकिन नहीं में एसRSRSTTRSEQUIJOINRRTRS; namely, precisely the set of tuples we have so far claimed.
Next, notice that the schema of (((PROJECT_T R) DIFFERENCE (PROJECT_T S)) is the same as that of RR (namely, (R′,T)(R′,T)), while the schema of ww is S′S′. The JOIN operation is therefore a Cartesian product, we we get all tuples of the form (r,t,w)(r,t,w) where there is no (t,s)(t,s) in SS corresponding to (r,t)(r,t) in RR.
To see that this is precisely the set of tuples we needed to add to R EQUIJOIN S in order to construct R LEFT JOIN S, consider the following: by construction, (3) is satisfied, since R EQUIJOIN S cannot contain (r,t,s)(r,t,s) if ((((PROJECT_T R) DIFFERENCE (PROJECT_T S)) EQUIJOIN R) JOIN w) contains (r,t,w)(r,t,w) (if it did, then the second part's containing (r,t,w)(r,t,w) would be a contradiction); if we were to add another (r,t,w)(r,t,w) not in ((((PROJECT_T R) DIFFERENCE (PROJECT_T S)) EQUIJOIN R) JOIN w), then there would be a (t,s)(t,s) in SS corresponding to (r,t)(r,t) in RR, and by the definition of EQUIJOIN, (r,t,s)(r,t,s) would also be in R LEFT JOIN S, a contradiction of (3). This completes the proof.
Now we show that left join can be used to construct difference:
Theorem: R DIFFERENCE S is equivalent to PROJECT_T(SELECT_{t'=w}(R LEFT JOIN (SELECT_{s=s'}(((S JOIN RENAME_{T->T'}(S)))))))
Proof: Notice that here, R′R′ and S′S′ are empty, since all attributes are shared for DIFFERENCE to make sense. First, we create a new relation from SS by duplicating the attribute set in SS (handled by RENAME and JOIN) so that it consists of tuples (t,t′)(t,t′) on attribute set (T,T′)(T,T′) where t=t′t=t′ (handled by the SELECT). The left join leaves us with tuples of the form (t,t′)(t,t′) where t=t′t=t′ or t′=wt′=w. Now, to get rid of entries which do also appear in SS, we must keep only the tuples of the form (t,w)(t,w), which is handled by the outermost SELECT. The last PROJECT gets rid of the temporary attribute set T′T′ and leaves us with the difference in terms of the original schema.
Example: Let R={(1,2),(3,4),(5,6)}R={(1,2),(3,4),(5,6)} and S={(3,4),(5,6),(7,8)}S={(3,4),(5,6),(7,8)}. We first get SS with the RENAMEd attribute set T′T′: {(3,4),(5,6),(7,8)}{(3,4),(5,6),(7,8)}. The JOIN operation gives us the Cartesian product with all nine possible pairings; this set is not written here for reasons of formatting. The SELECT then pares this down to {(3,4,3,4),(5,6,5,6),(7,8,7,8)}{(3,4,3,4),(5,6,5,6),(7,8,7,8)}. The LEFT JOIN with RR gives {(1,2,ϵ,ϵ),(3,4,3,4),(5,6,5,6)}{(1,2,ϵ,ϵ),(3,4,3,4),(5,6,5,6)}. The SELECT gives {(1,2,ϵ,ϵ)}{(1,2,ϵ,ϵ)}. The PROJECT gives {(1,2)}{(1,2)}, the desired answer.