opt: improve ColStatsMap so it's harder to misuse #62531
Labels
A-sql-optimizer
SQL logical planning and optimizations.
C-cleanup
Tech debt, refactors, loose ends, etc. Solution not expected to significantly change behavior.
C-enhancement
Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)
T-sql-queries
SQL Queries Team
There have been at least two cases of subtle bugs (#62289 and #37953) caused by misuse of
ColStatsMap.Lookup()
,ColStatsMap.Add()
, orColStatsMap.Get()
. All of these functions return pointers to aColumnStatistic
, but as the function comment says in each case:Although this comment is useful, there is nothing enforcing the requirement that variables containing column statistics fetched from these functions are no longer used after a call to
Add()
orRemoveIntersecting()
. It's easy to forget this requirement when updating the code instatistics_builder.go
.We should improve this interface so that this requirement is enforced in some way, or change
ColStatsMap
to remove the requirement (for example, by changing theother
field inColStatsMap
to store a[]*ColumnStatistic
instead of a[]ColumnStatistic
).Jira issue: CRDB-2774
The text was updated successfully, but these errors were encountered: