vitess.io/vitess@v0.16.2/go/vt/vtgate/planbuilder/vindex_op.go (about)

     1  /*
     2  Copyright 2022 The Vitess Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package planbuilder
    18  
    19  import (
    20  	"vitess.io/vitess/go/vt/sqlparser"
    21  	"vitess.io/vitess/go/vt/vterrors"
    22  	"vitess.io/vitess/go/vt/vtgate/engine"
    23  	"vitess.io/vitess/go/vt/vtgate/evalengine"
    24  	"vitess.io/vitess/go/vt/vtgate/planbuilder/operators"
    25  	"vitess.io/vitess/go/vt/vtgate/planbuilder/plancontext"
    26  
    27  	"vitess.io/vitess/go/vt/vtgate/vindexes"
    28  )
    29  
    30  func transformVindexPlan(ctx *plancontext.PlanningContext, op *operators.Vindex) (logicalPlan, error) {
    31  	single, ok := op.Vindex.(vindexes.SingleColumn)
    32  	if !ok {
    33  		return nil, vterrors.VT12001("multi-column vindexes not supported")
    34  	}
    35  
    36  	expr, err := evalengine.Translate(op.Value, ctx.SemTable)
    37  	if err != nil {
    38  		return nil, err
    39  	}
    40  	plan := &vindexFunc{
    41  		order:         1,
    42  		tableID:       op.Solved,
    43  		resultColumns: nil,
    44  		eVindexFunc: &engine.VindexFunc{
    45  			Opcode: op.OpCode,
    46  			Vindex: single,
    47  			Value:  expr,
    48  		},
    49  	}
    50  
    51  	for _, col := range op.Columns {
    52  		_, err := plan.SupplyProjection(&sqlparser.AliasedExpr{
    53  			Expr: col,
    54  			As:   sqlparser.IdentifierCI{},
    55  		}, false)
    56  		if err != nil {
    57  			return nil, err
    58  		}
    59  	}
    60  	return plan, nil
    61  }