@@ -21,6 +21,7 @@ import (
2121	"github.com/cockroachdb/cockroach/pkg/sql/sem/tree" 
2222	"github.com/cockroachdb/cockroach/pkg/sql/sem/tree/datumrange" 
2323	"github.com/cockroachdb/cockroach/pkg/sql/types" 
24+ 	"github.com/cockroachdb/cockroach/pkg/util/buildutil" 
2425	"github.com/cockroachdb/errors" 
2526	"github.com/olekukonko/tablewriter" 
2627)
@@ -75,6 +76,15 @@ func (h *Histogram) numEq(i int) float64 {
7576// selectivity applied. i must be greater than or equal to 0 and less than 
7677// bucketCount. 
7778func  (h  * Histogram ) numRange (i  int ) float64  {
79+ 	// The first bucket always has a zero value for NumRange, so the lower bound 
80+ 	// of the histogram is the upper bound of the first bucket. We only check this 
81+ 	// in test builds. 
82+ 	if  i  ==  0  &&  h .buckets [i ].NumRange  !=  0  {
83+ 		if  buildutil .CrdbTestBuild  {
84+ 			panic (errors .AssertionFailedf ("the first bucket should have NumRange=0" ))
85+ 		}
86+ 		return  0 
87+ 	}
7888	return  h .buckets [i ].NumRange  *  h .selectivity 
7989}
8090
@@ -85,6 +95,13 @@ func (h *Histogram) distinctRange(i int) float64 {
8595	n  :=  h .buckets [i ].NumRange 
8696	d  :=  h .buckets [i ].DistinctRange 
8797
98+ 	if  i  ==  0  &&  d  !=  0  {
99+ 		if  buildutil .CrdbTestBuild  {
100+ 			panic (errors .AssertionFailedf ("the first bucket should have DistinctRange=0" ))
101+ 		}
102+ 		return  0 
103+ 	}
104+ 
88105	if  d  ==  0  {
89106		return  0 
90107	}
@@ -203,11 +220,6 @@ func (h *Histogram) maxDistinctValuesCount() float64 {
203220		return  0 
204221	}
205222
206- 	// The first bucket always has a zero value for NumRange, so the lower bound 
207- 	// of the histogram is the upper bound of the first bucket. 
208- 	if  h .numRange (0 ) !=  0  {
209- 		panic (errors .AssertionFailedf ("the first bucket should have NumRange=0" ))
210- 	}
211223	previousUpperBound  :=  h .upperBound (0 )
212224
213225	var  count  float64 
@@ -322,12 +334,6 @@ func (h *Histogram) filter(
322334		return  filtered 
323335	}
324336
325- 	// The first bucket always has a zero value for NumRange, so the lower bound 
326- 	// of the histogram is the upper bound of the first bucket. 
327- 	if  h .numRange (0 ) !=  0  {
328- 		panic (errors .AssertionFailedf ("the first bucket should have NumRange=0" ))
329- 	}
330- 
331337	var  iter  histogramIter 
332338	iter .init (h , desc )
333339	spanIndex  :=  0 
0 commit comments