-
Notifications
You must be signed in to change notification settings - Fork 76
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
perf(weave): push heavy conditions into WHERE for calls stream query #3501
base: master
Are you sure you want to change the base?
Conversation
Preview this PR with FeatureBee: https://beta.wandb.ai/?betaVersion=93454a35a7f6c8aaae43c2b1004c43e4d08bd0b9 |
exp_formatted = sqlparse.format(exp_query, reindent=True) | ||
found_formatted = sqlparse.format(query, reindent=True) | ||
|
||
assert exp_formatted == found_formatted | ||
assert exp_params == params |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
easier to debug in this order
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before diving into the code, i have a concern:
I believe this will fail to return rows which have not been merged by the AMT. Referencing the example in the description: what happens if the start and end events are not merged? The resulting data will return the unmerged rows without their start events!
Hmm, looking at the query plan I do think this is correct, although i'm not sure how often this will happen in practice. I am immediately confronted with dumb ways around this, like, always including all the start events if conditioning on an end event and vice versa @tssweeney |
@tssweeney We could also force merges by using I'm still not exactly sure the best way to repro the conditions that would lead to the issue, merges are hard to predict... And the aggregation functions appear in my testing to actually be working as expected (ie, the query planner reports unmerged parts of the table, but doing filtering on the inputs still always returns the outputs as well). i'll use QA tomorrow. |
assert res[0].inputs["param"]["value1"] == "hello" | ||
|
||
# Does the query return the output? | ||
assert res[0].output["d"] == 5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test highlights the error case that the query creates.
Description
Push heavy conditions into WHERE clause before aggregating in calls query. In testing, while this did not improve the amount of time a query took, it decreased max memory usage by 10x.
When testing in the clickhouse console on one of the historically impossibly bad queries, this change allows it to actually complete, although it still takes 20+ seconds...
Technically, the queries are different. In prod, the groupby before filtering allows us to include additional rows that have the same call_id but don't have dynamic fields matching the filters. I think the aggregation functions built into the table (going from
call_parts
tocalls_merged
) mitigate most of the common cases of duplicate rows (likedeleted_at
ordisplay_name
).Example difference between master and branch query structure:
Master
Branch
Testing
Back to back testing in a local environment with 20,000 calls with very large payloads:
![Screenshot 2025-01-27 at 3 58 25 PM](https://private-user-images.githubusercontent.com/19414170/407132834-55c41ff0-3a70-41ce-9a1b-21ac7948883e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwNzkwMDYsIm5iZiI6MTczOTA3ODcwNiwicGF0aCI6Ii8xOTQxNDE3MC80MDcxMzI4MzQtNTVjNDFmZjAtM2E3MC00MWNlLTlhMWItMjFhYzc5NDg4ODNlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA5VDA1MjUwNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTJkNDY0ODk5MDYwY2Y0NjFlYzM3ZDE5ODgwYWZmYmVkOWVhYjE0ZDIzNWMzNTdmNDEzOGIyNDE1NDQ3MDZlYWImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.A8hY86HByf7AEFvFNcr4cgJMnFJTdl9kXDDPpfLzips)
Query generating above stats:
Master:
![filter-timing-master-2](https://private-user-images.githubusercontent.com/19414170/407138818-7e482290-2007-45fd-be23-f614acb75652.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwNzkwMDYsIm5iZiI6MTczOTA3ODcwNiwicGF0aCI6Ii8xOTQxNDE3MC80MDcxMzg4MTgtN2U0ODIyOTAtMjAwNy00NWZkLWJlMjMtZjYxNGFjYjc1NjUyLmdpZj9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA5VDA1MjUwNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWZmYzdmMDdiYWExMWQ1OGI4ODk1NGZjN2FkN2FjYTNiNjQ0Y2I1ZWQxYzFiYTFhN2IwOTQ4ZjQyOTliN2Q0NDYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.MIPnz8Yo2rAvzPT9XZmipeHuIgkJKGqf-GCiu2SCo1k)
Branch:
![filter-timing-branch-3](https://private-user-images.githubusercontent.com/19414170/407139852-4a3ed74e-5217-4c16-bbd0-a9267b763e5e.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwNzkwMDYsIm5iZiI6MTczOTA3ODcwNiwicGF0aCI6Ii8xOTQxNDE3MC80MDcxMzk4NTItNGEzZWQ3NGUtNTIxNy00YzE2LWJiZDAtYTkyNjdiNzYzZTVlLmdpZj9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA5VDA1MjUwNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTZjNDU4YjRhZjQzZTc0NzQzNGE5NmQyNzI2ODIxYjMzNmVlM2FhODQzYTVjODBmMDIyYTI5MjhmMzY3YWRlYTUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.98nwIKIBOXBoCxepN25lyudt6FW8IbhTG2OhECY6XbY)