MCPcopy Create free account
hub / github.com/erans/pgsqlite / test_insert_bottleneck_analysis

Function test_insert_bottleneck_analysis

tests/insert_optimization_test.rs:132–226  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

130
131#[tokio::test]
132async fn test_insert_bottleneck_analysis() {
133 use pgsqlite::session::DbHandler;
134 use std::time::Instant;
135 use pgsqlite::query::fast_path::can_use_fast_path_enhanced;
136
137 println!("\n=== INSERT BOTTLENECK ANALYSIS ===");
138
139 // Create in-memory database
140 let db = DbHandler::new(":memory:").expect("Failed to create database");
141
142 // Create a session
143 let session_id = Uuid::new_v4();
144 db.create_session_connection(session_id).await.expect("Failed to create session connection");
145
146 // Create test table without decimal columns
147 db.execute_with_session("CREATE TABLE perf_test (id INTEGER PRIMARY KEY, name TEXT, value INTEGER)", &session_id).await.expect("Failed to create table");
148
149 // Warm up the connection and caches
150 db.execute_with_session("INSERT INTO perf_test (name, value) VALUES ('warmup', 1)", &session_id).await.expect("Failed to warm up");
151
152 let test_query = "INSERT INTO perf_test (name, value) VALUES ('test', 42)";
153
154 // Test 1: Fast path detection overhead
155 let start = Instant::now();
156 for _ in 0..1000 {
157 let _ = can_use_fast_path_enhanced(test_query);
158 }
159 let fast_path_time = start.elapsed();
160 println!("Fast path detection (1000x): {:?}, avg: {:?}", fast_path_time, fast_path_time / 1000);
161
162 // Test 2: Schema cache lookup overhead
163 let start = Instant::now();
164 for _ in 0..1000 {
165 let _ = db.get_table_schema("perf_test").await;
166 }
167 let schema_lookup_time = start.elapsed();
168 println!("Schema cache lookup (1000x): {:?}, avg: {:?}", schema_lookup_time, schema_lookup_time / 1000);
169
170 // Test 3: Single INSERT with timing breakdown
171 println!("\nSingle INSERT timing breakdown:");
172
173 // Measure total time
174 let start_total = Instant::now();
175 db.execute_with_session("INSERT INTO perf_test (name, value) VALUES ('single', 100)", &session_id).await.expect("Failed to execute INSERT");
176 let total_time = start_total.elapsed();
177 println!("Total INSERT time: {total_time:?}");
178
179 // Test 4: Batch of INSERTs to see if there's per-operation overhead
180 println!("\nBatch INSERT performance:");
181 let batch_sizes = [10, 100, 500];
182
183 for &batch_size in &batch_sizes {
184 let start = Instant::now();
185 for i in 0..batch_size {
186 let query = format!("INSERT INTO perf_test (name, value) VALUES ('batch{i}', {i})");
187 db.execute_with_session(&query, &session_id).await.expect("Failed to execute INSERT");
188 }
189 let duration = start.elapsed();

Callers

nothing calls this directly

Calls 7

execute_with_sessionMethod · 0.45
get_table_schemaMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected