// Copyright 2025-present the zvec project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #pragma once #include #include #include #include #include #include #include "db/index/segment/segment.h" #include "db/sqlengine/analyzer/query_info.h" #include "db/sqlengine/planner/doc_filter.h" #include "plan_info.h" namespace zvec::sqlengine { class QueryPlanner { public: QueryPlanner(CollectionSchema *schema); Result make_plan( const std::vector &segments, const std::string &trace_id, std::vector *query_infos); private: Result make_physical_plan( const std::vector &segments, const std::string &trace_id, std::vector *query_infos); Result make_group_by_physical_plan( const std::vector &segments, const std::string &trace_id, std::vector *query_infos); private: Result parse_filter(const QueryNode *node); Result create_filter_node(const QueryNode *node); Result vector_scan( Segment::Ptr seg, QueryInfo::Ptr query_info, std::unique_ptr forward_filter, bool single_stage_search); Result invert_scan( Segment::Ptr seg, QueryInfo::Ptr query_info, std::unique_ptr forward_filter); Result forward_scan( Segment::Ptr seg, QueryInfo::Ptr query_info, std::unique_ptr forward_filter); Result fts_scan( Segment::Ptr seg, QueryInfo::Ptr query_info, std::unique_ptr forward_filter, bool single_stage_search); static DocFilter::Ptr build_doc_filter( const Segment::Ptr &seg, const QueryInfo::Ptr &query_info, std::unique_ptr &forward_filter, bool single_stage_search); static int get_batch_size(const QueryInfo &info, bool has_later_filter); private: CollectionSchema *schema_{nullptr}; }; } // namespace zvec::sqlengine