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 of relational query.
Implementation :
Selection of proper algorithms is necessary to optimize life and performance of disks, where data is stored. If lot of read and write operations are performed (data modification and updation) on disk, its life is reduced due to wear and tear.
Selection Operator :
- One Selection Condition - In case we need to use select operator for selecting particular tuples of relation based on condition, following things can be done. If there is only one selection condition, then we need to check for presence of indexes. If indexes are present on attribute, we can easily find selection based on these indexes as indexes provide record and block pointers that can be used in searching. For any reason, if indexes are absent, then entire file needs to be searched for selection.
- Multiple Conjunctive Selection Condition - In the case of multiple conjunctive selection condition, if none of attributes have any index, complete file scan needs to be done for selection of relevant tuples. However, if any of attributes do have index, then we need to go to relevant attribute and select tuples whose values for attribute are equivalent to given condition, and then in those records, other conjunctive conditions can be checked.
- Multiple Disjunctive Selection Condition - In case attributes have multiple disjunctive selection condition, it is of no use if only one attribute has index, rather it is necessary that all attributes have index. Otherwise, complete file scan is necessary to get selections.
- Selection of Predicates - If index is present for multiple attributes, one can choose highly selective attribute. This can be done by using Selectivity. The selectivity of any particular attribute is ratio of the number of records satisfying condition to total number of records. The selectivity can range anywhere between and including 0 and 1. The condition is rated as highly selective if it has low value of selectivity.
- In case of key attributes selectivity is roughly -
1 / (total db records)
- In case of non key attributes selectivity is roughly -
1 / distinct values of columns