/// Add SortExec operator on top of the input plan of the given chunk
/// The plan will be sorted on the chunk's primary key
Add SortExec operator on top of the input plan of the given chunk
The plan will be sorted on the chunk's primary key
Add SortExec operator on top of the input plan of the given chunk The plan will be sorted on the chunk ' s primary key
fn build_sort_plan(
        chunk: Arc<dyn QueryChunk>,
        input: Arc<dyn ExecutionPlan>,
        output_sort_key: &SortKey,
    ) -> Result<Arc<dyn ExecutionPlan>> {
        // output_sort_key cannot be empty
        if output_sort_key.is_empty() {
            panic!("Super sort key is empty");
        }
        debug!(output_sort_key=?output_sort_key, "Super sort key input to build_sort_plan");
        // Check to see if the plan is sorted on the subset of the output_sort_key
        let sort_key = chunk.sort_key();
        if let Some(chunk_sort_key) = sort_key {
            if let Some(merge_key) = SortKey::try_merge_key(output_sort_key, chunk_sort_key) {
                if merge_key == output_sort_key {
                    // the chunk is already sorted on the subset of the o_sort_key,
                    // no need to resort it
                    debug!(ChunkID=?chunk.id(), "Chunk is sorted and no need the sort operator");
                    return Ok(input);
                }
            } else {
                // The chunk is sorted but not on different order with super sort key.
                // Log it for investigating data set to improve performance further
                // This behavior should not happen when ingester, compactor and querier use the sort key
                warn!(chunk_type=?chunk.chunk_type(),
                    chunk_ID=?chunk.id(),
                    chunk_current_sort_order=?chunk_sort_key,
                    chunk_super_sort_key=?output_sort_key,
                    "Chunk will get resorted in build_sort_plan because it was sorted on different sort key");
            }
        } else {
            debug!(chunk_type=?chunk.chunk_type(),
                chunk_ID=?chunk.id(),
                "Chunk is not yet sorted and will get sorted in build_sort_plan");
        }
        // Build arrow sort expression for the chunk sort key
        let input_schema = input.schema();
        let sort_exprs = arrow_sort_key_exprs(output_sort_key, &input_schema);
        debug!(?sort_exprs, chunk_id=?chunk.id(), "Sort Expression for the sort operator of chunk");
        // Create SortExec operator
        Ok(Arc::new(
            SortExec::try_new(sort_exprs, input).context(InternalSortSnafu)?,
        ))
    }
fn build_sort_plan ( chunk : Arc < dyn QueryChunk > , input : Arc < dyn ExecutionPlan > , output_sort_key : & SortKey , ) -> Result < Arc < dyn ExecutionPlan > > { // output_sort_key cannot be empty if output_sort_key . is_empty ( ) { panic ! ( " " ) ; } debug ! ( output_sort_key output_sort_key " " ) ; // Check to see if the plan is sorted on the subset of the output_sort_key let sort_key = chunk . sort_key ( ) ; if let Some ( chunk_sort_key ) = sort_key { if let Some ( merge_key ) = SortKey :: try_merge_key ( output_sort_key , chunk_sort_key ) { if merge_key == output_sort_key { // the chunk is already sorted on the subset of the o_sort_key, // no need to resort it debug ! ( ChunkID chunk id ( ) " " ) ; return Ok ( input ) ; } } else { // The chunk is sorted but not on different order with super sort key. // Log it for investigating data set to improve performance further // This behavior should not happen when ingester, compactor and querier use the sort key warn ! ( chunk_type chunk chunk_type ( ) chunk_ID chunk id ( ) chunk_current_sort_order chunk_sort_key chunk_super_sort_key output_sort_key " " ) ; } } else { debug ! ( chunk_type chunk chunk_type ( ) chunk_ID chunk id ( ) " " ) ; } // Build arrow sort expression for the chunk sort key let input_schema = input . schema ( ) ; let sort_exprs = arrow_sort_key_exprs ( output_sort_key , & input_schema ) ; debug ! ( sort_exprs chunk_id chunk id ( ) " " ) ; // Create SortExec operator Ok ( Arc :: new ( SortExec :: try_new ( sort_exprs , input ) . context ( InternalSortSnafu ) ? , ) ) }
Add SortExec operator on top of the input plan of the given chunk
The plan will be sorted on the chunk's primary key
Add SortExec operator on top of the input plan of the given chunk The plan will be sorted on the chunk ' s primary key
chunk
Arc<dyn QueryChunk>
input
Arc<dyn ExecutionPlan>
output_sort_key
&SortKey