From ebd1c2a14dbfc05ebe635204ef0dd4320c5c9533 Mon Sep 17 00:00:00 2001 From: Tim Diekmann <21277928+TimDiekmann@users.noreply.github.com> Date: Mon, 2 Dec 2024 16:57:49 +0100 Subject: [PATCH] H-3612: Properly detect tables with different inheritance depths (#5770) --- .../src/store/postgres/query/compile.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libs/@local/graph/postgres-store/src/store/postgres/query/compile.rs b/libs/@local/graph/postgres-store/src/store/postgres/query/compile.rs index 8a616356dcb..b58bacc8355 100644 --- a/libs/@local/graph/postgres-store/src/store/postgres/query/compile.rs +++ b/libs/@local/graph/postgres-store/src/store/postgres/query/compile.rs @@ -1,5 +1,5 @@ use alloc::borrow::Cow; -use core::iter::once; +use core::{iter::once, mem}; use std::collections::{HashMap, HashSet}; use hash_graph_store::{ @@ -1018,6 +1018,16 @@ impl<'p, 'q: 'p, R: PostgresRecord> SelectCompiler<'p, 'q, R> { // column. We need to create a new join statement later on with a new, // unique alias. join_expression.table.alias.number += 1; + } else if let (Table::Reference(lhs), Table::Reference(rhs)) = + (&existing.table.table, &join_expression.table.table) + { + if mem::discriminant(lhs) == mem::discriminant(rhs) + && existing.table.alias == join_expression.table.alias + { + // We have a join statement for the same table but with different + // conditions. + join_expression.table.alias.number += 1; + } } }