Skip to content

Commit ecb3f80

Browse files
author
James Cor
committed
move applyEventScheduler logic and eventscheduler to builder
1 parent 1fde9d5 commit ecb3f80

32 files changed

+134
-153
lines changed

engine.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func (e *Engine) AnalyzeQuery(
209209
ctx *sql.Context,
210210
query string,
211211
) (sql.Node, error) {
212-
binder := planbuilder.New(ctx, e.Analyzer.Catalog, e.Parser)
212+
binder := planbuilder.New(ctx, e.Analyzer.Catalog, e.Parser, e.EventScheduler)
213213
parsed, _, _, qFlags, err := binder.Parse(query, nil, false)
214214
if err != nil {
215215
return nil, err
@@ -237,7 +237,7 @@ func (e *Engine) PrepareParsedQuery(
237237
statementKey, query string,
238238
stmt sqlparser.Statement,
239239
) (sql.Node, error) {
240-
binder := planbuilder.New(ctx, e.Analyzer.Catalog, e.Parser)
240+
binder := planbuilder.New(ctx, e.Analyzer.Catalog, e.Parser, e.EventScheduler)
241241
node, _, err := binder.BindOnly(stmt, query, nil)
242242

243243
if err != nil {
@@ -495,7 +495,7 @@ func (e *Engine) BoundQueryPlan(ctx *sql.Context, query string, parsed sqlparser
495495

496496
query = sql.RemoveSpaceAndDelimiter(query, ';')
497497

498-
binder := planbuilder.New(ctx, e.Analyzer.Catalog, e.Parser)
498+
binder := planbuilder.New(ctx, e.Analyzer.Catalog, e.Parser, e.EventScheduler)
499499
binder.SetBindings(bindings)
500500

501501
// Begin a transaction if necessary (no-op if one is in flight)
@@ -549,7 +549,7 @@ func (e *Engine) preparedStatement(ctx *sql.Context, query string, parsed sqlpar
549549
preparedAst, preparedDataFound = e.PreparedDataCache.GetCachedStmt(ctx.Session.ID(), query)
550550
}
551551

552-
binder := planbuilder.New(ctx, e.Analyzer.Catalog, e.Parser)
552+
binder := planbuilder.New(ctx, e.Analyzer.Catalog, e.Parser, e.EventScheduler)
553553
if preparedDataFound {
554554
parsed = preparedAst
555555
binder.SetBindings(bindings)
@@ -782,6 +782,10 @@ func (e *Engine) EngineAnalyzer() *analyzer.Analyzer {
782782
return e.Analyzer
783783
}
784784

785+
func (e *Engine) EngineEventScheduler() sql.EventScheduler {
786+
return e.EventScheduler
787+
}
788+
785789
// InitializeEventScheduler initializes the EventScheduler for the engine with the given sql.Context
786790
// getter function, |ctxGetterFunc, the EventScheduler |status|, and the |period| for the event scheduler
787791
// to check for events to execute. If |period| is less than 1, then it is ignored and the default period
@@ -792,8 +796,6 @@ func (e *Engine) InitializeEventScheduler(ctxGetterFunc func() (*sql.Context, fu
792796
if err != nil {
793797
return err
794798
}
795-
796-
e.Analyzer.EventScheduler = e.EventScheduler
797799
return nil
798800
}
799801

enginetest/engine_only_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ func TestAnalyzer_Exp(t *testing.T) {
442442
require.NoError(t, err)
443443

444444
ctx := enginetest.NewContext(harness)
445-
b := planbuilder.New(ctx, e.EngineAnalyzer().Catalog, sql.NewMysqlParser())
445+
b := planbuilder.New(ctx, e.EngineAnalyzer().Catalog, sql.NewMysqlParser(), e.EngineEventScheduler())
446446
parsed, _, _, _, err := b.Parse(tt.query, nil, false)
447447
require.NoError(t, err)
448448

enginetest/enginetests.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ func TestQueryPlanWithName(t *testing.T, name string, harness Harness, e QueryEn
584584
t.Run(name, func(t *testing.T) {
585585
ctx := NewContext(harness)
586586

587-
parsed, qFlags, err := planbuilder.Parse(ctx, e.EngineAnalyzer().Catalog, query)
587+
parsed, qFlags, err := planbuilder.Parse(ctx, e.EngineAnalyzer().Catalog, e.EngineEventScheduler(), query)
588588
require.NoError(t, err)
589589

590590
node, err := e.EngineAnalyzer().Analyze(ctx, parsed, nil, qFlags)
@@ -611,7 +611,7 @@ func TestQueryPlanWithName(t *testing.T, name string, harness Harness, e QueryEn
611611
func TestQueryPlanWithEngine(t *testing.T, harness Harness, e QueryEngine, tt queries.QueryPlanTest, verbose bool) {
612612
t.Run(tt.Query, func(t *testing.T) {
613613
ctx := NewContext(harness)
614-
parsed, qFlags, err := planbuilder.Parse(ctx, e.EngineAnalyzer().Catalog, tt.Query)
614+
parsed, qFlags, err := planbuilder.Parse(ctx, e.EngineAnalyzer().Catalog, e.EngineEventScheduler(), tt.Query)
615615
require.NoError(t, err)
616616

617617
node, err := e.EngineAnalyzer().Analyze(ctx, parsed, nil, qFlags)
@@ -1362,7 +1362,7 @@ func TestTruncate(t *testing.T, harness Harness) {
13621362
TestQueryWithContext(t, ctx, e, harness, "SELECT * FROM t5 ORDER BY 1", []sql.Row{{int64(1), int64(1)}, {int64(2), int64(2)}}, nil, nil, nil)
13631363

13641364
deleteStr := "DELETE FROM t5"
1365-
parsed, qFlags, err := planbuilder.Parse(ctx, e.EngineAnalyzer().Catalog, deleteStr)
1365+
parsed, qFlags, err := planbuilder.Parse(ctx, e.EngineAnalyzer().Catalog, e.EngineEventScheduler(), deleteStr)
13661366
require.NoError(t, err)
13671367
analyzed, err := e.EngineAnalyzer().Analyze(ctx, parsed, nil, qFlags)
13681368
require.NoError(t, err)
@@ -1391,7 +1391,7 @@ func TestTruncate(t *testing.T, harness Harness) {
13911391
RunQueryWithContext(t, e, harness, ctx, "INSERT INTO t6parent VALUES (1,1), (2,2)")
13921392
RunQueryWithContext(t, e, harness, ctx, "INSERT INTO t6child VALUES (1,1), (2,2)")
13931393

1394-
parsed, qFlags, err := planbuilder.Parse(ctx, e.EngineAnalyzer().Catalog, "DELETE FROM t6parent")
1394+
parsed, qFlags, err := planbuilder.Parse(ctx, e.EngineAnalyzer().Catalog, e.EngineEventScheduler(), "DELETE FROM t6parent")
13951395
require.NoError(t, err)
13961396
analyzed, err := e.EngineAnalyzer().Analyze(ctx, parsed, nil, qFlags)
13971397
require.NoError(t, err)
@@ -1419,7 +1419,7 @@ func TestTruncate(t *testing.T, harness Harness) {
14191419
TestQueryWithContext(t, ctx, e, harness, "SELECT * FROM t7i ORDER BY 1", []sql.Row{{int64(3), int64(3)}}, nil, nil, nil)
14201420

14211421
deleteStr := "DELETE FROM t7"
1422-
parsed, qFlags, err := planbuilder.Parse(ctx, e.EngineAnalyzer().Catalog, deleteStr)
1422+
parsed, qFlags, err := planbuilder.Parse(ctx, e.EngineAnalyzer().Catalog, e.EngineEventScheduler(), deleteStr)
14231423
require.NoError(t, err)
14241424
analyzed, err := e.EngineAnalyzer().Analyze(ctx, parsed, nil, qFlags)
14251425
require.NoError(t, err)
@@ -1447,7 +1447,7 @@ func TestTruncate(t *testing.T, harness Harness) {
14471447
TestQueryWithContext(t, ctx, e, harness, "SELECT * FROM t8 ORDER BY 1", []sql.Row{{int64(1), int64(4)}, {int64(2), int64(5)}}, nil, nil, nil)
14481448

14491449
deleteStr := "DELETE FROM t8"
1450-
parsed, qFlags, err := planbuilder.Parse(ctx, e.EngineAnalyzer().Catalog, deleteStr)
1450+
parsed, qFlags, err := planbuilder.Parse(ctx, e.EngineAnalyzer().Catalog, e.EngineEventScheduler(), deleteStr)
14511451
require.NoError(t, err)
14521452
analyzed, err := e.EngineAnalyzer().Analyze(ctx, parsed, nil, qFlags)
14531453
require.NoError(t, err)
@@ -1476,7 +1476,7 @@ func TestTruncate(t *testing.T, harness Harness) {
14761476
TestQueryWithContext(t, ctx, e, harness, "SELECT * FROM t9 ORDER BY 1", []sql.Row{{int64(7), int64(7)}, {int64(8), int64(8)}}, nil, nil, nil)
14771477

14781478
deleteStr := "DELETE FROM t9 WHERE pk > 0"
1479-
parsed, qFlags, err := planbuilder.Parse(ctx, e.EngineAnalyzer().Catalog, deleteStr)
1479+
parsed, qFlags, err := planbuilder.Parse(ctx, e.EngineAnalyzer().Catalog, e.EngineEventScheduler(), deleteStr)
14801480
require.NoError(t, err)
14811481
analyzed, err := e.EngineAnalyzer().Analyze(ctx, parsed, nil, qFlags)
14821482
require.NoError(t, err)
@@ -1503,7 +1503,7 @@ func TestTruncate(t *testing.T, harness Harness) {
15031503
TestQueryWithContext(t, ctx, e, harness, "SELECT * FROM t10 ORDER BY 1", []sql.Row{{int64(8), int64(8)}, {int64(9), int64(9)}}, nil, nil, nil)
15041504

15051505
deleteStr := "DELETE FROM t10 LIMIT 1000"
1506-
parsed, qFlags, err := planbuilder.Parse(ctx, e.EngineAnalyzer().Catalog, deleteStr)
1506+
parsed, qFlags, err := planbuilder.Parse(ctx, e.EngineAnalyzer().Catalog, e.EngineEventScheduler(), deleteStr)
15071507
require.NoError(t, err)
15081508
analyzed, err := e.EngineAnalyzer().Analyze(ctx, parsed, nil, qFlags)
15091509
require.NoError(t, err)
@@ -1530,7 +1530,7 @@ func TestTruncate(t *testing.T, harness Harness) {
15301530
TestQueryWithContext(t, ctx, e, harness, "SELECT * FROM t11 ORDER BY 1", []sql.Row{{int64(1), int64(1)}, {int64(9), int64(9)}}, nil, nil, nil)
15311531

15321532
deleteStr := "DELETE FROM t11 ORDER BY 1"
1533-
parsed, qFlags, err := planbuilder.Parse(ctx, e.EngineAnalyzer().Catalog, deleteStr)
1533+
parsed, qFlags, err := planbuilder.Parse(ctx, e.EngineAnalyzer().Catalog, e.EngineEventScheduler(), deleteStr)
15341534
require.NoError(t, err)
15351535
analyzed, err := e.EngineAnalyzer().Analyze(ctx, parsed, nil, qFlags)
15361536
require.NoError(t, err)
@@ -1561,7 +1561,7 @@ func TestTruncate(t *testing.T, harness Harness) {
15611561
TestQueryWithContext(t, ctx, e, harness, "SELECT * FROM t12b ORDER BY 1", []sql.Row{{int64(1), int64(1)}, {int64(2), int64(2)}}, nil, nil, nil)
15621562

15631563
deleteStr := "DELETE t12a, t12b FROM t12a INNER JOIN t12b WHERE t12a.pk=t12b.pk"
1564-
parsed, qFlags, err := planbuilder.Parse(ctx, e.EngineAnalyzer().Catalog, deleteStr)
1564+
parsed, qFlags, err := planbuilder.Parse(ctx, e.EngineAnalyzer().Catalog, e.EngineEventScheduler(), deleteStr)
15651565
require.NoError(t, err)
15661566
analyzed, err := e.EngineAnalyzer().Analyze(ctx, parsed, nil, qFlags)
15671567
require.NoError(t, err)

enginetest/evaluation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ func injectBindVarsAndPrepare(
526526
}
527527
}
528528

529-
b := planbuilder.New(ctx, e.EngineAnalyzer().Catalog, sql.NewMysqlParser())
529+
b := planbuilder.New(ctx, e.EngineAnalyzer().Catalog, sql.NewMysqlParser(), e.EngineEventScheduler())
530530
b.SetParserOptions(sql.LoadSqlMode(ctx).ParserOptions())
531531
resPlan, _, err := b.BindOnly(parsed, q, nil)
532532
if err != nil {

enginetest/join_planning_tests.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1777,7 +1777,7 @@ func evalJoinTypeTest(t *testing.T, harness Harness, e QueryEngine, query string
17771777
}
17781778

17791779
func analyzeQuery(ctx *sql.Context, e QueryEngine, query string) (sql.Node, error) {
1780-
parsed, qFlags, err := planbuilder.Parse(ctx, e.EngineAnalyzer().Catalog, query)
1780+
parsed, qFlags, err := planbuilder.Parse(ctx, e.EngineAnalyzer().Catalog, e.EngineEventScheduler(), query)
17811781
if err != nil {
17821782
return nil, err
17831783
}

enginetest/mysqlshim/table.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ func (t Table) getCreateTable() (*plan.CreateTable, error) {
381381
return nil, sql.ErrTableNotFound.New(t.name)
382382
}
383383
// TODO add catalog
384-
createTableNode, _, err := planbuilder.Parse(sql.NewEmptyContext(), sql.MapCatalog{Tables: map[string]sql.Table{t.name: t}}, rows[0][1].(string))
384+
createTableNode, _, err := planbuilder.Parse(sql.NewEmptyContext(), sql.MapCatalog{Tables: map[string]sql.Table{t.name: t}}, nil, rows[0][1].(string))
385385
if err != nil {
386386
return nil, err
387387
}

enginetest/query_engine.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type QueryEngine interface {
2828
Query(ctx *sql.Context, query string) (sql.Schema, sql.RowIter, *sql.QueryFlags, error)
2929
// TODO: get rid of this, should not be exposed to engine tests
3030
EngineAnalyzer() *analyzer.Analyzer
31+
EngineEventScheduler() sql.EventScheduler
3132
// TODO: get rid of this, should not be exposed to engine tests
3233
EnginePreparedDataCache() *sqle.PreparedDataCache
3334
QueryWithBindings(ctx *sql.Context, query string, parsed sqlparser.Statement, bindings map[string]sqlparser.Expr, qFlags *sql.QueryFlags) (sql.Schema, sql.RowIter, *sql.QueryFlags, error)

enginetest/server_engine.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ func (s *ServerQueryEngine) EngineAnalyzer() *analyzer.Analyzer {
150150
return s.engine.Analyzer
151151
}
152152

153+
func (s *ServerQueryEngine) EngineEventScheduler() sql.EventScheduler {
154+
return s.engine.EventScheduler
155+
}
156+
153157
func (s *ServerQueryEngine) EnginePreparedDataCache() *sqle.PreparedDataCache {
154158
return s.engine.PreparedDataCache
155159
}
@@ -632,7 +636,7 @@ func convertGoSqlType(columnType *gosql.ColumnType) (sql.Type, error) {
632636
// It cannot sort user-defined binding variables (e.g. :var, :foo)
633637
func prepareBindingArgs(ctx *sql.Context, bindings map[string]sqlparser.Expr) ([]any, error) {
634638
// NOTE: using binder with nil catalog and parser since we're only using it to convert SQLVal.
635-
binder := planbuilder.New(ctx, nil, nil)
639+
binder := planbuilder.New(ctx, nil, nil, nil)
636640
numBindVars := len(bindings)
637641
args := make([]any, numBindVars)
638642
for i := 0; i < numBindVars; i++ {

sql/analyzer/analyzer.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,6 @@ type Analyzer struct {
286286
Coster memo.Coster
287287
// ExecBuilder converts a sql.Node tree into an executable iterator.
288288
ExecBuilder sql.NodeExecBuilder
289-
// EventScheduler is used to communiate with the event scheduler
290-
// for any EVENT related statements. It can be nil if EventScheduler is not defined.
291-
EventScheduler sql.EventScheduler
292289
}
293290

294291
// NewDefault creates a default Analyzer instance with all default Rules and configuration.

sql/analyzer/apply_event_scheduler_notifier.go

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)