Skip to content

Commit 373ff5a

Browse files
authored
Merge pull request #152200 from Uzair5162/backport25.3-152033
release-25.3: sql/stats: ignore partial stats in `crdb_internal.table_row_statistics`
2 parents 97da885 + 625b4c8 commit 373ff5a

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

pkg/sql/crdb_internal.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,7 @@ CREATE TABLE crdb_internal.table_row_statistics (
777777
SELECT DISTINCT ON ("tableID") "tableID", "rowCount"
778778
FROM system.table_statistics
779779
AS OF SYSTEM TIME '%s'
780+
WHERE "partialPredicate" IS NULL
780781
ORDER BY "tableID", "createdAt" DESC, "rowCount" DESC`,
781782
statsAsOfTimeClusterMode.String(&p.ExecCfg().Settings.SV))
782783
statRows, err := p.ExtendedEvalContext().ExecCfg.InternalDB.Executor().QueryBufferedEx(

pkg/sql/logictest/testdata/logic_test/table

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,3 +674,23 @@ pr_check CHECK ((price > 0)) true
674674

675675
statement ok
676676
COMMIT;
677+
678+
subtest end
679+
680+
# Test that partial statistics are filtered out from table_row_statistics
681+
statement ok
682+
CREATE TABLE t (k INT PRIMARY KEY)
683+
684+
statement ok
685+
INSERT INTO t SELECT generate_series(0, 9)
686+
687+
statement ok
688+
ANALYZE t
689+
690+
statement ok
691+
CREATE STATISTICS partial FROM t USING EXTREMES
692+
693+
query I
694+
SELECT estimated_row_count FROM crdb_internal.table_row_statistics WHERE table_name = 't'
695+
----
696+
10

0 commit comments

Comments
 (0)