ClickHouse Parses SQL by Rewinding One Cursor: A 1,000,000-Backtrack Budget
ClickHouse’s SQL parser is a set of combinators that share one position, rewind it on failure, and budget every rewind.
All posts published on this site.
Everything published here, newest first.
ClickHouse’s SQL parser is a set of combinators that share one position, rewind it on failure, and budget every rewind.
ClickHouse’s parser unquotes identifiers, splits compound names, guesses the table qualifier and builds parameter nodes before the analyzer runs.
ClickHouse aggregate functions own no data; their state lives in a bump-allocated Arena and is destroyed by hand, one contiguous block per group.
ClickHouse builds new aggregate functions by suffixing names: a factory strips the suffix, recurses into the base function, and wraps it in a decorator.
ClickHouse’s topK uses Filtered Space-Saving: each candidate keeps a count and an error bound, and the least accurate counters are dropped when the table overflows.