diff --git a/pkg/sql/create_stats.go b/pkg/sql/create_stats.go index 2eb1f966e9bf..202f114fccc0 100644 --- a/pkg/sql/create_stats.go +++ b/pkg/sql/create_stats.go @@ -440,6 +440,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 diff --git a/pkg/sql/logictest/testdata/logic_test/distsql_stats b/pkg/sql/logictest/testdata/logic_test/distsql_stats index 19670a9f777c..a65447da464c 100644 --- a/pkg/sql/logictest/testdata/logic_test/distsql_stats +++ b/pkg/sql/logictest/testdata/logic_test/distsql_stats @@ -1218,3 +1218,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