Commit 852dc63e authored by Pierre-Elliott Bécue's avatar Pierre-Elliott Bécue

[comptage_upload] Amélioration de la requête SQL

parent aa63141c
......@@ -30,6 +30,15 @@ def get_stats(args):
pgsql.set_session(autocommit=True)
curseur = pgsql.cursor(cursor_factory=psycopg2.extras.DictCursor)
ip_requete = """
WITH
machines_sans_doublon
AS
(
SELECT DISTINCT ON(mac_addr)
*
FROM
machines
)
SELECT
SUM(upload) as tot_upload,
SUM(download) as tot_download,
......@@ -51,9 +60,9 @@ FROM (
FROM
upload
LEFT JOIN
machines
machines_sans_doublon
ON
machines.mac_addr = upload.mac_src
machines_sans_doublon.mac_addr = upload.mac_src
WHERE
ip_src=%(pg_value)s
AND NOT
......@@ -88,9 +97,9 @@ FROM (
FROM
upload
LEFT JOIN
machines
machines_sans_doublon
ON
machines.mac_addr = upload.mac_dst
machines_sans_doublon.mac_addr = upload.mac_dst
WHERE
ip_dst=%(pg_value)s
AND NOT
......@@ -123,6 +132,15 @@ GROUP BY
port_ext
"""
mac_requete = """
WITH
machines_sans_doublon
AS
(
SELECT DISTINCT ON(mac_addr)
*
FROM
machines
)
SELECT
SUM(upload) as tot_upload,
SUM(download) as tot_download,
......@@ -144,9 +162,9 @@ FROM (
FROM
upload
LEFT JOIN
machines
machines_sans_doublon
ON
machines.mac_addr = upload.mac_src
machines_sans_doublon.mac_addr = upload.mac_src
WHERE
mac_src=macaddr%(pg_value)s
AND NOT
......@@ -183,9 +201,9 @@ FROM (
FROM
upload
LEFT JOIN
machines
machines_sans_doublon
ON
machines.mac_addr = upload.mac_dst
machines_sans_doublon.mac_addr = upload.mac_dst
WHERE
mac_dst=macaddr%(pg_value)s
AND NOT
......@@ -220,6 +238,15 @@ GROUP BY
port_ext
"""
adh_requete = """
WITH
machines_sans_doublon
AS
(
SELECT DISTINCT ON(mac_addr)
*
FROM
machines
)
SELECT
SUM(upload) as tot_upload,
SUM(download) as tot_download,
......@@ -241,13 +268,13 @@ FROM (
FROM
upload
LEFT JOIN
machines
machines_sans_doublon
ON
machines.mac_addr = upload.mac_src
machines_sans_doublon.mac_addr = upload.mac_src
WHERE
machines.type=%(pg_filter)s
machines_sans_doublon.type=%(pg_filter)s
AND
machines.id=%(pg_value)s
machines_sans_doublon.id=%(pg_value)s
AND NOT
ip_src <<= inet%(ipv6_local)s
AND NOT
......@@ -282,13 +309,13 @@ FROM (
FROM
upload
LEFT JOIN
machines
machines_sans_doublon
ON
machines.mac_addr = upload.mac_dst
machines_sans_doublon.mac_addr = upload.mac_dst
WHERE
machines.type=%(pg_filter)s
machines_sans_doublon.type=%(pg_filter)s
AND
machines.id=%(pg_value)s
machines_sans_doublon.id=%(pg_value)s
AND NOT
ip_src <<= inet%(ipv6_local)s
AND NOT
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment