From ab92102cd86d7fe074c8b138cd8870bb069e996e Mon Sep 17 00:00:00 2001 From: Nikita Sivukhin Date: Tue, 30 Sep 2025 13:49:20 +0400 Subject: [PATCH] remove parameter id assign logic from core --- core/parameters.rs | 13 ------------- core/translate/expr.rs | 22 +++++----------------- 2 files changed, 5 insertions(+), 30 deletions(-) diff --git a/core/parameters.rs b/core/parameters.rs index bb29c5008..5ed520300 100644 --- a/core/parameters.rs +++ b/core/parameters.rs @@ -1,7 +1,5 @@ use std::num::NonZero; -pub const PARAM_PREFIX: &str = "__param_"; - #[derive(Clone, Debug)] pub enum Parameter { Anonymous(NonZero), @@ -78,17 +76,6 @@ impl Parameters { pub fn push(&mut self, name: impl AsRef) -> NonZero { match name.as_ref() { - param if param.is_empty() || param.starts_with(PARAM_PREFIX) => { - let index = self.next_index(); - let use_idx = if let Some(idx) = param.strip_prefix(PARAM_PREFIX) { - idx.parse().unwrap() - } else { - index - }; - self.list.push(Parameter::Anonymous(use_idx)); - tracing::trace!("anonymous parameter at {use_idx}"); - use_idx - } name if name.starts_with(['$', ':', '@', '#']) => { match self .list diff --git a/core/translate/expr.rs b/core/translate/expr.rs index 50d416aed..27616b918 100644 --- a/core/translate/expr.rs +++ b/core/translate/expr.rs @@ -10,7 +10,6 @@ use super::plan::TableReferences; use crate::function::JsonFunc; use crate::function::{Func, FuncCtx, MathFuncArity, ScalarFunc, VectorFunc}; use crate::functions::datetime; -use crate::parameters::PARAM_PREFIX; use crate::schema::{affinity, Affinity, Table, Type}; use crate::translate::optimizer::TakeOwnership; use crate::translate::plan::ResultSetColumn; @@ -3244,26 +3243,21 @@ where Ok(WalkControl::Continue) } -/// Context needed to walk all expressions in a INSERT|UPDATE|SELECT|DELETE body, -/// in the order they are encountered, to ensure that the parameters are rewritten from -/// anonymous ("?") to our internal named scheme so when the columns are re-ordered we are able -/// to bind the proper parameter values. pub struct ParamState { - /// ALWAYS starts at 1 - pub next_param_idx: usize, + pub allowed: bool, } impl Default for ParamState { fn default() -> Self { - Self { next_param_idx: 1 } + Self { allowed: true } } } impl ParamState { pub fn is_valid(&self) -> bool { - self.next_param_idx > 0 + self.allowed } pub fn disallow() -> Self { - Self { next_param_idx: 0 } + Self { allowed: false } } } @@ -3296,16 +3290,10 @@ pub fn bind_and_rewrite_expr<'a>( top_level_expr, &mut |expr: &mut ast::Expr| -> Result { match expr { - // Rewrite anonymous variables in encounter order. - ast::Expr::Variable(var) if var.is_empty() => { + ast::Expr::Variable(_) => { if !param_state.is_valid() { crate::bail_parse_error!("Parameters are not allowed in this context"); } - *expr = ast::Expr::Variable(format!( - "{}{}", - PARAM_PREFIX, param_state.next_param_idx - )); - param_state.next_param_idx += 1; } ast::Expr::Between { lhs,