Skip to content

Commit

Permalink
Merge pull request #64226 from mgartner/63387-inverted-stats
Browse files Browse the repository at this point in the history
release-20.2: sql: fix CREATE STATISTICS for partial indexes
  • Loading branch information
mgartner authored Apr 26, 2021
2 parents c159beb + 200a9e0 commit d196291
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/sql/create_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,12 @@ func createStatsDefaultColumns(

// Generate stats for each column individually.
for _, colID := range colIDs.Ordered() {
addIndexColumnStatsIfNotExists(colID, isInverted)
col, err := desc.FindColumnByID(colID)
if err != nil {
return nil, err
}
isInvertedCol := colinfo.ColumnTypeIsInvertedIndexable(col.Type)
addIndexColumnStatsIfNotExists(colID, isInvertedCol)
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/distsql_stats
Original file line number Diff line number Diff line change
Expand Up @@ -1036,3 +1036,14 @@ SHOW STATISTICS USING JSON FOR TABLE greeting_stats

statement ok
ALTER TABLE greeting_stats INJECT STATISTICS '$stats'

# Regression test for #63387. Stats collection should succeed when partial index
# predicates reference inverted-type columns.
statement ok
CREATE TABLE t63387 (
i INT,
j JSONB,
INDEX (i) WHERE j->>'a' = 'b'
);
INSERT INTO t63387 VALUES (1, '{}');
CREATE STATISTICS s FROM t63387;

0 comments on commit d196291

Please sign in to comment.