Skip to content

Commit

Permalink
sql: fix aggregation of statistics
Browse files Browse the repository at this point in the history
Previously, because we were using a join, we were double
counting statistics when we had the same fingerprint in
memory and persisted.
This commit adds a `DISTINCT` so we only count them once.

Fixes cockroachdb#85958

Release note: None
  • Loading branch information
maryliag committed Aug 11, 2022
1 parent 8e3ee57 commit 2e42e58
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/sql/crdb_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -5571,7 +5571,7 @@ SELECT
plan_hash,
app_name,
max(metadata) as metadata,
crdb_internal.merge_statement_stats(array_agg(statistics)),
crdb_internal.merge_statement_stats(array_agg(DISTINCT statistics)),
max(sampled_plan),
aggregation_interval,
array_remove(array_agg(index_rec), NULL) AS index_recommendations
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/create_statements
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,7 @@ CREATE VIEW crdb_internal.statement_statistics (
plan_hash,
app_name,
max(metadata) AS metadata,
crdb_internal.merge_statement_stats(array_agg(statistics)),
crdb_internal.merge_statement_stats(array_agg(DISTINCT statistics)),
max(sampled_plan),
aggregation_interval,
array_remove(array_agg(index_rec), NULL) AS index_recommendations
Expand Down Expand Up @@ -1571,7 +1571,7 @@ CREATE VIEW crdb_internal.statement_statistics (
plan_hash,
app_name,
max(metadata) AS metadata,
crdb_internal.merge_statement_stats(array_agg(statistics)),
crdb_internal.merge_statement_stats(array_agg(DISTINCT statistics)),
max(sampled_plan),
aggregation_interval,
array_remove(array_agg(index_rec), NULL) AS index_recommendations
Expand Down

0 comments on commit 2e42e58

Please sign in to comment.