Skip to content

Commit 627bcbc

Browse files
authored
Merge pull request #148479 from yuzefovich/backport23.2-148329
release-23.2: execbuilder: fix a silly bug around finding the most recent full stat
2 parents e143d1f + 2145163 commit 627bcbc

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

pkg/sql/opt/exec/execbuilder/relational.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,8 @@ func (b *Builder) maybeAnnotateWithEstimates(node exec.Node, e memo.RelExpr) {
431431
// The first stat is the most recent full one.
432432
var first int
433433
for first < tab.StatisticCount() &&
434-
tab.Statistic(first).IsPartial() ||
435-
(tab.Statistic(first).IsForecast() && !b.evalCtx.SessionData().OptimizerUseForecasts) {
434+
(tab.Statistic(first).IsPartial() ||
435+
(tab.Statistic(first).IsForecast() && !b.evalCtx.SessionData().OptimizerUseForecasts)) {
436436
first++
437437
}
438438

pkg/sql/opt/exec/execbuilder/testdata/partial_stats

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,3 +1261,34 @@ __merged__ {b} 2022-12-13 15:22:21.988179 +0000 UTC 61
12611261
# Finally, restore forecasts setting to its previous value.
12621262
statement ok
12631263
SET CLUSTER SETTING sql.stats.forecasts.enabled = $forecastsEnabledPrev
1264+
1265+
subtest regression_148316
1266+
1267+
# Ensure we can run DELETE statement on system.table_statistics.
1268+
statement ok
1269+
INSERT INTO system.users VALUES ('node', NULL, true, 3);
1270+
1271+
statement ok
1272+
GRANT node TO root;
1273+
1274+
# Keep only partial stats on the target table.
1275+
statement ok
1276+
DELETE FROM system.table_statistics WHERE name NOT LIKE '%partial%' AND "tableID" = 'g'::REGCLASS::OID;
1277+
1278+
query TT
1279+
SELECT statistics_name, column_names FROM [SHOW STATISTICS FOR TABLE g] ORDER BY created
1280+
----
1281+
partial {b}
1282+
1283+
query T
1284+
EXPLAIN SELECT * FROM g WHERE b = 10
1285+
----
1286+
distribution: local
1287+
vectorized: true
1288+
·
1289+
• scan
1290+
missing stats
1291+
table: g@g_pkey
1292+
spans: [/10 - /10]
1293+
1294+
subtest end

0 commit comments

Comments
 (0)