github.com/dolthub/dolt/go@v0.40.5-0.20240520175717-68db7794bea6/libraries/doltcore/schema/data_length.go (about) 1 // Copyright 2023 Dolthub, 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 // 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 schema 16 17 import ( 18 "github.com/dolthub/go-mysql-server/sql" 19 sqltypes "github.com/dolthub/go-mysql-server/sql/types" 20 ) 21 22 func SchemaAvgLength(schema sql.Schema) uint64 { 23 var numBytesPerRow uint64 = 0 24 for _, col := range schema { 25 switch n := col.Type.(type) { 26 case sql.NumberType: 27 numBytesPerRow += 8 28 case sql.StringType: 29 numBytesPerRow += uint64(n.MaxByteLength()) 30 case sqltypes.BitType: 31 numBytesPerRow += 8 32 case sql.DatetimeType: 33 numBytesPerRow += 8 34 case sql.DecimalType: 35 numBytesPerRow += uint64(n.MaximumScale()) 36 case sql.EnumType: 37 numBytesPerRow += 2 38 case sqltypes.JsonType: 39 numBytesPerRow += 20 40 case sql.NullType: 41 numBytesPerRow += 1 42 case sqltypes.TimeType: 43 numBytesPerRow += 16 44 case sql.YearType: 45 numBytesPerRow += 8 46 } 47 } 48 return numBytesPerRow 49 }