Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release-20.2: sql: ensure "promoted" temporary views are marked as such #63781

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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