chapter 1 Basic Algorithms for Executing Query Operations (6)
chapter 1 Basic Algorithms for Executing Query Operations (6)
Object-Oriented Concepts
1. Object Identity:
o In OOP, objects are instances of classes that have a unique identity.
o This identity is distinct from the object's state or attributes. Even if two objects
have the same state, they are considered different entities because they have
different identities.
o Object identity is crucial in distinguishing between object instances in memory
and is typically represented by a reference or pointer in programming languages.
2. Object Structure:
o An object is composed of attributes (data members) and methods (functions or
procedures).
o Attributes define the state of the object, while methods define the behavior.
o Object structure allows for complex data types that can aggregate attributes and
methods, enabling the modeling of real-world entities.
3. Type Constructors:
o Type constructors are mechanisms that allow the creation of new data types based
on existing ones.
o Common types of constructors include:
Classes: Define new objects with a specific structure and behavior.
Enumerations: Create a type with a fixed set of possible values.
Abstract Data Types (ADTs): Encapsulate data and operations together.
Encapsulation of Operations
Encapsulation refers to the bundling of data (attributes) and methods (operations) that
operate on that data into a single unit or object.
It restricts direct access to some of an object's components, which reduces complexity
and increases the robustness of the code.
Methods are the procedures defined within a class that can manipulate the object's state.
Persistence in OOP refers to the capability of an object to exist beyond the execution of a
program, often achieved through serialization (storing the object’s state in a file/database)
and deserialization (reconstructing the object from stored data).
1|Page
Advanced database
1. Type Hierarchies:
o Type hierarchies represent the relationships between classes in OOP, often
depicted as trees.
o This organization allows for polymorphism, where a method can operate on
objects of different classes that share a common parent class.
2. Inheritance:
o Inheritance is a cornerstone of OOP that allows a new class (subclass or derived
class) to inherit the properties and behaviors (methods) of another class
(superclass or base class).
o It promotes code reusability and can be classified into:
Single Inheritance: A subclass inherits from one superclass.
Multiple Inheritance: A subclass inherits from multiple superclasses
(supported in languages like C++ but not in others like Java).
Multilevel Inheritance: A subclass inherits from a superclass which, in
turn, is a subclass of another superclass.
o Inheritance enables developers to create more specialized subclasses that extend
or override behaviors of the parent class.
1. Nested Loop Join: For each row in one table, scan the other table to find matches.
2. Sort-Merge Join: Sort both tables by join keys, then merge them.
3. Hash Join: Build a hash table on the smallest table, then probe with the other table.
4. Selection and Projection Algorithms: Scan to filter rows or remove columns,
respectively.
5. Index-Based Access: Use indexes to speed up operations like selection and joins.
Heuristics are rules of thumb or guidelines that help optimize queries. Common heuristic rules
include:
1. Select before joins: Filter rows early to reduce the number of records processed in joins.
2. Push selections and projections down: Apply selection and projection operations as
early as possible in the query execution plan.
3. Join Ordering: Choose the order of joins to minimize intermediate result sizes.
4. Materialization: Decide when to materialize intermediate results based on costs.
2|Page
Advanced database
Selectivity: Refers to the fraction of rows that satisfy a condition in a selection operation.
High selectivity means fewer rows are returned, which is generally preferable for
efficiency.
Cost Estimates: Determine the estimated resource usage for different operations (CPU,
I/O, memory). Use information about the size of tables, distribution of data, and index
availability.
Optimizers often combine selectivity estimates with cost models to choose the best execution
plan.
Semantic query optimization uses knowledge of the data and its constraints to rewrite queries for
improved performance. Techniques include:
3|Page
Advanced database