diff options
author | Ting-Wei Lan <tingwei.lan@cobinhood.com> | 2019-03-13 17:35:40 +0800 |
---|---|---|
committer | Jhih-Ming Huang <jm.huang@cobinhood.com> | 2019-05-06 10:44:04 +0800 |
commit | 683a90aa4b2f5788ca7eb8554d35c333e5bef08f (patch) | |
tree | b34c8d3fdd37b1b6c64d3f8d39681232341e0a19 /core/vm/sqlvm | |
parent | 5ff5adc8cab2386c744bc69782cade71222b51b9 (diff) | |
download | dexon-683a90aa4b2f5788ca7eb8554d35c333e5bef08f.tar dexon-683a90aa4b2f5788ca7eb8554d35c333e5bef08f.tar.gz dexon-683a90aa4b2f5788ca7eb8554d35c333e5bef08f.tar.bz2 dexon-683a90aa4b2f5788ca7eb8554d35c333e5bef08f.tar.lz dexon-683a90aa4b2f5788ca7eb8554d35c333e5bef08f.tar.xz dexon-683a90aa4b2f5788ca7eb8554d35c333e5bef08f.tar.zst dexon-683a90aa4b2f5788ca7eb8554d35c333e5bef08f.zip |
core: vm: sqlvm: schema: mark if an index are referenced by foreign keys
In order to check foreign keys efficiently during deletion, an index
should be marked when it is referenced by foreign keys. Since we now
have flags which cannot be declared directly from the source code, two
helper functions are added to distinguish between two groups of flags.
Diffstat (limited to 'core/vm/sqlvm')
-rw-r--r-- | core/vm/sqlvm/schema/schema.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/core/vm/sqlvm/schema/schema.go b/core/vm/sqlvm/schema/schema.go index 638b85817..7bbe9518e 100644 --- a/core/vm/sqlvm/schema/schema.go +++ b/core/vm/sqlvm/schema/schema.go @@ -40,6 +40,25 @@ const ( ColumnAttrHasSequence ) +// GetDeclaredFlags returns flags which can be mapped to the source code tokens. +func (a ColumnAttr) GetDeclaredFlags() ColumnAttr { + mask := ColumnAttrPrimaryKey | + ColumnAttrNotNull | + ColumnAttrUnique | + ColumnAttrHasDefault | + ColumnAttrHasForeignKey | + ColumnAttrHasSequence + return a & mask + +} + +// GetDerivedFlags returns flags which are not declared in the source code but +// can be derived from it. +func (a ColumnAttr) GetDerivedFlags() ColumnAttr { + mask := ColumnAttr(0) + return a & mask +} + // TableRef defines the type for table index in Schema. type TableRef uint8 @@ -58,8 +77,25 @@ type IndexAttr uint16 const ( // IndexAttrUnique indicates whether an index is unique. IndexAttrUnique IndexAttr = 1 << iota + // IndexAttrReferenced indicates whether an index is referenced by columns + // with foreign key constraints. This attribute cannot be specified by + // users. It is computed automatically during contract creation. + IndexAttrReferenced ) +// GetDeclaredFlags returns flags which can be mapped to the source code tokens. +func (a IndexAttr) GetDeclaredFlags() IndexAttr { + mask := IndexAttrUnique + return a & mask +} + +// GetDerivedFlags returns flags which are not declared in the source code but +// can be derived from it. +func (a IndexAttr) GetDerivedFlags() IndexAttr { + mask := IndexAttrReferenced + return a & mask +} + // Schema defines sqlvm schema struct. type Schema []Table |