Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

explain: fix overflow when printing estimated row count #118970

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions pkg/sql/opt/exec/execbuilder/testdata/explain
Original file line number Diff line number Diff line change
Expand Up @@ -2393,3 +2393,36 @@ inner-join (hash)
│ └── unfiltered-cols: (6-9)
└── filters
└── k:6 = a:1 [outer=(1,6), constraints=(/1: (/NULL - ]; /6: (/NULL - ]), fd=(1)==(6), (6)==(1)]

# Regression test for overflow when printing out the estimated row count.
statement ok
CREATE TABLE very_large_table (k INT PRIMARY KEY);

statement ok
ALTER TABLE very_large_table INJECT STATISTICS '[
{
"columns": ["k"],
"created_at": "2024-01-01 1:00:00.00000+00:00",
"row_count": 1000000000000,
"distinct_count": 1000000000000
}
]'

query T
EXPLAIN SELECT t1.k FROM very_large_table AS t1, very_large_table AS t2;
----
distribution: local
vectorized: true
·
• cross join
│ estimated row count: 9,223,372,036,854,775,807
├── • scan
│ estimated row count: 1,000,000,000,000 (100% of the table; stats collected <hidden> ago)
│ table: very_large_table@very_large_table_pkey
│ spans: FULL SCAN
└── • scan
estimated row count: 1,000,000,000,000 (100% of the table; stats collected <hidden> ago)
table: very_large_table@very_large_table_pkey
spans: FULL SCAN
8 changes: 8 additions & 0 deletions pkg/util/humanizeutil/count.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,24 @@
package humanizeutil

import (
"math"

"github.com/cockroachdb/redact"
"github.com/dustin/go-humanize"
)

// Count formats a unitless integer value like a row count. It uses separating
// commas for large values (e.g. "1,000,000").
func Count(val uint64) redact.SafeString {
if val > math.MaxInt64 {
val = math.MaxInt64
}
return redact.SafeString(humanize.Comma(int64(val)))
}

func Countf(val float64) redact.SafeString {
if val > math.MaxInt64 {
val = math.MaxInt64
}
return redact.SafeString(humanize.Commaf(val))
}
Loading