@@ -68,7 +68,6 @@ import (
68
68
)
69
69
70
70
var (
71
- errNoKeyspace = vterrors .VT09005 ()
72
71
defaultTabletType = topodatapb .TabletType_PRIMARY
73
72
74
73
// TODO: @rafael - These two counters should be deprecated in favor of the ByTable ones in v17+. They are kept for now for backwards compatibility.
@@ -168,6 +167,7 @@ func NewExecutor(
168
167
pv plancontext.PlannerVersion ,
169
168
warmingReadsPercent int ,
170
169
) * Executor {
170
+ warnings .Add ("WarnUnshardedOnly" , 1 )
171
171
e := & Executor {
172
172
env : env ,
173
173
serv : serv ,
@@ -301,7 +301,7 @@ func (e *Executor) StreamExecute(
301
301
srr := & streaminResultReceiver {callback : callback }
302
302
var err error
303
303
304
- resultHandler := func (ctx context.Context , plan * engine.Plan , vc * vcursorImpl , bindVars map [string ]* querypb.BindVariable , execStart time.Time ) error {
304
+ resultHandler := func (ctx context.Context , plan * engine.Plan , vc * econtext. VCursorImpl , bindVars map [string ]* querypb.BindVariable , execStart time.Time ) error {
305
305
var seenResults atomic.Bool
306
306
var resultMu sync.Mutex
307
307
result := & sqltypes.Result {}
@@ -369,7 +369,7 @@ func (e *Executor) StreamExecute(
369
369
logStats .TablesUsed = plan .TablesUsed
370
370
logStats .TabletType = vc .TabletType ().String ()
371
371
logStats .ExecuteTime = time .Since (execStart )
372
- logStats .ActiveKeyspace = vc .keyspace
372
+ logStats .ActiveKeyspace = vc .GetKeyspace ()
373
373
374
374
e .updateQueryCounts (plan .Instructions .RouteType (), plan .Instructions .GetKeyspaceName (), plan .Instructions .GetTableName (), int64 (logStats .ShardQueries ))
375
375
@@ -435,7 +435,7 @@ func (e *Executor) execute(ctx context.Context, mysqlCtx vtgateservice.MySQLConn
435
435
var err error
436
436
var qr * sqltypes.Result
437
437
var stmtType sqlparser.StatementType
438
- err = e .newExecute (ctx , mysqlCtx , safeSession , sql , bindVars , logStats , func (ctx context.Context , plan * engine.Plan , vc * vcursorImpl , bindVars map [string ]* querypb.BindVariable , time time.Time ) error {
438
+ err = e .newExecute (ctx , mysqlCtx , safeSession , sql , bindVars , logStats , func (ctx context.Context , plan * engine.Plan , vc * econtext. VCursorImpl , bindVars map [string ]* querypb.BindVariable , time time.Time ) error {
439
439
stmtType = plan .Type
440
440
qr , err = e .executePlan (ctx , safeSession , plan , vc , bindVars , logStats , time )
441
441
return err
@@ -449,7 +449,7 @@ func (e *Executor) execute(ctx context.Context, mysqlCtx vtgateservice.MySQLConn
449
449
}
450
450
451
451
// addNeededBindVars adds bind vars that are needed by the plan
452
- func (e * Executor ) addNeededBindVars (vcursor * vcursorImpl , bindVarNeeds * sqlparser.BindVarNeeds , bindVars map [string ]* querypb.BindVariable , session * econtext.SafeSession ) error {
452
+ func (e * Executor ) addNeededBindVars (vcursor * econtext. VCursorImpl , bindVarNeeds * sqlparser.BindVarNeeds , bindVars map [string ]* querypb.BindVariable , session * econtext.SafeSession ) error {
453
453
for _ , funcName := range bindVarNeeds .NeedFunctionResult {
454
454
switch funcName {
455
455
case sqlparser .DBVarName :
@@ -542,7 +542,7 @@ func (e *Executor) addNeededBindVars(vcursor *vcursorImpl, bindVarNeeds *sqlpars
542
542
}
543
543
544
544
evalExpr , err := evalengine .Translate (expr , & evalengine.Config {
545
- Collation : vcursor .collation ,
545
+ Collation : vcursor .ConnCollation () ,
546
546
Environment : e .env ,
547
547
SQLMode : evalengine .ParseSQLMode (vcursor .SQLMode ()),
548
548
})
@@ -553,7 +553,7 @@ func (e *Executor) addNeededBindVars(vcursor *vcursorImpl, bindVarNeeds *sqlpars
553
553
if err != nil {
554
554
return err
555
555
}
556
- bindVars [key ] = sqltypes .ValueBindVariable (evaluated .Value (vcursor .collation ))
556
+ bindVars [key ] = sqltypes .ValueBindVariable (evaluated .Value (vcursor .ConnCollation () ))
557
557
}
558
558
}
559
559
}
@@ -723,7 +723,7 @@ func (e *Executor) CloseSession(ctx context.Context, safeSession *econtext.SafeS
723
723
return e .txConn .ReleaseAll (ctx , safeSession )
724
724
}
725
725
726
- func (e * Executor ) setVitessMetadata (ctx context.Context , name , value string ) error {
726
+ func (e * Executor ) SetVitessMetadata (ctx context.Context , name , value string ) error {
727
727
// TODO(kalfonso): move to its own acl check and consolidate into an acl component that can handle multiple operations (vschema, metadata)
728
728
user := callerid .ImmediateCallerIDFromContext (ctx )
729
729
allowed := vschemaacl .Authorized (user )
@@ -742,7 +742,7 @@ func (e *Executor) setVitessMetadata(ctx context.Context, name, value string) er
742
742
return ts .UpsertMetadata (ctx , name , value )
743
743
}
744
744
745
- func (e * Executor ) showVitessMetadata (ctx context.Context , filter * sqlparser.ShowFilter ) (* sqltypes.Result , error ) {
745
+ func (e * Executor ) ShowVitessMetadata (ctx context.Context , filter * sqlparser.ShowFilter ) (* sqltypes.Result , error ) {
746
746
ts , err := e .serv .GetTopoServer ()
747
747
if err != nil {
748
748
return nil , err
@@ -775,7 +775,7 @@ func (e *Executor) showVitessMetadata(ctx context.Context, filter *sqlparser.Sho
775
775
776
776
type tabletFilter func (tablet * topodatapb.Tablet , servingState string , primaryTermStartTime int64 ) bool
777
777
778
- func (e * Executor ) showShards (ctx context.Context , filter * sqlparser.ShowFilter , destTabletType topodatapb.TabletType ) (* sqltypes.Result , error ) {
778
+ func (e * Executor ) ShowShards (ctx context.Context , filter * sqlparser.ShowFilter , destTabletType topodatapb.TabletType ) (* sqltypes.Result , error ) {
779
779
showVitessShardsFilters := func (filter * sqlparser.ShowFilter ) ([]func (string ) bool , []func (string , * topodatapb.ShardReference ) bool ) {
780
780
keyspaceFilters := []func (string ) bool {}
781
781
shardFilters := []func (string , * topodatapb.ShardReference ) bool {}
@@ -859,7 +859,7 @@ func (e *Executor) showShards(ctx context.Context, filter *sqlparser.ShowFilter,
859
859
}, nil
860
860
}
861
861
862
- func (e * Executor ) showTablets (filter * sqlparser.ShowFilter ) (* sqltypes.Result , error ) {
862
+ func (e * Executor ) ShowTablets (filter * sqlparser.ShowFilter ) (* sqltypes.Result , error ) {
863
863
getTabletFilters := func (filter * sqlparser.ShowFilter ) []tabletFilter {
864
864
var filters []tabletFilter
865
865
@@ -932,7 +932,7 @@ func (e *Executor) showTablets(filter *sqlparser.ShowFilter) (*sqltypes.Result,
932
932
}, nil
933
933
}
934
934
935
- func (e * Executor ) showVitessReplicationStatus (ctx context.Context , filter * sqlparser.ShowFilter ) (* sqltypes.Result , error ) {
935
+ func (e * Executor ) ShowVitessReplicationStatus (ctx context.Context , filter * sqlparser.ShowFilter ) (* sqltypes.Result , error ) {
936
936
ctx , cancel := context .WithTimeout (ctx , healthCheckTimeout )
937
937
defer cancel ()
938
938
rows := [][]sqltypes.Value {}
@@ -1093,7 +1093,7 @@ func (e *Executor) ParseDestinationTarget(targetString string) (string, topodata
1093
1093
// the cache, it reuses it.
1094
1094
func (e * Executor ) getPlan (
1095
1095
ctx context.Context ,
1096
- vcursor * vcursorImpl ,
1096
+ vcursor * econtext. VCursorImpl ,
1097
1097
query string ,
1098
1098
stmt sqlparser.Statement ,
1099
1099
comments sqlparser.MarginComments ,
@@ -1131,10 +1131,10 @@ func (e *Executor) getPlan(
1131
1131
reservedVars ,
1132
1132
bindVars ,
1133
1133
parameterize ,
1134
- vcursor .keyspace ,
1135
- vcursor .safeSession . GetSelectLimit (),
1134
+ vcursor .GetKeyspace () ,
1135
+ vcursor .GetSelectLimit (),
1136
1136
setVarComment ,
1137
- vcursor .safeSession . SystemVariables ,
1137
+ vcursor .GetSystemVariablesCopy () ,
1138
1138
vcursor .GetForeignKeyChecksState (),
1139
1139
vcursor ,
1140
1140
)
@@ -1153,9 +1153,9 @@ func (e *Executor) getPlan(
1153
1153
return e .cacheAndBuildStatement (ctx , vcursor , query , stmt , reservedVars , bindVarNeeds , logStats )
1154
1154
}
1155
1155
1156
- func (e * Executor ) hashPlan (ctx context.Context , vcursor * vcursorImpl , query string ) PlanCacheKey {
1156
+ func (e * Executor ) hashPlan (ctx context.Context , vcursor * econtext. VCursorImpl , query string ) PlanCacheKey {
1157
1157
hasher := vthash .New256 ()
1158
- vcursor .keyForPlan (ctx , query , hasher )
1158
+ vcursor .KeyForPlan (ctx , query , hasher )
1159
1159
1160
1160
var planKey PlanCacheKey
1161
1161
hasher .Sum (planKey [:0 ])
@@ -1164,7 +1164,7 @@ func (e *Executor) hashPlan(ctx context.Context, vcursor *vcursorImpl, query str
1164
1164
1165
1165
func (e * Executor ) buildStatement (
1166
1166
ctx context.Context ,
1167
- vcursor * vcursorImpl ,
1167
+ vcursor * econtext. VCursorImpl ,
1168
1168
query string ,
1169
1169
stmt sqlparser.Statement ,
1170
1170
reservedVars * sqlparser.ReservedVars ,
@@ -1175,23 +1175,22 @@ func (e *Executor) buildStatement(
1175
1175
return nil , err
1176
1176
}
1177
1177
1178
- plan .Warnings = vcursor .warnings
1179
- vcursor .warnings = nil
1178
+ plan .Warnings = vcursor .GetAndEmptyWarnings ()
1180
1179
1181
1180
err = e .checkThatPlanIsValid (stmt , plan )
1182
1181
return plan , err
1183
1182
}
1184
1183
1185
1184
func (e * Executor ) cacheAndBuildStatement (
1186
1185
ctx context.Context ,
1187
- vcursor * vcursorImpl ,
1186
+ vcursor * econtext. VCursorImpl ,
1188
1187
query string ,
1189
1188
stmt sqlparser.Statement ,
1190
1189
reservedVars * sqlparser.ReservedVars ,
1191
1190
bindVarNeeds * sqlparser.BindVarNeeds ,
1192
1191
logStats * logstats.LogStats ,
1193
1192
) (* engine.Plan , error ) {
1194
- planCachable := sqlparser .CachePlan (stmt ) && vcursor .safeSession . CachePlan ()
1193
+ planCachable := sqlparser .CachePlan (stmt ) && vcursor .CachePlan ()
1195
1194
if planCachable {
1196
1195
planKey := e .hashPlan (ctx , vcursor , query )
1197
1196
@@ -1209,7 +1208,7 @@ func (e *Executor) canNormalizeStatement(stmt sqlparser.Statement, setVarComment
1209
1208
return sqlparser .CanNormalize (stmt ) || setVarComment != ""
1210
1209
}
1211
1210
1212
- func prepareSetVarComment (vcursor * vcursorImpl , stmt sqlparser.Statement ) (string , error ) {
1211
+ func prepareSetVarComment (vcursor * econtext. VCursorImpl , stmt sqlparser.Statement ) (string , error ) {
1213
1212
if vcursor == nil || vcursor .Session ().InReservedConn () {
1214
1213
return "" , nil
1215
1214
}
@@ -1405,9 +1404,29 @@ func (e *Executor) prepare(ctx context.Context, safeSession *econtext.SafeSessio
1405
1404
return nil , vterrors .Errorf (vtrpcpb .Code_INTERNAL , "[BUG] unrecognized prepare statement: %s" , sql )
1406
1405
}
1407
1406
1407
+ func (e * Executor ) getVCursorConfig () econtext.VCursorConfig {
1408
+ connCollation := collations .Unknown
1409
+ if gw , isTabletGw := e .resolver .resolver .GetGateway ().(* TabletGateway ); isTabletGw {
1410
+ connCollation = gw .DefaultConnCollation ()
1411
+ }
1412
+ return econtext.VCursorConfig {
1413
+ WarmingReadsPercent : warmingReadsPercent ,
1414
+ Collation : connCollation ,
1415
+ MaxMemoryRows : 0 ,
1416
+ EnableShardRouting : false ,
1417
+ DefaultTabletType : 0 ,
1418
+ QueryTimeout : 0 ,
1419
+ DBDDLPlugin : "" ,
1420
+ ForeignKeyMode : 0 ,
1421
+ SetVarEnabled : false ,
1422
+ EnableViews : false ,
1423
+ }
1424
+ }
1425
+
1408
1426
func (e * Executor ) handlePrepare (ctx context.Context , safeSession * econtext.SafeSession , sql string , bindVars map [string ]* querypb.BindVariable , logStats * logstats.LogStats ) ([]* querypb.Field , error ) {
1409
1427
query , comments := sqlparser .SplitMarginComments (sql )
1410
- vcursor , _ := newVCursorImpl (safeSession , comments , e , logStats , e .vm , e .VSchema (), e .resolver .resolver , e .serv , e .warnShardedOnly , e .pv )
1428
+
1429
+ vcursor , _ := econtext .NewVCursorImpl (safeSession , comments , e , logStats , e .vm , e .VSchema (), e .resolver .resolver , e .serv , e .warnShardedOnly , e .pv , e .getVCursorConfig ())
1411
1430
1412
1431
stmt , reservedVars , err := parseAndValidateQuery (query , e .env .Parser ())
1413
1432
if err != nil {
@@ -1456,12 +1475,12 @@ func parseAndValidateQuery(query string, parser *sqlparser.Parser) (sqlparser.St
1456
1475
}
1457
1476
1458
1477
// ExecuteMultiShard implements the IExecutor interface
1459
- func (e * Executor ) ExecuteMultiShard (ctx context.Context , primitive engine.Primitive , rss []* srvtopo.ResolvedShard , queries []* querypb.BoundQuery , session * econtext.SafeSession , autocommit bool , ignoreMaxMemoryRows bool , resultsObserver resultsObserver ) (qr * sqltypes.Result , errs []error ) {
1478
+ func (e * Executor ) ExecuteMultiShard (ctx context.Context , primitive engine.Primitive , rss []* srvtopo.ResolvedShard , queries []* querypb.BoundQuery , session * econtext.SafeSession , autocommit bool , ignoreMaxMemoryRows bool , resultsObserver econtext. ResultsObserver ) (qr * sqltypes.Result , errs []error ) {
1460
1479
return e .scatterConn .ExecuteMultiShard (ctx , primitive , rss , queries , session , autocommit , ignoreMaxMemoryRows , resultsObserver )
1461
1480
}
1462
1481
1463
1482
// StreamExecuteMulti implements the IExecutor interface
1464
- func (e * Executor ) StreamExecuteMulti (ctx context.Context , primitive engine.Primitive , query string , rss []* srvtopo.ResolvedShard , vars []map [string ]* querypb.BindVariable , session * econtext.SafeSession , autocommit bool , callback func (reply * sqltypes.Result ) error , resultsObserver resultsObserver ) []error {
1483
+ func (e * Executor ) StreamExecuteMulti (ctx context.Context , primitive engine.Primitive , query string , rss []* srvtopo.ResolvedShard , vars []map [string ]* querypb.BindVariable , session * econtext.SafeSession , autocommit bool , callback func (reply * sqltypes.Result ) error , resultsObserver econtext. ResultsObserver ) []error {
1465
1484
return e .scatterConn .StreamExecuteMulti (ctx , primitive , query , rss , vars , session , autocommit , callback , resultsObserver )
1466
1485
}
1467
1486
@@ -1581,21 +1600,21 @@ func (e *Executor) ReleaseLock(ctx context.Context, session *econtext.SafeSessio
1581
1600
return e .txConn .ReleaseLock (ctx , session )
1582
1601
}
1583
1602
1584
- // planPrepareStmt implements the IExecutor interface
1585
- func (e * Executor ) planPrepareStmt (ctx context.Context , vcursor * vcursorImpl , query string ) (* engine.Plan , sqlparser.Statement , error ) {
1603
+ // PlanPrepareStmt implements the IExecutor interface
1604
+ func (e * Executor ) PlanPrepareStmt (ctx context.Context , vcursor * econtext. VCursorImpl , query string ) (* engine.Plan , sqlparser.Statement , error ) {
1586
1605
stmt , reservedVars , err := parseAndValidateQuery (query , e .env .Parser ())
1587
1606
if err != nil {
1588
1607
return nil , nil , err
1589
1608
}
1590
1609
1591
1610
// creating this log stats to not interfere with the original log stats.
1592
- lStats := logstats .NewLogStats (ctx , "prepare" , query , vcursor .safeSession . SessionUUID , nil )
1611
+ lStats := logstats .NewLogStats (ctx , "prepare" , query , vcursor .Session (). GetSessionUUID () , nil )
1593
1612
plan , err := e .getPlan (
1594
1613
ctx ,
1595
1614
vcursor ,
1596
1615
query ,
1597
1616
sqlparser .Clone (stmt ),
1598
- vcursor .marginComments ,
1617
+ vcursor .GetMarginComments () ,
1599
1618
map [string ]* querypb.BindVariable {},
1600
1619
reservedVars , /* normalize */
1601
1620
false ,
@@ -1617,7 +1636,7 @@ func (e *Executor) Close() {
1617
1636
e .plans .Close ()
1618
1637
}
1619
1638
1620
- func (e * Executor ) environment () * vtenv.Environment {
1639
+ func (e * Executor ) Environment () * vtenv.Environment {
1621
1640
return e .env
1622
1641
}
1623
1642
@@ -1629,6 +1648,10 @@ func (e *Executor) UnresolvedTransactions(ctx context.Context, targets []*queryp
1629
1648
return e .txConn .UnresolvedTransactions (ctx , targets )
1630
1649
}
1631
1650
1651
+ func (e * Executor ) AddWarningCount (name string , count int64 ) {
1652
+ warnings .Add (name , count )
1653
+ }
1654
+
1632
1655
type (
1633
1656
errorTransformer interface {
1634
1657
TransformError (err error ) error
0 commit comments