Fix over-counting in the master_index_stats view

Unfortunately the size column can't be fixed in the same way, so I've
deleted it for now.

Signed-off-by: Graham <gpe@openrs2.org>
bzip2
Graham 4 years ago
parent 94992601f6
commit 42c3c4c120
  1. 19
      archive/src/main/resources/org/openrs2/archive/migrations/V1__init.sql

@ -172,8 +172,7 @@ CREATE MATERIALIZED VIEW master_index_stats (
valid_groups, valid_groups,
groups, groups,
valid_keys, valid_keys,
keys, keys
size
) AS ) AS
SELECT SELECT
a.master_index_id, a.master_index_id,
@ -182,13 +181,12 @@ SELECT
COALESCE(g.valid_groups, 0), COALESCE(g.valid_groups, 0),
COALESCE(g.groups, 0), COALESCE(g.groups, 0),
COALESCE(g.valid_keys, 0), COALESCE(g.valid_keys, 0),
COALESCE(g.keys, 0), COALESCE(g.keys, 0)
COALESCE(g.size, 0)
FROM ( FROM (
SELECT SELECT
a.master_index_id, a.master_index_id,
COUNT(i.container_id) AS valid_indexes, COUNT(DISTINCT a.archive_id) FILTER (WHERE i.container_id IS NOT NULL) AS valid_indexes,
COUNT(*) AS indexes COUNT(DISTINCT a.archive_id) AS indexes
FROM master_index_archives a FROM master_index_archives a
LEFT JOIN groups g ON g.archive_id = 255 AND g.group_id = a.archive_id::INTEGER AND LEFT JOIN groups g ON g.archive_id = 255 AND g.group_id = a.archive_id::INTEGER AND
g.version = a.version AND NOT g.version_truncated AND g.version = a.version AND NOT g.version_truncated AND
@ -200,11 +198,10 @@ FROM (
LEFT JOIN ( LEFT JOIN (
SELECT SELECT
i.master_index_id, i.master_index_id,
COUNT(g.container_id) AS valid_groups, COUNT(DISTINCT (i.archive_id, ig.group_id)) FILTER (WHERE c.id IS NOT NULL) AS valid_groups,
COUNT(*) AS groups, COUNT(DISTINCT (i.archive_id, ig.group_id)) AS groups,
COUNT(*) FILTER (WHERE c.key_id IS NOT NULL) AS valid_keys, COUNT(DISTINCT (i.archive_id, ig.group_id)) FILTER (WHERE c.key_id IS NOT NULL) AS valid_keys,
COUNT(*) FILTER (WHERE c.encrypted) AS keys, COUNT(DISTINCT (i.archive_id, ig.group_id)) FILTER (WHERE c.encrypted) AS keys
SUM(length(c.data)) AS size
FROM resolved_indexes i FROM resolved_indexes i
JOIN index_groups ig ON ig.container_id = i.container_id JOIN index_groups ig ON ig.container_id = i.container_id
LEFT JOIN groups g ON g.archive_id = i.archive_id AND g.group_id = ig.group_id AND ( LEFT JOIN groups g ON g.archive_id = i.archive_id AND g.group_id = ig.group_id AND (

Loading…
Cancel
Save