Skip to content

Commit 57e1ea5

Browse files
authored
fix(query): fix stack overflow if excessive use of union all (#17475)
* fix(query): add stateless tests * fix(query): add recursive for clone * fix(query): try fix stackoverflow * fix(query): try fix stackoverflow * fix(query): try fix stackoverflow * fix(query): try fix stackoverflow * fix(query): try fix stackoverflow * fix(query): try fix stackoverflow * fix(query): try fix stackoverflow * fix(query): try fix stackoverflow
1 parent 149c773 commit 57e1ea5

37 files changed

+167
-83
lines changed

Cargo.lock

Lines changed: 9 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ derive-visitor = { version = "0.4.0", features = ["std-types-drive"] }
288288
derive_more = { version = "1.0.0", features = ["full"] }
289289
dtparse = { git = "https://github.com/datafuse-extras/dtparse.git", rev = "30e28ca" }
290290
dyn-clone = "1.0.9"
291-
educe = "0.4" # FIXME: failed to upgrade to educe 0.6
291+
educe = { version = "0.6", features = ["default", "full"] }
292292
either = "1.9"
293293
enquote = "1.1.0"
294294
enum-as-inner = "0.6"
@@ -624,6 +624,7 @@ async-recursion = { git = "https://github.com/datafuse-extras/async-recursion.gi
624624
backtrace = { git = "https://github.com/rust-lang/backtrace-rs.git", rev = "72265be" }
625625
color-eyre = { git = "https://github.com/eyre-rs/eyre.git", rev = "e5d92c3" }
626626
deltalake = { git = "https://github.com/delta-io/delta-rs", rev = "3038c145" }
627+
educe = { git = "https://github.com/zhang2014/educe.git", rev = "ab34a19" }
627628
ethnum = { git = "https://github.com/datafuse-extras/ethnum-rs", rev = "4cb05f1" }
628629
openai_api_rust = { git = "https://github.com/datafuse-extras/openai-api", rev = "819a0ed" }
629630
openraft = { git = "https://github.com/databendlabs/openraft", tag = "v0.10.0-alpha.7" }

src/common/exception/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ doctest = false
1111
test = true
1212

1313
[dependencies]
14-
databend-common-ast = { workspace = true }
1514

1615
anyhow = { workspace = true }
1716
arrow-flight = { workspace = true }
1817
arrow-schema = { workspace = true }
1918
backtrace = { workspace = true, features = ["std", "serialize-serde"] }
2019
bincode = { workspace = true }
2120
cidr = { workspace = true }
21+
derive-visitor = { workspace = true }
2222
geozero = { workspace = true }
2323
gimli = { workspace = true }
2424
http = { workspace = true }
@@ -32,6 +32,7 @@ paste = { workspace = true }
3232
prost = { workspace = true }
3333
redis = { workspace = true }
3434
reqwest = { workspace = true }
35+
rspack-codespan-reporting = { workspace = true }
3536
rustc-demangle = { workspace = true }
3637
serde = { workspace = true }
3738
serde_json = { workspace = true }

src/common/exception/src/exception.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ use std::fmt::Display;
1919
use std::fmt::Formatter;
2020
use std::marker::PhantomData;
2121

22-
use databend_common_ast::span::pretty_print_error;
23-
use databend_common_ast::Span;
2422
use thiserror::Error;
2523

2624
use crate::exception_backtrace::capture;
25+
use crate::span::pretty_print_error;
2726
use crate::ErrorFrame;
27+
use crate::Span;
2828
use crate::StackTrace;
2929

3030
#[derive(Error)]

src/common/exception/src/exception_into.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ use std::fmt::Debug;
1717
use std::fmt::Display;
1818
use std::fmt::Formatter;
1919

20-
use databend_common_ast::Span;
2120
use geozero::error::GeozeroError;
2221

2322
use crate::exception_backtrace::capture;
2423
use crate::ErrorCode;
2524
use crate::ErrorFrame;
25+
use crate::ParseError;
26+
use crate::Span;
2627
use crate::StackTrace;
2728

2829
#[derive(thiserror::Error)]
@@ -221,8 +222,8 @@ impl From<std::string::FromUtf8Error> for ErrorCode {
221222
}
222223
}
223224

224-
impl From<databend_common_ast::ParseError> for ErrorCode {
225-
fn from(error: databend_common_ast::ParseError) -> Self {
225+
impl From<ParseError> for ErrorCode {
226+
fn from(error: ParseError) -> Self {
226227
ErrorCode::SyntaxException(error.1).set_span(error.0)
227228
}
228229
}

src/common/exception/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ mod exception_backtrace;
2424
mod exception_code;
2525
mod exception_flight;
2626
mod exception_into;
27+
mod parser_error;
28+
mod span;
2729

2830
pub use context::display_error_stack;
2931
pub use context::ErrorFrame;
@@ -35,3 +37,9 @@ pub use exception_backtrace::set_backtrace;
3537
pub use exception_backtrace::StackTrace;
3638
pub use exception_backtrace::USER_SET_ENABLE_BACKTRACE;
3739
pub use exception_into::SerializedError;
40+
pub use parser_error::ParseError;
41+
pub use span::merge_span;
42+
pub use span::offset_span;
43+
pub use span::pretty_print_error;
44+
pub use span::Range;
45+
pub use span::Span;
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ use std::fmt::Formatter;
1818
use crate::span::pretty_print_error;
1919
use crate::Span;
2020

21-
pub type Result<T> = std::result::Result<T, ParseError>;
22-
2321
#[derive(Debug)]
2422
pub struct ParseError(pub Span, pub String);
2523

src/query/ast/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ repository = "https://github.com/datafuselabs/databend/tree/main/src/query/ast"
1212
doctest = false
1313

1414
[dependencies]
15+
databend-common-exception = { workspace = true }
1516
derive-visitor = { workspace = true }
17+
educe = { workspace = true }
1618
enum-as-inner = { workspace = true }
1719
ethnum = { workspace = true }
1820
fast-float2 = { workspace = true }
@@ -27,7 +29,6 @@ percent-encoding = { workspace = true }
2729
pratt = { workspace = true }
2830
pretty_assertions = { workspace = true }
2931
recursive = { workspace = true }
30-
rspack-codespan-reporting = { workspace = true }
3132
serde = { workspace = true }
3233
serde_json = { workspace = true }
3334
strsim = { workspace = true }

src/query/ast/src/ast/expr.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ use std::collections::HashMap;
1616
use std::fmt::Display;
1717
use std::fmt::Formatter;
1818

19+
use databend_common_exception::merge_span;
1920
use derive_visitor::Drive;
2021
use derive_visitor::DriveMut;
22+
use educe::Educe;
2123
use enum_as_inner::EnumAsInner;
2224
use ethnum::i256;
2325
use pratt::Affix;
@@ -40,12 +42,16 @@ use crate::ast::write_comma_separated_list;
4042
use crate::ast::Identifier;
4143
use crate::ast::Query;
4244
use crate::ast::SetExpr;
43-
use crate::span::merge_span;
4445
use crate::ParseError;
4546
use crate::Result;
4647
use crate::Span;
4748

48-
#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
49+
#[derive(Educe, Drive, DriveMut)]
50+
#[educe(
51+
PartialEq(bound = false, attrs = "#[recursive::recursive]"),
52+
Clone(bound = false, attrs = "#[recursive::recursive]"),
53+
Debug(bound = false, attrs = "#[recursive::recursive]")
54+
)]
4955
pub enum Expr {
5056
/// Column reference, with indirection like `table.column`
5157
ColumnRef {

0 commit comments

Comments
 (0)