Fix LEFT JOINs in queries for listing missing groups

The previous code included too many rows as the use of LEFT JOINs meant
candidate group orws with an incorrect container_id were still included
in the results.

Using an IN clause with a subquery allows us to remove those rows,
though it's a bit hacky.

(Really I want to be able to use the JOIN on the right side of a LEFT
JOIN to restrict the rows that appear in the results of the LEFT JOIN,
but that doesn't seem to be possible.)

This is similar to the issue fixed by
a920570f04.

Signed-off-by: Graham <gpe@openrs2.org>
Graham 4 years ago
parent d7919da2a3
commit 833373a70e
  1. 9
      archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt

@ -217,8 +217,9 @@ public class CacheImporter @Inject constructor(
LEFT JOIN master_index_archives a2 ON a2.master_index_id = ? AND a2.archive_id = a.archive_id AND
a2.crc32 = a.crc32 AND a2.version = a.version
LEFT JOIN groups g ON g.archive_id = 255 AND g.group_id = a2.archive_id::INTEGER AND
g.version = a2.version AND NOT g.version_truncated
LEFT JOIN containers c ON c.id = g.container_id AND c.crc32 = a2.crc32
g.version = a2.version AND NOT g.version_truncated AND
g.container_id IN (SELECT id FROM containers WHERE crc32 = a2.crc32)
LEFT JOIN containers c ON c.id = g.container_id
LEFT JOIN indexes i ON i.container_id = g.container_id AND i.version = a2.version
WHERE a.master_index_id = ?
ORDER BY a.archive_id ASC
@ -280,8 +281,8 @@ public class CacheImporter @Inject constructor(
LEFT JOIN index_groups ig2 ON ig2.container_id = i.container_id AND ig2.group_id = ig.group_id AND
ig2.crc32 = ig.crc32 AND ig2.version = ig.version
LEFT JOIN groups g ON g.archive_id = i.archive_id AND g.group_id = ig2.group_id AND
g.version = ig2.version AND NOT g.version_truncated
LEFT JOIN containers c ON c.id = g.container_id AND c.crc32 = ig2.crc32
g.version = ig2.version AND NOT g.version_truncated AND
g.container_id IN (SELECT id FROM containers WHERE crc32 = ig2.crc32)
WHERE ig.container_id = ? AND g.container_id IS NULL
ORDER BY ig.group_id ASC
""".trimIndent()

Loading…
Cancel
Save