Skip to content

Commit c5e87b4

Browse files
committed
optbuilder: don't track deps for virtual tables
A previous fix in #146250 added dependency tracking for tables in appendOrdinaryColumnsFromTable. This fix missed that the table could be a virtual table, in which case we don't need (and in some places can't handle) tracking dependencies. This commit adds a filter to avoid tracking virtual tables. The only place I've found where this mattered was in the cross-DB check for views, which led to a test flake after some changes in the previous commit. Informs #158154 Release note: None
1 parent 4849559 commit c5e87b4

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

pkg/sql/opt/optbuilder/partial_index.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,16 @@ import (
2727
// scan. A scan and its logical properties are required in order to fully
2828
// normalize the partial index predicates.
2929
func (b *Builder) addPartialIndexPredicatesForTable(tabMeta *opt.TableMeta, scan memo.RelExpr) {
30-
// We do not want to track view/function deps here, otherwise a
31-
// view/function depending on a table with a partial index predicate using
32-
// a UDT will result in a type dependency being added between the
33-
// view/function and the UDT.
34-
defer b.DisableSchemaDepTracking()()
30+
if !b.evalCtx.SessionData().UseImprovedRoutineDepsTriggersAndComputedCols {
31+
// We do not want to track view/function deps here, otherwise a
32+
// view/function depending on a table with a partial index predicate using
33+
// a UDT will result in a type dependency being added between the
34+
// view/function and the UDT.
35+
//
36+
// This is the legacy path; with the session setting on, we will disable
37+
// dependency tracking in buildPartialIndexPredicate below.
38+
defer b.DisableSchemaDepTracking()()
39+
}
3540

3641
tab := tabMeta.Table
3742
numIndexes := tab.DeletableIndexCount()

pkg/sql/opt/optbuilder/util.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,8 @@ func (b *Builder) appendOrdinaryColumnsFromTable(
875875
visibility: columnVisibility(tabCol.Visibility()),
876876
})
877877
}
878-
if b.trackSchemaDeps && b.evalCtx.SessionData().UseImprovedRoutineDependencyTracking {
878+
if !tab.IsVirtualTable() && b.trackSchemaDeps &&
879+
b.evalCtx.SessionData().UseImprovedRoutineDependencyTracking {
879880
dep := opt.SchemaDep{DataSource: tab}
880881
for i, n := 0, tab.ColumnCount(); i < n; i++ {
881882
if tab.Column(i).Kind() != cat.Ordinary {

0 commit comments

Comments
 (0)