github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/causetstore/petri/acyclic/causet/implementation/base.go (about) 1 // Copyright 2020 WHTCORPS INC, Inc. 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 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package implementation 15 16 import ( 17 causetembedded "github.com/whtcorpsinc/milevadb/causet/embedded" 18 "github.com/whtcorpsinc/milevadb/causet/memo" 19 ) 20 21 type baseImpl struct { 22 cost float64 23 plan causetembedded.PhysicalCauset 24 } 25 26 func (impl *baseImpl) CalcCost(outCount float64, children ...memo.Implementation) float64 { 27 impl.cost = 0 28 for _, child := range children { 29 impl.cost += child.GetCost() 30 } 31 return impl.cost 32 } 33 34 func (impl *baseImpl) SetCost(cost float64) { 35 impl.cost = cost 36 } 37 38 func (impl *baseImpl) GetCost() float64 { 39 return impl.cost 40 } 41 42 func (impl *baseImpl) GetCauset() causetembedded.PhysicalCauset { 43 return impl.plan 44 } 45 46 func (impl *baseImpl) AttachChildren(children ...memo.Implementation) memo.Implementation { 47 childrenCauset := make([]causetembedded.PhysicalCauset, len(children)) 48 for i, child := range children { 49 childrenCauset[i] = child.GetCauset() 50 } 51 impl.plan.SetChildren(childrenCauset...) 52 return impl 53 } 54 55 func (impl *baseImpl) ScaleCostLimit(costLimit float64) float64 { 56 return costLimit 57 } 58 59 func (impl *baseImpl) GetCostLimit(costLimit float64, children ...memo.Implementation) float64 { 60 childrenCost := 0.0 61 for _, child := range children { 62 childrenCost += child.GetCost() 63 } 64 return costLimit - childrenCost 65 }