Files
finetuning_aufgabe4/main.py
T
Sandro Fuetsch TitanandClaude Opus 4.7 d8a906e2d4 Load DBLP data once instead of reloading per index config
The Manager previously called setupBoth() on every test step, which
dropped both PostgreSQL and MariaDB tables and re-imported the full
DBLP TSVs (~9 reloads across 2 DBs in a single run, even though only
PostgreSQL was used). Now data is loaded once via load_data_postgres()
and only the indexes are swapped between tests via apply_indexes_postgres().

A reset_postgres(config, reload_data=False) helper lets callers force
a full reload when needed -- used after 'cl-both' tests, since CLUSTER
physically reorders the table and dropping the index alone does not
restore the original layout.

Also fixes two bugs found while reading the code:
- baseStrategy.run iterated 'self.queries' instead of '.items()',
  which would crash on the first unpack.
- main.py was missing an execute() call after the Aufgabe 3 'cl-both'
  setup, silently skipping that test.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-26 19:50:07 +02:00

48 lines
2.0 KiB
Python

from manager import Manager
from baseStrategy import BaseStrategy
from nestedInnerLoopStrategy import NestedInnerLoopStrategy
from sortMergeStrategy import SortMergeStrategy
from hashJoinStrategy import HashJoinStrategy
from setup import get_connection, load_data_postgres
from repositories.all_queries import queries_postgres
if __name__ == '__main__':
db_post, conn_postsql = get_connection(maria=False)
# Daten einmalig laden; danach werden zwischen den Tests nur die Indexe getauscht.
load_data_postgres()
# Aufgabe 1
join_manager = Manager(BaseStrategy(conn_postsql, db_post, queries_postgres["with_index"]))
# join_manager.setup_db("no-index")
# join_manager.execute() # 3 Mrd. Tupel via Kreuzprodukt -> > 10 min
join_manager.setup_db("unique-publ")
join_manager.execute()
join_manager.setup_db("cl-both")
join_manager.execute()
# Aufgabe 2 — vorheriger Lauf war 'cl-both' (CLUSTER hat Tabelle physisch sortiert);
# reload_data=True stellt die ursprüngliche Ladereihenfolge wieder her.
join_manager.setStrategy(NestedInnerLoopStrategy(conn_postsql, db_post, queries_postgres["with_index"]))
join_manager.setup_db("nc-publ", reload_data=True)
join_manager.execute()
join_manager.setup_db("nc-auth")
join_manager.execute()
join_manager.setup_db("nc-both")
join_manager.execute()
# Aufgabe 3 — Tabelle ist noch im Original-Layout, kein Reload nötig.
join_manager.setStrategy(SortMergeStrategy(conn_postsql, db_post, queries_postgres["no_index"]))
join_manager.setup_db("no-index")
join_manager.execute()
join_manager.setQueries(queries_postgres["with_index"])
join_manager.setup_db("nc-both")
join_manager.execute()
join_manager.setup_db("cl-both")
join_manager.execute()
# Aufgabe 4 — wieder vom CLUSTER-Zustand wegkommen.
join_manager.setStrategy(HashJoinStrategy(conn_postsql, db_post, queries_postgres["no_index"]))
join_manager.setup_db("no-index", reload_data=True)
join_manager.execute()