From 10c69b910ec3fbb74036b282b7b16bd3b68bc1b3 Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Thu, 16 Oct 2025 16:39:10 -0400 Subject: [PATCH] Prevent ambiguous self-join table reference --- core/translate/select.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/translate/select.rs b/core/translate/select.rs index 59b6ff6cb..376745f77 100644 --- a/core/translate/select.rs +++ b/core/translate/select.rs @@ -225,6 +225,16 @@ fn prepare_one_select_plan( &mut table_references, connection, )?; + // Validate that all table references have unique identifiers + let mut seen_identifiers = std::collections::HashSet::new(); + for table in table_references.joined_tables().iter() { + if !seen_identifiers.insert(&table.identifier) { + crate::bail_parse_error!( + "table name {} specified more than once - use aliases to distinguish multiple references", + table.identifier + ); + } + } // Preallocate space for the result columns let result_columns = Vec::with_capacity(