remove parameter id assign logic from core

This commit is contained in:
Nikita Sivukhin
2025-09-30 13:49:20 +04:00
parent 30a9b2b860
commit ab92102cd8
2 changed files with 5 additions and 30 deletions

View File

@@ -1,7 +1,5 @@
use std::num::NonZero;
pub const PARAM_PREFIX: &str = "__param_";
#[derive(Clone, Debug)]
pub enum Parameter {
Anonymous(NonZero<usize>),
@@ -78,17 +76,6 @@ impl Parameters {
pub fn push(&mut self, name: impl AsRef<str>) -> NonZero<usize> {
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

View File

@@ -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<WalkControl> {
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,