Page 217 - DCAP402_DCAO204_DATABASE MANAGEMENT SYSTEM_MANAGING DATABASE
P. 217

Database Management Systems/Managing Database




                    Notes          12.5 Evaluation of Expression

                                   Before we discuss the evaluation of a query expression, let us briefly explain how a SQL query
                                   may be represented. Consider the following student and marks relations:

                                          STUDENT (enrolno, name, phone)
                                          MARKS (enrolno, subjectcode, grade)
                                   To find the results of the student(s) whose phone number is ‘1129250025’, the following query
                                   may be given.
                                          SELECT enrolno, name, subjectcode, grade
                                          FROM STUDENT s, MARKS m

                                          WEHRE s.enrolno=m.enrolno AND phone= ’1129250025’
                                   The equivalent relational algebraic query for this will be:
                                                                               
                                                         (           (STUDENT)  MARKS)
                                            enrolno, name, subjectcode   phone=’1129250025’
                                   This is a very good internal representation however, it may be a good idea to represent the
                                   relational algebraic expression to a query tree on which algorithms for query optimisation can
                                   be designed easily. In a query tree, nodes are the operators and relations represent the leaf. The
                                   query tree for the relational expression above would be:
                                                           Figure  12.5: A  Sample Query  Tree





















                                   In the previous section, we have seen the algorithms for individual operations. Now let us look
                                   at the methods for evaluating an entire expression. In general we use two methods:
                                   1.  Materialisation
                                   2.  Pipelining.

                                   Materialisation

                                   Evaluate a relational  algebraic expression  from the  bottom-up, by explicitly generating  and
                                   storing the results of each operation in the expression. For example, in Figure 12.5 compute and
                                   store the result of the selection operation on STUDENT relation, then take the join of this result
                                   with MARKS relation and then finally compile the projection operation.
                                   Materialised evaluation is always possible though; the cost of writing/reading results to/from
                                   disk can be quite high.




          210                               LOVELY PROFESSIONAL UNIVERSITY
   212   213   214   215   216   217   218   219   220   221   222