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

sql: support views that depend on virtual views #39195

Merged
merged 1 commit into from
Aug 1, 2019
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
16 changes: 9 additions & 7 deletions pkg/sql/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,16 @@ func (p *planner) getViewPlan(

// Register the dependency to the planner, if requested.
if p.curPlan.deps != nil {
usedColumns := make([]sqlbase.ColumnID, len(desc.Columns))
for i := range desc.Columns {
usedColumns[i] = desc.Columns[i].ID
if !desc.IsVirtualTable() {
usedColumns := make([]sqlbase.ColumnID, len(desc.Columns))
for i := range desc.Columns {
usedColumns[i] = desc.Columns[i].ID
}
deps := p.curPlan.deps[desc.ID]
deps.desc = desc
deps.deps = append(deps.deps, sqlbase.TableDescriptor_Reference{ColumnIDs: usedColumns})
p.curPlan.deps[desc.ID] = deps
}
deps := p.curPlan.deps[desc.ID]
deps.desc = desc
deps.deps = append(deps.deps, sqlbase.TableDescriptor_Reference{ColumnIDs: usedColumns})
p.curPlan.deps[desc.ID] = deps

// We are only interested in the dependency to this view descriptor. Any
// further dependency by the view's query should not be tracked in this planner.
Expand Down
14 changes: 14 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/views
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,20 @@ DROP VIEW v1
statement error pgcode 42P01 relation "v1" does not exist
DROP VIEW v1

# Verify that we can depend on virtual tables.
statement ok
CREATE VIEW virt1 AS SELECT table_schema FROM information_schema.columns

statement ok
DROP VIEW virt1

# Verify that we can depend on virtual views.
statement ok
CREATE VIEW virt2 AS SELECT range_id, lease_holder FROM crdb_internal.ranges

statement ok
DROP VIEW virt2

# Verify correct rejection of star expressions
# TODO(a-robinson): Support star expressions as soon as we can (#10028)

Expand Down