Skip to content

Commit 808640e

Browse files
5tanmobuchowski
authored andcommitted
Boxed Query body to save some stack space (apache#540)
1 parent a70d87b commit 808640e

File tree

6 files changed

+24
-24
lines changed

6 files changed

+24
-24
lines changed

src/ast/query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub struct Query {
2626
/// WITH (common table expressions, or CTEs)
2727
pub with: Option<With>,
2828
/// SELECT or UNION / EXCEPT / INTERSECT
29-
pub body: SetExpr,
29+
pub body: Box<SetExpr>,
3030
/// ORDER BY
3131
pub order_by: Vec<OrderByExpr>,
3232
/// `LIMIT { <N> | ALL }`

src/parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3242,7 +3242,7 @@ impl<'a> Parser<'a> {
32423242
};
32433243

32443244
if !self.parse_keyword(Keyword::INSERT) {
3245-
let body = self.parse_query_body(0)?;
3245+
let body = Box::new(self.parse_query_body(0)?);
32463246

32473247
let order_by = if self.parse_keywords(&[Keyword::ORDER, Keyword::BY]) {
32483248
self.parse_comma_separated(Parser::parse_order_by_expr)?
@@ -3294,7 +3294,7 @@ impl<'a> Parser<'a> {
32943294

32953295
Ok(Query {
32963296
with,
3297-
body: SetExpr::Insert(insert),
3297+
body: Box::new(SetExpr::Insert(insert)),
32983298
limit: None,
32993299
order_by: vec![],
33003300
offset: None,

src/test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl TestedDialects {
115115
/// Ensures that `sql` parses as a single [Select], and is not modified
116116
/// after a serialization round-trip.
117117
pub fn verified_only_select(&self, query: &str) -> Select {
118-
match self.verified_query(query).body {
118+
match *self.verified_query(query).body {
119119
SetExpr::Select(s) => *s,
120120
_ => panic!("Expected SetExpr::Select"),
121121
}

tests/sqlparser_common.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn parse_insert_values() {
8585
for (index, column) in columns.iter().enumerate() {
8686
assert_eq!(column, &Ident::new(expected_columns[index].clone()));
8787
}
88-
match &source.body {
88+
match &*source.body {
8989
SetExpr::Values(Values(values)) => assert_eq!(values.as_slice(), expected_rows),
9090
_ => unreachable!(),
9191
}
@@ -3988,7 +3988,7 @@ fn parse_offset() {
39883988
assert_eq!(ast.offset, expect);
39893989
let ast = verified_query("SELECT foo FROM (SELECT * FROM bar OFFSET 2 ROWS) OFFSET 2 ROWS");
39903990
assert_eq!(ast.offset, expect);
3991-
match ast.body {
3991+
match *ast.body {
39923992
SetExpr::Select(s) => match only(s.from).relation {
39933993
TableFactor::Derived { subquery, .. } => {
39943994
assert_eq!(subquery.offset, expect);
@@ -4082,7 +4082,7 @@ fn parse_fetch() {
40824082
"SELECT foo FROM (SELECT * FROM bar FETCH FIRST 2 ROWS ONLY) FETCH FIRST 2 ROWS ONLY",
40834083
);
40844084
assert_eq!(ast.fetch, fetch_first_two_rows_only);
4085-
match ast.body {
4085+
match *ast.body {
40864086
SetExpr::Select(s) => match only(s.from).relation {
40874087
TableFactor::Derived { subquery, .. } => {
40884088
assert_eq!(subquery.fetch, fetch_first_two_rows_only);
@@ -4100,7 +4100,7 @@ fn parse_fetch() {
41004100
})
41014101
);
41024102
assert_eq!(ast.fetch, fetch_first_two_rows_only);
4103-
match ast.body {
4103+
match *ast.body {
41044104
SetExpr::Select(s) => match only(s.from).relation {
41054105
TableFactor::Derived { subquery, .. } => {
41064106
assert_eq!(
@@ -4638,7 +4638,7 @@ fn parse_merge() {
46384638
lateral: false,
46394639
subquery: Box::new(Query {
46404640
with: None,
4641-
body: SetExpr::Select(Box::new(Select {
4641+
body: Box::new(SetExpr::Select(Box::new(Select {
46424642
distinct: false,
46434643
top: None,
46444644
projection: vec![SelectItem::Wildcard],
@@ -4660,7 +4660,7 @@ fn parse_merge() {
46604660
sort_by: vec![],
46614661
having: None,
46624662
qualify: None,
4663-
})),
4663+
}))),
46644664
order_by: vec![],
46654665
limit: None,
46664666
offset: None,

tests/sqlparser_mysql.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ fn parse_quote_identifiers_2() {
313313
mysql().verified_stmt(sql),
314314
Statement::Query(Box::new(Query {
315315
with: None,
316-
body: SetExpr::Select(Box::new(Select {
316+
body: Box::new(SetExpr::Select(Box::new(Select {
317317
distinct: false,
318318
top: None,
319319
projection: vec![SelectItem::UnnamedExpr(Expr::Identifier(Ident {
@@ -330,7 +330,7 @@ fn parse_quote_identifiers_2() {
330330
sort_by: vec![],
331331
having: None,
332332
qualify: None
333-
})),
333+
}))),
334334
order_by: vec![],
335335
limit: None,
336336
offset: None,
@@ -347,7 +347,7 @@ fn parse_quote_identifiers_3() {
347347
mysql().verified_stmt(sql),
348348
Statement::Query(Box::new(Query {
349349
with: None,
350-
body: SetExpr::Select(Box::new(Select {
350+
body: Box::new(SetExpr::Select(Box::new(Select {
351351
distinct: false,
352352
top: None,
353353
projection: vec![SelectItem::UnnamedExpr(Expr::Identifier(Ident {
@@ -364,7 +364,7 @@ fn parse_quote_identifiers_3() {
364364
sort_by: vec![],
365365
having: None,
366366
qualify: None
367-
})),
367+
}))),
368368
order_by: vec![],
369369
limit: None,
370370
offset: None,
@@ -392,7 +392,7 @@ fn parse_escaped_string() {
392392
let stmt = mysql().one_statement_parses_to(sql, "");
393393

394394
match stmt {
395-
Statement::Query(query) => match query.body {
395+
Statement::Query(query) => match *query.body {
396396
SetExpr::Select(value) => {
397397
let expr = expr_from_projection(only(&value.projection));
398398
assert_eq!(
@@ -517,7 +517,7 @@ fn parse_simple_insert() {
517517
assert_eq!(
518518
Box::new(Query {
519519
with: None,
520-
body: SetExpr::Values(Values(vec![
520+
body: Box::new(SetExpr::Values(Values(vec![
521521
vec![
522522
Expr::Value(Value::SingleQuotedString("Test Some Inserts".to_string())),
523523
Expr::Value(Value::Number("1".to_string(), false))
@@ -530,7 +530,7 @@ fn parse_simple_insert() {
530530
Expr::Value(Value::SingleQuotedString("Test Entry 3".to_string())),
531531
Expr::Value(Value::Number("3".to_string(), false))
532532
]
533-
])),
533+
]))),
534534
order_by: vec![],
535535
limit: None,
536536
offset: None,
@@ -574,7 +574,7 @@ fn parse_insert_with_on_duplicate_update() {
574574
assert_eq!(
575575
Box::new(Query {
576576
with: None,
577-
body: SetExpr::Values(Values(vec![vec![
577+
body: Box::new(SetExpr::Values(Values(vec![vec![
578578
Expr::Value(Value::SingleQuotedString("accounting_manager".to_string())),
579579
Expr::Value(Value::SingleQuotedString(
580580
"Some description about the group".to_string()
@@ -583,7 +583,7 @@ fn parse_insert_with_on_duplicate_update() {
583583
Expr::Value(Value::Boolean(true)),
584584
Expr::Value(Value::Boolean(true)),
585585
Expr::Value(Value::Boolean(true)),
586-
]])),
586+
]]))),
587587
order_by: vec![],
588588
limit: None,
589589
offset: None,
@@ -767,7 +767,7 @@ fn parse_substring_in_select() {
767767
assert_eq!(
768768
Box::new(Query {
769769
with: None,
770-
body: SetExpr::Select(Box::new(Select {
770+
body: Box::new(SetExpr::Select(Box::new(Select {
771771
distinct: true,
772772
top: None,
773773
projection: vec![SelectItem::UnnamedExpr(Expr::Substring {
@@ -805,7 +805,7 @@ fn parse_substring_in_select() {
805805
sort_by: vec![],
806806
having: None,
807807
qualify: None
808-
})),
808+
}))),
809809
order_by: vec![],
810810
limit: None,
811811
offset: None,

tests/sqlparser_postgres.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ fn parse_update_set_from() {
427427
lateral: false,
428428
subquery: Box::new(Query {
429429
with: None,
430-
body: SetExpr::Select(Box::new(Select {
430+
body: Box::new(SetExpr::Select(Box::new(Select {
431431
distinct: false,
432432
top: None,
433433
projection: vec![
@@ -452,7 +452,7 @@ fn parse_update_set_from() {
452452
sort_by: vec![],
453453
having: None,
454454
qualify: None
455-
})),
455+
}))),
456456
order_by: vec![],
457457
limit: None,
458458
offset: None,
@@ -1042,7 +1042,7 @@ fn parse_prepare() {
10421042
Expr::Identifier("a2".into()),
10431043
Expr::Identifier("a3".into()),
10441044
]];
1045-
match &source.body {
1045+
match &*source.body {
10461046
SetExpr::Values(Values(values)) => assert_eq!(values.as_slice(), &expected_values),
10471047
_ => unreachable!(),
10481048
}

0 commit comments

Comments
 (0)