aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/sqlvm/runtime
diff options
context:
space:
mode:
authoryenlin.lai <yenlin.lai@cobinhood.com>2019-04-18 10:13:29 +0800
committerJhih-Ming Huang <jm.huang@cobinhood.com>2019-05-06 10:44:04 +0800
commit107dbb1954ac76647d4fceab5770285a5f7ecfe1 (patch)
tree333a4e5a2f5713f0c91dd1efa443dff079c77468 /core/vm/sqlvm/runtime
parent5b71bbd50a64d3b1576626d4cf0ca22569b57cf8 (diff)
downloaddexon-107dbb1954ac76647d4fceab5770285a5f7ecfe1.tar
dexon-107dbb1954ac76647d4fceab5770285a5f7ecfe1.tar.gz
dexon-107dbb1954ac76647d4fceab5770285a5f7ecfe1.tar.bz2
dexon-107dbb1954ac76647d4fceab5770285a5f7ecfe1.tar.lz
dexon-107dbb1954ac76647d4fceab5770285a5f7ecfe1.tar.xz
dexon-107dbb1954ac76647d4fceab5770285a5f7ecfe1.tar.zst
dexon-107dbb1954ac76647d4fceab5770285a5f7ecfe1.zip
sqlvm: common: replace table/index name with TableRef/IndexRef
Names will be mapped to references after parsing. Use references in hash will have better performance.
Diffstat (limited to 'core/vm/sqlvm/runtime')
-rw-r--r--core/vm/sqlvm/runtime/instructions.go4
-rw-r--r--core/vm/sqlvm/runtime/instructions_test.go9
2 files changed, 8 insertions, 5 deletions
diff --git a/core/vm/sqlvm/runtime/instructions.go b/core/vm/sqlvm/runtime/instructions.go
index 92d5753f5..e3a414123 100644
--- a/core/vm/sqlvm/runtime/instructions.go
+++ b/core/vm/sqlvm/runtime/instructions.go
@@ -15,6 +15,7 @@ import (
"github.com/dexon-foundation/dexon/core/vm/sqlvm/common"
dec "github.com/dexon-foundation/dexon/core/vm/sqlvm/common/decimal"
se "github.com/dexon-foundation/dexon/core/vm/sqlvm/errors"
+ "github.com/dexon-foundation/dexon/core/vm/sqlvm/schema"
)
var (
@@ -104,6 +105,7 @@ func opLoad(ctx *common.Context, input []*Operand, registers []*Operand, output
return se.ErrorCodeIndexOutOfRange
}
table := ctx.Storage.Schema[tableIdx]
+ tableRef := schema.TableRef(tableIdx)
ids, err := input[1].toUint64()
if err != nil {
@@ -127,7 +129,7 @@ func opLoad(ctx *common.Context, input []*Operand, registers []*Operand, output
}
for i, id := range ids {
slotDataCache := make(map[dexCommon.Hash]dexCommon.Hash)
- head := ctx.Storage.GetRowPathHash(table.Name, id)
+ head := ctx.Storage.GetRowPathHash(tableRef, id)
for j := range fields {
col := table.Columns[int(fields[j])]
byteOffset := col.ByteOffset
diff --git a/core/vm/sqlvm/runtime/instructions_test.go b/core/vm/sqlvm/runtime/instructions_test.go
index 7cf05c9f5..c071045e6 100644
--- a/core/vm/sqlvm/runtime/instructions_test.go
+++ b/core/vm/sqlvm/runtime/instructions_test.go
@@ -211,18 +211,19 @@ type opLoadTestCase struct {
func (s *opLoadSuite) SetupTest() {
s.ctx = &common.Context{}
s.ctx.Storage = s.newStorage()
- s.headHash = s.ctx.Storage.GetRowPathHash([]byte("Table_B"), uint64(123456))
+ targetTableRef := schema.TableRef(1)
+ s.headHash = s.ctx.Storage.GetRowPathHash(targetTableRef, uint64(123456))
s.address = dexCommon.HexToAddress("0x6655")
s.ctx.Storage.CreateAccount(s.address)
s.ctx.Contract = vm.NewContract(vm.AccountRef(s.address),
vm.AccountRef(s.address), new(big.Int), 0)
s.slotHash, s.raws = setSlotDataInStateDB(s.headHash, s.address, s.ctx.Storage)
createSchema(s.ctx.Storage, s.raws)
- s.setColData("Table_B", 654321)
+ s.setColData(targetTableRef, 654321)
}
-func (s *opLoadSuite) setColData(tableName string, id uint64) {
- h := s.ctx.Storage.GetRowPathHash([]byte(tableName), id)
+func (s *opLoadSuite) setColData(tableRef schema.TableRef, id uint64) {
+ h := s.ctx.Storage.GetRowPathHash(tableRef, id)
setSlotDataInStateDB(h, s.address, s.ctx.Storage)
}