Skip to content

sql/stats: can't merge partial and full statistics with outer buckets #126822

@Uzair5162

Description

@Uzair5162

Similar to #93094, the statistic merging logic in:

func mergeExtremesStatistic(
ctx context.Context, fullStat *TableStatistic, partialStat *TableStatistic, st *cluster.Settings,
) (*TableStatistic, error) {
breaks when either statistic has outer buckets. Outer buckets have column-type max or min values and will always overlap with the buckets of the other stats being merged with, and fail to produce a merged statistic.

Example:

SET enable_create_stats_using_extremes = on;
CREATE TABLE a (a PRIMARY KEY) WITH (sql_stats_automatic_collection_enabled = false) AS SELECT generate_series(0, 9999);
CREATE STATISTICS a_full ON a FROM a;
SHOW STATISTICS FOR TABLE a;
SHOW HISTOGRAM $full_stat_hist_id;

INSERT INTO a VALUES (10000);
CREATE STATISTICS a_partial ON a FROM a USING EXTREMES;
SHOW STATISTICS FOR TABLE a WITH MERGE;

Observe that the full stat histogram creates a histogram with outer buckets, and that there is no __merged__ statistic after creating partial stats.

Jira issue: CRDB-40154

Metadata

Metadata

Assignees

Labels

A-sql-table-statsTable statistics (and their automatic refresh).C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.T-sql-queriesSQL Queries Teambranch-masterFailures and bugs on the master branch.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions