Docsity

homework on query optimization, Assignments of Database Management Systems (DBMS)

Partial preview of the text

Download homework on query optimization and more Assignments Database Management Systems (DBMS) in PDF only on Docsity!

Advanced DataBase

DB Assignment

Members :

  • Amira Mereddef G6 - Benmansour Aya G
  • Aya Khaldi G6 - Hadj Messaoud Maria G
  • Benbouabdellah Nadia G

Query 1:

Before optimizing

After optimizing using a materialized view :

section shows several complex join conditions (e.g., "IDSHOW"="E"."IDSHOW", "IDSTAFF"="P"."IDSTAFF") that would benefit from appropriate indexes. Optimized Query Analysis: ● Hash joins with HASH JOIN operations (ids 2, 3, 4) ● Multiple full table scans (STAFF: 1048K rows, PRINCIPALS: 1048K rows, EPISODE: 1048K rows) ● Lower cost of 10338 compared to previous query (19778) ● Materialized view operations (operations 5-7) ● Adaptive plan usage noted at bottom Comparison with Previous Plan: ● This plan is more efficient (10338 vs 19778 cost) ● Uses materialized view access (MV_SHOW_RATINGS) rather than joining raw tables. ● More efficient use of memory (27M bytes vs 1107M bytes) ● Better join organization with fewer hash joins Possible Improvements: ● partitioning large tables like STAFF and EPISODE ● Add bitmap indexes for frequently filtered columns Query 2: Before optimizing

After optimizing using a materialized view

Optimization Method Cost Plan Depth Full Table Scans Complexity Original Query 1839 16 levels Multiple High Materialized View 2 1 level 1 (on small MV) Very Low Best Optimization Method

The materialized view approach is clearly the most effective optimization for Query 2 with:

● 99.9% cost reduction compared to the original query ● Elimination of all complex joins and aggregations at runtime ● Simplest execution plan with just a single operation

The materialized view strategy works exceptionally well for this query because:

  1. The query involves multiple joins between large tables
  2. The filtering conditions (startYear < 2000, category = 'Director') significantly reduce the result set
  3. The aggregation with HAVING COUNT >= 10 is expensive at runtime
  4. The query likely returns a relatively small result set compared to the source tables Trade-offs to Consider

While the materialized view provides the best performance, there are trade-offs:

  1. Storage requirements : The materialized view consumes additional storage
  2. Freshness : If the underlying data changes frequently, you'll need to refresh the materialized view
  3. Maintenance overhead : Managing materialized views adds administrative complexity

In this case, the dramatic performance improvement (from cost 1839 to just 2) justifies these

trade-offs, especially if this query runs frequently.

Conclusion

The materialized view approach is the clear winner for optimizing Query 2. The execution

plan confirms it eliminated all the expensive operations from the original query, resulting in

an execution plan that's orders of magnitude more efficient.

For this type of query pattern (multiple joins + filtering + aggregation), materialized views

consistently outperform other optimization techniques when the query runs frequently and the

data doesn't change too often.