Skip to content

Commit

Permalink
Merge pull request cockroachdb#63781 from ajwerner/ajwerner/fix-20.2-…
Browse files Browse the repository at this point in the history
…drop-database-bug
  • Loading branch information
ajwerner authored Apr 16, 2021
2 parents 287fd22 + 0cc9a15 commit 0f4525d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/sql/create_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (n *createViewNode) startExec(params runParams) error {
privs,
&params.p.semaCtx,
params.p.EvalContext(),
n.persistence,
persistence,
)
if err != nil {
return err
Expand Down
39 changes: 39 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/temp_table
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,42 @@ grant testuser to root

statement ok
ALTER TABLE second_db.pg_temp.a OWNER TO testuser


# Below is a regression test to deal ensure that views which are "upgraded" to
# temporary because they reference temporary tables are indeed marked as
# temporary.
subtest upgraded_view_marked_temporary

statement ok
CREATE DATABASE upgraded_view_marked_temporary;
USE upgraded_view_marked_temporary;
CREATE TEMPORARY TABLE t (i INT PRIMARY KEY);
CREATE VIEW v AS SELECT i FROM t;

# Confirm at a low-level that the descriptor for v is marked temporary.

query T
SELECT crdb_internal.pb_to_json(
'cockroach.sql.sqlbase.Descriptor',
descriptor
)->'table'->>'temporary'
FROM system.descriptor
WHERE id = 'v'::REGCLASS;
----
true

statement ok
USE test

# Switch to a different user and thus different connection and attempt to
# drop the database which contains the promoted temporary view. If the view
# were not properly marked as temporary, this would fail with an opaque error
# about not being able to find the descriptor.

user root

statement ok
DROP DATABASE upgraded_view_marked_temporary CASCADE;

user testuser

0 comments on commit 0f4525d

Please sign in to comment.