Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
ma_code
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sven-Ove Hänsel
ma_code
Commits
abed4aa3
Commit
abed4aa3
authored
7 months ago
by
julian
Browse files
Options
Downloads
Patches
Plain Diff
small fixes, script to collect statistics from db
parent
96dc4155
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
compose.yml
+2
-0
2 additions, 0 deletions
compose.yml
postgres/initdb/03-initdb_fill_edge_uuid.sql
+2
-1
2 additions, 1 deletion
postgres/initdb/03-initdb_fill_edge_uuid.sql
postgres/queries.sql
+11
-1
11 additions, 1 deletion
postgres/queries.sql
stats.py
+72
-0
72 additions, 0 deletions
stats.py
with
87 additions
and
2 deletions
compose.yml
+
2
−
0
View file @
abed4aa3
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
postgres/initdb/03-initdb_fill_edge_uuid.sql
+
2
−
1
View file @
abed4aa3
...
@@ -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
;
This diff is collapsed.
Click to expand it.
postgres/queries.sql
+
11
−
1
View file @
abed4aa3
...
@@ -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
This diff is collapsed.
Click to expand it.
stats.py
0 → 100644
+
72
−
0
View file @
abed4aa3
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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment