[Windowing] Rewrite window function implementation to use real SQLite windows #20
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.
This drastically improves the performance of complex queries that use window functions by no longer requiring duplicate subqueries and delegating sorting / partitioning to SQLite directly.
For one of our ingest views, the compiled query goes from ~217,000 characters with
272
SELECT
statements down to ~117,000 characters with78
SELECT
statements.The numbering functions such as
RANK()
,DENSE_RANK()
,CUME_DIST()
implementations are nearly identical to both SQLite's and Postgres' internal implementation.SQLite window functions are implemented using the following interface:
Closes Recidiviz/recidiviz-data#20742
Closes Recidiviz/recidiviz-data#20739
Closes Recidiviz/recidiviz-data#20740
Closes Recidiviz/recidiviz-data#20751
Closes Recidiviz/recidiviz-data#20773
Closes Recidiviz/recidiviz-data#20754
Closes Recidiviz/recidiviz-data#27338