Skip to content
Snippets Groups Projects
Commit abed4aa3 authored by julian's avatar julian
Browse files

small fixes, script to collect statistics from db

parent 96dc4155
No related branches found
No related tags found
No related merge requests found
...@@ -43,6 +43,8 @@ services: ...@@ -43,6 +43,8 @@ services:
- POSTGRES_USER=$PGUSER - POSTGRES_USER=$PGUSER
- POSTGRES_DB=$PGDATABASE - POSTGRES_DB=$PGDATABASE
- POSTGRES_PASSWORD_FILE=/run/secrets/postgres_db_pass - POSTGRES_PASSWORD_FILE=/run/secrets/postgres_db_pass
ports:
- 5432:5432
healthcheck: healthcheck:
test: pg_isready -U postgres test: pg_isready -U postgres
start_period: 5s start_period: 5s
......
...@@ -34,4 +34,5 @@ with new_edges as( ...@@ -34,4 +34,5 @@ with new_edges as(
where type='UnnamedPipeObject' where type='UnnamedPipeObject'
) )
insert into edge (origin, destination, type) insert into edge (origin, destination, type)
select origin, destination, type::EDGE_TYPE from new_edges; select origin::UUID, destination::UUID, type::EDGE_TYPE from new_edges
where destination is not null;
...@@ -66,7 +66,7 @@ PREPARE shortest_path (int, int, int) AS ...@@ -66,7 +66,7 @@ PREPARE shortest_path (int, int, int) AS
PREPARE two_hop_old (INTEGER) AS PREPARE two_hop_old (INTEGER) AS
WITH hop1 AS ( WITH hop1 AS (
SELECT origin, destination SELECT DISTINCT origin, destination
FROM edge FROM edge
WHERE origin = $1 WHERE origin = $1
OR destination = $1 OR destination = $1
...@@ -103,3 +103,13 @@ PREPARE two_hop (INTEGER) AS ...@@ -103,3 +103,13 @@ PREPARE two_hop (INTEGER) AS
SELECT destination SELECT destination
FROM double_edge FROM double_edge
JOIN hop1 ON vertex = origin AND destination <> $1; JOIN hop1 ON vertex = origin AND destination <> $1;
PREPARE neighborhood (INTEGER) AS
WITH double_edge AS NOT MATERIALIZED (
SELECT origin, destination FROM edge
UNION ALL
SELECT destination, origin FROM edge
)
SELECT destination AS vertex
FROM double_edge
WHERE origin = $1 AND destination <> $1;
\ No newline at end of file
stats.py 0 → 100644
import csv
from statistics import fmean, mode, pvariance
from os import environ
from random import sample
from typing import Any
import psycopg
max_vert = 46761949
neighbors = """
explain (analyze, format json) (
WITH double_edge AS NOT MATERIALIZED (
SELECT origin, destination FROM edge
UNION ALL
SELECT destination, origin FROM edge
)
SELECT destination AS vertex
FROM double_edge
WHERE origin = %(id)s AND destination <> %(id)s
);
"""
two_hop = """
explain (analyze, format json) (
WITH double_edge AS NOT MATERIALIZED (
SELECT origin, destination FROM edge
UNION ALL
SELECT destination, origin FROM edge
), hop1 AS (
SELECT destination AS vertex
FROM double_edge
WHERE origin = %(id)s AND destination <> %(id)s AND destination <> 5
)
SELECT vertex
FROM hop1
UNION
SELECT destination
FROM double_edge
JOIN hop1 ON vertex = origin AND destination <> %(id)s
);
"""
environ["PGHOST"] = "localhost"
environ["PGPASSFILE"] = ".pgpass"
with psycopg.connect() as conn, conn.cursor() as cur:
selected = (
{"id": id}
for id in {
22280515,
29465322,
29545621,
29701639,
30584080,
31295043,
35584630,
35723190,
36003677,
}
)
stats = []
for id in selected:
result: Any = cur.execute(two_hop, id, prepare=True).fetchone()
rows = result[0][0]["Plan"]["Actual Rows"]
time = result[0][0]["Plan"]["Actual Total Time"]
stats.append((id["id"], int(rows), float(time)))
stats.sort(key=lambda tpl: tpl[1])
with open("result/two_hop_stats.csv", mode="x") as file:
writer = csv.writer(file)
writer.writerow(("VERTEX", "RESULT_SIZE", "QUERY_LATENCY"))
writer.writerows(stats)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment