From 833373a70e5514f87b1a2702983b6e351f49e36b Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 20 Feb 2021 10:30:06 +0000 Subject: [PATCH] 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 a920570f042ff27e476429d1caaea69dce2120fa. Signed-off-by: Graham --- .../kotlin/org/openrs2/archive/cache/CacheImporter.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt b/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt index 07e83d8d..bb74de5d 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt +++ b/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()