Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Stack overflow in sql planning in debug builds #4779

Merged
merged 6 commits into from
Jan 1, 2023

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Dec 31, 2022

Which issue does this PR close?

Closes #4065 from @andygrove
Closes #4728 from @Jefffrey

Also reported by @maxburke in slack

Rationale for this change

Debug builds are overflowing the stack causing pain and suffering for users.

What changes are included in this PR?

  1. Extract several parts of the body of SqlToRel::sql_expr_to_logical_expr into separate functions

The reason this reduces stack size in debug builds is explained in the "Technical Backstory" heading of #1047

Are these changes tested?

Covered by existing coverage

Are there any user-facing changes?

None intended (other than avoiding stack overflows)

@github-actions github-actions bot added core Core DataFusion crate sql SQL Planner labels Dec 31, 2022
}))
}
}
SQLExpr::Identifier(id) => self.sql_identifier_to_expr(id),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just applied this pattern several times: extract code into a separate function


SQLExpr::Function(mut function) => {
let name = if function.name.0.len() > 1 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the expanded handling of SQLExpr::Function is likely the thing that resulted in significantly larger stacks and thus overflows

@@ -2375,6 +2072,395 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
}
}

fn sql_function_to_expr(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All this code was simply moved from above

Copy link
Member

@andygrove andygrove left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL... thanks @alamb!

@alamb
Copy link
Contributor Author

alamb commented Dec 31, 2022

https://github.com/apache/arrow-datafusion/actions/runs/3812581550/jobs/6485893384

😢 still overflows on windows

test tpcds_physical_q70 ... ok
test tpcds_physical_q71 ... ok
test tpcds_physical_q72 ... ok
test tpcds_physical_q73 ... ok

thread 'tpcds_physical_q64' has overflowed its stack
error: test failed, to rerun pass `-p datafusion --test tpcds_planning`

@alamb
Copy link
Contributor Author

alamb commented Dec 31, 2022

Looks like q64 needs some more work -- will do so

@alamb
Copy link
Contributor Author

alamb commented Jan 1, 2023

I have one more PR that should avoid stack overflows while planning (SQL --> LogicalPlan) but then planning overflows at a later step -- see #4786

@ursabot
Copy link

ursabot commented Jan 1, 2023

Benchmark runs are scheduled for baseline = 9a8190a and contender = 0d6d371. 0d6d371 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core DataFusion crate sql SQL Planner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cargo test failing on master due to tpcds_logical_q41 stackoverflow Stack overflow planning complex query
3 participants