From 97b7044a459f4ad881d8e8787ca8fbb238936bad Mon Sep 17 00:00:00 2001 From: "yenlin.lai" Date: Mon, 25 Feb 2019 16:16:31 +0800 Subject: core: sqlvm: schema: define type for table/column/index/sequence size The size of table in db and column/index/sequence in a table is bounded by uint8. Define types for better readability. --- core/vm/sqlvm/schema/schema.go | 20 ++++++++++++++++---- core/vm/sqlvm/schema/schema_test.go | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/core/vm/sqlvm/schema/schema.go b/core/vm/sqlvm/schema/schema.go index 4529fd7d5..76c843387 100644 --- a/core/vm/sqlvm/schema/schema.go +++ b/core/vm/sqlvm/schema/schema.go @@ -27,6 +27,18 @@ const ( ColumnAttrHasForeignKey ) +// TableRef defines the type for table index in Schema. +type TableRef uint8 + +// ColumnRef defines the type for column index in Table.Columns. +type ColumnRef uint8 + +// IndexRef defines the type for array index of Column.Indices. +type IndexRef uint8 + +// SequenceRef defines the type for sequence index in Table. +type SequenceRef uint8 + // IndexAttr defines bit flags for describing index attribute. type IndexAttr uint16 @@ -49,16 +61,16 @@ type Table struct { type Index struct { Name []byte Attr IndexAttr - Columns []uint8 + Columns []ColumnRef } type column struct { Name []byte Type ast.DataType Attr ColumnAttr - Sequence uint8 - ForeignTable uint8 - ForeignColumn uint8 + Sequence SequenceRef + ForeignTable TableRef + ForeignColumn ColumnRef Rest interface{} } diff --git a/core/vm/sqlvm/schema/schema_test.go b/core/vm/sqlvm/schema/schema_test.go index 92bfa6c91..5d252ef85 100644 --- a/core/vm/sqlvm/schema/schema_test.go +++ b/core/vm/sqlvm/schema/schema_test.go @@ -82,7 +82,7 @@ func (s *SchemaTestSuite) TestEncodeAndDecodeSchema() { { Name: []byte("idx"), Attr: IndexAttrUnique, - Columns: []uint8{0}, + Columns: []ColumnRef{0}, }, }, }, -- cgit v1.2.3