Skip to content

Commit 67e6f07

Browse files
committed
chore: add ngram index options check
Signed-off-by: Kould <[email protected]>
1 parent cf5b818 commit 67e6f07

File tree

3 files changed

+43
-9
lines changed

3 files changed

+43
-9
lines changed

src/query/sql/src/planner/binder/ddl/index.rs

+33-8
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ use crate::MetadataRef;
6565
use crate::RefreshAggregatingIndexRewriter;
6666
use crate::SUPPORTED_AGGREGATING_INDEX_FUNCTIONS;
6767

68+
const MAXIMUM_BLOOM_BITMAP_SIZE: usize = 128 * 1024 * 1024;
69+
6870
// valid values for inverted index option tokenizer
6971
static INDEX_TOKENIZER_VALUES: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
7072
let mut r = HashSet::new();
@@ -580,18 +582,41 @@ impl Binder {
580582
let value = val.to_lowercase();
581583
match key.as_str() {
582584
"gram_size" => {
583-
if value.parse::<usize>().is_err() {
584-
return Err(ErrorCode::IndexOptionInvalid(format!(
585-
"value `{value}` is not a legal number",
586-
)));
585+
match value.parse::<usize>() {
586+
Ok(num) => {
587+
if num == 0 {
588+
return Err(ErrorCode::IndexOptionInvalid(
589+
"`gram_size` cannot be 0",
590+
));
591+
}
592+
}
593+
Err(_) => {
594+
return Err(ErrorCode::IndexOptionInvalid(format!(
595+
"value `{value}` is not a legal number",
596+
)));
597+
}
587598
}
588599
options.insert("gram_size".to_string(), value);
589600
}
590601
"bitmap_size" => {
591-
if value.parse::<usize>().is_err() {
592-
return Err(ErrorCode::IndexOptionInvalid(format!(
593-
"value `{value}` is not a legal number",
594-
)));
602+
match value.parse::<usize>() {
603+
Ok(num) => {
604+
if num == 0 {
605+
return Err(ErrorCode::IndexOptionInvalid(
606+
"`bitmap_size` cannot be 0",
607+
));
608+
}
609+
if num > MAXIMUM_BLOOM_BITMAP_SIZE {
610+
return Err(ErrorCode::IndexOptionInvalid(format!(
611+
"bitmap_size: `{num}` is too large (bitmap_size is maximum: {MAXIMUM_BLOOM_BITMAP_SIZE})",
612+
)));
613+
}
614+
}
615+
Err(_) => {
616+
return Err(ErrorCode::IndexOptionInvalid(format!(
617+
"value `{value}` is not a legal number",
618+
)));
619+
}
595620
}
596621
options.insert("bitmap_size".to_string(), value);
597622
}

src/query/storages/common/index/src/bloom_index.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ impl BloomIndex {
369369
arg.index(i).and_then(|scalar| {
370370
scalar.as_string().and_then(|text| {
371371
let text = text.to_lowercase();
372-
if text.is_empty() || gram_size == 0 {
372+
if text.is_empty() {
373373
return None;
374374
}
375375

tests/sqllogictests/suites/ee/08_ee_ngram_index/08_0000_ngram_index_base.test

+9
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ CREATE TABLE t1 (id int, content string, NGRAM INDEX idx1 (content) gram_size =
2727
statement ok
2828
CREATE TABLE t2 (id int, content string)
2929

30+
statement error
31+
CREATE NGRAM INDEX idx2 ON t2(content) gram_size = 0
32+
33+
statement error
34+
CREATE NGRAM INDEX idx2 ON t2(content) bitmap_size = 0
35+
36+
statement error
37+
CREATE NGRAM INDEX idx2 ON t2(content) bitmap_size = 134217729
38+
3039
statement ok
3140
CREATE NGRAM INDEX idx2 ON t2(content) gram_size = 5
3241

0 commit comments

Comments
 (0)