github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/engine/tae/catalog/model.go (about)

     1  // Copyright 2021 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 catalog
    16  
    17  import (
    18  	"github.com/matrixorigin/matrixone/pkg/catalog"
    19  	"github.com/matrixorigin/matrixone/pkg/container/types"
    20  )
    21  
    22  const (
    23  	PhyAddrColumnName    = catalog.Row_ID
    24  	PhyAddrColumnComment = "Physical address"
    25  	SortKeyNamePrefx     = "_SORT_"
    26  
    27  	AttrRowID    = PhyAddrColumnName
    28  	AttrCommitTs = catalog.TableTailAttrCommitTs
    29  	AttrAborted  = catalog.TableTailAttrAborted
    30  	AttrPKVal    = catalog.TableTailAttrPKVal
    31  
    32  	TenantSysID = uint32(0)
    33  )
    34  
    35  var SystemDBSchema *Schema
    36  var SystemTableSchema *Schema
    37  var SystemTableSchema_V1 *Schema
    38  var SystemColumnSchema *Schema
    39  var SystemColumnSchema_V1 *Schema
    40  
    41  var SystemObject_DB_ID types.Uuid
    42  var SystemObject_Table_ID types.Uuid
    43  var SystemObject_Columns_ID types.Uuid
    44  var SystemBlock_DB_ID types.Blockid
    45  var SystemBlock_Table_ID types.Blockid
    46  var SystemBlock_Columns_ID types.Blockid
    47  
    48  const (
    49  	ModelSchemaName   = "_ModelSchema"
    50  	ModelAttrET       = "ET"
    51  	ModelAttrID       = "ID"
    52  	ModelAttrName     = "NAME"
    53  	ModelAttrTS       = "TS"
    54  	ModelAttrOpT      = "OPT"
    55  	ModelAttrLogIdx   = "LOGIDX"
    56  	ModelAttrInfo     = "INFO"
    57  	ModelAttrParentID = "PARENTID"
    58  )
    59  
    60  func init() {
    61  
    62  	SystemObject_DB_ID = types.Uuid{101}
    63  	SystemObject_Table_ID = types.Uuid{102}
    64  	SystemObject_Columns_ID = types.Uuid{103}
    65  	SystemBlock_DB_ID = types.Blockid{101}
    66  	SystemBlock_Table_ID = types.Blockid{102}
    67  	SystemBlock_Columns_ID = types.Blockid{103}
    68  
    69  	var err error
    70  
    71  	SystemDBSchema = NewEmptySchema(catalog.MO_DATABASE)
    72  	for i, colname := range catalog.MoDatabaseSchema {
    73  		if i == 0 {
    74  			if err = SystemDBSchema.AppendPKCol(colname, catalog.MoDatabaseTypes[i], 0); err != nil {
    75  				panic(err)
    76  			}
    77  		} else {
    78  			if err = SystemDBSchema.AppendCol(colname, catalog.MoDatabaseTypes[i]); err != nil {
    79  				panic(err)
    80  			}
    81  		}
    82  	}
    83  	if err = SystemDBSchema.Finalize(true); err != nil {
    84  		panic(err)
    85  	}
    86  
    87  	SystemTableSchema = NewEmptySchema(catalog.MO_TABLES)
    88  	for i, colname := range catalog.MoTablesSchema {
    89  		if i == 0 {
    90  			if err = SystemTableSchema.AppendPKCol(colname, catalog.MoTablesTypes[i], 0); err != nil {
    91  				panic(err)
    92  			}
    93  		} else {
    94  			if err = SystemTableSchema.AppendCol(colname, catalog.MoTablesTypes[i]); err != nil {
    95  				panic(err)
    96  			}
    97  		}
    98  	}
    99  	if err = SystemTableSchema.Finalize(true); err != nil {
   100  		panic(err)
   101  	}
   102  
   103  	SystemTableSchema_V1 = NewEmptySchema(catalog.MO_TABLES + "_v1")
   104  	for i, colname := range catalog.MoTablesSchema_V1 {
   105  		if i == 0 {
   106  			if err = SystemTableSchema_V1.AppendPKCol(colname, catalog.MoTablesTypes_V1[i], 0); err != nil {
   107  				panic(err)
   108  			}
   109  		} else {
   110  			if err = SystemTableSchema_V1.AppendCol(colname, catalog.MoTablesTypes_V1[i]); err != nil {
   111  				panic(err)
   112  			}
   113  		}
   114  	}
   115  	if err = SystemTableSchema_V1.Finalize(true); err != nil {
   116  		panic(err)
   117  	}
   118  
   119  	SystemColumnSchema = NewEmptySchema(catalog.MO_COLUMNS)
   120  	for i, colname := range catalog.MoColumnsSchema {
   121  		if i == 0 {
   122  			if err = SystemColumnSchema.AppendPKCol(colname, catalog.MoColumnsTypes[i], 0); err != nil {
   123  				panic(err)
   124  			}
   125  		} else {
   126  			if err = SystemColumnSchema.AppendCol(colname, catalog.MoColumnsTypes[i]); err != nil {
   127  				panic(err)
   128  			}
   129  		}
   130  	}
   131  	if err = SystemColumnSchema.Finalize(true); err != nil {
   132  		panic(err)
   133  	}
   134  
   135  	SystemColumnSchema_V1 = NewEmptySchema(catalog.MO_COLUMNS)
   136  	for i, colname := range catalog.MoColumnsSchema_V1 {
   137  		if i == 0 {
   138  			if err = SystemColumnSchema_V1.AppendPKCol(colname, catalog.MoColumnsTypes_V1[i], 0); err != nil {
   139  				panic(err)
   140  			}
   141  		} else {
   142  			if err = SystemColumnSchema_V1.AppendCol(colname, catalog.MoColumnsTypes_V1[i]); err != nil {
   143  				panic(err)
   144  			}
   145  		}
   146  	}
   147  	if err = SystemColumnSchema_V1.Finalize(true); err != nil {
   148  		panic(err)
   149  	}
   150  }