MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / test_large_query_no_panic

Function test_large_query_no_panic

crates/core/src/sql/execute.rs:1421–1470  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1419 /// Exercise the limit [`recursion::MAX_RECURSION_EXPR`]
1420 #[test]
1421 fn test_large_query_no_panic() -> ResultTest<()> {
1422 let db = TestDB::durable()?;
1423
1424 let _table_id = db
1425 .create_table_for_test_multi_column(
1426 "test",
1427 &[("x", AlgebraicType::I32), ("y", AlgebraicType::I32)],
1428 col_list![0, 1],
1429 )
1430 .unwrap();
1431
1432 let build_query = |total| {
1433 let mut sql = "select * from test where ".to_string();
1434 for x in 1..total {
1435 let fragment = format!("x = {x} or ");
1436 sql.push_str(&fragment.repeat((total - 1) as usize));
1437 }
1438 sql.push_str("(y = 0)");
1439 sql
1440 };
1441 let run = |db: &Arc<RelationalDB>, sep: char, sql_text: &str| {
1442 run_for_testing(db, sql_text).map_err(|e| e.to_string().split(sep).next().unwrap_or_default().to_string())
1443 };
1444 let sql = build_query(1_000);
1445 assert_eq!(
1446 run(&db, ':', &sql),
1447 Err("SQL query exceeds maximum allowed length".to_string())
1448 );
1449
1450 let sql = build_query(41); // This causes stack overflow without the limit
1451 assert_eq!(run(&db, ',', &sql), Err("Recursion limit exceeded".to_string()));
1452
1453 let sql = build_query(40); // The max we can with the current limit
1454 assert!(run(&db, ',', &sql).is_ok(), "Expected query to run without panic");
1455
1456 // Check no overflow with lot of joins
1457 let mut sql = "SELECT test.* FROM test ".to_string();
1458 // We could push up to 700 joins without overflow as long we don't have any conditions,
1459 // but here execution become too slow.
1460 // TODO: Move this test to the `Plan`
1461 for i in 0..200 {
1462 sql.push_str(&format!("JOIN test AS m{i} ON test.x = m{i}.y "));
1463 }
1464
1465 assert!(
1466 run(&db, ',', &sql).is_ok(),
1467 "Query with many joins and conditions should not overflow"
1468 );
1469 Ok(())
1470 }
1471
1472 #[test]
1473 fn test_impossible_bounds_no_panic() -> ResultTest<()> {

Callers

nothing calls this directly

Calls 7

run_for_testingFunction · 0.85
splitMethod · 0.80
OkFunction · 0.50
unwrapMethod · 0.45
to_stringMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…