@@ -10,14 +10,12 @@ import (
1010 "math"
1111 "time"
1212
13- hllNew "github.com/axiomhq/hyperloglog"
14- hllOld "github.com/axiomhq/hyperloglog/000"
13+ "github.com/axiomhq/hyperloglog"
1514 "github.com/cockroachdb/cockroach/pkg/jobs"
1615 "github.com/cockroachdb/cockroach/pkg/server/telemetry"
1716 "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
1817 "github.com/cockroachdb/cockroach/pkg/sql/execinfra"
1918 "github.com/cockroachdb/cockroach/pkg/sql/execinfrapb"
20- "github.com/cockroachdb/cockroach/pkg/sql/execversion"
2119 "github.com/cockroachdb/cockroach/pkg/sql/isql"
2220 "github.com/cockroachdb/cockroach/pkg/sql/parser"
2321 "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode"
@@ -103,7 +101,6 @@ func newSampleAggregator(
103101 return nil , errors .Errorf ("histograms require one column" )
104102 }
105103 }
106- useNewHLL := execversion .FromContext (ctx ) >= execversion .V25_1
107104
108105 // Limit the memory use by creating a child monitor with a hard limit.
109106 // The processor will disable histogram collection if this limit is not
@@ -144,14 +141,10 @@ func newSampleAggregator(
144141 for i := range spec .Sketches {
145142 s .sketches [i ] = sketchInfo {
146143 spec : spec .Sketches [i ],
144+ sketch : hyperloglog .New14 (),
147145 numNulls : 0 ,
148146 numRows : 0 ,
149147 }
150- if useNewHLL {
151- s .sketches [i ].sketchNew = hllNew .New14 ()
152- } else {
153- s .sketches [i ].sketchOld = hllOld .New14 ()
154- }
155148 if spec .Sketches [i ].GenerateHistogram {
156149 sampleCols .Add (int (spec .Sketches [i ].Columns [0 ]))
157150 }
@@ -173,14 +166,10 @@ func newSampleAggregator(
173166 s .invSr [col ] = & sr
174167 s .invSketch [col ] = & sketchInfo {
175168 spec : spec .InvertedSketches [i ],
169+ sketch : hyperloglog .New14 (),
176170 numNulls : 0 ,
177171 numRows : 0 ,
178172 }
179- if useNewHLL {
180- s .invSketch [col ].sketchNew = hllNew .New14 ()
181- } else {
182- s .invSketch [col ].sketchOld = hllOld .New14 ()
183- }
184173 }
185174
186175 if err := s .Init (
@@ -372,6 +361,8 @@ func (s *sampleAggregator) mainLoop(
372361func (s * sampleAggregator ) processSketchRow (
373362 sketch * sketchInfo , row rowenc.EncDatumRow , da * tree.DatumAlloc ,
374363) error {
364+ var tmpSketch hyperloglog.Sketch
365+
375366 numRows , err := row [s .numRowsCol ].GetInt ()
376367 if err != nil {
377368 return err
@@ -398,22 +389,11 @@ func (s *sampleAggregator) processSketchRow(
398389 if d == tree .DNull {
399390 return errors .AssertionFailedf ("NULL sketch data" )
400391 }
401- if sketch .sketchNew != nil {
402- var tmpSketch hllNew.Sketch
403- if err := tmpSketch .UnmarshalBinary ([]byte (* d .(* tree.DBytes ))); err != nil {
404- return err
405- }
406- if err := sketch .sketchNew .Merge (& tmpSketch ); err != nil {
407- return errors .NewAssertionErrorWithWrappedErrf (err , "merging sketch data" )
408- }
409- } else {
410- var tmpSketch hllOld.Sketch
411- if err := tmpSketch .UnmarshalBinary ([]byte (* d .(* tree.DBytes ))); err != nil {
412- return err
413- }
414- if err := sketch .sketchOld .Merge (& tmpSketch ); err != nil {
415- return errors .NewAssertionErrorWithWrappedErrf (err , "merging sketch data" )
416- }
392+ if err := tmpSketch .UnmarshalBinary ([]byte (* d .(* tree.DBytes ))); err != nil {
393+ return err
394+ }
395+ if err := sketch .sketch .Merge (& tmpSketch ); err != nil {
396+ return errors .NewAssertionErrorWithWrappedErrf (err , "merging sketch data" )
417397 }
418398 return nil
419399}
@@ -631,12 +611,7 @@ func (s *sampleAggregator) getAvgSize(si *sketchInfo) int64 {
631611// getDistinctCount returns the number of distinct values in the given sketch,
632612// optionally including null values.
633613func (s * sampleAggregator ) getDistinctCount (si * sketchInfo , includeNulls bool ) int64 {
634- var distinctCount int64
635- if si .sketchNew != nil {
636- distinctCount = int64 (si .sketchNew .Estimate ())
637- } else {
638- distinctCount = int64 (si .sketchOld .Estimate ())
639- }
614+ distinctCount := int64 (si .sketch .Estimate ())
640615 if si .numNulls > 0 && ! includeNulls {
641616 // Nulls are included in the estimate, so reduce the count by 1 if nulls are
642617 // not requested.
0 commit comments