You are on page 1of 3

DBMS DA - 2

REG NO: 18BCE0341


NAME: K. RAKSHA

QUERY TREE AND QUERY GRAPH

WHAT IS QUERY TREE?

Query tree is a tree data structure that is used to represent relational


algebra expressions. Query tree input relations are represented the leaf
nodes and relational algebra operations as the internal nodes. The
result is at the root node.

HOW IS QUERY TREE EXECUTED?

When the query tree is executed-

1. First the internal node operation is executed, whenever its operands


are available.

2. Then the internal node is replaced by the relation resulted after the
execution of the operations.

3. The execution terminates when the root is executed and the result
of the query is produced.

EXAMPLE:

Consider the following query:

SELECT S.sid, COUNT(*) AS numres


FROM Boats B, Reserves R, Sailors S
WHERE R.sid = S.sid AND B.bid=R.bid AND Rcolor = 'red'
GROUP BY S.sid

DIAGRAM

Hence the query tree for the above query is given as below.

WHAT IS QUERY GRAPH?

A more natural representation of a query is called query graph.

Graph queries, for the most part, attempt to identify an explicit pattern
within the graph database. Graph queries have an expressive power to
return something at the level of an analytic in a normal data processing
system. And to be fair, many analytics that you find in the normal world
are really just good SQL queries, so this makes sense. What graph
queries usually do is find a known subset of the important nodes in the
graph haystack.

EXAMPLE

Consider the following query:

SELECT CNUMBER,DNUM, LNAME, ADDRESS, BDATE

FROM COURSE, DEPARTMENT, FACULTY

WHERE DNUM=DNUMBER AND FACULTYID = ID AND


CNAME=‘DBMS’

DIAGRAM

Hence the diagram is given as below-

[C.CNUM,C.CNUM]
[F.LNAME,F.ADDRESS,F.BDATE]

C D F
C.DNUM=D.DNUMBER D.ID=F.ID

C.NAME=‘DBMS’

DBMS

THANK YOU.

You might also like