How RDBMS compute Where Clause | RDBMS Implementation in C from Scratch

Published: 15 August 2023
on channel: CSE Practicals
72
3

So, How RDBMS compute Where Clause of SQL Queries ?

select blah, blah... from table where salary less than 10000 and dept = 'R&D' or salary greater than 20000 and dept = 'HR';

STEPS :

Step1 :
Isolate the conditions from the Where expressions :
C1 = salary less than 100000
C2 = dept = 'R&D'
C3 = salary greater than 20000
C4 = dept = 'HR';
So, Expression becomes : C1 && C2 || C3 && C4

Step 2 : Now, Convert infix to Postfix, expression becomes :

C1 C2 && C3 C4 && ||

( considering && has higher precedence over || , and consider conditions as Variables and && and || as operators )

Step 3 : Now from postfix expression, construct Expression Tree. ( There is a standard algorithm to do this )

Expression Tree

||
/ \
&& &&
/ \ / \
C1 C2 C3 C4

Step 4: Write a function which can compute individual unit of conditions like below. Pass C1, C2... to this function. Ofcourse variable values ( eg salary) need to be fetched from DBMS current record which is being evaluated.

bool
compute_where (condition C) ;

Step 5 :
Parse the expression tree using DFS algorithm and compute the final boolean result. Depending on the result, eliminate the records as soon as they are read from Database. Where Caluse should be executed as close as possible to the data source.

Same technique is applied to evaluate Mathematical expressions - (2 + 3 * 5 )

Watch github dev : https://lnkd.in/g_AGM4rz
Join Telegram grp of 1000 Exp enginners : https://lnkd.in/gy93YX9
youtube channel : https://lnkd.in/gT2c6Yq2

Visit https://csepracticals.com/ for more courses and Projects.


Watch video How RDBMS compute Where Clause | RDBMS Implementation in C from Scratch online, duration hours minute second in high quality that is uploaded to the channel CSE Practicals 15 August 2023. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 72 times and liked it 3 visitors.