elif_orm/query/
performance.rs1use super::builder::QueryBuilder;
4use serde_json::Value;
5
6impl<M> QueryBuilder<M> {
7 pub fn bindings(&self) -> Vec<Value> {
10 let mut bindings = Vec::new();
11
12 for condition in &self.where_conditions {
13 if matches!(condition.column.as_str(), "RAW" | "EXISTS" | "NOT EXISTS") {
15 continue;
16 }
17
18 if let Some(value) = &condition.value {
19 if let Value::String(val_str) = value {
21 if !val_str.starts_with('(') || !val_str.ends_with(')') {
22 bindings.push(value.clone());
23 }
24 } else {
25 bindings.push(value.clone());
26 }
27 }
28 bindings.extend(condition.values.clone());
29 }
30
31 for condition in &self.having_conditions {
32 if let Some(value) = &condition.value {
33 bindings.push(value.clone());
34 }
35 bindings.extend(condition.values.clone());
36 }
37
38 bindings
39 }
40
41 pub fn clone_for_subquery(&self) -> Self {
43 self.clone()
44 }
45
46 pub fn optimize(self) -> Self {
48 self
53 }
54
55 pub fn complexity_score(&self) -> u32 {
57 let mut score = 0;
58
59 score += self.where_conditions.len() as u32;
60 score += self.joins.len() as u32 * 2; score += self.group_by.len() as u32;
62 score += self.having_conditions.len() as u32;
63
64 if self.distinct {
65 score += 1;
66 }
67
68 score
69 }
70}