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-21.1: sql: do no collect multi-column stats for indexes with only virtual columns #77566

Merged
merged 1 commit into from
Mar 9, 2022
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
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