Repository navigation
Support project expression pushdown with derived field script - #4288
songkant-aws wants to merge 50 commits into
Conversation
Signed-off-by: Lantao Jin <[email protected]>
Signed-off-by: Lantao Jin <[email protected]>
Signed-off-by: Songkan Tang <[email protected]>
Signed-off-by: Songkan Tang <[email protected]>
Signed-off-by: Songkan Tang <[email protected]>
Signed-off-by: Songkan Tang <[email protected]>
Signed-off-by: Songkan Tang <[email protected]>
Signed-off-by: Songkan Tang <[email protected]>
| OpenSearchIndexScanRule::isScriptProjectPushed) | ||
| .and(OpenSearchIndexScanRule::isProjectPushed) | ||
| .and(OpenSearchIndexScanRule::noLimitPushed) |
There was a problem hiding this comment.
Ideally, we don't need such complex condition check. Script project pushdown can be merged to project pushdown method. Will optimize it later.
There was a problem hiding this comment.
Merged two kinds of project into one method. This reduces the dependency on each other and reduces the times of rewriting plan. Additionally, if we introduce more rules related to project pushdown, it could be easier to modify current logic.
Signed-off-by: Songkan Tang <[email protected]>
Signed-off-by: Songkan Tang <[email protected]>
Signed-off-by: Songkan Tang <[email protected]>
Signed-off-by: Songkan Tang <[email protected]>
Signed-off-by: Songkan Tang <[email protected]>
|
Could you review this PR with another look? @qianheng-aws @LantaoJin @yuancu |
| "source=opensearch-sql_test_index_account" | ||
| + "| eval age = age + 2" | ||
| + "| fields age, lastname")); | ||
| } |
There was a problem hiding this comment.
It seems in the plan the new age field becomes age0. I'm curious where is it set back to name age
There was a problem hiding this comment.
Seems the column names in our final results are derived from the original plan(i.e. logical plan), so the final plan(i.e. physical plan) is allowed to produce a different row type as long as the types can match.
|
@LantaoJin Please take another look at this PR. |
Signed-off-by: Songkan Tang <[email protected]>
Signed-off-by: Songkan Tang <[email protected]>
Signed-off-by: Songkan Tang <[email protected]>
dd22241
Signed-off-by: Songkan Tang <[email protected]>
|
To be conservative here, I added some minor protection in the script project cost computation. With mini benchmark of very few rows(less than 5 rows), if we push down around 15 derived fields, the performance is almost equal to no pushdown query. To balance the pushdown benefit and cost, I pick an upper limit like half of 15, aka 7 script here. If the derived field script is less than 7, we think it will more likely bring performance benefit to the query. So a minor improvement logic is, if the derived scripts to be pushed is more than 7. We will give more penalty cost like |
synced offline. we need to benchmark on big size dataset. And I think this feature is only worth to enable with sort script pushdown as project expression only pushdown would be a high cost operator for OpenSearch cluster. |
| * Considering the case of wide schema table, it will likely allow more than this | ||
| * cap derived field script pushdown. | ||
| * | ||
| * For example, say we have a 300 column wide table. We want to pushdown 9 derived fields. |
There was a problem hiding this comment.
Should the approach of blocking pushing down script_project with scripts more than 9 more straightforward?
There was a problem hiding this comment.
I was thinking the same thing. But in other side, pruning a wide schema table to keep very less fields is probably still valuable. Anyway, this feature will be shown with very less performance improvement by a potential waste of CPU for each shard. I will close this PR.
| // almost equal to no pushdown query. To balance the pushdown benefit and cost, we pick an upper | ||
| // limit like half of 15, aka 7 script here. If the derived field script is less than 7, | ||
| // We think it will more likely bring performance benefit to the query. | ||
| private static final int SCRIPT_PROJECT_SOFT_CAP = 7; |
There was a problem hiding this comment.
Should these threshold be configurable?
|
I did some benchmark test. Query top 10000 documents in single shard cluster with nearly 100,000,000 rows profile:Profile Result: Query top 10000 documents and compute derived field in single shard cluster with nearly 100,000,000 rows profile:Profile result: This experiment demonstrates computing derived field not involved in filter query has similar performance to list required columns. Because both of them go through |
The second experiment proves the derived field script will be executed in each shardCreate index: Put some data Query: Profile result: The above profile result shows the query hits all of shards and performs script execution. |
Derived field will be executed on each row when it's involved in filter queryDerived field of filter query on single shard cluster with 100,000,000 rows: Profile result: Filter script has far better performance than computing derived field with filter queryProfile result: The above benchmark proves derived field script will be only executed on each document when it's involved in filter query. But its performance is far worse than the same filter script. |
|
@LantaoJin I will close this feature PR and mark it 'won't do'. I have done several benchmarks and pasted result in above comments. Here are the conclusions:
This PR introduces a process where derived fields are computed via script on each shard for the top 10,000 documents. OpenSearch’s FetchPhase then collects these documents and returns the results to the coordinator node. However, this approach offers limited performance gains—since the same script runs on the same input size, whether sequentially on one node or in parallel across multiple nodes. The primary benefit is offloading CPU pressure from the coordinator node, at the cost of increased CPU usage across the data nodes. |
Description
Support project expression pushdown with derived field script.
This is the first phase of script project pushdown with partial script project supported. Follow-up like supporting partial filter pushdown after script project pushdown will be implemented later.
DerivedFieldScript Pros and Cons:
Pros:
Cons:
Script field Pros and Cons:
Pros:
Cons:
Benchmark Results After Optimization
CalcitePPLBig5IT:
Summary:
asc_sort_timestamp: 8 ms
asc_sort_timestamp_can_match_shortcut: 13 ms
asc_sort_timestamp_no_can_match_shortcut: 12 ms
asc_sort_with_after_timestamp: 9 ms
bin_bins: 7 ms
bin_span_log: 8 ms
bin_span_time: 16 ms
composite_date_histogram_daily: 23 ms
composite_terms: 52 ms
composite_terms_keyword: 27 ms
date_histogram_hourly_agg: 13 ms
date_histogram_minute_agg: 22 ms
default: 9 ms
desc_sort_timestamp: 10 ms
desc_sort_timestamp_can_match_shortcut: 16 ms
desc_sort_timestamp_no_can_match_shortcut: 24 ms
desc_sort_with_after_timestamp: 9 ms
keyword_in_range: 23 ms
keyword_terms: 17 ms
keyword_terms_low_cardinality: 13 ms
multi_terms_keyword: 25 ms
query_string_on_message: 14 ms
query_string_on_message_filtered: 34 ms
query_string_on_message_filtered_sorted_num: 39 ms
range: 12 ms
range_auto_date_histo: 37 ms
range_auto_date_histo_with_metrics: 72 ms
range_field_conjunction_big_range_big_term_query: 10 ms
range_field_conjunction_small_range_big_term_query: 8 ms
range_field_conjunction_small_range_small_term_query: 15 ms
range_field_disjunction_big_range_small_term_query: 10 ms
range_numeric: 11 ms
range_with_asc_sort: 17 ms
range_with_desc_sort: 15 ms
scroll: 7 ms
sort_keyword_can_match_shortcut: 14 ms
sort_keyword_no_can_match_shortcut: 14 ms
sort_numeric_asc: 14 ms
sort_numeric_asc_with_match: 17 ms
sort_numeric_desc: 22 ms
sort_numeric_desc_with_match: 15 ms
term: 17 ms
terms_significant_1: 19 ms
terms_significant_2: 16 ms
Total 44 queries succeed. Average duration: 18 ms
CalcitePPLClickBenchIT:
Summary:
q1: 21 ms
q10: 59 ms
q11: 26 ms
q12: 31 ms
q13: 15 ms
q14: 21 ms
q15: 18 ms
q16: 13 ms
q17: 14 ms
q18: 10 ms
q19: 19 ms
q2: 18 ms
q20: 8 ms
q21: 11 ms
q22: 19 ms
q23: 24 ms
q24: 17 ms
q25: 15 ms
q26: 13 ms
q27: 15 ms
q28: 32 ms
q3: 21 ms
q31: 29 ms
q32: 31 ms
q33: 24 ms
q34: 12 ms
q35: 15 ms
q36: 18 ms
q37: 24 ms
q38: 22 ms
q39: 23 ms
q4: 16 ms
q40: 26 ms
q41: 27 ms
q42: 23 ms
q43: 31 ms
q5: 12 ms
q6: 12 ms
q7: 17 ms
q8: 21 ms
q9: 23 ms
Total 41 queries succeed. Average duration: 20 ms
Related Issues
Resolves #3387
Check List
--signoffor-s.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.