Relational operations Algebra (select, project, union, intersection, rename)

Relational algebra database filtering और combining operations के लिए mathematical blueprints देता है, tables पर logical filters की एक श्रृंखला के रूप में काम करते हुए।

12 min read · 12 cards · 3 checks

Read in: English · हिन्दी · ગુજરાતી


Theory

Digital Needle की खोज

कल्पना कीजिए आपका university database हर semester, stream, और campus city में दस हज़ार से ज़्यादा active student records वाला एक अकेला master spreadsheet store करता है। अगर एक faculty advisor को जल्दी केवल उन Semester 2 BCA students के email addresses देखने हैं जिन्होंने programming labs में अस्सी प्रतिशत से ज़्यादा score किया, system उस बिल्कुल chunk को कैसे fetch करता है बिना एक इंसान को हर row और column पढ़वाए? आप जो हर SQL query लिखते हैं, उसके पीछे एक अदृश्य mathematical engine equations चलाकर tables को काटता, slice करता, और मिलाता है। ये operators एक शुद्ध mathematical स्तर पर कैसे काम करते हैं?

Theory

Kitchen Sieve बनाम Vertical Veggie Chopper

relational algebra operators को एक व्यस्त college hostel kitchen के अंदर tools की तरह सोचिए। एक Selection चलाना एक बारीक wire mesh sieve से mixed दालें डालने जैसा है: यह केवल आपके बिल्कुल horizontal size criteria से मेल खाते items रखता है, बाक़ी rows हटाते हुए। एक Projection चलाना एक बड़ा cleaver लेकर vertically काटने जैसा है, केवल आपकी चाही vegetable lanes अलग करते हुए (जैसे केवल potato column रखना जबकि onions और carrots फेंक देना)। जब आप उन्हें जोड़ते हैं, आपको बिल्कुल वे टुकड़े मिलते हैं जो आपको चाहिए बिना memory बर्बाद किए!

Theory

पाँच प्राथमिक Mathematical Blueprints

relational database theory में, Relational Algebra एक procedural query language है जो एक या ज़्यादा relations को inputs के रूप में लेती है और output के रूप में एक बिल्कुल नई relation बनाती है। पाँच foundational operations इस mathematical system का आधार बनाती हैं: Selection (σ) एक condition के आधार पर rows filter करता है; Projection (π) ख़ास vertical columns अलग करता है; Union (∪) दो compatible tables से records merge करता है; Intersection (∩) केवल दोनों tables में मौजूद rows निकालता है; और Rename (ρ) ambiguity रोकने के लिए table या column label titles बदलता है।

At a glance

Table 1: Relational Algebra के foundational operators और उनके mathematical focus axes।

Algebraic OperatorSymbol UsedStructural Axis FocusExam Notation Example
Selectionσ (Sigma)Horizontal (Row Subsets filter करता है)σ marks > 80 (STUDENTS)
Projectionπ (Pi)Vertical (Column Attributes filter करता है)π roll_no, email (STUDENTS)
Union∪ (Union)मेल खाती rows vertically जोड़ता हैCLASS_A ∪ CLASS_B
Intersection∩ (Intersection)duplicate shared rows निकालता हैLAB_ATTEND ∩ LECTURE_ATTEND
Renameρ (Rho)Metadata alias modificationρ NEW_LIST (STUDENTS)

Theory

Worked Example: Lab Attendance को Filter करना

आइए एक exam-style challenge कदम-दर-कदम हल करें। हमारे पास MARKS नामक एक input relation है जिसमें columns हैं: Roll, Sub, और Score। हमारा काम केवल वे Roll identifiers निकालना है जहाँ Sub बिल्कुल 'BCA204' है और Score 75 से बड़ा या बराबर है। आइए operational execution का क्रम नक़्शा बनाएँ।

Follow along

Query Synthesis Pipeline

  1. Step 1: पहले Rows Filter करें target tuples अलग करने के लिए Sigma इस्तेमाल करके horizontal row selection criteria लागू करें: σ Sub = 'BCA204' ∧ Score ≥ 75 (MARKS)।
  2. Step 2: Targeted Column अलग करें केवल roll column पकड़ने के लिए selection statement को Pi इस्तेमाल करके एक vertical projection में लपेटें: π Roll ( σ Sub = 'BCA204' ∧ Score ≥ 75 (MARKS) )।
  3. Step 3: Output Invariant मूल्यांकन database processing memory बचाने के लिए पहले inner filter evaluate करता है, केवल मेल खाते student IDs रखता एक साफ़ tabular sequence return करते हुए।

Think first

Mental Check: Set Union नियम

मान लीजिए Table X में 3 rows हैं और Table Y में 3 rows। अगर आप relational algebra expression X ∪ Y compute करते हैं, परिणामी output table में rows की अधिकतम और न्यूनतम संभावित संख्या क्या है?

Show the answer

अधिकतम संभव rows 6 हैं (अगर दोनों tables के बीच शून्य एक जैसी rows हैं)। न्यूनतम संभव rows 3 हैं (अगर Table X और Table Y में बिल्कुल एक जैसे duplicate records हैं)। क्यों? क्योंकि relational algebra सख़्ती से शुद्ध mathematical sets पर काम करता है, यानी duplicate records हमेशा एक Union output से अपने-आप हटा दिए जाते हैं!

Quiz

दो अलग relational database tables के बीच एक Union (∪) या Intersection (∩) operation सुरक्षित रूप से करने से पहले कौन सी संरचनात्मक condition पूरी तरह संतुष्ट होनी चाहिए?

  1. दोनों tables में बिल्कुल एक जैसी horizontal row records की संख्या होनी चाहिए।
  2. दोनों tables Union Compatible होनी चाहिए, यानी वे क्रम में मेल खाते domain data types के साथ एक जैसी columns की संख्या साझा करती हों।
  3. एक table में केवल string data होना चाहिए, जबकि दूसरी में केवल integers।
  4. tables को एक ही physical SSD storage partition block पर save होना चाहिए।
Show the answer

दोनों tables Union Compatible होनी चाहिए, यानी वे क्रम में मेल खाते domain data types के साथ एक जैसी columns की संख्या साझा करती हों।

rows को सुरक्षित रूप से blend या intersect करने के लिए, tables Union Compatible होनी चाहिए। इसका मतलब उनमें attributes की बिल्कुल एक जैसी count होनी चाहिए, और adjacent vertical columns को मेल खाते compatible data domains (types) साझा करने चाहिए ताकि rows seamlessly align हों।

Quiz

अगर आप 50 student records वाली एक table पर एक Projection operation π name (STUDENTS) करते हैं जहाँ 5 students duplicate नाम 'Amit Sharma' साझा करते हैं, कितनी rows return होंगी?

  1. 50 rows, सारे duplicate नाम समेत।
  2. केवल 5 rows।
  3. 46 rows, क्योंकि set theory परिभाषाओं द्वारा duplicate values अपने-आप हटा दी जाती हैं।
  4. यह एक UnionCompatibilityException error फेंकता है।
Show the answer

46 rows, क्योंकि set theory परिभाषाओं द्वारा duplicate values अपने-आप हटा दी जाती हैं।

mathematical relational algebra में, एक relation सख़्ती से unique tuples के एक set के रूप में परिभाषित है। जब आप केवल 'name' column project करते हैं, 'Amit Sharma' के सारे duplicate instances एक अकेली unique value में सिमट जाते हैं, कुल 46 rows return करते हुए।

Watch out

Classic जाल: Symbol Confusion की चूक

semester exams में सबसे आम marks-गँवाने वाली ग़लती selection और projection के लिए symbols अदल-बदल करना है। students selection के लिए Pi (π) लिखते हैं क्योंकि यह rows 'picking' के लिए एक 'P' जैसा दिखता है, और projection के लिए Sigma (σ) क्योंकि यह column 'subsets' के लिए एक 'S' जैसा दिखता है। याद रखिए: σ का मतलब Selection (rows), और π का मतलब Projection (columns)। इस layout mapping पर आसान marks मत खोइए!

Theory

Math को Semester 3 से जोड़ना

Relational algebra formulas असली दुनिया के tools के internal compilation engine के रूप में काम करते हैं। Semester 3 Database Systems (BCA301) और Query Optimization modules में, आप देखेंगे कि database parsers आपकी raw SQL commands (SELECT और WHERE) को production servers पर बिजली-तेज़ lookups execute करने के लिए सीधे optimized algebraic trees में कैसे बदलते हैं।

Summary

Key takeaways

  • Relational algebra relational database query execution के लिए अंतर्निहित procedural language बनाता है।
  • Selection एक logical condition से मेल खाते horizontal row subsets निकालने के लिए Sigma symbol इस्तेमाल करता है।
  • Projection अलग vertical columns अलग करने के लिए Pi symbol इस्तेमाल करता है, ग़ैर-ज़रूरी fields हटाते हुए।
  • Union और Intersection operations दोनों target inputs के बीच सख़्त union compatibility की माँग करते हैं।
  • हर operator mathematical sets process करता है, यानी duplicate entries outputs से हटा दी जाती हैं।
  • Memory Hook: Sigma rows select करता है, Pi columns project करता है, और sets कभी duplicates नहीं रखते!

Study this properly

This page is the lesson to read. In Gri-Learn the same topic is a graded deck: the self-checks are scored and your weak topics are tracked. Free to start.

Start this topic

Already have an account? Sign in

More from Introduction of Relational Model

Gri-Learn · syllabus-mapped B.C.A. lessons in English, Hindi and Gujarati