github.com/matrixorigin/matrixone@v0.7.0/pkg/pb/plan/plan.go (about)

     1  // Copyright 2022 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package plan
    16  
    17  // when autocommit is set to false, and no active txn is started
    18  // an implicit txn need to be started for statements , like insert/delete/update
    19  // and most select statement, like select * from t1.
    20  // but for statement like select 1 or SELECT @@session.autocommit , implicit txn is not needed
    21  // walk through the plan for select statement and check if there is an node_table_scan
    22  func (p *Plan) NeedImplicitTxn() bool {
    23  	if p.GetQuery().GetStmtType() != Query_SELECT {
    24  		return true
    25  	}
    26  	for _, n := range p.GetQuery().GetNodes() {
    27  		if n.GetNodeType() == Node_TABLE_SCAN {
    28  			return true
    29  		}
    30  	}
    31  	return false
    32  }
    33  
    34  func (p *Plan) MarshalBinary() ([]byte, error) {
    35  	data := make([]byte, p.ProtoSize())
    36  	_, err := p.MarshalTo(data)
    37  	return data, err
    38  }
    39  
    40  func (p *Plan) UnmarshalBinary(data []byte) error {
    41  	return p.Unmarshal(data)
    42  }
    43  
    44  func (p *PartitionByDef) MarshalPartitionInfo() ([]byte, error) {
    45  	data := make([]byte, p.ProtoSize())
    46  	_, err := p.MarshalTo(data)
    47  	return data, err
    48  }
    49  
    50  func (p *PartitionByDef) UnMarshalPartitionInfo(data []byte) error {
    51  	return p.Unmarshal(data)
    52  }