From c49ce684c87e7b4b84a6c5f553f73bba49793993 Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 21 Mar 2021 17:36:13 +0000 Subject: [PATCH] Optimize master_index_stats We no longer need COUNT DISTINCT - the resolve_* functions can only return a single row. Signed-off-by: Graham --- .../org/openrs2/archive/migrations/V1__init.sql | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/archive/src/main/resources/org/openrs2/archive/migrations/V1__init.sql b/archive/src/main/resources/org/openrs2/archive/migrations/V1__init.sql index d1bc9752..41a83ccf 100644 --- a/archive/src/main/resources/org/openrs2/archive/migrations/V1__init.sql +++ b/archive/src/main/resources/org/openrs2/archive/migrations/V1__init.sql @@ -253,8 +253,8 @@ FROM master_indexes m LEFT JOIN ( SELECT a.master_index_id, - COUNT(DISTINCT a.archive_id) FILTER (WHERE c.id IS NOT NULL OR (a.version = 0 AND a.crc32 = 0)) AS valid_indexes, - COUNT(DISTINCT a.archive_id) AS indexes + COUNT(*) FILTER (WHERE c.id IS NOT NULL OR (a.version = 0 AND a.crc32 = 0)) AS valid_indexes, + COUNT(*) AS indexes FROM master_index_archives a LEFT JOIN LATERAL resolve_index(a.archive_id, a.crc32, a.version) c ON TRUE GROUP BY a.master_index_id @@ -262,10 +262,10 @@ LEFT JOIN ( LEFT JOIN ( SELECT i.master_index_id, - COUNT(DISTINCT (i.archive_id, ig.group_id)) FILTER (WHERE c.id IS NOT NULL) AS valid_groups, - COUNT(DISTINCT (i.archive_id, ig.group_id)) AS groups, - COUNT(DISTINCT (i.archive_id, ig.group_id)) FILTER (WHERE c.key_id IS NOT NULL) AS valid_keys, - COUNT(DISTINCT (i.archive_id, ig.group_id)) FILTER (WHERE c.encrypted) AS keys + COUNT(*) FILTER (WHERE c.id IS NOT NULL) AS valid_groups, + COUNT(*) AS groups, + COUNT(*) FILTER (WHERE c.key_id IS NOT NULL) AS valid_keys, + COUNT(*) FILTER (WHERE c.encrypted) AS keys FROM resolved_indexes i JOIN index_groups ig ON ig.container_id = i.container_id LEFT JOIN LATERAL resolve_group(i.archive_id, ig.group_id, ig.crc32, ig.version) c ON TRUE