Skip to content

Commit

Permalink
Merge pull request #77566 from mgartner/backport21.1-77507
Browse files Browse the repository at this point in the history
release-21.1: sql: do no collect multi-column stats for indexes with only virtual columns
  • Loading branch information
mgartner authored Mar 9, 2022
2 parents 5302b9f + 59814fa commit 6ef65c3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/sql/create_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,12 @@ func createStatsDefaultColumns(
colIDs = append(colIDs, col.GetID())
}

// Do not attempt to create multi-column stats with no columns. This
// can happen when an index contains only virtual computed columns.
if len(colIDs) == 0 {
continue
}

// Check for existing stats and remember the requested stats.
if !trackStatsIfNotExists(colIDs) {
continue
Expand Down
13 changes: 13 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/distsql_stats
Original file line number Diff line number Diff line change
Expand Up @@ -1156,3 +1156,16 @@ CREATE STATISTICS s ON b FROM t71080;

statement error cannot create statistics on virtual column \"b\"
CREATE STATISTICS s ON a, b FROM t71080;

# Regression test for #76867. Do not attempt to collect empty multi-column stats
# when there are indexes on columns that are all virtual.
statement ok
CREATE TABLE t76867 (
a INT,
b INT AS (a + 1) VIRTUAL,
c INT AS (a + 2) VIRTUAL,
INDEX (b, c)
)

statement ok
ANALYZE t76867

0 comments on commit 6ef65c3

Please sign in to comment.