Files
finetuning_aufgabe4/baseStrategy.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

41 lines
1.2 KiB
Python

from setup import get_connection
import time
import psycopg2
import mariadb
class BaseStrategy:
def __init__(self, conn: psycopg2.extensions.connection | mariadb.Connection, db_name, queries: dict[str, str]):
self.connection = conn
self.cursor = conn.cursor()
self.db_name = db_name
self.queries = queries
def set_queries(self, queries):
self.queries = queries
def run(self):
for strategy, query in self.queries.items():
print("Running: " + strategy + "\n")
start = time.time()
self.cursor.execute(query)
end = time.time()
self._print_result(strategy, end, start)
def _print_result(self, strategy, end, start):
duration = end - start
minutes= int(duration // 60)
seconds = duration % 60
print(f"---- RESULTS FROM {self.db_name} Strategy: {strategy} ----\n")
print(f"duration: {minutes}m {seconds:.2f}s")
_print_cursor(self.cursor)
def _print_cursor(cursor):
for row in cursor.fetchall():
print(f"{row} '\n'")