Skip to content
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
5 changes: 3 additions & 2 deletions pkg/sql/opt/exec/execbuilder/relational.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,9 @@ func (b *Builder) maybeAnnotateWithEstimates(node exec.Node, e memo.RelExpr) {
// The first stat is the most recent full one.
var first int
for first < tab.StatisticCount() &&
tab.Statistic(first).IsPartial() ||
(tab.Statistic(first).IsForecast() && !b.evalCtx.SessionData().OptimizerUseForecasts) {
(tab.Statistic(first).IsPartial() ||
(tab.Statistic(first).IsMerged() && !b.evalCtx.SessionData().OptimizerUseMergedPartialStatistics) ||
(tab.Statistic(first).IsForecast() && !b.evalCtx.SessionData().OptimizerUseForecasts)) {
first++
}

Expand Down
37 changes: 36 additions & 1 deletion pkg/sql/opt/exec/execbuilder/testdata/partial_stats
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ distribution: local
vectorized: true
·
• scan
estimated row count: 4 (36% of the table; stats collected <hidden> ago)
estimated row count: 4 (40% of the table; stats collected <hidden> ago)
table: ka@ka_a_idx
spans: [/6 - ]

Expand Down Expand Up @@ -1420,3 +1420,38 @@ vectorized: true
estimated row count: 1 (9.1% of the table; stats collected <hidden> ago)
table: ka@ka_a_idx
spans: [/10 - /10]

subtest regression_148316

# Ensure we can run DELETE statement on system.table_statistics.
statement ok
INSERT INTO system.users VALUES ('node', NULL, true, 3);

statement ok
GRANT node TO root;

# Keep only partial stats on the target table.
statement ok
DELETE FROM system.table_statistics WHERE name NOT LIKE '%partial%' AND "tableID" = 'ka'::REGCLASS::OID;

query TT
SELECT statistics_name, column_names FROM [SHOW STATISTICS FOR TABLE ka] ORDER BY created
----
ka_partialstat {a}

# Ensure that the system table is read on the next query.
statement ok
SELECT crdb_internal.clear_table_stats_cache();

query T
EXPLAIN SELECT * FROM ka WHERE a = 10
----
distribution: local
vectorized: true
·
• scan
missing stats
table: ka@ka_a_idx
spans: [/10 - /10]

subtest end