Skip to content

Commit fddfe85

Browse files
committed
enhance: support configurable estimation on variable legnth field
Signed-off-by: xiaofanluan <[email protected]>
1 parent 9b4b0cb commit fddfe85

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

pkg/util/typeutil/varchar_limit.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Licensed to the LF AI & Data foundation under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
package typeutil
18+
19+
import "sync/atomic"
20+
21+
const defaultVarCharEstimateLengthLimit = 256
22+
23+
var varCharEstimateLengthLimit atomic.Int64
24+
25+
func init() {
26+
SetVarCharEstimateLengthLimit(defaultVarCharEstimateLengthLimit)
27+
}
28+
29+
// SetVarCharEstimateLengthLimit updates the global cap applied when estimating
30+
// record sizes for VarChar fields.
31+
func SetVarCharEstimateLengthLimit(limit int) {
32+
if limit <= 0 {
33+
limit = defaultVarCharEstimateLengthLimit
34+
}
35+
varCharEstimateLengthLimit.Store(int64(limit))
36+
}
37+
38+
// GetVarCharEstimateLengthLimit returns the current cap used when estimating
39+
// VarChar field sizes.
40+
func GetVarCharEstimateLengthLimit() int {
41+
limit := int(varCharEstimateLengthLimit.Load())
42+
if limit <= 0 {
43+
return defaultVarCharEstimateLengthLimit
44+
}
45+
return limit
46+
}

0 commit comments

Comments
 (0)