Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
83134: sql: remove `ttl_automatic_column` storage parameter r=otan a=ecwall

fixes cockroachdb#83133

Release note (sql change): Remove ttl_automatic_column storage param.
The crdb_internal_expiration column is created when ttl_expire_after is set and
removed when ttl_expire_after is reset.

83615: sql: don't clear the memory account of the prepared stmt r=yuzefovich a=yuzefovich

Previously, we had a bug of clearing the memory account of the prepared
statements right after that prepared statement is created although we do
keep the struct around. I believe this bug was introduced long time ago,
and it could result in some memory not being accounted for. This is now
fixed.

Partially addresses: cockroachdb#72581.

Release note: None

Co-authored-by: Evan Wall <[email protected]>
Co-authored-by: Yahor Yuzefovich <[email protected]>
  • Loading branch information
3 people committed Jul 6, 2022
3 parents 41228d1 + 965f7c6 + ac40016 commit 0848d90
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 135 deletions.
6 changes: 3 additions & 3 deletions pkg/ccl/backupccl/testdata/backup-restore/row_level_ttl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ CREATE TABLE public.t (
id INT8 NOT NULL,
crdb_internal_expiration TIMESTAMPTZ NOT VISIBLE NOT NULL DEFAULT current_timestamp():::TIMESTAMPTZ + '00:10:00':::INTERVAL ON UPDATE current_timestamp():::TIMESTAMPTZ + '00:10:00':::INTERVAL,
CONSTRAINT t_pkey PRIMARY KEY (id ASC)
) WITH (ttl = 'on', ttl_automatic_column = 'on', ttl_expire_after = '00:10:00':::INTERVAL, ttl_job_cron = '@hourly')
) WITH (ttl = 'on', ttl_expire_after = '00:10:00':::INTERVAL, ttl_job_cron = '@hourly')

query-sql
SELECT count(1) FROM [SHOW SCHEDULES]
Expand Down Expand Up @@ -72,7 +72,7 @@ CREATE TABLE public.t (
id INT8 NOT NULL,
crdb_internal_expiration TIMESTAMPTZ NOT VISIBLE NOT NULL DEFAULT current_timestamp():::TIMESTAMPTZ + '00:10:00':::INTERVAL ON UPDATE current_timestamp():::TIMESTAMPTZ + '00:10:00':::INTERVAL,
CONSTRAINT t_pkey PRIMARY KEY (id ASC)
) WITH (ttl = 'on', ttl_automatic_column = 'on', ttl_expire_after = '00:10:00':::INTERVAL, ttl_job_cron = '@hourly')
) WITH (ttl = 'on', ttl_expire_after = '00:10:00':::INTERVAL, ttl_job_cron = '@hourly')

query-sql
SELECT count(1) FROM [SHOW SCHEDULES]
Expand Down Expand Up @@ -109,7 +109,7 @@ CREATE TABLE public.t (
id INT8 NOT NULL,
crdb_internal_expiration TIMESTAMPTZ NOT VISIBLE NOT NULL DEFAULT current_timestamp():::TIMESTAMPTZ + '00:10:00':::INTERVAL ON UPDATE current_timestamp():::TIMESTAMPTZ + '00:10:00':::INTERVAL,
CONSTRAINT t_pkey PRIMARY KEY (id ASC)
) WITH (ttl = 'on', ttl_automatic_column = 'on', ttl_expire_after = '00:10:00':::INTERVAL, ttl_job_cron = '@hourly')
) WITH (ttl = 'on', ttl_expire_after = '00:10:00':::INTERVAL, ttl_job_cron = '@hourly')

query-sql
SELECT count(1) FROM [SHOW SCHEDULES]
Expand Down
2 changes: 0 additions & 2 deletions pkg/sql/alter_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,6 @@ func (n *alterTableNode) startExec(params runParams) error {
ttlBefore = protoutil.Clone(ttl).(*catpb.RowLevelTTL)
}
if err := storageparam.Set(
params.ctx,
params.p.SemaCtx(),
params.EvalContext(),
t.StorageParams,
Expand Down Expand Up @@ -767,7 +766,6 @@ func (n *alterTableNode) startExec(params runParams) error {
ttlBefore = protoutil.Clone(ttl).(*catpb.RowLevelTTL)
}
if err := storageparam.Reset(
params.ctx,
params.EvalContext(),
t.Params,
tablestorageparam.NewSetter(n.tableDesc),
Expand Down
1 change: 0 additions & 1 deletion pkg/sql/catalog/tabledesc/structured.go
Original file line number Diff line number Diff line change
Expand Up @@ -2567,7 +2567,6 @@ func (desc *wrapper) GetStorageParams(spaceBetweenEqual bool) []string {
if ttl := desc.GetRowLevelTTL(); ttl != nil {
appendStorageParam(`ttl`, `'on'`)
if ttl.HasDurationExpr() {
appendStorageParam(`ttl_automatic_column`, `'on'`)
appendStorageParam(`ttl_expire_after`, string(ttl.DurationExpr))
}
if ttl.HasExpirationExpr() {
Expand Down
3 changes: 0 additions & 3 deletions pkg/sql/conn_executor_prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,6 @@ func (ex *connExecutor) prepare(
createdAt: timeutil.Now(),
origin: origin,
}
// NB: if we start caching the plan, we'll want to keep around the memory
// account used for the plan, rather than clearing it.
defer prepared.memAcc.Clear(ctx)

if stmt.AST == nil {
return prepared, nil
Expand Down
1 change: 0 additions & 1 deletion pkg/sql/create_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ func makeIndexDescriptor(
}

if err := storageparam.Set(
params.ctx,
params.p.SemaCtx(),
params.EvalContext(),
n.StorageParams,
Expand Down
2 changes: 0 additions & 2 deletions pkg/sql/create_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,6 @@ func NewTableDesc(
)

if err := storageparam.Set(
ctx,
semaCtx,
evalCtx,
n.StorageParams,
Expand Down Expand Up @@ -1863,7 +1862,6 @@ func NewTableDesc(
idx.Predicate = expr
}
if err := storageparam.Set(
ctx,
semaCtx,
evalCtx,
d.StorageParams,
Expand Down
93 changes: 48 additions & 45 deletions pkg/sql/logictest/testdata/logic_test/row_level_ttl

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/sql/schema_changer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7605,7 +7605,7 @@ CREATE TABLE t.test (id TEXT PRIMARY KEY) WITH (ttl_expire_after = '10 hours');`
id STRING NOT NULL,
crdb_internal_expiration TIMESTAMPTZ NOT VISIBLE NOT NULL DEFAULT current_timestamp():::TIMESTAMPTZ + '10:00:00':::INTERVAL ON UPDATE current_timestamp():::TIMESTAMPTZ + '10:00:00':::INTERVAL,
CONSTRAINT test_pkey PRIMARY KEY (id ASC)
) WITH (ttl = 'on', ttl_automatic_column = 'on', ttl_expire_after = '10:00:00':::INTERVAL, ttl_job_cron = '@hourly')`
) WITH (ttl = 'on', ttl_expire_after = '10:00:00':::INTERVAL, ttl_job_cron = '@hourly')`
)

testCases := []struct {
Expand Down
1 change: 0 additions & 1 deletion pkg/sql/sem/builtins/geo_builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -7674,7 +7674,6 @@ func applyGeoindexConfigStorageParams(
}
semaCtx := tree.MakeSemaContext()
if err := storageparam.Set(
evalCtx.Context,
&semaCtx,
evalCtx,
stmt.AST.(*tree.CreateIndex).StorageParams,
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func TestShowCreateTable(t *testing.T) {
pk INT8 NOT NULL,
crdb_internal_expiration TIMESTAMPTZ NOT VISIBLE NOT NULL DEFAULT current_timestamp():::TIMESTAMPTZ + '00:10:00':::INTERVAL ON UPDATE current_timestamp():::TIMESTAMPTZ + '00:10:00':::INTERVAL,
CONSTRAINT %[1]s_pkey PRIMARY KEY (pk ASC)
) WITH (ttl = 'on', ttl_automatic_column = 'on', ttl_expire_after = '00:10:00':::INTERVAL, ttl_job_cron = '@hourly')`,
) WITH (ttl = 'on', ttl_expire_after = '00:10:00':::INTERVAL, ttl_job_cron = '@hourly')`,
},
// Check that FK dependencies inside the current database
// have their db name omitted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
package indexstorageparam

import (
"context"

"github.com/cockroachdb/cockroach/pkg/geo/geoindex"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
"github.com/cockroachdb/cockroach/pkg/sql/paramparse"
Expand Down Expand Up @@ -109,11 +107,7 @@ func (po *Setter) applyGeometryIndexSetting(

// Set implements the Setter interface.
func (po *Setter) Set(
ctx context.Context,
semaCtx *tree.SemaContext,
evalCtx *eval.Context,
key string,
expr tree.Datum,
semaCtx *tree.SemaContext, evalCtx *eval.Context, key string, expr tree.Datum,
) error {
switch key {
case `fillfactor`:
Expand Down
18 changes: 5 additions & 13 deletions pkg/sql/storageparam/storage_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
package storageparam

import (
"context"

"github.com/cockroachdb/cockroach/pkg/server/telemetry"
"github.com/cockroachdb/cockroach/pkg/sql/paramparse"
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode"
Expand All @@ -31,7 +29,7 @@ import (
type Setter interface {
// Set is called during CREATE [TABLE | INDEX] ... WITH (...) or
// ALTER [TABLE | INDEX] ... WITH (...).
Set(ctx context.Context, semaCtx *tree.SemaContext, evalCtx *eval.Context, key string, datum tree.Datum) error
Set(semaCtx *tree.SemaContext, evalCtx *eval.Context, key string, datum tree.Datum) error
// Reset is called during ALTER [TABLE | INDEX] ... RESET (...)
Reset(evalCtx *eval.Context, key string) error
// RunPostChecks is called after all storage parameters have been set.
Expand All @@ -43,11 +41,7 @@ type Setter interface {
// Set sets the given storage parameters using the
// given observer.
func Set(
ctx context.Context,
semaCtx *tree.SemaContext,
evalCtx *eval.Context,
params tree.StorageParams,
setter Setter,
semaCtx *tree.SemaContext, evalCtx *eval.Context, params tree.StorageParams, setter Setter,
) error {
for _, sp := range params {
key := string(sp.Key)
Expand All @@ -61,7 +55,7 @@ func Set(
expr := paramparse.UnresolvedNameToStrVal(sp.Value)

// Convert the expressions to a datum.
typedExpr, err := tree.TypeCheck(ctx, expr, semaCtx, types.Any)
typedExpr, err := tree.TypeCheck(evalCtx.Context, expr, semaCtx, types.Any)
if err != nil {
return err
}
Expand All @@ -73,7 +67,7 @@ func Set(
return err
}

if err := setter.Set(ctx, semaCtx, evalCtx, key, datum); err != nil {
if err := setter.Set(semaCtx, evalCtx, key, datum); err != nil {
return err
}
}
Expand All @@ -82,9 +76,7 @@ func Set(

// Reset sets the given storage parameters using the
// given observer.
func Reset(
ctx context.Context, evalCtx *eval.Context, params tree.NameList, paramObserver Setter,
) error {
func Reset(evalCtx *eval.Context, params tree.NameList, paramObserver Setter) error {
for _, p := range params {
telemetry.Inc(sqltelemetry.ResetTableStorageParameter(string(p)))
if err := paramObserver.Reset(evalCtx, string(p)); err != nil {
Expand Down
Loading

0 comments on commit 0848d90

Please sign in to comment.