Skip to main content
An valid dynamic filter comprises the following components:
  • A comparison operator including <, >, <=, >= and BETWEEN
  • A column as the left side
  • A scalar subquery as the right side
Additionally, the dynamic filter condition must not be part of an OR expression. For example, v > (select max(v) from t2) OR a > 0 is invalid. The following query returns the name of all products whose profit margin is greater than the maximum profit margin recorded in the sales table.
The dynamic filter in this query is in the WHERE clause. The filter condition product_profit > max compares the product_profit column from the products table to the maximum value of the profit_margin column from the sales table, which is stored in the subquery max_profit. The value of the maximum profit margin is dynamic and changes based on the values in the sales table. The following query calculates the parts that cost more than 0.01% of the total money spent.
Under the hood, RisingWave maintains this materialized view with a continuous streaming job that filters the aggregation results according to the HAVING clause. Note that the subquery result, which is 0.01% of the total cost, is constantly changing, either increasing or decreasing, depending on the incoming changes to the partsupp table. As this value increases, more results will satisfy this condition and be output; conversely, as this value decreases, more rows are filtered out, and fewer results will be output. RisingWave implements this using dynamic filters, internal stateful operators that keep a full set of results before filtering and decides which changes should be output.