Skip to content

Commit ff7e81d

Browse files
authored
feat(query): Add columns to display index sizes in system.tables (#18411)
* tmp fix feat(query): Add columns to display index sizes in `system.tables` * fix tests
1 parent 9980510 commit ff7e81d

File tree

37 files changed

+578
-32
lines changed

37 files changed

+578
-32
lines changed

โ€Žsrc/meta/app/src/schema/table.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,18 @@ pub struct TableStatistics {
241241
pub data_bytes: u64,
242242
/// Size of data compressed in bytes
243243
pub compressed_data_bytes: u64,
244-
/// Size of index data in bytes
244+
/// Size of all index data in bytes
245245
pub index_data_bytes: u64,
246-
246+
/// Size of bloom index in bytes
247+
pub bloom_index_size: Option<u64>,
248+
/// Size of ngram index in bytes
249+
pub ngram_index_size: Option<u64>,
250+
/// Size of inverted index in bytes
251+
pub inverted_index_size: Option<u64>,
252+
/// Size of vector index in bytes
253+
pub vector_index_size: Option<u64>,
254+
/// Size of virtual column in bytes
255+
pub virtual_column_size: Option<u64>,
247256
/// number of segments
248257
pub number_of_segments: Option<u64>,
249258

โ€Žsrc/meta/proto-conv/src/table_from_to_protobuf_impl.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,11 @@ impl FromToProto for mt::TableStatistics {
305305
index_data_bytes: p.index_data_bytes,
306306
number_of_segments: p.number_of_segments,
307307
number_of_blocks: p.number_of_blocks,
308+
bloom_index_size: p.bloom_index_size,
309+
ngram_index_size: p.ngram_index_size,
310+
inverted_index_size: p.inverted_index_size,
311+
vector_index_size: p.vector_index_size,
312+
virtual_column_size: p.virtual_column_size,
308313
};
309314

310315
Ok(v)
@@ -320,6 +325,11 @@ impl FromToProto for mt::TableStatistics {
320325
index_data_bytes: self.index_data_bytes,
321326
number_of_segments: self.number_of_segments,
322327
number_of_blocks: self.number_of_blocks,
328+
bloom_index_size: self.bloom_index_size,
329+
ngram_index_size: self.ngram_index_size,
330+
inverted_index_size: self.inverted_index_size,
331+
vector_index_size: self.vector_index_size,
332+
virtual_column_size: self.virtual_column_size,
323333
};
324334
Ok(p)
325335
}

โ€Žsrc/meta/proto-conv/src/util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ const META_CHANGE_LOG: &[(u64, &str)] = &[
167167
(135, "2025-07-16: Add: UDFServer.immutable, UDFScript.immutable"),
168168
(136, "2025-07-17: Add: Task"),
169169
(137, "2025-07-22: Add: GrantConnectionObject and UserPrivilegeType AccessConnection, AccessConnection"),
170+
(138, "2025-07-23: Add: TableStatistics add index size"),
170171
// Dear developer:
171172
// If you're gonna add a new metadata version, you'll have to add a test for it.
172173
// You could just copy an existing test file(e.g., `../tests/it/v024_table_meta.rs`)

โ€Žsrc/meta/proto-conv/tests/it/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,4 @@ mod v134_add_sequence_meta_storage_version;
129129
mod v135_udf_immutable;
130130
mod v136_add_task;
131131
mod v137_add_grant_object_connection;
132+
mod v138_table_statistics;

โ€Žsrc/meta/proto-conv/tests/it/proto_conv.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@ fn new_table_statistics() -> databend_common_meta_app::schema::TableStatistics {
258258
data_bytes: 200,
259259
compressed_data_bytes: 15,
260260
index_data_bytes: 20,
261+
bloom_index_size: None,
262+
ngram_index_size: None,
263+
inverted_index_size: None,
264+
vector_index_size: None,
265+
virtual_column_size: None,
261266
number_of_segments: Some(1),
262267
number_of_blocks: Some(2),
263268
}

โ€Žsrc/meta/proto-conv/tests/it/v043_table_statistics.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ fn test_decode_v43_table_statistics() -> anyhow::Result<()> {
3636
data_bytes: 200,
3737
compressed_data_bytes: 15,
3838
index_data_bytes: 20,
39+
bloom_index_size: None,
40+
ngram_index_size: None,
41+
inverted_index_size: None,
42+
vector_index_size: None,
43+
virtual_column_size: None,
3944
number_of_segments: Some(1),
4045
number_of_blocks: Some(2),
4146
};

โ€Žsrc/meta/proto-conv/tests/it/v129_vector_datatype.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ fn test_decode_v129_schema() -> anyhow::Result<()> {
108108
];
109109
let want = || TableSchema::new(fields.clone());
110110
common::test_pb_from_to(func_name!(), want())?;
111-
// common::test_pb_from_to2(func_name!(), want())?;
112111
common::test_load_old(func_name!(), table_schema_v129.as_slice(), 129, want())?;
113112
Ok(())
114113
}
@@ -264,7 +263,6 @@ fn test_decode_v129_table_meta() -> anyhow::Result<()> {
264263
}},
265264
};
266265
common::test_pb_from_to(func_name!(), want())?;
267-
// common::test_pb_from_to2(func_name!(), want())?;
268266
common::test_load_old(func_name!(), table_meta_v129.as_slice(), 129, want())?;
269267

270268
Ok(())
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2023 Datafuse Labs.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
use databend_common_meta_app::schema::TableStatistics;
16+
use fastrace::func_name;
17+
18+
use crate::common;
19+
20+
// These bytes are built when a new version in introduced,
21+
// and are kept for backward compatibility test.
22+
//
23+
// *************************************************************
24+
// * These messages should never be updated, *
25+
// * only be added when a new version is added, *
26+
// * or be removed when an old version is no longer supported. *
27+
// *************************************************************
28+
//
29+
// The message bytes are built from the output of `test_pb_from_to()`
30+
#[test]
31+
fn test_decode_v138_table_statistics() -> anyhow::Result<()> {
32+
let bytes = vec![
33+
8, 100, 16, 128, 8, 24, 128, 6, 32, 128, 8, 40, 1, 48, 2, 56, 128, 2, 64, 128, 1, 72, 128,
34+
1, 80, 128, 4, 160, 6, 138, 1, 168, 6, 24,
35+
];
36+
let want = || TableStatistics {
37+
number_of_rows: 100,
38+
data_bytes: 1024,
39+
compressed_data_bytes: 768,
40+
index_data_bytes: 1024,
41+
bloom_index_size: Some(256),
42+
ngram_index_size: Some(128),
43+
inverted_index_size: Some(128),
44+
vector_index_size: Some(512),
45+
virtual_column_size: None,
46+
number_of_segments: Some(1),
47+
number_of_blocks: Some(2),
48+
};
49+
50+
common::test_pb_from_to(func_name!(), want())?;
51+
common::test_load_old(func_name!(), bytes.as_slice(), 138, want())
52+
}

โ€Žsrc/meta/protos/proto/table.proto

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,17 @@ message TableStatistics {
188188

189189
// Number of blocks
190190
optional uint64 number_of_blocks = 6;
191+
192+
// Size of bloom index in bytes
193+
optional uint64 bloom_index_size = 7;
194+
// Size of ngram index in bytes
195+
optional uint64 ngram_index_size = 8;
196+
// Size of inverted index in bytes
197+
optional uint64 inverted_index_size = 9;
198+
// Size of vector index in bytes
199+
optional uint64 vector_index_size = 10;
200+
// Size of virtual column in bytes
201+
optional uint64 virtual_column_size = 11;
191202
}
192203

193204
message DatabaseIdTableName {

โ€Žsrc/query/catalog/src/table.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,12 @@ pub struct TableStatistics {
571571
pub data_size: Option<u64>,
572572
pub data_size_compressed: Option<u64>,
573573
pub index_size: Option<u64>,
574+
pub bloom_index_size: Option<u64>,
575+
pub ngram_index_size: Option<u64>,
576+
pub inverted_index_size: Option<u64>,
577+
pub vector_index_size: Option<u64>,
578+
pub virtual_column_size: Option<u64>,
579+
574580
pub number_of_blocks: Option<u64>,
575581
pub number_of_segments: Option<u64>,
576582
}

0 commit comments

Comments
ย (0)