Skip to content

Commit 8f024fd

Browse files
author
James Cor
committed
field align memory
1 parent dd53e26 commit 8f024fd

File tree

8 files changed

+62
-79
lines changed

8 files changed

+62
-79
lines changed

memory/database.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ var _ sql.SchemaValidator = (*BaseDatabase)(nil)
5555

5656
// BaseDatabase is an in-memory database that can't store views, only for testing the engine
5757
type BaseDatabase struct {
58-
name string
5958
tables map[string]MemTable
6059
fkColl *ForeignKeyCollection
60+
tablesMu *sync.RWMutex
61+
name string
6162
triggers []sql.TriggerDefinition
6263
storedProcedures []sql.StoredProcedureDetails
6364
events []sql.EventDefinition
64-
primaryKeyIndexes bool
6565
collation sql.CollationID
66-
tablesMu *sync.RWMutex
66+
primaryKeyIndexes bool
6767
}
6868

6969
var _ MemoryDatabase = (*Database)(nil)

memory/index.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,23 @@ import (
2828
const CommentPreventingIndexBuilding = "__FOR TESTING: I cannot be built__"
2929

3030
type Index struct {
31-
DB string // required for engine tests with driver
32-
DriverName string // required for engine tests with driver
33-
Tbl *Table // required for engine tests with driver
34-
TableName string
35-
Exprs []sql.Expression
36-
Name string
37-
Unique bool
38-
Spatial bool
39-
Fulltext bool
4031
// If SupportedVectorFunction is non-nil, this index can be used to optimize ORDER BY
4132
// expressions on this type of distance function.
4233
SupportedVectorFunction vector.DistanceType
43-
CommentStr string
44-
PrefixLens []uint16
34+
35+
Tbl *Table // required for engine tests with driver
36+
DriverName string // required for engine tests with driver
37+
DB string // required for engine tests with driver
38+
TableName string
39+
Name string
40+
CommentStr string
41+
42+
Exprs []sql.Expression
43+
PrefixLens []uint16
4544
fulltextInfo
45+
Unique bool
46+
Spatial bool
47+
Fulltext bool
4648
}
4749

4850
type fulltextInfo struct {

memory/index_driver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ const IndexDriverId = "MemoryIndexDriver"
2424
// create or delete indexes, but will use the index types defined in this package to alter how queries are executed,
2525
// retrieving values from the indexes rather than from the tables directly.
2626
type TestIndexDriver struct {
27-
db string
2827
indexes map[string][]sql.DriverIndex
28+
db string
2929
}
3030

3131
// NewIndexDriver returns a new index driver for database and the indexes given, keyed by the table name.

memory/provider.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ var _ sql.ExternalStoredProcedureProvider = (*DbProvider)(nil)
1717
// DbProvider is a provider for in-memory databases
1818
type DbProvider struct {
1919
dbs map[string]sql.Database
20+
tableFunctions map[string]sql.TableFunction
21+
externalProcedureRegistry sql.ExternalStoredProcedureRegistry
22+
mu *sync.RWMutex
2023
history bool
2124
readOnly bool
2225
nativeIndexes bool
23-
mu *sync.RWMutex
24-
tableFunctions map[string]sql.TableFunction
25-
externalProcedureRegistry sql.ExternalStoredProcedureRegistry
2626
}
2727

2828
type ProviderOption func(*DbProvider)

memory/required_lookup_table.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ var _ sql.IndexRequired = RequiredLookupTable{}
1818

1919
// RequiredLookupTable is a table that will error if not executed as an index lookup
2020
type RequiredLookupTable struct {
21-
indexOk bool
2221
IntSequenceTable
22+
indexOk bool
2323
}
2424

2525
func (s RequiredLookupTable) RequiredPredicates() []string {

memory/table.go

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,15 @@ type MemTable interface {
4545

4646
// Table represents an in-memory database table.
4747
type Table struct {
48-
name string
49-
50-
// Schema and related info
51-
data *TableData
52-
// ignoreSessionData is used to ignore session data for versioned tables (smoke tests only), unused otherwise
48+
data *TableData
49+
db *BaseDatabase
50+
name string
51+
projection []string
52+
projectedSchema sql.Schema
53+
columns []int
54+
filters []sql.Expression
5355
ignoreSessionData bool
54-
55-
// Projection info and settings
56-
pkIndexesEnabled bool
57-
projection []string
58-
projectedSchema sql.Schema
59-
columns []int
60-
61-
// filters is used for primary index scans with an index lookup
62-
filters []sql.Expression
63-
64-
db *BaseDatabase
56+
pkIndexesEnabled bool
6557
}
6658

6759
var _ sql.Table = (*Table)(nil)
@@ -301,16 +293,16 @@ func (i rangePartitionIter) Next(ctx *sql.Context) (sql.Partition, error) {
301293

302294
// indexScanPartitionIter is a partition iterator that returns a single partition for an index scan
303295
type indexScanPartitionIter struct {
304-
once sync.Once
305296
index *Index
306297
ranges sql.Expression
307298
lookup sql.IndexLookup
299+
once sync.Once
308300
}
309301

310302
type indexScanPartition struct {
311303
index *Index
312-
lookup sql.IndexLookup
313304
ranges sql.Expression
305+
lookup sql.IndexLookup
314306
}
315307

316308
func (i indexScanPartition) Key() []byte {
@@ -414,17 +406,18 @@ func (t *Table) PartitionCount(ctx *sql.Context) (int64, error) {
414406
}
415407

416408
type indexScanRowIter struct {
417-
i int
409+
index *Index
410+
ranges sql.Expression
411+
lookup sql.IndexLookup
412+
indexRows []sql.Row
413+
418414
incrementFunc func()
419-
index *Index
420-
lookup sql.IndexLookup
421-
ranges sql.Expression
422415
primaryRows map[string][]sql.Row
423-
indexRows []sql.Row
424416

425417
columns []int
426-
numColumns int
427418
virtualCols []int
419+
i int
420+
numColumns int
428421
}
429422

430423
func newIndexScanRowIter(
@@ -677,13 +670,12 @@ func (p *partitionIter) Next(*sql.Context) (sql.Partition, error) {
677670
func (p *partitionIter) Close(*sql.Context) error { return nil }
678671

679672
type tableIter struct {
673+
indexValues sql.IndexValueIter
674+
rows []sql.Row
675+
filters []sql.Expression
680676
columns []int
681677
virtualCols []int
682678
numColumns int
683-
684-
rows []sql.Row
685-
filters []sql.Expression
686-
indexValues sql.IndexValueIter
687679
pos int
688680
}
689681

@@ -2240,8 +2232,8 @@ func (t *Table) CreatePrimaryKey(ctx *sql.Context, columns []sql.IndexColumn) er
22402232
}
22412233

22422234
type pkfield struct {
2243-
i int
22442235
c *sql.Column
2236+
i int
22452237
}
22462238

22472239
type partitionRow struct {
@@ -2250,11 +2242,11 @@ type partitionRow struct {
22502242
}
22512243

22522244
type partitionssort struct {
2253-
pk []pkfield
2245+
ctx *sql.Context
22542246
ps map[string][]sql.Row
2255-
allRows []partitionRow
22562247
indexes map[indexName][]sql.Row
2257-
ctx *sql.Context
2248+
pk []pkfield
2249+
allRows []partitionRow
22582250
}
22592251

22602252
func (ps partitionssort) Len() int {

memory/table_data.go

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,21 @@ import (
3333
// freely as needed for different views on a table (column projections, index lookups, filters, etc.) but the
3434
// storage of underlying data lives here.
3535
type TableData struct {
36-
dbName string
37-
tableName string
38-
comment string
39-
40-
// Schema / config data
41-
schema sql.PrimaryKeySchema
4236
indexes map[string]sql.Index
4337
fkColl *ForeignKeyCollection
38+
secondaryIndexStorage map[indexName][]sql.Row
39+
partitions map[string][]sql.Row
40+
fullTextConfigTableName string
41+
tableName string
42+
comment string
43+
dbName string
44+
schema sql.PrimaryKeySchema
4445
checks []sql.CheckDefinition
45-
collation sql.CollationID
46+
partitionKeys [][]byte
4647
autoColIdx int
48+
autoIncVal uint64
49+
collation sql.CollationID
4750
primaryKeyIndexes bool
48-
fullTextConfigTableName string
49-
50-
// Data storage
51-
partitions map[string][]sql.Row
52-
partitionKeys [][]byte
53-
autoIncVal uint64
54-
55-
// Indexes are implemented as an unordered slice of rows. The first N elements in the row are the values of the
56-
// indexed columns, and the final value is the location of the row in the primary storage.
57-
// TODO: we could make these much more performant by using a tree or other ordered collection
58-
secondaryIndexStorage map[indexName][]sql.Row
5951
}
6052

6153
type indexName string
@@ -374,7 +366,7 @@ func (td *TableData) sortRows(ctx *sql.Context) {
374366
for _, column := range td.schema.Schema {
375367
if column.PrimaryKey {
376368
idx, col := td.getColumnOrdinal(column.Name)
377-
pk = append(pk, pkfield{idx, col})
369+
pk = append(pk, pkfield{i: idx, c: col})
378370
}
379371
}
380372

memory/table_editor.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,13 @@ import (
2828

2929
// tableEditor manages the edits that a targetTable receives.
3030
type tableEditor struct {
31-
editedTable *Table
32-
initialTable *Table
33-
34-
discardChanges bool
3531
ea tableEditAccumulator
36-
37-
// array of key ordinals for each unique index defined on the targetTable
38-
uniqueIdxCols [][]int
39-
prefixLengths [][]uint16
40-
fkTable *Table
32+
editedTable *Table
33+
initialTable *Table
34+
fkTable *Table
35+
uniqueIdxCols [][]int
36+
prefixLengths [][]uint16
37+
discardChanges bool
4138
}
4239

4340
var _ sql.Table = (*tableEditor)(nil)

0 commit comments

Comments
 (0)