Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4b16464
perf(vindex): add detailed build timing logs
jerry-024 Aug 17, 2026
ed768cb
fix(vindex): gate training_rows_retained diagnostics on timing flag
jerry-024 Aug 18, 2026
ef692e2
build(vindex): use core 0.4.0
jerry-024 Aug 18, 2026
1b31280
perf(vindex): enlarge index add batches
jerry-024 Aug 18, 2026
0cff10a
feat: diagnose parquet row group reads
jerry-024 Aug 18, 2026
85b906a
perf(vindex): diagnose per-file read waits
jerry-024 Aug 20, 2026
b445750
perf(vindex): finalize read-path optimization
jerry-024 Aug 20, 2026
d6ec9f7
perf(vindex): upload index parts concurrently
jerry-024 Aug 20, 2026
3a5eceb
Merge branch 'main' into perf/ivfpq-build-performance
jerry-024 Aug 21, 2026
d553633
fix
jerry-024 Aug 21, 2026
bad3f34
fix
jerry-024 Aug 21, 2026
c07b87f
perf: cap single row-group budget accounting to a fair share
jerry-024 Aug 21, 2026
2491580
bench(vindex): add IVF-PQ build benchmark
jerry-024 Aug 21, 2026
ccc3b8d
fix(parquet): preserve strict read budget accounting
jerry-024 Aug 21, 2026
267b6d8
perf(vindex): enable approximate IVF-PQ assignment
jerry-024 Aug 21, 2026
bbf6399
fix(vindex): keep options compatible with core 0.3
jerry-024 Aug 21, 2026
46d22b7
Warn when Parquet row groups exceed read budget
jerry-024 Aug 21, 2026
08afe2c
Fix Parquet read budget warning threshold
jerry-024 Aug 24, 2026
23e352d
fix: bound vector index upload buffering
jerry-024 Aug 24, 2026
aa9eb0e
fix: record parquet diagnostics for selected reads
jerry-024 Aug 25, 2026
a185b24
fix: remove unused concurrent writer helper
jerry-024 Aug 26, 2026
0fdb964
fix: satisfy latest clippy chunk lint
jerry-024 Aug 27, 2026
1ea2345
fix: report selected parquet row groups in diagnostics
jerry-024 Aug 27, 2026
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
93 changes: 93 additions & 0 deletions crates/paimon/examples/ivfpq_build_benchmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

//! Build an IVF-PQ index through the production Paimon path.
//!
//! ```text
//! PAIMON_CATALOG_OPTIONS='{"metastore":"filesystem","warehouse":"/tmp/warehouse"}' \
//! PAIMON_LOG_VECTOR_INDEX_BUILD_TIMING=1 \
//! cargo run --release -p paimon --example ivfpq_build_benchmark -- \
//! <database> <table> <vector-column> [--drop-existing]
//! ```

use std::collections::HashMap;
use std::error::Error;
use std::time::Instant;

use paimon::catalog::Identifier;
use paimon::{CatalogFactory, Options};

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let mut args = std::env::args().skip(1);
let database = required_arg(&mut args, "database")?;
let table_name = required_arg(&mut args, "table")?;
let column = required_arg(&mut args, "vector-column")?;
let drop_existing = args.any(|arg| arg == "--drop-existing");

let catalog_options = std::env::var("PAIMON_CATALOG_OPTIONS")?;
let catalog =
CatalogFactory::create(Options::from_map(serde_json::from_str(&catalog_options)?)).await?;
let table = catalog
.get_table(&Identifier::new(&database, &table_name))
.await?;

let dropped_index_files = if drop_existing {
let mut builder = table.new_global_index_drop_builder();
builder.with_index_column(&column).with_index_type("ivf-pq");
builder.execute().await?
} else {
0
};

let options = HashMap::from([
("dimension".to_string(), "768".to_string()),
("metric".to_string(), "cosine".to_string()),
("nlist".to_string(), "4096".to_string()),
("pq.m".to_string(), "192".to_string()),
]);
let started = Instant::now();
let built_shards = table
.new_vindex_index_build_builder("ivf-pq")
.with_index_column(&column)
.with_options(options.clone())
.execute()
.await?;

println!(
"{}",
serde_json::to_string_pretty(&serde_json::json!({
"database": database,
"table": table_name,
"column": column,
"index_type": "ivf-pq",
"build_options": options,
"dropped_index_files": dropped_index_files,
"built_shards": built_shards,
"duration_seconds": started.elapsed().as_secs_f64(),
}))?
);
Ok(())
}

fn required_arg(
args: &mut impl Iterator<Item = String>,
name: &str,
) -> Result<String, Box<dyn Error>> {
args.next()
.ok_or_else(|| format!("missing <{name}> argument").into())
}
72 changes: 59 additions & 13 deletions crates/paimon/src/arrow/format/parquet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,8 @@ impl FormatFileReader for ParquetFormatReader {
combined_selection =
intersect_optional_row_selections(combined_selection, Some(range_selection));
}
if let Some(sel) = combined_selection {
batch_stream_builder = batch_stream_builder.with_row_selection(sel);
if let Some(ref selection) = combined_selection {
batch_stream_builder = batch_stream_builder.with_row_selection(selection.clone());
}
if let Some(size) = batch_size {
batch_stream_builder = batch_stream_builder.with_batch_size(size);
Expand All @@ -490,29 +490,46 @@ impl FormatFileReader for ParquetFormatReader {
// preserving positional `_ROW_ID`, sort order, and batch backpressure. Reads
// with predicates or an explicit row selection retain the original
// single-stream path until their selections are split per row group.
let row_group_parallelism = self
.read_budget
.as_ref()
.filter(|_| preds.is_empty() && row_filter_factory.is_none() && row_selection.is_none())
let read_budget = self.read_budget.as_ref().filter(|_| {
preds.is_empty() && row_filter_factory.is_none() && row_selection.is_none()
});
let row_group_parallelism = read_budget
.map(|budget| {
budget
.parallelism()
.min(batch_stream_builder.metadata().num_row_groups())
})
.unwrap_or(1);
let projected_bytes = self
.read_budget
.as_ref()
.filter(|budget| row_group_parallelism > 1 || budget.diagnostics_enabled())
.map(|budget| {
let mut diagnostic_selection = combined_selection;
let projected_bytes = batch_stream_builder
.metadata()
.row_groups()
.iter()
.filter(|row_group| {
diagnostic_selection.as_mut().is_none_or(|selection| {
selection
.split_off(row_group.num_rows() as usize)
.selects_any()
})
})
.map(|row_group| projected_row_group_bytes(row_group, &mask))
.collect::<Vec<_>>();
budget.record_projected_row_groups(&projected_bytes);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: this avoids the previous all-zero diagnostics for selected reads, but it now records metadata for all row groups in the file rather than only the row groups touched by the effective selection. The added test selects rows 0..9 from a two-row-group file and expects row_group_count == 2, even though only the first row group is involved. As a result, parquet_row_group_count and the projected-byte min/max/total can overstate the work performed by partial reads.

Could we either filter these values by the effective RowSelection, or rename/document them as file-level projected metadata rather than read-level diagnostics?

projected_bytes
});
if row_group_parallelism > 1 {
let row_group_count = batch_stream_builder.metadata().num_row_groups();
let reader_metadata = ArrowReaderMetadata::try_new(
batch_stream_builder.metadata().clone(),
ArrowReaderOptions::new(),
)?;
let projected_bytes = batch_stream_builder
.metadata()
.row_groups()
.iter()
.map(|row_group| projected_row_group_bytes(row_group, &mask))
.collect::<Vec<_>>();
let read_budget = Arc::clone(self.read_budget.as_ref().expect("checked above"));
let projected_bytes = projected_bytes.expect("parallel row-group reads need sizes");
let read_budget = Arc::clone(read_budget.expect("checked above"));
let (row_group_tx, mut row_group_rx) = mpsc::channel(row_group_parallelism);
tokio::spawn(async move {
for (row_group_index, projected_bytes) in projected_bytes.into_iter().enumerate() {
Expand Down Expand Up @@ -2885,6 +2902,35 @@ mod tests {
);
}

#[tokio::test]
async fn test_parquet_diagnostics_include_reads_with_row_selection() {
let data = write_multi_row_group_parquet(32, 64, EnabledStatistics::Chunk).await;
let budget = Arc::new(ParquetReadBudget::new(8, 256 * 1024 * 1024).unwrap());
budget.enable_diagnostics();
let file_size = data.len() as u64;
let fields = vec![int_field("id")];
let batches = ParquetFormatReader::with_read_budget(Arc::clone(&budget))
.read_batch_stream(
Box::new(TrackingFileRead::new(Bytes::from(data))),
file_size,
&fields,
None,
Some(32),
Some(vec![RowRange::new(0, 9)]),
)
.await
.unwrap()
.try_collect::<Vec<_>>()
.await
.unwrap();

assert_eq!(batches.iter().map(RecordBatch::num_rows).sum::<usize>(), 10);
let diagnostics = budget.diagnostics();
assert_eq!(diagnostics.row_group_count, 1);
assert!(diagnostics.projected_bytes_total > 0);
assert_eq!(diagnostics.peak_inflight, 0);
}

#[tokio::test]
async fn test_row_group_batch_forwarding_applies_backpressure() {
let schema = Arc::new(ArrowSchema::empty());
Expand Down
Loading