The Wayback Machine - https://web.archive.org/web/20240710040004/https://www.geeksforgeeks.org/relational-query-evaluation-set-2/
Open In App

Relational Query Evaluation | Set 2

Last Updated : 14 Jul, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

Prerequisite – Relational Query Evaluation | Set 1
Data is stored in disks. Disks are then manipulated using read and write methods. More number of manipulations, lesser number of disks would be failing. To overcome this and to increase life of disks we want to optimize disks used by ensuring fact that we minimize read and write operations using disks.

  1. Projection Operation –
    This operation involves selection of attributes from record. This operation is costly one. For carrying out projection operation, every record in file needs to be scanned to formulate resulting record. Duplicate records in resulting record need to be eliminated using sort or hash-based functions. It is essential to do entire file scan in case of using projection operation. A cost-friendly method would involve using projection operations only after selection operations. This is because there would be fewer records after selection is done and then, projection operation can occur involving lesser cost, lesser read and write operations and more life of disks.


  2. Sorting –
    Sorting is very commonly applied operation. It has its usage in removing duplicate elements, record grouping, joining, etc. External sorting involves huge files present on disk. We can arrange files in increasing or decreasing order of records. We use merge sort for these operations. The merge sort involves 2 phases, namely, sort phase and merge phase. Use of sort phase is in creation of sub-files which are sorted is prevalent. These sorted sub-files are also known as runs. The merge phase is known for merging the sub-files to eventually create one sorted file.

Assumption :
The assumption is that data is very huge and it is stored in n number of blocks and memory (m blocks) is much smaller than data. The next steps that would be involved are reading m blocks, sorting it in memory and then writing to disk as single file called run.
These steps are to be repeated –

(n / m) number of times 

Take, ceiling value whenever value is not integer.

Complexity :

(2*n) times block access

We can say that creation of “r” number of sub-files has taken place, each of which is sorted. Buffer space being only m blocks, we can operate on only m blocks at time. Then, move operated part to memory and operate on next blocks (at max m blocks at a time).



Previous Article
Next Article

Similar Reads

Relational Query Evaluation | Set 1
There is a need for conversion of relational query to algebraic expressions. This expression is operated on so that final output is received. The relational algebra operators that are present are Union, Select, Join, Project, etc. These are used to formulate relational query for adequate results. Grouping, partitioning and aggregation are all parts
3 min read
Difference between Relational Algebra and Relational Calculus
Both Relational Algebra and Relational Calculus are formal query languages. Relational Algebra: Relational Algebra is a procedural language. In Relational Algebra, The order is specified in which the operations have to be performed. In Relational Algebra, frameworks are created to implement the queries. The basic operation included in relational al
3 min read
Difference between Tuple Relational Calculus (TRC) and Domain Relational Calculus (DRC)
1. Tuple Relational Calculus (TRC) : A tuple relational calculus is a non-procedural query language that specifies to select of the tuples in a relation. It can select the tuples with a range of values or tuples for certain attribute values etc. The resulting relation can have one or more tuples. Notation : {T | P (T)} or {T | Condition (T)} where
3 min read
Query-Evaluation Plan in SQL
Pre requisites: Query Execution Engine in SQL, Query-Execution Plan in SQL In this article, we will see about Query Evaluation Plan in SQL and how the system optimizes the given query. Basically, Query Processing in SQL is extracting data from the datasets. There are various steps involved like Parsing and translation, Optimization, and Query Evalu
2 min read
Deductive Database Semantics and Query Evaluation
Pre-requisites: What is a Database? We classify the relation in Datalog Program or deductive database as either output relation or input relation. output relations are defined by rules and input relations have a set of tuples explicitly listed (e.g. assembly) given the instance of the input relation we must compute instances for the output relation
3 min read
Relational Query Language in DBMS
SQL has its own querying methods to interact with the database. But how do these queries work in the database? These queries work similarly to Relational Algebra that we study in mathematics. In the database, we have tables participating in relational Algebra. Relational Database systems are expected to be equipped with a query language that assist
4 min read
Query Optimization in Relational Algebra
Query: A query is a request for information from a database. Query Plans: A query plan (or query execution plan) is an ordered set of steps used to access data in a SQL relational database management system. Query Optimization: A single query can be executed through different algorithms or re-written in different forms and structures. Hence, the qu
10 min read
Query Tree in Relational Algebra
A Query Tree is a data structure used for the internal representation of a query in RDBMS. It is also known as the Query Evaluation/Execution Tree. The leaf nodes of the query tree represent the relations, and the internal nodes are the relational algebra operators like SELECT (σ), JOIN (⋈), etc. The root node gives the output of the query on execu
4 min read
Set Difference Operator in Relational Algebra
Relational Algebra is used to play with the data stored in relational databases. Relational Algebra has many operations to play with tables. One of the fundamental operations is set difference. This article will discuss Set Difference, its condition, and its examples. Key Terms Used in Set Difference Operator Relation- In Relational Algebra 'Table'
4 min read
Set Theory Operations in Relational Algebra
Relational Algebra in DBMS These Set Theory operations are the standard mathematical operations on set. These operations are Binary operations that are, operated on 2 relations unlike PROJECT, SELECT and RENAME operations. These operations are used to merge 2 sets in various ways. The set operation is mainly categorized into the following: Union op
3 min read
Article Tags :