Skip to content

Commit ac12ad1

Browse files
authored
chore: short_sql from 10KB to 30KB (#15575)
1 parent 6a89aa1 commit ac12ad1

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/query/service/src/sessions/query_ctx_shared.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,14 +582,17 @@ impl Drop for QueryContextShared {
582582

583583
pub fn short_sql(sql: String) -> String {
584584
use unicode_segmentation::UnicodeSegmentation;
585+
const MAX_LENGTH: usize = 30 * 1024; // 30KB
586+
585587
let query = sql.trim_start();
586-
if query.as_bytes().len() > 10240 && query.as_bytes()[..6].eq_ignore_ascii_case(b"INSERT") {
587-
// keep first 10KB (10,240 bytes)
588+
if query.as_bytes().len() > MAX_LENGTH && query.as_bytes()[..6].eq_ignore_ascii_case(b"INSERT")
589+
{
590+
// keep first 30KB
588591
let mut result = Vec::new();
589592
let mut bytes_taken = 0;
590593
for grapheme in query.graphemes(true) {
591594
let grapheme_bytes = grapheme.as_bytes();
592-
if bytes_taken + grapheme_bytes.len() <= 10240 {
595+
if bytes_taken + grapheme_bytes.len() <= MAX_LENGTH {
593596
result.extend_from_slice(grapheme_bytes);
594597
bytes_taken += grapheme_bytes.len();
595598
} else {

src/query/service/tests/it/sessions/query_ctx.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,19 @@ async fn test_get_storage_accessor_fs() -> Result<()> {
6969

7070
#[test]
7171
fn test_short_sql() {
72-
// Test case 1: SQL query shorter than 10KB
72+
// Test case 1: SQL query shorter than 30KB
7373
let sql1 = "SELECT * FROM users WHERE id = 1;".to_string();
7474
assert_eq!(short_sql(sql1.clone()), sql1);
7575

76-
// Test case 2: SQL query longer than 10KB and starts with "INSERT"
76+
// Test case 2: SQL query longer than 30KB and starts with "INSERT"
7777
let long_sql = "INSERT INTO users (id, name, email) VALUES ".to_string()
78-
+ &"(1, 'John Doe', 'john@example.com'), ".repeat(1000);
79-
let expected_result = long_sql.as_bytes()[..10240].to_vec();
78+
+ &"(1, 'John Doe', 'john@example.com'), ".repeat(1500); // Adjusted for 30KB
79+
let expected_result = long_sql.as_bytes()[..30 * 1024].to_vec();
8080
let expected_result = String::from_utf8(expected_result).unwrap() + "...";
8181
assert_eq!(short_sql(long_sql), expected_result);
8282

83-
// Test case 3: SQL query longer than 10KB but does not start with "INSERT"
84-
let long_sql = "SELECT * FROM users WHERE ".to_string() + &"id = 1 OR ".repeat(1000);
83+
// Test case 3: SQL query longer than 30KB but does not start with "INSERT"
84+
let long_sql = "SELECT * FROM users WHERE ".to_string() + &"id = 1 OR ".repeat(1500); // Adjusted for 30KB
8585
assert_eq!(short_sql(long_sql.clone()), long_sql);
8686

8787
// Test case 4: Empty SQL query

0 commit comments

Comments
 (0)