diff --git a/src/query/sql/src/planner/binder/ddl/table.rs b/src/query/sql/src/planner/binder/ddl/table.rs index 219247b538dc8..47aa44e6a1327 100644 --- a/src/query/sql/src/planner/binder/ddl/table.rs +++ b/src/query/sql/src/planner/binder/ddl/table.rs @@ -16,6 +16,7 @@ use std::collections::BTreeMap; use std::collections::HashSet; use std::sync::Arc; +use chrono::Utc; use databend_common_ast::ast::AddColumnOption as AstAddColumnOption; use databend_common_ast::ast::AlterTableAction; use databend_common_ast::ast::AlterTableStmt; @@ -1141,22 +1142,20 @@ impl Binder { let partitions = settings.get_hilbert_num_range_ids()?; let sample_size = settings.get_hilbert_sample_size_per_block()?; - let keys_bounds_str = cluster_key_strs - .iter() - .map(|s| format!("range_bound({partitions}, {sample_size})({s}) AS {s}_bound")) - .collect::>() - .join(", "); - - let hilbert_keys_str = cluster_key_strs - .iter() - .map(|s| { - format!( - "hilbert_key(cast(ifnull(range_partition_id({table}.{s}, _keys_bound.{s}_bound), {}) as uint16))", - partitions - ) - }) - .collect::>() - .join(", "); + let mut keys_bounds = Vec::with_capacity(cluster_key_strs.len()); + let mut hilbert_keys = Vec::with_capacity(cluster_key_strs.len()); + let suffix = format!("{:08x}", Utc::now().timestamp()); + for (index, cluster_key_str) in cluster_key_strs.into_iter().enumerate() { + hilbert_keys.push(format!( + "hilbert_key(cast(ifnull(range_partition_id({table}.{cluster_key_str}, \ + _keys_bound._bound{index}_{suffix}), {partitions}) as uint16))" + )); + keys_bounds.push(format!( + "range_bound({partitions}, {sample_size})({cluster_key_str}) AS _bound{index}_{suffix}" + )); + } + let keys_bounds_str = keys_bounds.join(", "); + let hilbert_keys_str = hilbert_keys.join(", "); let quote = settings.get_sql_dialect()?.default_ident_quote(); let schema = tbl.schema_with_stream();