Skip to content

Commit 53ac7a8

Browse files
authored
align struct fields to reduce memory usage (#3168)
1 parent 7db3859 commit 53ac7a8

File tree

229 files changed

+1582
-1583
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

229 files changed

+1582
-1583
lines changed

driver/conn.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ import (
2323

2424
// Conn is a connection to a database.
2525
type Conn struct {
26-
dsn string
27-
options *Options
28-
dbConn *dbConn
2926
session sql.Session
3027
contexts ContextBuilder
28+
options *Options
29+
dbConn *dbConn
3130
indexes *sql.IndexRegistry
3231
views *sql.ViewRegistry
32+
dsn string
3333
}
3434

3535
// DSN returns the driver connection string.

driver/driver.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,11 @@ type ProviderWithSessionBuilder interface {
8282
// A Driver exposes an engine as a stdlib SQL driver.
8383
type Driver struct {
8484
provider Provider
85-
options *Options
8685
sessions SessionBuilder
8786
contexts ContextBuilder
88-
89-
mu sync.Mutex
90-
dbs map[string]*dbConn
87+
options *Options
88+
dbs map[string]*dbConn
89+
mu sync.Mutex
9190
}
9291

9392
// New returns a driver using the specified provider.
@@ -223,9 +222,9 @@ func (c *dbConn) close() error {
223222
type Connector struct {
224223
driver *Driver
225224
options *Options
225+
dbConn *dbConn
226226
serverName string
227227
dsn string
228-
dbConn *dbConn
229228
}
230229

231230
// Driver returns the driver.

driver/rows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ import (
2626

2727
// Rows is an iterator over an executed query's results.
2828
type Rows struct {
29+
rows sql.RowIter
2930
options *Options
3031
ctx *sql.Context
3132
cols sql.Schema
32-
rows sql.RowIter
3333
}
3434

3535
// Columns returns the names of the columns. The number of

driver/stmt.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,10 @@ func (s *Stmt) query(ctx context.Context, bindings map[string]sqlparser.Expr) (d
117117
return nil, err
118118
}
119119

120-
return &Rows{s.conn.options, qctx, cols, rows}, nil
120+
return &Rows{
121+
options: s.conn.options,
122+
ctx: qctx,
123+
cols: cols,
124+
rows: rows,
125+
}, nil
121126
}

engine.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ func init() {
5353
type Config struct {
5454
// VersionPostfix to display with the `VERSION()` UDF.
5555
VersionPostfix string
56+
// TemporaryUsers adds any users that should be included when the engine is created. By default, authentication is
57+
// disabled, and including any users here will enable authentication. All users in this list will have full access.
58+
// This field is only temporary, and will be removed as development on users and authentication continues.
59+
TemporaryUsers []TemporaryUser
5660
// IsReadOnly sets the engine to disallow modification queries.
5761
IsReadOnly bool
5862
IsServerLocked bool
5963
// IncludeRootAccount adds the root account (with no password) to the list of accounts, and also enables
6064
// authentication.
6165
IncludeRootAccount bool
62-
// TemporaryUsers adds any users that should be included when the engine is created. By default, authentication is
63-
// disabled, and including any users here will enable authentication. All users in this list will have full access.
64-
// This field is only temporary, and will be removed as development on users and authentication continues.
65-
TemporaryUsers []TemporaryUser
6666
}
6767

6868
// TemporaryUser is a user that will be added to the engine. This is for temporary use while the remaining features
@@ -136,18 +136,18 @@ func (p *PreparedDataCache) UncacheStmt(sessId uint32, query string) {
136136

137137
// Engine is a SQL engine.
138138
type Engine struct {
139+
Parser sql.Parser
140+
ProcessList sql.ProcessList
139141
Analyzer *analyzer.Analyzer
140142
LS *sql.LockSubsystem
141-
ProcessList sql.ProcessList
142143
MemoryManager *sql.MemoryManager
143144
BackgroundThreads *sql.BackgroundThreads
144-
ReadOnly atomic.Bool
145-
IsServerLocked bool
146145
PreparedDataCache *PreparedDataCache
147146
mu *sync.Mutex
148-
Version sql.AnalyzerVersion
149147
EventScheduler *eventscheduler.EventScheduler
150-
Parser sql.Parser
148+
ReadOnly atomic.Bool
149+
IsServerLocked bool
150+
Version sql.AnalyzerVersion
151151
}
152152

153153
var _ sql.StatementRunner = (*Engine)(nil)

enginetest/queries/check_scripts.go

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -540,16 +540,36 @@ var ChecksOnUpdateScriptTests = []ScriptTest{
540540
},
541541
Assertions: []ScriptTestAssertion{
542542
{
543-
Query: "UPDATE sales JOIN (SELECT year_built FROM sales) AS t ON sales.year_built = t.year_built SET sales.year_built = 1901;",
544-
Expected: []sql.Row{{types.OkResult{1, 0, plan.UpdateInfo{1, 1, 0}}}},
543+
Query: "UPDATE sales JOIN (SELECT year_built FROM sales) AS t ON sales.year_built = t.year_built SET sales.year_built = 1901;",
544+
Expected: []sql.Row{
545+
{
546+
types.OkResult{
547+
RowsAffected: 1,
548+
Info: plan.UpdateInfo{
549+
Matched: 1,
550+
Updated: 1,
551+
},
552+
},
553+
},
554+
},
545555
},
546556
{
547557
Query: "select * from sales;",
548558
Expected: []sql.Row{{1901}},
549559
},
550560
{
551-
Query: "UPDATE sales as s1 JOIN (SELECT year_built FROM sales) AS t SET S1.year_built = 1902;",
552-
Expected: []sql.Row{{types.OkResult{1, 0, plan.UpdateInfo{1, 1, 0}}}},
561+
Query: "UPDATE sales as s1 JOIN (SELECT year_built FROM sales) AS t SET S1.year_built = 1902;",
562+
Expected: []sql.Row{
563+
{
564+
types.OkResult{
565+
RowsAffected: 1,
566+
Info: plan.UpdateInfo{
567+
Matched: 1,
568+
Updated: 1,
569+
},
570+
},
571+
},
572+
},
553573
},
554574
{
555575
Query: "select * from sales;",
@@ -599,8 +619,18 @@ var ChecksOnUpdateScriptTests = []ScriptTest{
599619
Expected: []sql.Row{{"WA"}},
600620
},
601621
{
602-
Query: "UPDATE sales JOIN locations SET sales.year_built = 2000, locations.state = 'CA';",
603-
Expected: []sql.Row{{types.OkResult{2, 0, plan.UpdateInfo{2, 2, 0}}}},
622+
Query: "UPDATE sales JOIN locations SET sales.year_built = 2000, locations.state = 'CA';",
623+
Expected: []sql.Row{
624+
{
625+
types.OkResult{
626+
RowsAffected: 2,
627+
Info: plan.UpdateInfo{
628+
Matched: 2,
629+
Updated: 2,
630+
},
631+
},
632+
},
633+
},
604634
},
605635
{
606636
Query: "select * from sales;",

eventscheduler/enabled_event.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ import (
2626

2727
// enabledEvent is used for storing a list of events that are enabled in EventScheduler.
2828
type enabledEvent struct {
29-
edb sql.EventDatabase
30-
event sql.EventDefinition
3129
nextExecutionAt time.Time
30+
edb sql.EventDatabase
3231
username string
3332
address string
33+
event sql.EventDefinition
3434
}
3535

3636
var _ fmt.Stringer = (*enabledEvent)(nil)

eventscheduler/event_executor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ import (
3030
// to update the enabled events list in the eventExecutor. It also handles updating the event
3131
// metadata in the database or dropping it from the database after its execution.
3232
type eventExecutor struct {
33+
catalog sql.Catalog
3334
bThreads *sql.BackgroundThreads
3435
list *enabledEventsList
3536
runningEventsStatus *runningEventsStatus
3637
ctxGetterFunc func() (*sql.Context, error)
3738
queryRunFunc func(ctx *sql.Context, dbName, query, username, address string) error
38-
stop atomic.Bool
39-
catalog sql.Catalog
4039
tokenTracker *tokenTracker
4140
period int
41+
stop atomic.Bool
4242
}
4343

4444
// newEventExecutor returns a new eventExecutor instance with an empty enabled events list.

eventscheduler/event_scheduler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ var _ sql.EventScheduler = (*EventScheduler)(nil)
5050

5151
// EventScheduler is responsible for SQL events execution.
5252
type EventScheduler struct {
53-
status SchedulerStatus
5453
executor *eventExecutor
5554
ctxGetterFunc func() (*sql.Context, error)
55+
status SchedulerStatus
5656
}
5757

5858
// InitEventScheduler is called at the start of the server. This function returns EventScheduler object

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/dolthub/go-icu-regex v0.0.0-20250820171420-f2b78f56ce9f
77
github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71
88
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81
9-
github.com/dolthub/vitess v0.0.0-20250814204310-c749d213f235
9+
github.com/dolthub/vitess v0.0.0-20250828002016-b8fc8e714bf8
1010
github.com/go-sql-driver/mysql v1.7.2-0.20231213112541-0004702b931d
1111
github.com/gocraft/dbr/v2 v2.7.2
1212
github.com/google/uuid v1.3.0

0 commit comments

Comments
 (0)