github.com/dolthub/dolt/go@v0.40.5-0.20240520175717-68db7794bea6/libraries/doltcore/schema/statistic.go (about) 1 // Copyright 2024 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 "github.com/dolthub/go-mysql-server/sql/types" 20 21 stypes "github.com/dolthub/dolt/go/store/types" 22 ) 23 24 const StatsVersion int64 = 1 25 26 const ( 27 StatsQualifierColName = "qualifier" 28 StatsDbColName = "database_name" 29 StatsTableColName = "table_name" 30 StatsIndexColName = "index_name" 31 StatsPositionColName = "position" 32 StatsCommitHashColName = "commit_hash" 33 StatsRowCountColName = "row_count" 34 StatsDistinctCountColName = "distinct_count" 35 StatsNullCountColName = "null_count" 36 StatsColumnsColName = "columns" 37 StatsTypesColName = "types" 38 StatsUpperBoundColName = "upper_bound" 39 StatsUpperBoundCntColName = "upper_bound_cnt" 40 StatsCreatedAtColName = "created_at" 41 StatsMcv1ColName = "mcv1" 42 StatsMcv2ColName = "mcv2" 43 StatsMcv3ColName = "mcv3" 44 StatsMcv4ColName = "mcv4" 45 StatsMcvCountsColName = "mcvCounts" 46 StatsVersionColName = "version" 47 ) 48 49 const ( 50 StatsDbTag uint64 = iota 51 StatsTableTag 52 StatsIndexTag 53 StatsPositionTag 54 StatsVersionTag 55 StatsCommitHashTag 56 StatsRowCountTag 57 StatsDistinctCountTag 58 StatsNullCountTag 59 StatsColumnsTag 60 StatsTypesTag 61 StatsUpperBoundTag 62 StatsUpperBoundCntTag 63 StatsCreatedAtTag 64 StatsMcv1Tag 65 StatsMcv2Tag 66 StatsMcv3Tag 67 StatsMcv4Tag 68 StatsMcvCountsTag 69 ) 70 71 func StatsTableSqlSchema(dbName string) sql.PrimaryKeySchema { 72 return sql.PrimaryKeySchema{ 73 Schema: sql.Schema{ 74 &sql.Column{Name: StatsDbColName, Type: types.Text, PrimaryKey: true, DatabaseSource: dbName}, 75 &sql.Column{Name: StatsTableColName, Type: types.Text, PrimaryKey: true, DatabaseSource: dbName}, 76 &sql.Column{Name: StatsIndexColName, Type: types.Text, PrimaryKey: true, DatabaseSource: dbName}, 77 &sql.Column{Name: StatsRowCountColName, Type: types.Int64, DatabaseSource: dbName}, 78 &sql.Column{Name: StatsDistinctCountColName, Type: types.Int64, DatabaseSource: dbName}, 79 &sql.Column{Name: StatsNullCountColName, Type: types.Int64, DatabaseSource: dbName}, 80 &sql.Column{Name: StatsColumnsColName, Type: types.Text, DatabaseSource: dbName}, 81 &sql.Column{Name: StatsTypesColName, Type: types.Text, DatabaseSource: dbName}, 82 &sql.Column{Name: StatsUpperBoundColName, Type: types.Text, DatabaseSource: dbName}, 83 &sql.Column{Name: StatsUpperBoundCntColName, Type: types.Int64, DatabaseSource: dbName}, 84 &sql.Column{Name: StatsCreatedAtColName, Type: types.Datetime, DatabaseSource: dbName}, 85 &sql.Column{Name: StatsMcv1ColName, Type: types.Text, DatabaseSource: dbName}, 86 &sql.Column{Name: StatsMcv2ColName, Type: types.Text, DatabaseSource: dbName}, 87 &sql.Column{Name: StatsMcv3ColName, Type: types.Text, DatabaseSource: dbName}, 88 &sql.Column{Name: StatsMcv4ColName, Type: types.Text, DatabaseSource: dbName}, 89 &sql.Column{Name: StatsMcvCountsColName, Type: types.Text, DatabaseSource: dbName}, 90 }, 91 PkOrdinals: []int{0, 1}, 92 } 93 } 94 95 var StatsTableDoltSchema = StatsTableDoltSchemaGen() 96 97 func StatsTableDoltSchemaGen() Schema { 98 colColl := NewColCollection( 99 NewColumn(StatsDbColName, StatsDbTag, stypes.StringKind, true, NotNullConstraint{}), 100 NewColumn(StatsTableColName, StatsTableTag, stypes.StringKind, true, NotNullConstraint{}), 101 NewColumn(StatsIndexColName, StatsIndexTag, stypes.StringKind, true, NotNullConstraint{}), 102 NewColumn(StatsPositionColName, StatsPositionTag, stypes.IntKind, true, NotNullConstraint{}), 103 NewColumn(StatsVersionColName, StatsVersionTag, stypes.IntKind, false, NotNullConstraint{}), 104 NewColumn(StatsCommitHashColName, StatsCommitHashTag, stypes.StringKind, false, NotNullConstraint{}), 105 NewColumn(StatsRowCountColName, StatsRowCountTag, stypes.IntKind, false, NotNullConstraint{}), 106 NewColumn(StatsDistinctCountColName, StatsDistinctCountTag, stypes.IntKind, false, NotNullConstraint{}), 107 NewColumn(StatsNullCountColName, StatsNullCountTag, stypes.IntKind, false, NotNullConstraint{}), 108 NewColumn(StatsColumnsColName, StatsColumnsTag, stypes.StringKind, false, NotNullConstraint{}), 109 NewColumn(StatsTypesColName, StatsTypesTag, stypes.StringKind, false, NotNullConstraint{}), 110 NewColumn(StatsUpperBoundColName, StatsUpperBoundTag, stypes.StringKind, false, NotNullConstraint{}), 111 NewColumn(StatsUpperBoundCntColName, StatsUpperBoundCntTag, stypes.IntKind, false, NotNullConstraint{}), 112 NewColumn(StatsCreatedAtColName, StatsCreatedAtTag, stypes.TimestampKind, false, NotNullConstraint{}), 113 NewColumn(StatsMcv1ColName, StatsMcv1Tag, stypes.StringKind, false), 114 NewColumn(StatsMcv2ColName, StatsMcv2Tag, stypes.StringKind, false), 115 NewColumn(StatsMcv3ColName, StatsMcv3Tag, stypes.StringKind, false), 116 NewColumn(StatsMcv4ColName, StatsMcv4Tag, stypes.StringKind, false), 117 NewColumn(StatsMcvCountsColName, StatsMcvCountsTag, stypes.StringKind, false, NotNullConstraint{}), 118 ) 119 return MustSchemaFromCols(colColl) 120 }