Skip to content

Commit

Permalink
Merge pull request cockroachdb#48078 from otan-cockroach/backport20.1…
Browse files Browse the repository at this point in the history
…-47482

release-20.1: sql: fix TRUNCATE for temporary tables
  • Loading branch information
otan authored May 1, 2020
2 parents d6232da + 3f208f9 commit a31c1e1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
18 changes: 18 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/temp_table
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,21 @@ subtest table_with_on_commit

statement error ON COMMIT can only be used on temporary tables
CREATE TABLE a (a int) ON COMMIT PRESERVE ROWS

subtest regression_47030

statement ok
CREATE TEMP TABLE regression_47030(c0 INT); INSERT INTO regression_47030 VALUES (1);

query I
SELECT * FROM regression_47030
----
1

statement ok
TRUNCATE regression_47030; INSERT INTO regression_47030 VALUES (2)

query I
SELECT * FROM regression_47030
----
2
15 changes: 13 additions & 2 deletions pkg/sql/truncate.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,19 @@ func (p *planner) truncateTable(
//
// TODO(vivek): Fix properly along with #12123.
zoneKey := config.MakeZoneKey(uint32(tableDesc.ID))
nameKey := sqlbase.MakePublicTableNameKey(ctx, p.ExecCfg().Settings, tableDesc.ParentID, tableDesc.GetName()).Key()
key := sqlbase.MakePublicTableNameKey(ctx, p.ExecCfg().Settings, newTableDesc.ParentID, newTableDesc.Name).Key()
nameKey := sqlbase.MakeObjectNameKey(
ctx,
p.ExecCfg().Settings,
tableDesc.ParentID,
tableDesc.GetParentSchemaID(),
tableDesc.GetName(),
).Key()
key := sqlbase.MakeObjectNameKey(
ctx, p.ExecCfg().Settings,
newTableDesc.ParentID,
newTableDesc.GetParentSchemaID(),
newTableDesc.Name,
).Key()

b := &kv.Batch{}
// Use CPut because we want to remove a specific name -> id map.
Expand Down

0 comments on commit a31c1e1

Please sign in to comment.