From f4ee0457b23b321a0cbbdbb7ae7df154eb9efb8c Mon Sep 17 00:00:00 2001 From: Jussi Saurio Date: Thu, 2 Oct 2025 21:22:35 +0300 Subject: [PATCH] Collate: add proper collation info to compound select deduplication indexes --- core/translate/compound_select.rs | 35 ++++++++++++++++++------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/core/translate/compound_select.rs b/core/translate/compound_select.rs index 4ffbc62a9..08a55d099 100644 --- a/core/translate/compound_select.rs +++ b/core/translate/compound_select.rs @@ -1,4 +1,5 @@ use crate::schema::{Index, IndexColumn, Schema}; +use crate::translate::collate::get_collseq_from_expr; use crate::translate::emitter::{emit_query, LimitCtx, Resolver, TranslateCtx}; use crate::translate::expr::translate_expr; use crate::translate::plan::{Plan, QueryDestination, SelectPlan}; @@ -382,21 +383,27 @@ fn create_dedupe_index( crate::bail_parse_error!("UNION OR INTERSECT or EXCEPT is not supported without indexes"); } + let mut dedupe_columns = select + .result_columns + .iter() + .map(|c| IndexColumn { + name: c + .name(&select.table_references) + .map(|n| n.to_string()) + .unwrap_or_default(), + order: SortOrder::Asc, + pos_in_table: 0, + default: None, + collation: None, + }) + .collect::>(); + for (i, column) in dedupe_columns.iter_mut().enumerate() { + column.collation = + get_collseq_from_expr(&select.result_columns[i].expr, &select.table_references)?; + } + let dedupe_index = Arc::new(Index { - columns: select - .result_columns - .iter() - .map(|c| IndexColumn { - name: c - .name(&select.table_references) - .map(|n| n.to_string()) - .unwrap_or_default(), - order: SortOrder::Asc, - pos_in_table: 0, - default: None, - collation: None, // FIXME: this should be inferred - }) - .collect(), + columns: dedupe_columns, name: "compound_dedupe".to_string(), root_page: 0, ephemeral: true,