You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
sql/stats: merge all arbitrary partial and full table statistics
This commit generalizes partial and full stat merging in the stats cache
to support partial stats collected over any range of values in a column.
Non-extreme partial stats are treated as covering a single span, and
extreme partials continue to separate the lower and upper extreme
buckets as before.
Additionally, merged stats now apply all partial stats collected after
the latest full stat, in order of creation. Previously, we could only
merge partial stats collected at the extremes of the index, and would
only merge the latest one.
Part of: #93998
Release note (sql change): The optimizer can now use table statistics
that merge the latest full statistic with all newer partial statistics,
including those over arbitrary constraints over a single span.
# Verify that a non-inverted index string column with a string histogram
2679
2691
# can have partial statistics
2680
2692
statement ok
@@ -2730,9 +2742,15 @@ CREATE TABLE xyz (x INT, y INT, z INT, INDEX (x, y));
2730
2742
statement error pq: column x does not have a prior statistic
2731
2743
EXPLAIN ANALYZE CREATE STATISTICS xyz_x ON x FROM xyz USING EXTREMES;
2732
2744
2745
+
statement error pq: column x does not have a prior statistic
2746
+
EXPLAIN ANALYZE CREATE STATISTICS xyz_x ON x FROM xyz WHERE x > 5;
2747
+
2733
2748
statement error pq: the latest full statistic for column a has no histogram
2734
2749
EXPLAIN ANALYZE CREATE STATISTICS u_partial ON a FROM u USING EXTREMES;
2735
2750
2751
+
statement error pq: the latest full statistic for column a has no histogram
2752
+
EXPLAIN ANALYZE CREATE STATISTICS u_partial ON a FROM u WHERE a > 5;
2753
+
2736
2754
statement error pq: table xy does not contain a non-partial forward index with y as a prefix column
2737
2755
CREATE STATISTICS xy_y_partial ON y FROM xy USING EXTREMES;
2738
2756
@@ -2750,9 +2768,12 @@ CREATE STATISTICS only_null_stat ON a FROM only_null;
2750
2768
statement ok
2751
2769
SELECT crdb_internal.clear_table_stats_cache();
2752
2770
2753
-
statement error pq: only outer or NULL bounded buckets exist in only_null@only_null_a_idx \(table ID \d+, column IDs \[1\]\), so partial stats cannot be collected
2771
+
statement error pq: the latest full statistic histogram for column a has only NULL values
2754
2772
EXPLAIN ANALYZE CREATE STATISTICS only_null_partial ON a FROM only_null USING EXTREMES;
2755
2773
2774
+
statement error pq: the latest full statistic histogram for column a has only NULL values
2775
+
EXPLAIN ANALYZE CREATE STATISTICS only_null_partial ON a FROM only_null WHERE a > 5;
0 commit comments