Skip to content

Commit

Permalink
Avoid deserializing QueryAST for every split.
Browse files Browse the repository at this point in the history
  • Loading branch information
fulmicoton committed Jul 31, 2024
1 parent 6fa3c29 commit bab2176
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions quickwit/quickwit-search/src/leaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ fn get_leaf_resp_from_count(count: u64) -> LeafSearchResponse {
async fn leaf_search_single_split(
searcher_context: &SearcherContext,
mut search_request: SearchRequest,
query_ast: Arc<QueryAst>,
storage: Arc<dyn Storage>,
split: SplitIdAndFooterOffsets,
doc_mapper: Arc<dyn DocMapper>,
Expand All @@ -363,9 +364,6 @@ async fn leaf_search_single_split(
return Ok(cached_answer);
}

let query_ast: QueryAst = serde_json::from_str(search_request.query_ast.as_str())
.map_err(|err| SearchError::InvalidQuery(err.to_string()))?;

// CanSplitDoBetter or rewrite_request may have changed the request to be a count only request
// This may be the case for AllQuery with a sort by date and time filter, where the current
// split can't have better results.
Expand Down Expand Up @@ -394,7 +392,7 @@ async fn leaf_search_single_split(
let mut collector =
make_collector_for_split(split_id.clone(), &search_request, aggregations_limits)?;

let (query, mut warmup_info) = doc_mapper.query(split_schema.clone(), &query_ast, false)?;
let (query, mut warmup_info) = doc_mapper.query(split_schema.clone(), &*query_ast, false)?;

let collector_warmup_info = collector.warmup_info();
warmup_info.merge(collector_warmup_info);
Expand All @@ -413,7 +411,7 @@ async fn leaf_search_single_split(
// request based on the results of the preceding searches
check_optimize_search_request(&mut search_request, &split, &split_filter);
collector.update_search_param(&search_request);
if is_metadata_count_request_with_ast(&query_ast, &search_request) {
if is_metadata_count_request_with_ast(&*query_ast, &search_request) {
return Ok((
search_request,
get_leaf_resp_from_count(searcher.num_docs() as u64),
Expand Down Expand Up @@ -1223,6 +1221,10 @@ pub async fn leaf_search(
let incremental_merge_collector = IncrementalCollector::new(merge_collector);
let incremental_merge_collector = Arc::new(Mutex::new(incremental_merge_collector));

let query_ast: Arc<QueryAst> = serde_json::from_str::<QueryAst>(&request.query_ast)
.map_err(|err| SearchError::InvalidQuery(err.to_string()))?
.into();

for (split, mut request) in split_with_req {
let leaf_split_search_permit = searcher_context.leaf_search_split_semaphore
.clone()
Expand All @@ -1239,6 +1241,7 @@ pub async fn leaf_search(
leaf_search_single_split_futures.push(tokio::spawn(
leaf_search_single_split_wrapper(
request,
query_ast.clone(),
searcher_context.clone(),
index_storage.clone(),
doc_mapper.clone(),
Expand Down Expand Up @@ -1289,6 +1292,7 @@ pub async fn leaf_search(
#[instrument(skip_all, fields(split_id = split.split_id))]
async fn leaf_search_single_split_wrapper(
request: SearchRequest,
query_ast: Arc<QueryAst>,
searcher_context: Arc<SearcherContext>,
index_storage: Arc<dyn Storage>,
doc_mapper: Arc<dyn DocMapper>,
Expand All @@ -1305,6 +1309,7 @@ async fn leaf_search_single_split_wrapper(
let leaf_search_single_split_res = leaf_search_single_split(
&searcher_context,
request,
query_ast,
index_storage,
split.clone(),
doc_mapper,
Expand Down

0 comments on commit bab2176

Please sign in to comment.