-
Notifications
You must be signed in to change notification settings - Fork 3
Normalizer-based SQL pattern recognition (planner + query engine + ingest) #561
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
Draft
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1e1666f
Adds a shared sql_utilities::ast_matching::pattern_rewrites module that
hshafqat-art 6297073
feat(types): expand aggregation/statistic model for exact cardinality...
hshafqat-art 0ee3ea7
feat(sql_utilities): extract spatial_filter module and expand the sha...
hshafqat-art 23b4cfd
feat(planner): register the new shapes, fix exact-cardinality treatme...
hshafqat-art e1fa4a1
feat(precompute): add MRT ingest, row-expansion fanout, and wire stat...
hshafqat-art 9841c7c
feat(precompute_operators): add MultipleArg (argMax/argMin) accumulat...
hshafqat-art dd2048c
feat(engine): serve every new shape; fix zero-vs-missing results and ...
hshafqat-art 5b772cf
test(engine): cover the new shapes and fixes
hshafqat-art 177bcc3
chore: update lockfile and ignore the local experiments venv
hshafqat-art 1cd9a00
docs: add SQL query-shape recognition design doc
hshafqat-art File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
.design_docs/SQL_SHAPE_RECOGNITION_DESIGN.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # SQL Query-Shape Recognition and Maintenance — Design | ||
|
|
||
| This document describes the `(ρ, τ, γ, eval, π)` decomposition the SQL path uses to decide | ||
| which analyst queries can be answered from a continuously maintained summary instead of a | ||
| full scan, what gets maintained for each recognized shape, and where that logic lives in the | ||
| codebase. It complements `CAPABILITY_MATCHING_DESIGN.md` (how a query at serve time is matched | ||
| against whatever got registered) by covering the layer above it: how a query gets *recognized* | ||
| and *registered* in the first place. | ||
|
|
||
| ## The decomposition | ||
|
|
||
| BGPSketch never assumes an incoming query begins as a conventional SQL aggregate it can just | ||
| execute. It first works out what shape the query is, what a continuously maintained summary for | ||
| that shape would need to look like, and only then decides how to serve it: | ||
|
|
||
| ``` | ||
| ρ(Q) -> (Q', π) | ||
| D --τ--> D' --γ--> D'' | ||
| A = π(eval(Q', D'')) | ||
| ``` | ||
|
|
||
| - **ρ (recognize)** — classifies an incoming query `Q` against a fixed vocabulary of shapes, | ||
| splitting it into `Q'` (the portion whose required statistics can be derived and maintained | ||
| ahead of time) and `π` (the residual, result-level computation left for query time). ρ runs | ||
| identically at planner time (deciding what to maintain) and query time (deciding how to serve | ||
| a live query), from one shared AST-level pattern library in `sql_utilities` — so a query is | ||
| never classified differently depending on which one is asking. | ||
| - **τ (derive)** — converts raw BGP records into the observations `Q'` actually needs. Three | ||
| forms recur: a **stateless projection** (extracting the origin ASN from an AS path, bucketing | ||
| a timestamp), a **fanout** (one record emitting several observations — every ASN in a path, or | ||
| every adjacent AS-path edge), and a **stateful comparison** (checking the current observation | ||
| against previously observed route state to detect a path change or measure an inter-arrival | ||
| gap). | ||
| - **γ (maintain)** — folds τ's observations into maintained state `D''`. Summary-polymorphic: | ||
| which sketch or exact structure it picks is determined by the statistic the query needs and | ||
| whether it asked for an exact or approximate answer, not hardcoded per shape. | ||
| - **eval, π (answer)** — reads whatever `D''` holds and applies the residual computation `π` | ||
| deferred from ρ's split. π is computation deliberately *not* run over every arriving record, | ||
| because its input is already the small maintained result: ranking, ratios, percentages of a | ||
| total, and set-membership joins all live here. | ||
|
|
||
| ### A layer beneath ρ: spatial-filter enforceability | ||
|
|
||
| ρ's shape recognition ("is this a classic single aggregate, a multi-aggregate row, a correlated | ||
| subquery, ...") is a different question from a second one asked of every recognized query's WHERE | ||
| clause: **can each of its predicates actually be folded into the per-row ingest-time filter?** | ||
| That second question has its own dedicated family of recognizers — | ||
| `parse_spatial_predicate` and its per-shape helpers (`parse_eq`, `parse_range`, `parse_in`, | ||
| `parse_match_call`, `parse_has_split_member`, ...) in | ||
| `asap-common/dependencies/rs/sql_utilities/src/ast_matching/spatial_filter.rs` — answering a | ||
| narrower, lower-level question than ρ's shape classification. A query can be unambiguously | ||
| "classic single aggregate" at the ρ layer and still fail to register at all if one of its WHERE | ||
| predicates isn't one `parse_spatial_predicate` recognizes (`is_ingest_filter_fully_enforceable`), | ||
| in which case it falls back to exact/ClickHouse execution instead. This isn't a peer to ρ/τ/γ/π — | ||
| it has no τ, γ, or π of its own — it's a precondition inside ρ's own "can this be maintained at | ||
| all" decision, and it's the reason two queries with the identical aggregate shape can land in | ||
| different places depending on what's in their WHERE clause. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,3 +8,4 @@ preprocessed_configs/ | |
| status | ||
| uuid | ||
| store/ | ||
| local_experiments/.venv/ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.