Skip to content
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

chore(weave): Implement Predicate Pushdown for Calls #1712

Merged
merged 10 commits into from
Jun 3, 2024

Conversation

tssweeney
Copy link
Contributor

@tssweeney tssweeney commented Jun 3, 2024

This PR implements predicate pushdown for the primary filter clause (not yet implemented for the dynamic mongo queries). It was raised that our filter conditions are being applied after grouping, which is certainly not as efficient as applying the filter pre-grouped (since applying after grouping requires operating on far more rows than needed). In this PR we do the following:

  1. Refactor many symbols/params from conditions to having_conditions to specifically mean the conditions applied after the group by (in the having clause of the query)
  2. Modify the query builder functions to accept start_event_conditions and end_event_conditions which can be used to apply filters before the aggregation. If these conditions are supplied, an inner query is executed which generates an id IN (...) condition that is applied in the WHERE clause.
  3. Modify the filter builder to produce these more specific conditions when appropriate

Testing:

  • Current filter tests cover all sorts of cases here
  • Also tested in the UI manually

@circle-job-mirror
Copy link

circle-job-mirror bot commented Jun 3, 2024

@circle-job-mirror
Copy link

2 similar comments
@circle-job-mirror
Copy link

@circle-job-mirror
Copy link

proj_params = {"project_id": req.project_id}

# get all parents
parents = self._select_calls_query(
req.project_id,
conditions=[proj_cond, "id IN {ids: Array(String)}"],
start_event_conditions=[
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes should make deletion a bit faster

conditions_part = _combine_conditions(conditions, "AND")
having_conditions_part = _combine_conditions(having_conditions, "AND")

where_conditions_part = _make_calls_where_condition_from_event_conditions(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is one of the new clauses

conditions_part = _combine_conditions(conditions, "AND")
having_conditions_part = _combine_conditions(having_conditions, "AND")

where_conditions_part = _make_calls_where_condition_from_event_conditions(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another new clause

def _process_calls_filter_to_conditions(
filter: tsi._CallsFilter,
param_builder: typing.Optional[ParamBuilder] = None,
) -> tuple[list[str], set[str]]:
) -> FilterToConditions:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method has been refactored to return specific conditions where possible, using correct namespacing

@@ -1898,3 +1952,31 @@ def process_operand(operand: tsi_query.Operand) -> str:
conditions.append(filter_cond)

return conditions, raw_fields_used


def _make_calls_where_condition_from_event_conditions(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create an aggregate filter

@tssweeney tssweeney requested a review from shawnlewis June 3, 2024 21:21
@tssweeney tssweeney marked this pull request as ready for review June 3, 2024 21:21
@tssweeney tssweeney requested a review from a team as a code owner June 3, 2024 21:21
@tssweeney tssweeney merged commit 1f5e495 into master Jun 3, 2024
26 checks passed
@tssweeney tssweeney deleted the tim/predicate_pushdown branch June 3, 2024 22:13
@github-actions github-actions bot locked and limited conversation to collaborators Jun 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants