From 0999b14277976e47cf4d546a989c85e30ffadce0 Mon Sep 17 00:00:00 2001 From: Yahor Yuzefovich Date: Fri, 5 Aug 2022 02:18:07 +0000 Subject: [PATCH] sql: disallow distsql_workmem of less than 2B This commit disallows users to set `distsql_workmem` session variable (as well as the corresponding cluster setting) to a value lower than 2B. The rationale is that internally we treat 1B as "force disk spilling" testing scenario and have some places where the setting is ignored if it is 1B. Non-positive values don't make sense too. It shouldn't really be a problem to users since nobody should be setting this value this low. Release note: None --- pkg/sql/exec_util.go | 6 ++++++ pkg/sql/vars.go | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/sql/exec_util.go b/pkg/sql/exec_util.go index fe77f9dcb502..2324afc5ebdc 100644 --- a/pkg/sql/exec_util.go +++ b/pkg/sql/exec_util.go @@ -529,6 +529,12 @@ var settingWorkMemBytes = settings.RegisterByteSizeSetting( "sql.distsql.temp_storage.workmem", "maximum amount of memory in bytes a processor can use before falling back to temp storage", execinfra.DefaultMemoryLimit, /* 64MiB */ + func(v int64) error { + if v <= 1 { + return errors.Errorf("can only be set to a value greater than 1: %d", v) + } + return nil + }, ).WithPublic() // ExperimentalDistSQLPlanningClusterSettingName is the name for the cluster diff --git a/pkg/sql/vars.go b/pkg/sql/vars.go index d6cbf9025c72..0a76fe4a3bac 100644 --- a/pkg/sql/vars.go +++ b/pkg/sql/vars.go @@ -567,8 +567,8 @@ var varGen = map[string]sessionVar{ if err != nil { return err } - if limit <= 0 { - return errors.New("distsql_workmem can only be set to a positive value") + if limit <= 1 { + return errors.New("distsql_workmem can only be set to a value greater than 1") } m.SetDistSQLWorkMem(limit) return nil