| 169 | /// Main entry point - ultra-optimized for simple queries |
| 170 | #[inline(always)] |
| 171 | pub fn process_query<'a>( |
| 172 | query: &'a str, |
| 173 | conn: &Connection, |
| 174 | schema_cache: &SchemaCache, |
| 175 | ) -> Result<Cow<'a, str>, rusqlite::Error> { |
| 176 | // Quick length check |
| 177 | let len = query.len(); |
| 178 | if !(10..=10000).contains(&len) { |
| 179 | return process_complex_query(query, conn, schema_cache); |
| 180 | } |
| 181 | |
| 182 | let bytes = query.as_bytes(); |
| 183 | |
| 184 | // Ultra-fast first byte check for query type |
| 185 | let first_byte = bytes[0].to_ascii_uppercase(); |
| 186 | |
| 187 | match first_byte { |
| 188 | b'S' if len >= 7 && bytes[..7].eq_ignore_ascii_case(b"SELECT ") => { |
| 189 | // SELECT queries - fast path for simple ones |
| 190 | if !has_any_special_pattern_fast(bytes) { |
| 191 | return Ok(Cow::Borrowed(query)); // Zero allocation! |
| 192 | } |
| 193 | } |
| 194 | b'I' if len >= 12 && bytes[..12].eq_ignore_ascii_case(b"INSERT INTO ") => { |
| 195 | // INSERT queries - check for patterns that need translation |
| 196 | if !has_insert_special_patterns(bytes) { |
| 197 | // Even with RETURNING, if it's simple, pass through |
| 198 | if let Some(ret_pos) = find_returning_fast(bytes) { |
| 199 | if is_simple_returning(&bytes[ret_pos..]) { |
| 200 | tracing::debug!("UNIFIED: Simple INSERT with RETURNING using fast path: {}", query); |
| 201 | return Ok(Cow::Borrowed(query)); |
| 202 | } |
| 203 | tracing::debug!("UNIFIED: Complex RETURNING, needs processing: {}", query); |
| 204 | // Complex RETURNING, needs processing |
| 205 | } else { |
| 206 | // No RETURNING, simple INSERT |
| 207 | tracing::debug!("UNIFIED: Simple INSERT without RETURNING using fast path: {}", query); |
| 208 | return Ok(Cow::Borrowed(query)); |
| 209 | } |
| 210 | } else { |
| 211 | tracing::debug!("UNIFIED: INSERT has special patterns, needs processing: {}", query); |
| 212 | } |
| 213 | } |
| 214 | b'U' if len >= 7 && bytes[..7].eq_ignore_ascii_case(b"UPDATE ") => { |
| 215 | // UPDATE queries |
| 216 | if !has_update_special_patterns(bytes) { |
| 217 | // Check for RETURNING |
| 218 | if let Some(ret_pos) = find_returning_fast(bytes) { |
| 219 | if is_simple_returning(&bytes[ret_pos..]) { |
| 220 | return Ok(Cow::Borrowed(query)); |
| 221 | } |
| 222 | } else { |
| 223 | return Ok(Cow::Borrowed(query)); |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | b'D' if len >= 12 && bytes[..12].eq_ignore_ascii_case(b"DELETE FROM ") => { |
| 228 | // DELETE queries |