Repository navigation
Flag inputs to SELECT queries as monotonic if until is set. - #14607
frankmcsherry wants to merge 6 commits into
Conversation
0c57d2f to
e6b87f1
Compare
|
I have verified that this produces monotonic query plans manually, as I can't think of a good way to introspect on this (the explained plans are with non-monotonic inputs, which seems good as we are plausibly explaining what an installed view would look like). I'm going to try and get materialize to admit that the performance is better by using some otherwise fairly silly queries, and I'll report back about that. |
|
Also, just for further commentary, setting the inputs to monotonic is probably not the best answer here, as while true it won't unlock all of the good query plans, as some operators like |
|
@antiguru observes that this may be DOA as we are not assured that the data we get are consolidated, and we cannot afford to Closing for now! |
|
Notes for future selves: it is plausible that an |
|
This PR can be a good starting point for work in epic MaterializeInc/database-issues#4125, including issue MaterializeInc/database-issues#5030. |
e6b87f1 to
e5dcc02
Compare
Just to make sure this observation gets recorded: We already had For this PR, we argue that consolidating in all monotonic variants increases consistency and moves us forward regarding one-off |
|
An evaluation of the effect of this PR can be found in the linked spreadsheet. The setup is of a local developer machine running the TPC-H load generator without updates at scale factor 1. The queries were designed to hit min/max aggregates, top-1, and top-k. The vast majority of the queries evaluated get meaningful speedups, some of over an order of magnitude, as expected. On average across the 7 queries evaluated, the speedup is around 5x. |
This commit moves the code for monotonic top-k into its own method, mirroring what is done for monotonic top-1 and basic top-k. Additionally, some documentation is added to the related functions. This commit should not include any functional changes.
This commit ensures that monotonic top-k processing is resilient to logically monotonic input. This is achieved by consolidating the input to transform (assumed) logical monotonicity into physical monotonicity and ensuring that physical monotonicity was then attained. The code also makes comments related to this step in the rendering more consistent across monotonic top-k, monotonic top-1, and monotonic hierarchical reductions.
This commit fixes the invalid accumulation tests in the mzcompose cluster test workflows to use non-monotonic rendering whenever a min/max aggregate is employed. This is ensured by use of materialized views instead of one-off SELECTs in the tests, since the latter now exploit logical monotonicity.
This commit refactors the if let pattern that computes as_of + 1 in setting the until of a DataflowDescription in the case of one-off SELECT queries. The small refactor avoids explicit array access by going through the as_option method of Antichain.
|
@antiguru and I decided to run the slow SQL Logic Tests on this PR and got this output. Note that the only two tests that failed were due to the changes introduced in PR #18302. After rebasing to catch the changes in the latter PR, one of the tests was removed, and the other passed. |
|
For further validation, I ran also a subset of the nightlies, namely all From the test results, it appears that this PR is pretty safe. Additionally, we are using plans that can be produced for append-only sources already, except that we are making this plan usage more frequent by also including one-shot |
This commit introduces the feature flag enable_monotonic_oneshot_selects, turned off by default, and gates the optimization of using monotonic plans for one-shot SELECTs behind this flag. As a consequence, after this commit, all tests in CI will by default execute against non-monotonic plans, as previously. The commit enables us to carefully evaluate when to make the functionality of monotonic plans for one-shot SELECTs available by default.
ca6a0e1 to
fd85912
Compare
| /// Here, we observe that monotonicity implies that we do not need to maintain | ||
| /// state proportional to the size of the input collection, as loser rows | ||
| /// can never become part of the top-k. We apply an inter-timestamp thinning | ||
| /// step that discards losers rows as well as an inter-timestamp thinning step |
There was a problem hiding this comment.
This should be "intra-timestamp", right?
|
I am closing this PR again, as we have agreed to merge #18546 instead. |
This PR flags sources and indexes as
monotonicif we are in aPeeksetting and have successfully setuntilto be one greater than the query timestamp. In such a setting, we will ingest only the snapshot and no further modifications, which means no retractions. We can use simpler dataflow fragments in cases such asmin,max, andtop_k.Motivation
One-off
SELECTqueries use dataflows that are more general than strictly required, and this is one example of how that can be relaxed.Tips for reviewer
Checklist
This PR has adequate test coverage / QA involvement has been duly considered.
This PR evolves an existing
$T ⇔ Proto$Tmapping (possibly in a backwards-incompatible way) and therefore is tagged with aT-protobuflabel.This PR includes the following user-facing behavior changes: