This project demonstrates how Segment Trees can be utilized to optimize aggregate queries in a simulated database system. Using B-Trees for CRUD operations and Segment Trees for rapid aggregation, this system efficiently handles queries for operations like SUM
, MIN
, and MAX
, while supporting SQL-like WHERE
clauses to add flexibility in query selection.
Aggregate queries such as SUM
, COUNT
, MIN
, and MAX
are common in databases but can become slow with large datasets if not optimized. This project uses Segment Trees—common in competitive programming for range queries—to speed up aggregate query processing in a database setting. Key components of the project include:
- Database Simulation: CRUD operations implemented using B-Trees for efficient storage and retrieval.
- Optimized Aggregate Queries: Standard database queries are optimized with Segment Trees for faster processing.
- Advanced Querying: Support for SQL-like
WHERE
clauses to provide flexible selection.
- Database Simulation: Basic CRUD operations simulated with B-Trees for efficient data handling.
- Optimized Querying: Segment Trees enable rapid execution of aggregate queries like
SUM
,MIN
, andMAX
. - WHERE Clause Support: SQL-like filtering with
WHERE
clauses for flexible query handling. - Fast Query Processing: Combination of Binary Search and Segment Trees ensures fast, efficient data processing.
This project is organized to simulate a database environment with optimized query execution.
-
CRUD Operations with B-Trees: Implements basic database operations with B-Trees for effective insertion, deletion, and update functionality.
-
Optimized Aggregate Functions:
- Segment Tree: Builds and maintains a Segment Tree for performing fast aggregate queries, with operations executed in O(log n) time for each segment.
- Binary Search: Used for quick record retrieval, further enhanced by Segment Trees for range queries.
- SQL-like WHERE Clause: Adds filtering capability, enabling users to specify conditions, making query handling dynamic and versatile.
- B-Trees: Efficient for CRUD operations, maintaining the simulated database’s records.
- Segment Trees: The core data structure for efficient aggregate queries over specific ranges.
- Creating Data Records: Users add records to the database using the CRUD module.
- Executing Queries:
- Users input optimized aggregate queries, like calculating the
SUM
orMIN
over specified ranges. - Queries with a
WHERE
clause are filtered before aggregation, providing an efficient way to handle conditional queries.
- Users input optimized aggregate queries, like calculating the
- Getting Results: The system provides quick results by leveraging Segment Trees, making the querying experience seamless even with large datasets.
- Segment Trees: CSES Handbook, Chapter 9 - Range Queries
- Basic SQL Aggregate Functions: SQL Tutorial on Aggregate Functions
Check out the repository for code and additional documentation: Group2-G4 on GitHub