From bab2176cbb38115c654ee95e8d64a84a9ddb3736 Mon Sep 17 00:00:00 2001 From: Paul Masurel Date: Thu, 1 Aug 2024 00:00:47 +0900 Subject: [PATCH] Avoid deserializing QueryAST for every split. --- quickwit/quickwit-search/src/leaf.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/quickwit/quickwit-search/src/leaf.rs b/quickwit/quickwit-search/src/leaf.rs index b225a53c13d..df563c231b0 100644 --- a/quickwit/quickwit-search/src/leaf.rs +++ b/quickwit/quickwit-search/src/leaf.rs @@ -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, storage: Arc, split: SplitIdAndFooterOffsets, doc_mapper: Arc, @@ -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. @@ -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); @@ -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), @@ -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 = serde_json::from_str::(&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() @@ -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(), @@ -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, searcher_context: Arc, index_storage: Arc, doc_mapper: Arc, @@ -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,