Download Final Report - Chair of Software Engineering

Transcript
• intersection of two results (at line 11)
• subtraction between two sets (at line 17)
Evaluation of a simple item
The evaluation of a simple item can be easily mapped to a SELECT SQL statement of the form:
SELECT DISTINCT <field> FROM <index table> WHERE ‘key‘="<value>"
An exception is made for the prefix items. These items need pattern matching
in order to find out if a key has some value as prefix. The mapping for them is:
SELECT DISTINCT <field> FROM <table> WHERE ‘key‘ LIKE("<value>%")
Queries of this type very efficient (execution time around 0.2 seconds).
Union of two results
The union operation is already part of SQL. If we want to merge tables q1 and
q2 we can perform the following statement:
(SELECT <field> FROM q1) UNION (SELECT <field> FROM q2)
The result contains no duplicate entries: rows that appear both in q1 and q2
appear only once in the result. Query of these type are efficient, they usually
have an execution time smaller than 0.5 seconds.
Intersection of two results
The intersection of two result sets can be mapped to another SELECT SQL
statement. Let’s assume the two sets are stored in tables q1 and q2 and these
tables contains some message id field to identify the messages called “mid”. The
intersection of these two table can be done with the following statement:
SELECT DISTINCT q1.mid FROM q1,q2 WHERE q1.mid = q2.mid
The execution of this type of queries is not too efficient for huge sets, in order to
achieve a good performance we need to avoid them if it is possible or to reduce
the size of the two sets.
Subtraction of two results
The subtraction of two result sets is done by removing from the first set everything which belongs to the second set. This operation can be mapped to a
DELETE statement. Let’s assume that we want to subtract the content of table
q2 from table q1 and these tables contains some message id field to identify the
messages called “mid”. The subtraction is then done whit the following statement:
DELETE q1 FROM q1,q2 WHERE q1.mid = q2.mid
42