Skip to content

Commit

Permalink
sql: use NewInternalSessionData for InternalDB
Browse files Browse the repository at this point in the history
Prevent zero-values from being used for session vars when creating an InternalDB.

Release note: None
  • Loading branch information
rafiss committed Apr 28, 2023
1 parent 546419f commit da664e3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pkg/sql/catalog/descs/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ parent schema name id kind version dropped public
`, formatCatalog(allDescs.OrderedDescriptors()))
return nil
}
sd := sql.NewInternalSessionData(&s0.ClusterSettings().SV, "TestGetAllDescriptorsInDatabase")
sd := sql.NewInternalSessionData(ctx, s0.ClusterSettings(), "TestGetAllDescriptorsInDatabase")
sd.Database = "db"
require.NoError(t, tm.DescsTxn(ctx, run, isql.WithSessionData(sd)))
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/sql/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ func (ie *InternalExecutor) execInternal(
// TODO(andrei): Properly clone (deep copy) ie.sessionData.
sd = ie.sessionDataStack.Top().Clone()
} else {
sd = newSessionData(SessionArgs{})
sd = NewInternalSessionData(context.Background(), ie.s.cfg.Settings, "" /* opName */)
}

applyInternalExecutorSessionExceptions(sd)
Expand Down Expand Up @@ -1176,7 +1176,7 @@ func (ie *InternalExecutor) commitTxn(ctx context.Context) error {
if ie.sessionDataStack != nil {
sd = ie.sessionDataStack.Top().Clone()
} else {
sd = newSessionData(SessionArgs{})
sd = NewInternalSessionData(ctx, ie.s.cfg.Settings, "" /* opName */)
}

rw := newAsyncIEResultChannel()
Expand Down Expand Up @@ -1761,7 +1761,7 @@ func (ief *InternalDB) txn(
type SessionDataOverride = func(sd *sessiondata.SessionData)

type internalDBWithOverrides struct {
baseDB isql.DB
baseDB *InternalDB
sessionDataOverrides []SessionDataOverride
}

Expand All @@ -1773,7 +1773,7 @@ var _ isql.DB = (*internalDBWithOverrides)(nil)
// sessiondata.InternalExecutorOverride parameter to the "*Ex()"
// methods of Executor.
func NewInternalDBWithSessionDataOverrides(
baseDB isql.DB, sessionDataOverrides ...SessionDataOverride,
baseDB *InternalDB, sessionDataOverrides ...SessionDataOverride,
) isql.DB {
return &internalDBWithOverrides{
baseDB: baseDB,
Expand Down Expand Up @@ -1804,9 +1804,9 @@ func (db *internalDBWithOverrides) Executor(opts ...isql.ExecutorOption) isql.Ex
cfg.Init(opts...)
sd := cfg.GetSessionData()
if sd == nil {
// newSessionData is the default value used by InternalExecutor
// NewInternalSessionData is the default value used by InternalExecutor
// when no session data is provided otherwise.
sd = newSessionData(SessionArgs{})
sd = NewInternalSessionData(context.Background(), db.baseDB.server.cfg.Settings, "" /* opName */)
}
for _, o := range db.sessionDataOverrides {
o(sd)
Expand Down
8 changes: 4 additions & 4 deletions pkg/sql/internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,23 +624,23 @@ func TestInternalDBWithOverrides(t *testing.T) {
s, _, _ := serverutils.StartServer(t, base.TestServerArgs{})
defer s.Stopper().Stop(ctx)

idb1 := s.InternalDB().(isql.DB)
idb1 := s.InternalDB().(*sql.InternalDB)

_ = idb1.Txn(ctx, func(ctx context.Context, txn isql.Txn) error {
assert.Equal(t, 0, int(txn.SessionData().DefaultIntSize))
assert.Equal(t, 8, int(txn.SessionData().DefaultIntSize))
assert.Equal(t, sessiondatapb.DistSQLAuto, txn.SessionData().DistSQLMode)
assert.Equal(t, "root", string(txn.SessionData().UserProto))

row, err := txn.QueryRow(ctx, "test", txn.KV(), "show default_int_size")
require.NoError(t, err)
assert.Equal(t, "'0'", row[0].String())
assert.Equal(t, "'8'", row[0].String())

return nil
})

drow, err := idb1.Executor().QueryRow(ctx, "test", nil, "show default_int_size")
require.NoError(t, err)
assert.Equal(t, "'0'", drow[0].String())
assert.Equal(t, "'8'", drow[0].String())

idb2 := sql.NewInternalDBWithSessionDataOverrides(idb1,
func(sd *sessiondata.SessionData) {
Expand Down

0 comments on commit da664e3

Please sign in to comment.