diff --git a/benchmark/BerlinMOD/run_queries.py b/benchmark/BerlinMOD/run_queries.py index dbd271b9..b18134e6 100644 --- a/benchmark/BerlinMOD/run_queries.py +++ b/benchmark/BerlinMOD/run_queries.py @@ -1,7 +1,5 @@ #!/usr/bin/env python3 -""" -Query runner for BerlinMOD benchmark -""" +"""Query runner for BerlinMOD benchmark.""" import subprocess import time @@ -10,176 +8,163 @@ import os import argparse import re -from typing import Dict, Tuple +from typing import Dict, Optional, Tuple +QUERIES_FILE = "./sql/berlinmod_r_queries.sql" QUERIES_NUM = 17 + +def _parse_queries(queries_file: str) -> Dict[int, str]: + """Split berlinmod_r_queries.sql into {query_num: sql} by -- QN: markers.""" + with open(queries_file, encoding="utf-8") as f: + content = f.read() + parts = re.split(r"(?=^-- Q\d+:)", content, flags=re.MULTILINE) + queries: Dict[int, str] = {} + for part in parts: + m = re.match(r"-- Q(\d+):", part.strip()) + if m: + n = int(m.group(1)) + sql = re.sub(r"^-- Q\d+:.*\n", "", part.strip(), count=1).strip() + queries[n] = sql + return queries + + class QueryRunner: - def __init__(self, duckdb_path: str = "../../build/release/duckdb", - benchmark: str = "default", - queries_path: str = "./sql/queries", - explain_path: str = "./sql/explain", - output_path: str = "./results/output"): + def __init__( + self, + duckdb_path: str = "../../build/release/duckdb", + benchmark: str = "default", + queries_file: str = QUERIES_FILE, + output_path: str = "./results/output", + ): self.duckdb_path = duckdb_path self.benchmark = benchmark - self.queries_path = queries_path - self.explain_path = explain_path + self.queries_file = queries_file self.output_path = output_path self.queries_num = QUERIES_NUM + self._queries: Optional[Dict[int, str]] = None + + def _get_queries(self) -> Dict[int, str]: + if self._queries is None: + self._queries = _parse_queries(self.queries_file) + return self._queries + + def _run_sql(self, sql: str) -> subprocess.CompletedProcess: + return subprocess.run( + [self.duckdb_path, f"./databases/{self.benchmark}.db"], + input=sql, + capture_output=True, + text=True, + ) + + def run_query(self, query_num: int) -> Tuple[float, int]: + queries = self._get_queries() + if query_num not in queries: + print(f"\tError: Q{query_num} not found in {self.queries_file}") + return -1, -1 + + print(f"\nRunning Q{query_num}") + output_file = f"{self.output_path}/{self.benchmark}/query_{query_num}.csv" + full_sql = f".mode csv\n.output {output_file}\n{queries[query_num]}" - def run_sql(self, filename: str) -> Tuple[float, int]: - success = False - print(f"\nRunning {filename}") start_time = time.time() - sql_path = os.path.join(self.queries_path, filename) - if not os.path.exists(sql_path): - print(f"\tError: Query file not found: {sql_path}") - return -1, -1 - - with open(sql_path, "r") as f: - sql = f.read() - - sql = sql.replace(".output results/output/query", f".output results/output/{self.benchmark}/query") - - while not success: - result = subprocess.run( - [self.duckdb_path, f"./databases/{self.benchmark}.db"], - input=sql, - capture_output=True, - text=True - ) + while True: + result = self._run_sql(full_sql) if result.returncode == 0: - success = True - else: - print(f"\tError running query: {result.stderr}") - print("\tTrying again...") - time.sleep(1) - start_time = time.time() - - end_time = time.time() - elapsed = (end_time - start_time) * 1000 # milliseconds + break + print(f"\tError: {result.stderr}") + print("\tRetrying...") + time.sleep(1) + start_time = time.time() + elapsed = (time.time() - start_time) * 1000 print(f"\tDone in {elapsed:.2f}ms") - line_count = self.run_validation(filename) + line_count = self._count_output_rows(output_file) print(f"\tOutput row count: {line_count}") - return elapsed, line_count - def run_validation(self, filename: str) -> int: - output_file = f"{self.output_path}/{self.benchmark}/{filename.replace('.sql', '.csv')}" + def _count_output_rows(self, output_file: str) -> int: if not os.path.exists(output_file): - print(f"\tError: Output file not found: {output_file}") + print(f"\tError: output file not found: {output_file}") return -1 - with open(output_file, "r") as f: - line_count = sum(1 for _ in f) - if line_count > 0: - line_count -= 1 - return line_count + with open(output_file, encoding="utf-8") as f: + count = sum(1 for _ in f) + return max(0, count - 1) def run_queries(self) -> Dict: - results = dict() - - for query_num in range(1, self.queries_num + 1): - filename = f"query_{query_num}.sql" - elapsed, line_count = self.run_sql(filename) + results: Dict = {} + for n in range(1, self.queries_num + 1): + elapsed, line_count = self.run_query(n) if elapsed != -1: - results[filename] = { + results[f"query_{n}.sql"] = { "elapsed": elapsed, - "row_count": line_count + "row_count": line_count, } - return results - def run_explain_sql(self, filename: str) -> Tuple[float, int]: - output_file = f"{self.output_path}/{self.benchmark}/explain/{filename.replace('.sql', '.txt')}" - - success = False - print(f"\nRunning {filename}") - sql_path = os.path.join(self.explain_path, filename) - if not os.path.exists(sql_path): - print(f"\tError: Query file not found: {sql_path}") - return -1, -1 - - with open(sql_path, "r") as f: - sql = f.read() - - sql = sql.replace(".output results/output/explain", f".output results/output/{self.benchmark}/explain") - - while not success: - result = subprocess.run( - [self.duckdb_path, f"./databases/{self.benchmark}.db"], - input=sql, - capture_output=True, - text=True - ) - if result.returncode == 0: - success = True - else: - print(f"\tError running query: {result.stderr}") - print("\tTrying again...") - time.sleep(1) - start_time = time.time() - - with open(output_file, "r") as f: - output = f.readlines() - - elapsed = -1.0 - for line in output: - match = re.search(r"Total Time:\s*([0-9.]+)s", line) - if match: - try: - elapsed = float(match.group(1)) * 1000 # convert to ms - except ValueError: - elapsed = -1.0 - break - - print(f"\tDone in {elapsed:.2f}ms") - - return elapsed - def run_explain(self) -> Dict: - if not os.path.exists(f"./results/output/{self.benchmark}/explain"): - os.makedirs(f"./results/output/{self.benchmark}/explain") - - results = dict() - for query_num in range(1, self.queries_num + 1): - filename = f"query_{query_num}.sql" - elapsed = self.run_explain_sql(filename) - if elapsed != -1: - results[filename] = elapsed + queries = self._get_queries() + explain_dir = f"{self.output_path}/{self.benchmark}/explain" + os.makedirs(explain_dir, exist_ok=True) + + results: Dict = {} + for n in range(1, self.queries_num + 1): + if n not in queries: + continue + output_file = f"{explain_dir}/query_{n}.txt" + full_sql = ( + f".output {output_file}\n" + f"SET memory_limit = '20GB';\n" + f"EXPLAIN ANALYZE\n{queries[n]}" + ) + print(f"\nRunning EXPLAIN Q{n}") + result = self._run_sql(full_sql) + if result.returncode != 0: + print(f"\tError: {result.stderr}") + continue + + elapsed = -1.0 + if os.path.exists(output_file): + with open(output_file, encoding="utf-8") as f: + for line in f: + m = re.search(r"Total Time:\s*([0-9.]+)s", line) + if m: + try: + elapsed = float(m.group(1)) * 1000 + except ValueError: + pass + break + + print(f"\tDone in {elapsed:.2f}ms") + results[f"query_{n}.sql"] = elapsed return results -def main(): - parser = argparse.ArgumentParser(description="Data loader for BerlinMOD benchmark") - parser.add_argument("--benchmark", type=str, required=True, help="Name of the benchmark run") - parser.add_argument("--explain", type=int, default=0, choices=[0, 1], help="Run explain queries") - benchmark = parser.parse_args().benchmark - explain = parser.parse_args().explain - if not os.path.exists(f"./results/output/{benchmark}"): - os.makedirs(f"./results/output/{benchmark}") +def main(): + parser = argparse.ArgumentParser(description="BerlinMOD query runner for DuckDB") + parser.add_argument("--benchmark", type=str, required=True) + parser.add_argument("--explain", type=int, default=0, choices=[0, 1]) + args = parser.parse_args() duckdb_path = "../../build/release/duckdb" if not os.path.exists(duckdb_path): - print(f"Error: DuckDB executable not found at {duckdb_path}") - print("Please make sure you're running this from the benchmark directory and DuckDB is built.") + print(f"Error: DuckDB not found at {duckdb_path}") sys.exit(1) - - runner = QueryRunner(duckdb_path, benchmark) - if explain: - results = runner.run_explain() - else: - results = runner.run_queries() - - if not os.path.exists(f"./results/stats/{benchmark}"): - os.makedirs(f"./results/stats/{benchmark}") - - stats_filename = "run_queries.json" if not explain else "run_explain.json" - with open(f"./results/stats/{benchmark}/{stats_filename}", "w") as f: + + output_path = "./results/output" + os.makedirs(f"{output_path}/{args.benchmark}", exist_ok=True) + + runner = QueryRunner(duckdb_path, args.benchmark) + results = runner.run_explain() if args.explain else runner.run_queries() + + stats_dir = f"./results/stats/{args.benchmark}" + os.makedirs(stats_dir, exist_ok=True) + stats_file = "run_explain.json" if args.explain else "run_queries.json" + with open(f"{stats_dir}/{stats_file}", "w", encoding="utf-8") as f: json.dump(results, f, indent=4) - - print(f"\nResults saved to ./results/stats/{benchmark}/{stats_filename}") + print(f"\nResults saved to {stats_dir}/{stats_file}") + if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/benchmark/BerlinMOD/sql/berlinmod_r_queries.sql b/benchmark/BerlinMOD/sql/berlinmod_r_queries.sql new file mode 100644 index 00000000..1268ff9d --- /dev/null +++ b/benchmark/BerlinMOD/sql/berlinmod_r_queries.sql @@ -0,0 +1,235 @@ +/*----------------------------------------------------------------------------- +-- BerlinMOD Range Queries — Portable Dialect (Q1–Q17) +------------------------------------------------------------------------------- + +This file is part of MobilityDB. +Copyright(c) 2020-2026, Université libre de Bruxelles and MobilityDB +contributors + +Portable variant of `berlinmod_r_queries.sql` for the cross-platform +edge-to-cloud benchmark. The PG-specific PL/pgSQL harness, the +`EXPLAIN (ANALYZE, FORMAT JSON)` capture, and the +`execution_tests_explain` results table belong to the canonical file +and are not reproduced here. This file is the 17 query bodies as +runnable, platform-agnostic SQL. + +Operator-to-function mapping (PG → portable): + && (bbox overlap) → drop as a prefilter; rely on semantic + predicate. The portable form retains + correctness; per-platform performance + comes from each platform's own + indexing / pushdown. + @> (bbox contains) → drop; rely on `valueAtTimestamp IS NOT NULL` + or `eIntersects` for the actual containment. + _ST_Intersects → `ST_Intersects` (bbox-bypass form is + a PG-only optimization). + +Schema: + Trips(TripId, VehicleId, Trip tgeompoint, Trajectory geometry, …) + Vehicles(VehicleId, Licence, VehicleType, Model) + Licences(LicenceId, Licence, VehicleId) + Licences1, Licences2 (subsets) + Points(PointId, PosX, PosY, Geom) + Points1 (subset) + Regions(RegionId, RegionName, Geom) + Regions1 (subset) + Instants(InstantId, Instant) + Instants1 (subset) + Periods(PeriodId, Period) + Periods1 (subset) + +Expected row counts (BerlinMOD scalefactor 0.005, Brussels) — identical +on PostgreSQL, DuckDB, and Spark when the LIMIT-10 parameter views use +deterministic `ORDER BY ` (per the matching fix in +`berlinmod_load.sql`): + Q1:72 Q2:1 Q3:6 Q4:80 Q5:100 Q6:0 Q7:26 Q8:75 Q9:94 + Q10:21 Q11:0 Q12:0 Q13:278 Q14:1 Q15:118 Q16:6 Q17:1 + +-----------------------------------------------------------------------------*/ + +-- Q1: Models of vehicles with licences from Licences +SELECT DISTINCT l.Licence, v.Model AS Model +FROM Vehicles v, Licences l +WHERE v.Licence = l.Licence +ORDER BY l.Licence; + +-- Q2: How many vehicles are passenger cars? +SELECT COUNT(Licence) +FROM Vehicles v +WHERE VehicleType = 'passenger'; + +-- Q3: Position of each Licences1 vehicle at each Instants1 instant +SELECT DISTINCT l.Licence, i.InstantId, i.Instant AS Instant, + valueAtTimestamp(t.Trip, i.Instant) AS Location +FROM Trips t, Licences1 l, Instants1 i +WHERE t.VehicleId = l.VehicleId + AND valueAtTimestamp(t.Trip, i.Instant) IS NOT NULL +ORDER BY l.Licence, i.InstantId; + +-- Q4: Which vehicles passed any Points? +SELECT DISTINCT p.PointId, p.Geom, v.Licence +FROM Trips t, Vehicles v, Points p +WHERE t.VehicleId = v.VehicleId + AND ST_Intersects(trajectory(t.Trip), p.Geom) +ORDER BY p.PointId, v.Licence; + +-- Q5: Minimum distance between trip locations of two licence sets +-- Each side aggregates its licence-group of trips into a tgeompoint +-- array; `minDistance(tgeompoint[], tgeompoint[])` then returns the +-- exact set-set spatial minimum distance, equivalent to +-- `ST_Distance(ST_Collect(trajectory(...)), ST_Collect(trajectory(...)))` +-- but with each trip's STBox used as a sound lower-bound prefilter so +-- trip pairs whose bounding boxes are already farther apart than the +-- running minimum are skipped. The per-pair distance still uses +-- liblwgeom's segment-pair sweep so the answer is bit-identical to the +-- aggregated form (see MobilityDB PR #1007). +WITH Temp1(Licence1, Trips) AS ( + SELECT l1.Licence, array_agg(t1.Trip) + FROM Trips t1, Licences1 l1 + WHERE t1.VehicleId = l1.VehicleId + GROUP BY l1.Licence), +Temp2(Licence2, Trips) AS ( + SELECT l2.Licence, array_agg(t2.Trip) + FROM Trips t2, Licences2 l2 + WHERE t2.VehicleId = l2.VehicleId + GROUP BY l2.Licence) +SELECT Licence1, Licence2, minDistance(t1.Trips, t2.Trips) AS MinDist +FROM Temp1 t1, Temp2 t2 +ORDER BY Licence1, Licence2; + +-- Q6: Truck pairs that ever met within 10 m +WITH Temp(Licence, VehicleId, Trip) AS ( + SELECT v.Licence, t.VehicleId, t.Trip + FROM Trips t, Vehicles v + WHERE t.VehicleId = v.VehicleId + AND v.VehicleType = 'truck') +SELECT DISTINCT t1.Licence, t2.Licence +FROM Temp t1, Temp t2 +WHERE t1.VehicleId < t2.VehicleId + AND eDwithin(t1.Trip, t2.Trip, 10.0) +ORDER BY t1.Licence, t2.Licence; + +-- Q7: For each Points geometry, earliest passenger-car visit +WITH Temp AS ( + SELECT DISTINCT v.Licence, p.PointId, p.Geom, + MIN(startTimestamp(atValues(t.Trip, p.Geom))) AS Instant + FROM Trips t, Vehicles v, Points p + WHERE t.VehicleId = v.VehicleId + AND v.VehicleType = 'passenger' + AND ST_Intersects(trajectory(t.Trip), p.Geom) + GROUP BY v.Licence, p.PointId, p.Geom) +SELECT t1.Licence, t1.PointId, t1.Geom, t1.Instant +FROM Temp t1 +WHERE t1.Instant <= ALL ( + SELECT t2.Instant + FROM Temp t2 + WHERE t1.PointId = t2.PointId) +ORDER BY t1.PointId, t1.Licence; + +-- Q8: Total distance per licence × Periods1 period +SELECT l.Licence, p.PeriodId, p.Period, + SUM(length(atTime(t.Trip, p.Period))) AS Dist +FROM Trips t, Licences1 l, Periods1 p +WHERE t.VehicleId = l.VehicleId + AND atTime(t.Trip, p.Period) IS NOT NULL +GROUP BY l.Licence, p.PeriodId, p.Period +ORDER BY l.Licence, p.PeriodId; + +-- Q9: Longest single-period vehicle distance per Periods period +WITH Distances AS ( + SELECT p.PeriodId, p.Period, t.VehicleId, + SUM(length(atTime(t.Trip, p.Period))) AS Dist + FROM Trips t, Periods p + WHERE atTime(t.Trip, p.Period) IS NOT NULL + GROUP BY p.PeriodId, p.Period, t.VehicleId) +SELECT PeriodId, Period, MAX(Dist) AS MaxDist +FROM Distances +GROUP BY PeriodId, Period +ORDER BY PeriodId; + +-- Q10: When and where each Licences1 vehicle was within 3 m of another +WITH Temp AS ( + SELECT l1.Licence AS Licence1, t2.VehicleId AS Car2Id, + whenTrue(tDwithin(t1.Trip, t2.Trip, 3.0)) AS Periods + FROM Trips t1, Licences1 l1, Trips t2, Vehicles v + WHERE t1.VehicleId = l1.VehicleId + AND t2.VehicleId = v.VehicleId + AND t1.VehicleId <> t2.VehicleId) +SELECT Licence1, Car2Id, Periods +FROM Temp +WHERE Periods IS NOT NULL; + +-- Q11: Vehicles passing a Points1 at an Instants1 instant +WITH Temp AS ( + SELECT p.PointId, p.Geom, i.InstantId, i.Instant, t.VehicleId + FROM Trips t, Points1 p, Instants1 i + WHERE valueAtTimestamp(t.Trip, i.Instant) = p.Geom) +SELECT t.PointId, t.Geom, t.InstantId, t.Instant, v.Licence +FROM Temp t JOIN Vehicles v ON t.VehicleId = v.VehicleId +ORDER BY t.PointId, t.InstantId, v.Licence; + +-- Q12: Pairs of vehicles meeting at a Points1 at an Instants1 instant +WITH Temp AS ( + SELECT DISTINCT p.PointId, p.Geom, i.InstantId, i.Instant, t.VehicleId + FROM Trips t, Points1 p, Instants1 i + WHERE valueAtTimestamp(t.Trip, i.Instant) = p.Geom) +SELECT DISTINCT t1.PointId, t1.Geom, t1.InstantId, t1.Instant, + v1.Licence AS Licence1, v2.Licence AS Licence2 +FROM Temp t1 +JOIN Vehicles v1 ON t1.VehicleId = v1.VehicleId +JOIN Temp t2 ON t1.VehicleId < t2.VehicleId + AND t1.PointId = t2.PointId + AND t1.InstantId = t2.InstantId +JOIN Vehicles v2 ON t2.VehicleId = v2.VehicleId +ORDER BY t1.PointId, t1.InstantId, v1.Licence, v2.Licence; + +-- Q13: Vehicles ever in a Regions1 during a Periods1 period +WITH Temp AS ( + SELECT DISTINCT r.RegionId, p.PeriodId, p.Period, t.VehicleId + FROM Trips t, Regions1 r, Periods1 p + WHERE ST_Intersects(trajectory(atTime(t.Trip, p.Period)), r.Geom)) +SELECT DISTINCT t.RegionId, t.PeriodId, t.Period, v.Licence +FROM Temp t, Vehicles v +WHERE t.VehicleId = v.VehicleId +ORDER BY t.RegionId, t.PeriodId, v.Licence; + +-- Q14: Vehicles inside a Regions1 at an Instants1 instant +WITH Temp AS ( + SELECT DISTINCT r.RegionId, i.InstantId, i.Instant, t.VehicleId + FROM Trips t, Regions1 r, Instants1 i + WHERE ST_Contains(r.Geom, valueAtTimestamp(t.Trip, i.Instant))) +SELECT DISTINCT t.RegionId, t.InstantId, t.Instant, v.Licence +FROM Temp t JOIN Vehicles v ON t.VehicleId = v.VehicleId +ORDER BY t.RegionId, t.InstantId, v.Licence; + +-- Q15: Vehicles passing a Points1 during a Periods1 period +WITH Temp AS ( + SELECT DISTINCT pt.PointId, pt.Geom, pr.PeriodId, pr.Period, t.VehicleId + FROM Trips t, Points1 pt, Periods1 pr + WHERE ST_Intersects(trajectory(atTime(t.Trip, pr.Period)), pt.Geom)) +SELECT DISTINCT t.PointId, t.Geom, t.PeriodId, t.Period, v.Licence +FROM Temp t, Vehicles v +WHERE t.VehicleId = v.VehicleId +ORDER BY t.PointId, t.PeriodId, v.Licence; + +-- Q16: Pairs of vehicles that ever met in a Regions1 during a Periods1 +SELECT p.PeriodId, p.Period, r.RegionId, + l1.Licence AS Licence1, l2.Licence AS Licence2 +FROM Trips t1, Licences1 l1, Trips t2, Licences2 l2, Periods1 p, Regions1 r +WHERE t1.VehicleId = l1.VehicleId + AND t2.VehicleId = l2.VehicleId + AND l1.Licence < l2.Licence + AND ST_Intersects(trajectory(atTime(t1.Trip, p.Period)), r.Geom) + AND ST_Intersects(trajectory(atTime(t2.Trip, p.Period)), r.Geom) + AND aDisjoint(atTime(t1.Trip, p.Period), atTime(t2.Trip, p.Period)) +ORDER BY PeriodId, RegionId, Licence1, Licence2; + +-- Q17: Points visited by the maximum number of vehicles +WITH PointCount AS ( + SELECT p.PointId, COUNT(DISTINCT t.VehicleId) AS Hits + FROM Trips t, Points p + WHERE ST_Intersects(trajectory(t.Trip), p.Geom) + GROUP BY p.PointId) +SELECT PointId, Hits +FROM PointCount AS p +WHERE p.Hits = (SELECT MAX(Hits) FROM PointCount); diff --git a/benchmark/BerlinMOD/sql/explain/query_1.sql b/benchmark/BerlinMOD/sql/explain/query_1.sql deleted file mode 100644 index 0f612c43..00000000 --- a/benchmark/BerlinMOD/sql/explain/query_1.sql +++ /dev/null @@ -1,8 +0,0 @@ -.output results/output/explain/query_1.txt - -SET memory_limit = '20GB'; - -EXPLAIN ANALYZE -SELECT DISTINCT l.Licence, v.Model AS Model -FROM Vehicles v, Licences l -WHERE v.Licence = l.Licence; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/explain/query_10.sql b/benchmark/BerlinMOD/sql/explain/query_10.sql deleted file mode 100644 index 4f04737f..00000000 --- a/benchmark/BerlinMOD/sql/explain/query_10.sql +++ /dev/null @@ -1,30 +0,0 @@ -.output results/output/explain/query_10.txt - -SET memory_limit = '20GB'; - -/* Old version -EXPLAIN ANALYZE -WITH Values AS ( - SELECT DISTINCT l1.Licence AS QueryLicence, l2.Licence AS OtherLicence, - atTime(t1.Trip, getTime(atValues(tdwithin(t1.Trip, t2.Trip, 3.0), TRUE))) AS Pos - FROM Trips t1, Licences1 l1, Trips t2, Licences2 l2 - WHERE t1.VehicleId = l1.VehicleId AND t2.VehicleId = l2.VehicleId AND - t1.VehicleId < t2.VehicleId AND - expandSpace(t1.Trip::STBOX, 3) && expandSpace(t2.Trip::STBOX, 3) AND - eDwithin(t1.Trip, t2.Trip, 3.0) ) -SELECT QueryLicence, OtherLicence, array_agg(Pos ORDER BY startTimestamp(Pos)) AS Pos -FROM Values -GROUP BY QueryLicence, OtherLicence -ORDER BY QueryLicence, OtherLicence; -*/ - -EXPLAIN ANALYZE -WITH Temp AS ( - SELECT l1.Licence AS Licence1, t2.VehicleId AS Car2Id, - whenTrue(tDwithin(t1.Trip, t2.Trip, 3.0)) AS Periods - FROM Trips t1, Licences1 l1, Trips t2, Vehicles v - WHERE t1.VehicleId = l1.VehicleId AND t2.VehicleId = v.VehicleId AND - t1.VehicleId <> t2.VehicleId AND t2.Trip && expandSpace(t1.trip::STBOX, 3.0) ) -SELECT Licence1, Car2Id, Periods -FROM Temp -WHERE Periods IS NOT NULL; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/explain/query_11.sql b/benchmark/BerlinMOD/sql/explain/query_11.sql deleted file mode 100644 index 5a8711ca..00000000 --- a/benchmark/BerlinMOD/sql/explain/query_11.sql +++ /dev/null @@ -1,25 +0,0 @@ -.output results/output/explain/query_11.txt - -SET memory_limit = '20GB'; - -/* Old version -EXPLAIN ANALYZE -SELECT p.PointId, p.Geom, i.InstantId, i.Instant, v.Licence -FROM Trips t, Vehicles v, Points1 p, Instants1 i -WHERE - t.VehicleId = v.VehicleId - AND t.Trip @> stbox(p.Geom::WKB_BLOB, i.Instant) - AND valueAtTimestamp(t.Trip, i.Instant) = p.Geom -ORDER BY p.PointId, i.InstantId, v.Licence; -*/ - -EXPLAIN ANALYZE -WITH Temp AS ( - SELECT p.PointId, p.Geom, i.InstantId, i.Instant, t.VehicleId - FROM Trips t, Points1 p, Instants1 i - WHERE - t.Trip @> stbox(p.Geom::WKB_BLOB, i.Instant) - AND valueAtTimestamp(t.Trip, i.Instant) = p.Geom ) -SELECT t.PointId, t.Geom, t.InstantId, t.Instant, v.Licence -FROM Temp t JOIN Vehicles v ON t.VehicleId = v.VehicleId -ORDER BY t.PointId, t.InstantId, v.Licence; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/explain/query_12.sql b/benchmark/BerlinMOD/sql/explain/query_12.sql deleted file mode 100644 index be419bd9..00000000 --- a/benchmark/BerlinMOD/sql/explain/query_12.sql +++ /dev/null @@ -1,35 +0,0 @@ -.output results/output/explain/query_12.txt - -SET memory_limit = '20GB'; - -/* Old version -EXPLAIN ANALYZE -SELECT DISTINCT p.PointId, p.Geom, i.InstantId, i.Instant, - v1.Licence AS Licence1, v2.Licence AS Licence2 -FROM Trips t1, Vehicles v1, Trips t2, Vehicles v2, Points1 p, Instants1 i -WHERE - t1.VehicleId = v1.VehicleId - AND t2.VehicleId = v2.VehicleId - AND t1.VehicleId < t2.VehicleId - AND t1.Trip @> stbox(p.Geom::WKB_BLOB, i.Instant) - AND t2.Trip @> stbox(p.Geom::WKB_BLOB, i.Instant) - AND valueAtTimestamp(t1.Trip, i.Instant) = p.Geom - AND valueAtTimestamp(t2.Trip, i.Instant) = p.Geom -ORDER BY p.PointId, i.InstantId, v1.Licence, v2.Licence; -*/ - -EXPLAIN ANALYZE -WITH Temp AS ( - SELECT DISTINCT p.PointId, p.Geom, i.InstantId, i.Instant, t.VehicleId - FROM Trips t, Points1 p, Instants1 i - WHERE t.Trip @> stbox(p.Geom::WKB_BLOB, i.Instant) - AND valueAtTimestamp(t.Trip, i.Instant) = p.Geom ) -SELECT DISTINCT t1.PointId, t1.Geom, t1.InstantId, t1.Instant, - v1.Licence AS Licence1, v2.Licence AS Licence2 -FROM Temp t1 - JOIN Vehicles v1 ON t1.VehicleId = v1.VehicleId - JOIN Temp t2 ON t1.VehicleId < t2.VehicleId - AND t1.PointID = t2.PointID - AND t1.InstantId = t2.InstantId - JOIN Vehicles v2 ON t2.VehicleId = v2.VehicleId -ORDER BY t1.PointId, t1.InstantId, v1.Licence, v2.Licence; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/explain/query_13.sql b/benchmark/BerlinMOD/sql/explain/query_13.sql deleted file mode 100644 index 3bfdcdff..00000000 --- a/benchmark/BerlinMOD/sql/explain/query_13.sql +++ /dev/null @@ -1,27 +0,0 @@ -.output results/output/explain/query_13.txt - -SET memory_limit = '20GB'; - -/* Old version -EXPLAIN ANALYZE -SELECT DISTINCT r.RegionId, p.PeriodId, p.Period, v.Licence -FROM Trips t, Vehicles v, Regions1 r, Periods1 p -WHERE - t.VehicleId = v.VehicleId - AND t.trip && stbox(r.Geom::WKB_BLOB, p.Period) - AND ST_Intersects(trajectory(atTime(t.Trip, p.Period))::GEOMETRY, r.Geom) -ORDER BY r.RegionId, p.PeriodId, v.Licence; -*/ - -EXPLAIN ANALYZE -WITH Temp AS ( - SELECT DISTINCT r.RegionId, p.PeriodId, p.Period, t.VehicleId - FROM Trips t, Regions1 r, Periods1 p - WHERE - t.trip && stbox(r.Geom::WKB_BLOB, p.Period) - AND ST_Intersects(trajectory(atTime(t.Trip, p.Period))::GEOMETRY, r.Geom) - ORDER BY r.RegionId, p.PeriodId ) -SELECT DISTINCT t.RegionId, t.PeriodId, t.Period, v.Licence -FROM Temp t, Vehicles v -WHERE t.VehicleId = v.VehicleId -ORDER BY t.RegionId, t.PeriodId, v.Licence; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/explain/query_14.sql b/benchmark/BerlinMOD/sql/explain/query_14.sql deleted file mode 100644 index 16ca6377..00000000 --- a/benchmark/BerlinMOD/sql/explain/query_14.sql +++ /dev/null @@ -1,25 +0,0 @@ -.output results/output/explain/query_14.txt - -SET memory_limit = '20GB'; - -/* Old version -EXPLAIN ANALYZE -SELECT DISTINCT r.RegionId, i.InstantId, i.Instant, v.Licence -FROM Trips t, Vehicles v, Regions1 r, Instants1 i -WHERE - t.VehicleId = v.VehicleId - AND t.Trip && stbox(r.Geom::WKB_BLOB, i.Instant) - AND ST_Contains(r.Geom, valueAtTimestamp(t.Trip, i.Instant)::GEOMETRY) -ORDER BY r.RegionId, i.InstantId, v.Licence; -*/ - -EXPLAIN ANALYZE -WITH Temp AS ( - SELECT DISTINCT r.RegionId, i.InstantId, i.Instant, t.VehicleId - FROM Trips t, Regions1 r, Instants1 i - WHERE - t.Trip && stbox(r.Geom::WKB_BLOB, i.Instant) - AND ST_Contains(r.Geom, valueAtTimestamp(t.Trip, i.Instant)::GEOMETRY) ) -SELECT DISTINCT t.RegionId, t.InstantId, t.Instant, v.Licence -FROM Temp t JOIN Vehicles v ON t.VehicleId = v.VehicleId -ORDER BY t.RegionId, t.InstantId, v.Licence; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/explain/query_15.sql b/benchmark/BerlinMOD/sql/explain/query_15.sql deleted file mode 100644 index 09225d73..00000000 --- a/benchmark/BerlinMOD/sql/explain/query_15.sql +++ /dev/null @@ -1,25 +0,0 @@ -.output results/output/explain/query_15.txt - -SET memory_limit = '20GB'; - -/* Old version -EXPLAIN ANALYZE -SELECT DISTINCT pt.PointId, pt.Geom, pr.PeriodId, pr.Period, v.Licence -FROM Trips t, Vehicles v, Points1 pt, Periods1 pr -WHERE - t.VehicleId = v.VehicleId - AND t.Trip && stbox(pt.Geom::WKB_BLOB, pr.Period) - AND ST_Intersects(trajectory(atTime(t.Trip, pr.Period))::GEOMETRY, pt.Geom) -ORDER BY pt.PointId, pr.PeriodId, v.Licence; -*/ - -EXPLAIN ANALYZE -WITH Temp AS ( - SELECT DISTINCT pt.PointId, pt.Geom, pr.PeriodId, pr.Period, t.VehicleId - FROM Trips t, Points1 pt, Periods1 pr - WHERE t.Trip && stbox(pt.Geom::WKB_BLOB, pr.Period) - AND ST_Intersects(trajectory(atTime(t.Trip, pr.Period))::GEOMETRY, pt.Geom) ) -SELECT DISTINCT t.PointId, t.Geom, t.PeriodId, t.Period, v.Licence -FROM Temp t, Vehicles v -WHERE t.VehicleId = v.VehicleId -ORDER BY t.PointId, t.PeriodId, v.Licence; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/explain/query_16.sql b/benchmark/BerlinMOD/sql/explain/query_16.sql deleted file mode 100644 index f8682e05..00000000 --- a/benchmark/BerlinMOD/sql/explain/query_16.sql +++ /dev/null @@ -1,17 +0,0 @@ -.output results/output/explain/query_16.txt - -SET memory_limit = '20GB'; - -EXPLAIN ANALYZE -SELECT p.PeriodId, p.Period, r.RegionId, l1.Licence AS Licence1, l2.Licence AS Licence2 -FROM Trips t1, Licences1 l1, Trips t2, Licences2 l2, Periods1 p, Regions1 r -WHERE - t1.VehicleId = l1.VehicleId - AND t2.VehicleId = l2.VehicleId - AND l1.Licence < l2.Licence - -- AND t1.Trip && stbox(r.Geom::WKB_BLOB, p.Period) - -- AND t2.Trip && stbox(r.Geom::WKB_BLOB, p.Period) - AND ST_Intersects(trajectory(atTime(t1.Trip, p.Period))::GEOMETRY, r.Geom) - AND ST_Intersects(trajectory(atTime(t2.Trip, p.Period))::GEOMETRY, r.Geom) - AND aDisjoint(atTime(t1.Trip, p.Period), atTime(t2.Trip, p.Period)) -ORDER BY PeriodId, RegionId, Licence1, Licence2; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/explain/query_17.sql b/benchmark/BerlinMOD/sql/explain/query_17.sql deleted file mode 100644 index a632d1d7..00000000 --- a/benchmark/BerlinMOD/sql/explain/query_17.sql +++ /dev/null @@ -1,13 +0,0 @@ -.output results/output/explain/query_17.txt - -SET memory_limit = '20GB'; - -EXPLAIN ANALYZE -WITH PointCount AS ( - SELECT p.PointId, COUNT(DISTINCT t.VehicleId) AS Hits - FROM Trips t, Points p - WHERE ST_Intersects(trajectory(t.Trip)::GEOMETRY, p.Geom) - GROUP BY p.PointId ) -SELECT PointId, Hits -FROM PointCount AS p -WHERE p.Hits = ( SELECT MAX(Hits) FROM PointCount ); \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/explain/query_2.sql b/benchmark/BerlinMOD/sql/explain/query_2.sql deleted file mode 100644 index 9b60eae0..00000000 --- a/benchmark/BerlinMOD/sql/explain/query_2.sql +++ /dev/null @@ -1,8 +0,0 @@ -.output results/output/explain/query_2.txt - -SET memory_limit = '20GB'; - -EXPLAIN ANALYZE -SELECT COUNT (DISTINCT Licence) -FROM Vehicles v -WHERE VehicleType = 'passenger'; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/explain/query_3.sql b/benchmark/BerlinMOD/sql/explain/query_3.sql deleted file mode 100644 index 370ac23b..00000000 --- a/benchmark/BerlinMOD/sql/explain/query_3.sql +++ /dev/null @@ -1,10 +0,0 @@ -.output results/output/explain/query_3.txt - -SET memory_limit = '20GB'; - -EXPLAIN ANALYZE -SELECT DISTINCT l.Licence, i.InstantId, i.Instant AS Instant, - valueAtTimestamp(t.Trip, i.Instant)::GEOMETRY AS Pos -FROM Trips t, Licences1 l, Instants1 i -WHERE t.VehicleId = l.VehicleId AND t.Trip::tstzspan @> i.Instant -ORDER BY l.Licence, i.InstantId; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/explain/query_4.sql b/benchmark/BerlinMOD/sql/explain/query_4.sql deleted file mode 100644 index d8bd744d..00000000 --- a/benchmark/BerlinMOD/sql/explain/query_4.sql +++ /dev/null @@ -1,11 +0,0 @@ -.output results/output/explain/query_4.txt - -SET memory_limit = '20GB'; - -EXPLAIN ANALYZE -SELECT DISTINCT p.PointId, p.Geom, v.Licence -FROM Trips t, Vehicles v, Points p -WHERE - t.VehicleId = v.VehicleId - AND ST_Intersects(trajectory(t.Trip)::GEOMETRY, p.Geom) -ORDER BY p.PointId, v.Licence; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/explain/query_5.sql b/benchmark/BerlinMOD/sql/explain/query_5.sql deleted file mode 100644 index e1eb3164..00000000 --- a/benchmark/BerlinMOD/sql/explain/query_5.sql +++ /dev/null @@ -1,32 +0,0 @@ -.output results/output/explain/query_5.txt - -SET memory_limit = '20GB'; - -/* Slow version -EXPLAIN ANALYZE -SELECT l1.Licence AS Licence1, l2.Licence AS Licence2, - MIN(ST_Distance(trajectory(t1.Trip)::GEOMETRY, - trajectory(t2.Trip)::GEOMETRY)) AS MinDist -FROM Trips t1, Licences1 l1, Trips t2, Licences2 l2 -WHERE - t1.VehicleId = l1.VehicleId - AND t2.VehicleId = l2.VehicleId - AND t1.VehicleId < t2.VehicleId -GROUP BY l1.Licence, l2.Licence -ORDER BY l1.Licence, l2.Licence; -*/ - -EXPLAIN ANALYZE -WITH Temp1(Licence1, Trajs) AS ( - SELECT l1.Licence, collect_gs(list(trajectory_gs(t1.Trip))) - FROM Trips t1, Licences1 l1 - WHERE t1.VehicleId = l1.VehicleId - GROUP BY l1.Licence ), -Temp2(Licence2, Trajs) AS ( - SELECT l2.Licence, collect_gs(list(trajectory_gs(t2.Trip))) - FROM Trips t2, Licences2 l2 - WHERE t2.VehicleId = l2.VehicleId - GROUP BY l2.Licence ) -SELECT Licence1, Licence2, distance_gs(t1.Trajs, t2.Trajs) AS MinDist -FROM Temp1 t1, Temp2 t2 -ORDER BY Licence1, Licence2; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/explain/query_6.sql b/benchmark/BerlinMOD/sql/explain/query_6.sql deleted file mode 100644 index 23a015c3..00000000 --- a/benchmark/BerlinMOD/sql/explain/query_6.sql +++ /dev/null @@ -1,33 +0,0 @@ -.output results/output/explain/query_6.txt - -SET memory_limit = '20GB'; - -/* SLOWER VERSION - -EXPLAIN ANALYZE -SELECT DISTINCT v1.Licence AS Licence1, v2.Licence AS Licence2 -FROM Trips t1, Vehicles v1, Trips t2, Vehicles v2 -WHERE - t1.VehicleId = v1.VehicleId - AND t2.VehicleId = v2.VehicleId - AND t1.VehicleId < t2.VehicleId - AND v1.VehicleType = 'truck' - AND v2.VehicleType = 'truck' - AND t1.Trip && expandSpace(t2.Trip::STBOX, 10) - AND eDwithin(t1.Trip, t2.Trip, 10.0) -ORDER BY v1.Licence, v2.Licence; - -*/ - -EXPLAIN ANALYZE -WITH Temp(Licence, VehicleId, Trip) AS ( - SELECT v.Licence, t.VehicleId, t.Trip - FROM Trips t, Vehicles v - WHERE t.VehicleId = v.VehicleId - AND v.VehicleType = 'truck' ) -SELECT t1.Licence, t2.Licence -FROM Temp t1, Temp t2 -WHERE t1.VehicleId < t2.VehicleId - AND t1.Trip && expandSpace(t2.Trip::STBOX, 10) - AND eDwithin(t1.Trip, t2.Trip, 10.0) -ORDER BY t1.Licence, t2.Licence; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/explain/query_7.sql b/benchmark/BerlinMOD/sql/explain/query_7.sql deleted file mode 100644 index d95e94de..00000000 --- a/benchmark/BerlinMOD/sql/explain/query_7.sql +++ /dev/null @@ -1,22 +0,0 @@ -.output results/output/explain/query_7.txt - -SET memory_limit = '20GB'; - -EXPLAIN ANALYZE -WITH Timestamps AS ( - SELECT DISTINCT v.Licence, p.PointId, p.Geom, - MIN(startTimestamp(atValues(t.Trip,p.Geom::WKB_BLOB))) AS Instant - FROM Trips t, Vehicles v, Points1 p - WHERE - t.VehicleId = v.VehicleId - AND v.VehicleType = 'passenger' - AND t.Trip && stbox(p.Geom::WKB_BLOB) - AND ST_Intersects(trajectory(t.Trip)::GEOMETRY, p.Geom) - GROUP BY v.Licence, p.PointId, p.Geom ) -SELECT t1.Licence, t1.PointId, t1.Geom, t1.Instant -FROM Timestamps t1 -WHERE t1.Instant <= ALL ( - SELECT t2.Instant - FROM Timestamps t2 - WHERE t1.PointId = t2.PointId ) -ORDER BY t1.PointId, t1.Licence; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/explain/query_8.sql b/benchmark/BerlinMOD/sql/explain/query_8.sql deleted file mode 100644 index 1f623b96..00000000 --- a/benchmark/BerlinMOD/sql/explain/query_8.sql +++ /dev/null @@ -1,11 +0,0 @@ -.output results/output/explain/query_8.txt - -SET memory_limit = '20GB'; - -EXPLAIN ANALYZE -SELECT l.Licence, p.PeriodId, p.Period, - SUM(length(atTime(t.Trip, p.Period))) AS Dist -FROM Trips t, Licences1 l, Periods1 p -WHERE t.VehicleId = l.VehicleId AND t.Trip && p.Period -GROUP BY l.Licence, p.PeriodId, p.Period -ORDER BY l.Licence, p.PeriodId; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/explain/query_9.sql b/benchmark/BerlinMOD/sql/explain/query_9.sql deleted file mode 100644 index 795d41d3..00000000 --- a/benchmark/BerlinMOD/sql/explain/query_9.sql +++ /dev/null @@ -1,15 +0,0 @@ -.output results/output/explain/query_9.txt - -SET memory_limit = '20GB'; - -EXPLAIN ANALYZE -WITH Distances AS ( - SELECT p.PeriodId, p.Period, t.VehicleId, - SUM(length(atTime(t.Trip, p.Period))) AS Dist - FROM Trips t, Periods p - WHERE t.Trip && p.Period - GROUP BY p.PeriodId, p.Period, t.VehicleId ) -SELECT PeriodId, Period, MAX(Dist) AS MaxDist -FROM Distances -GROUP BY PeriodId, Period -ORDER BY PeriodId; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/load/03_points.sql b/benchmark/BerlinMOD/sql/load/03_points.sql index 40ef9b77..cbf3302a 100644 --- a/benchmark/BerlinMOD/sql/load/03_points.sql +++ b/benchmark/BerlinMOD/sql/load/03_points.sql @@ -11,7 +11,7 @@ CREATE OR REPLACE TABLE Points ( COPY Points(PointId, PosX, PosY) FROM './data/points.csv'; UPDATE Points -SET Geom = ST_Point(PosX, PosY); +SET Geom = ST_Transform(ST_Point(PosX, PosY), 'EPSG:4326', 'EPSG:3857', always_xy := true); CREATE OR REPLACE VIEW Points1(PointId, PosX, PosY, Geom) AS SELECT PointId, PosX, PosY, Geom diff --git a/benchmark/BerlinMOD/sql/queries/query_1.sql b/benchmark/BerlinMOD/sql/queries/query_1.sql deleted file mode 100644 index e48b22c5..00000000 --- a/benchmark/BerlinMOD/sql/queries/query_1.sql +++ /dev/null @@ -1,6 +0,0 @@ -.mode csv -.output results/output/query_1.csv - -SELECT DISTINCT l.Licence, v.Model AS Model -FROM Vehicles v, Licences l -WHERE v.Licence = l.Licence; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/queries/query_10.sql b/benchmark/BerlinMOD/sql/queries/query_10.sql deleted file mode 100644 index 49be73cb..00000000 --- a/benchmark/BerlinMOD/sql/queries/query_10.sql +++ /dev/null @@ -1,27 +0,0 @@ -.mode csv -.output results/output/query_10.csv - -/* Old version -WITH Values AS ( - SELECT DISTINCT l1.Licence AS QueryLicence, l2.Licence AS OtherLicence, - atTime(t1.Trip, getTime(atValues(tdwithin(t1.Trip, t2.Trip, 3.0), TRUE))) AS Pos - FROM Trips t1, Licences1 l1, Trips t2, Licences2 l2 - WHERE t1.VehicleId = l1.VehicleId AND t2.VehicleId = l2.VehicleId AND - t1.VehicleId < t2.VehicleId AND - expandSpace(t1.Trip::STBOX, 3) && expandSpace(t2.Trip::STBOX, 3) AND - eDwithin(t1.Trip, t2.Trip, 3.0) ) -SELECT QueryLicence, OtherLicence, array_agg(Pos ORDER BY startTimestamp(Pos)) AS Pos -FROM Values -GROUP BY QueryLicence, OtherLicence -ORDER BY QueryLicence, OtherLicence; -*/ - -WITH Temp AS ( - SELECT l1.Licence AS Licence1, t2.VehicleId AS Car2Id, - whenTrue(tDwithin(t1.Trip, t2.Trip, 3.0)) AS Periods - FROM Trips t1, Licences1 l1, Trips t2, Vehicles v - WHERE t1.VehicleId = l1.VehicleId AND t2.VehicleId = v.VehicleId AND - t1.VehicleId <> t2.VehicleId AND t2.Trip && expandSpace(t1.trip::STBOX, 3.0) ) -SELECT Licence1, Car2Id, Periods -FROM Temp -WHERE Periods IS NOT NULL; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/queries/query_11.sql b/benchmark/BerlinMOD/sql/queries/query_11.sql deleted file mode 100644 index 31a19bd6..00000000 --- a/benchmark/BerlinMOD/sql/queries/query_11.sql +++ /dev/null @@ -1,22 +0,0 @@ -.mode csv -.output results/output/query_11.csv - -/* Old version -SELECT p.PointId, p.Geom, i.InstantId, i.Instant, v.Licence -FROM Trips t, Vehicles v, Points1 p, Instants1 i -WHERE - t.VehicleId = v.VehicleId - AND t.Trip @> stbox(p.Geom::WKB_BLOB, i.Instant) - AND valueAtTimestamp(t.Trip, i.Instant) = p.Geom -ORDER BY p.PointId, i.InstantId, v.Licence; -*/ - -WITH Temp AS ( - SELECT p.PointId, p.Geom, i.InstantId, i.Instant, t.VehicleId - FROM Trips t, Points1 p, Instants1 i - WHERE - t.Trip @> stbox(p.Geom::WKB_BLOB, i.Instant) - AND valueAtTimestamp(t.Trip, i.Instant) = p.Geom ) -SELECT t.PointId, t.Geom, t.InstantId, t.Instant, v.Licence -FROM Temp t JOIN Vehicles v ON t.VehicleId = v.VehicleId -ORDER BY t.PointId, t.InstantId, v.Licence; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/queries/query_12.sql b/benchmark/BerlinMOD/sql/queries/query_12.sql deleted file mode 100644 index cf4ab9da..00000000 --- a/benchmark/BerlinMOD/sql/queries/query_12.sql +++ /dev/null @@ -1,32 +0,0 @@ -.mode csv -.output results/output/query_12.csv - -/* Old version -SELECT DISTINCT p.PointId, p.Geom, i.InstantId, i.Instant, - v1.Licence AS Licence1, v2.Licence AS Licence2 -FROM Trips t1, Vehicles v1, Trips t2, Vehicles v2, Points1 p, Instants1 i -WHERE - t1.VehicleId = v1.VehicleId - AND t2.VehicleId = v2.VehicleId - AND t1.VehicleId < t2.VehicleId - AND t1.Trip @> stbox(p.Geom::WKB_BLOB, i.Instant) - AND t2.Trip @> stbox(p.Geom::WKB_BLOB, i.Instant) - AND valueAtTimestamp(t1.Trip, i.Instant) = p.Geom - AND valueAtTimestamp(t2.Trip, i.Instant) = p.Geom -ORDER BY p.PointId, i.InstantId, v1.Licence, v2.Licence; -*/ - -WITH Temp AS ( - SELECT DISTINCT p.PointId, p.Geom, i.InstantId, i.Instant, t.VehicleId - FROM Trips t, Points1 p, Instants1 i - WHERE t.Trip @> stbox(p.Geom::WKB_BLOB, i.Instant) - AND valueAtTimestamp(t.Trip, i.Instant) = p.Geom ) -SELECT DISTINCT t1.PointId, t1.Geom, t1.InstantId, t1.Instant, - v1.Licence AS Licence1, v2.Licence AS Licence2 -FROM Temp t1 - JOIN Vehicles v1 ON t1.VehicleId = v1.VehicleId - JOIN Temp t2 ON t1.VehicleId < t2.VehicleId - AND t1.PointID = t2.PointID - AND t1.InstantId = t2.InstantId - JOIN Vehicles v2 ON t2.VehicleId = v2.VehicleId -ORDER BY t1.PointId, t1.InstantId, v1.Licence, v2.Licence; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/queries/query_13.sql b/benchmark/BerlinMOD/sql/queries/query_13.sql deleted file mode 100644 index e12fe8ce..00000000 --- a/benchmark/BerlinMOD/sql/queries/query_13.sql +++ /dev/null @@ -1,24 +0,0 @@ -.mode csv -.output results/output/query_13.csv - -/* Old version -SELECT DISTINCT r.RegionId, p.PeriodId, p.Period, v.Licence -FROM Trips t, Vehicles v, Regions1 r, Periods1 p -WHERE - t.VehicleId = v.VehicleId - AND t.trip && stbox(r.Geom::WKB_BLOB, p.Period) - AND ST_Intersects(trajectory(atTime(t.Trip, p.Period))::GEOMETRY, r.Geom) -ORDER BY r.RegionId, p.PeriodId, v.Licence; -*/ - -WITH Temp AS ( - SELECT DISTINCT r.RegionId, p.PeriodId, p.Period, t.VehicleId - FROM Trips t, Regions1 r, Periods1 p - WHERE - t.trip && stbox(r.Geom::WKB_BLOB, p.Period) - AND ST_Intersects(trajectory(atTime(t.Trip, p.Period))::GEOMETRY, r.Geom) - ORDER BY r.RegionId, p.PeriodId ) -SELECT DISTINCT t.RegionId, t.PeriodId, t.Period, v.Licence -FROM Temp t, Vehicles v -WHERE t.VehicleId = v.VehicleId -ORDER BY t.RegionId, t.PeriodId, v.Licence; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/queries/query_14.sql b/benchmark/BerlinMOD/sql/queries/query_14.sql deleted file mode 100644 index 4c88648e..00000000 --- a/benchmark/BerlinMOD/sql/queries/query_14.sql +++ /dev/null @@ -1,22 +0,0 @@ -.mode csv -.output results/output/query_14.csv - -/* Old version -SELECT DISTINCT r.RegionId, i.InstantId, i.Instant, v.Licence -FROM Trips t, Vehicles v, Regions1 r, Instants1 i -WHERE - t.VehicleId = v.VehicleId - AND t.Trip && stbox(r.Geom::WKB_BLOB, i.Instant) - AND ST_Contains(r.Geom, valueAtTimestamp(t.Trip, i.Instant)::GEOMETRY) -ORDER BY r.RegionId, i.InstantId, v.Licence; -*/ - -WITH Temp AS ( - SELECT DISTINCT r.RegionId, i.InstantId, i.Instant, t.VehicleId - FROM Trips t, Regions1 r, Instants1 i - WHERE - t.Trip && stbox(r.Geom::WKB_BLOB, i.Instant) - AND ST_Contains(r.Geom, valueAtTimestamp(t.Trip, i.Instant)::GEOMETRY) ) -SELECT DISTINCT t.RegionId, t.InstantId, t.Instant, v.Licence -FROM Temp t JOIN Vehicles v ON t.VehicleId = v.VehicleId -ORDER BY t.RegionId, t.InstantId, v.Licence; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/queries/query_15.sql b/benchmark/BerlinMOD/sql/queries/query_15.sql deleted file mode 100644 index f7b98838..00000000 --- a/benchmark/BerlinMOD/sql/queries/query_15.sql +++ /dev/null @@ -1,22 +0,0 @@ -.mode csv -.output results/output/query_15.csv - -/* Old version -SELECT DISTINCT pt.PointId, pt.Geom, pr.PeriodId, pr.Period, v.Licence -FROM Trips t, Vehicles v, Points1 pt, Periods1 pr -WHERE - t.VehicleId = v.VehicleId - AND t.Trip && stbox(pt.Geom::WKB_BLOB, pr.Period) - AND ST_Intersects(trajectory(atTime(t.Trip, pr.Period))::GEOMETRY, pt.Geom) -ORDER BY pt.PointId, pr.PeriodId, v.Licence; -*/ - -WITH Temp AS ( - SELECT DISTINCT pt.PointId, pt.Geom, pr.PeriodId, pr.Period, t.VehicleId - FROM Trips t, Points1 pt, Periods1 pr - WHERE t.Trip && stbox(pt.Geom::WKB_BLOB, pr.Period) - AND ST_Intersects(trajectory(atTime(t.Trip, pr.Period))::GEOMETRY, pt.Geom) ) -SELECT DISTINCT t.PointId, t.Geom, t.PeriodId, t.Period, v.Licence -FROM Temp t, Vehicles v -WHERE t.VehicleId = v.VehicleId -ORDER BY t.PointId, t.PeriodId, v.Licence; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/queries/query_16.sql b/benchmark/BerlinMOD/sql/queries/query_16.sql deleted file mode 100644 index 3a017ef1..00000000 --- a/benchmark/BerlinMOD/sql/queries/query_16.sql +++ /dev/null @@ -1,15 +0,0 @@ -.mode csv -.output results/output/query_16.csv - -SELECT p.PeriodId, p.Period, r.RegionId, l1.Licence AS Licence1, l2.Licence AS Licence2 -FROM Trips t1, Licences1 l1, Trips t2, Licences2 l2, Periods1 p, Regions1 r -WHERE - t1.VehicleId = l1.VehicleId - AND t2.VehicleId = l2.VehicleId - AND l1.Licence < l2.Licence - -- AND t1.Trip && stbox(r.Geom::WKB_BLOB, p.Period) - -- AND t2.Trip && stbox(r.Geom::WKB_BLOB, p.Period) - AND ST_Intersects(trajectory(atTime(t1.Trip, p.Period))::GEOMETRY, r.Geom) - AND ST_Intersects(trajectory(atTime(t2.Trip, p.Period))::GEOMETRY, r.Geom) - AND aDisjoint(atTime(t1.Trip, p.Period), atTime(t2.Trip, p.Period)) -ORDER BY PeriodId, RegionId, Licence1, Licence2; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/queries/query_17.sql b/benchmark/BerlinMOD/sql/queries/query_17.sql deleted file mode 100644 index 71dd8a9b..00000000 --- a/benchmark/BerlinMOD/sql/queries/query_17.sql +++ /dev/null @@ -1,11 +0,0 @@ -.mode csv -.output results/output/query_17.csv - -WITH PointCount AS ( - SELECT p.PointId, COUNT(DISTINCT t.VehicleId) AS Hits - FROM Trips t, Points p - WHERE ST_Intersects(trajectory(t.Trip)::GEOMETRY, p.Geom) - GROUP BY p.PointId ) -SELECT PointId, Hits -FROM PointCount AS p -WHERE p.Hits = ( SELECT MAX(Hits) FROM PointCount ); \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/queries/query_2.sql b/benchmark/BerlinMOD/sql/queries/query_2.sql deleted file mode 100644 index 81e4e686..00000000 --- a/benchmark/BerlinMOD/sql/queries/query_2.sql +++ /dev/null @@ -1,6 +0,0 @@ -.mode csv -.output results/output/query_2.csv - -SELECT COUNT (DISTINCT Licence) -FROM Vehicles v -WHERE VehicleType = 'passenger'; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/queries/query_3.sql b/benchmark/BerlinMOD/sql/queries/query_3.sql deleted file mode 100644 index 2f6b19a4..00000000 --- a/benchmark/BerlinMOD/sql/queries/query_3.sql +++ /dev/null @@ -1,8 +0,0 @@ -.mode csv -.output results/output/query_3.csv - -SELECT DISTINCT l.Licence, i.InstantId, i.Instant AS Instant, - valueAtTimestamp(t.Trip, i.Instant)::GEOMETRY AS Pos -FROM Trips t, Licences1 l, Instants1 i -WHERE t.VehicleId = l.VehicleId AND t.Trip::tstzspan @> i.Instant -ORDER BY l.Licence, i.InstantId; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/queries/query_4.sql b/benchmark/BerlinMOD/sql/queries/query_4.sql deleted file mode 100644 index 1267a3a1..00000000 --- a/benchmark/BerlinMOD/sql/queries/query_4.sql +++ /dev/null @@ -1,9 +0,0 @@ -.mode csv -.output results/output/query_4.csv - -SELECT DISTINCT p.PointId, p.Geom, v.Licence -FROM Trips t, Vehicles v, Points p -WHERE - t.VehicleId = v.VehicleId - AND ST_Intersects(trajectory(t.Trip)::GEOMETRY, p.Geom) -ORDER BY p.PointId, v.Licence; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/queries/query_5.sql b/benchmark/BerlinMOD/sql/queries/query_5.sql deleted file mode 100644 index e644a36b..00000000 --- a/benchmark/BerlinMOD/sql/queries/query_5.sql +++ /dev/null @@ -1,29 +0,0 @@ -.mode csv -.output results/output/query_5.csv - -/* Slow version -SELECT l1.Licence AS Licence1, l2.Licence AS Licence2, - MIN(ST_Distance(trajectory(t1.Trip)::GEOMETRY, - trajectory(t2.Trip)::GEOMETRY)) AS MinDist -FROM Trips t1, Licences1 l1, Trips t2, Licences2 l2 -WHERE - t1.VehicleId = l1.VehicleId - AND t2.VehicleId = l2.VehicleId - AND t1.VehicleId < t2.VehicleId -GROUP BY l1.Licence, l2.Licence -ORDER BY l1.Licence, l2.Licence; -*/ - -WITH Temp1(Licence1, Trajs) AS ( - SELECT l1.Licence, collect_gs(list(trajectory_gs(t1.Trip))) - FROM Trips t1, Licences1 l1 - WHERE t1.VehicleId = l1.VehicleId - GROUP BY l1.Licence ), -Temp2(Licence2, Trajs) AS ( - SELECT l2.Licence, collect_gs(list(trajectory_gs(t2.Trip))) - FROM Trips t2, Licences2 l2 - WHERE t2.VehicleId = l2.VehicleId - GROUP BY l2.Licence ) -SELECT Licence1, Licence2, distance_gs(t1.Trajs, t2.Trajs) AS MinDist -FROM Temp1 t1, Temp2 t2 -ORDER BY Licence1, Licence2; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/queries/query_6.sql b/benchmark/BerlinMOD/sql/queries/query_6.sql deleted file mode 100644 index c3a85a13..00000000 --- a/benchmark/BerlinMOD/sql/queries/query_6.sql +++ /dev/null @@ -1,30 +0,0 @@ -.mode csv -.output results/output/query_6.csv - -/* SLOWER VERSION - -SELECT DISTINCT v1.Licence AS Licence1, v2.Licence AS Licence2 -FROM Trips t1, Vehicles v1, Trips t2, Vehicles v2 -WHERE - t1.VehicleId = v1.VehicleId - AND t2.VehicleId = v2.VehicleId - AND t1.VehicleId < t2.VehicleId - AND v1.VehicleType = 'truck' - AND v2.VehicleType = 'truck' - AND t1.Trip && expandSpace(t2.Trip::STBOX, 10) - AND eDwithin(t1.Trip, t2.Trip, 10.0) -ORDER BY v1.Licence, v2.Licence; - -*/ - -WITH Temp(Licence, VehicleId, Trip) AS ( - SELECT v.Licence, t.VehicleId, t.Trip - FROM Trips t, Vehicles v - WHERE t.VehicleId = v.VehicleId - AND v.VehicleType = 'truck' ) -SELECT t1.Licence, t2.Licence -FROM Temp t1, Temp t2 -WHERE t1.VehicleId < t2.VehicleId - AND t1.Trip && expandSpace(t2.Trip::STBOX, 10) - AND eDwithin(t1.Trip, t2.Trip, 10.0) -ORDER BY t1.Licence, t2.Licence; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/queries/query_7.sql b/benchmark/BerlinMOD/sql/queries/query_7.sql deleted file mode 100644 index 39811c9e..00000000 --- a/benchmark/BerlinMOD/sql/queries/query_7.sql +++ /dev/null @@ -1,20 +0,0 @@ -.mode csv -.output results/output/query_7.csv - -WITH Timestamps AS ( - SELECT DISTINCT v.Licence, p.PointId, p.Geom, - MIN(startTimestamp(atValues(t.Trip,p.Geom::WKB_BLOB))) AS Instant - FROM Trips t, Vehicles v, Points1 p - WHERE - t.VehicleId = v.VehicleId - AND v.VehicleType = 'passenger' - AND t.Trip && stbox(p.Geom::WKB_BLOB) - AND ST_Intersects(trajectory(t.Trip)::GEOMETRY, p.Geom) - GROUP BY v.Licence, p.PointId, p.Geom ) -SELECT t1.Licence, t1.PointId, t1.Geom, t1.Instant -FROM Timestamps t1 -WHERE t1.Instant <= ALL ( - SELECT t2.Instant - FROM Timestamps t2 - WHERE t1.PointId = t2.PointId ) -ORDER BY t1.PointId, t1.Licence; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/queries/query_8.sql b/benchmark/BerlinMOD/sql/queries/query_8.sql deleted file mode 100644 index 87a15e8b..00000000 --- a/benchmark/BerlinMOD/sql/queries/query_8.sql +++ /dev/null @@ -1,9 +0,0 @@ -.mode csv -.output results/output/query_8.csv - -SELECT l.Licence, p.PeriodId, p.Period, - SUM(length(atTime(t.Trip, p.Period))) AS Dist -FROM Trips t, Licences1 l, Periods1 p -WHERE t.VehicleId = l.VehicleId AND t.Trip && p.Period -GROUP BY l.Licence, p.PeriodId, p.Period -ORDER BY l.Licence, p.PeriodId; \ No newline at end of file diff --git a/benchmark/BerlinMOD/sql/queries/query_9.sql b/benchmark/BerlinMOD/sql/queries/query_9.sql deleted file mode 100644 index 36eae37a..00000000 --- a/benchmark/BerlinMOD/sql/queries/query_9.sql +++ /dev/null @@ -1,13 +0,0 @@ -.mode csv -.output results/output/query_9.csv - -WITH Distances AS ( - SELECT p.PeriodId, p.Period, t.VehicleId, - SUM(length(atTime(t.Trip, p.Period))) AS Dist - FROM Trips t, Periods p - WHERE t.Trip && p.Period - GROUP BY p.PeriodId, p.Period, t.VehicleId ) -SELECT PeriodId, Period, MAX(Dist) AS MaxDist -FROM Distances -GROUP BY PeriodId, Period -ORDER BY PeriodId; \ No newline at end of file