Skip to content
Draft
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
2 changes: 1 addition & 1 deletion core-relations/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub use query::{
CachedPlan, QueryBuilder, QueryError, RuleBuilder, RuleId, RuleSet, RuleSetBuilder,
};
pub use row_buffer::TaggedRowBuffer;
pub use table::{MergeFn, SortedWritesTable};
pub use table::{MergeFn, SequenceTable, SortedWritesTable};
pub use table_spec::{
ColumnId, Constraint, MutationBuffer, Offset, Rebuilder, Row, Table, TableChange, TableSpec,
TableVersion, ValueRebuilder, WrappedTable,
Expand Down
5 changes: 4 additions & 1 deletion core-relations/src/parallel_heuristics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ pub(crate) fn parallelize_index_construction(items_to_insert: usize) -> bool {
should_parallelize(items_to_insert, cutoffs().index_construction)
}

/// Whether or not to use a parallel algorithm to rebuild a [`crate::table::SortedWritesTable`].
/// Whether or not to use a parallel algorithm for a full table rebuild.
///
/// This applies to both fixed-arity [`crate::table::SortedWritesTable`] and
/// variable-arity [`crate::table::SequenceTable`] scans.
pub(crate) fn parallelize_rebuild(table_size: usize) -> bool {
should_parallelize(table_size, cutoffs().rebuild)
}
Expand Down
2 changes: 2 additions & 0 deletions core-relations/src/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ pool_set! {
pub PoolSet {
vec_vals: Vec<Value> [ 1 << 25 ],
vec_cell_vals: Vec<Cell<Value>> [ 1 << 25 ],
sequence_offsets: Vec<Cell<u32>> [ 1 << 25 ],
// TODO: work on scaffolding/DI/etc. so that we can share allocations
// between vec_vals and shared_vals.
rows: Vec<RowId> [ 1 << 25 ],
Expand All @@ -434,6 +435,7 @@ pool_set! {
instrs: Vec<Instr> [ 1 << 20 ],
tuple_indexes: HashTable<TableEntry<BufferedSubset>> [ 1 << 20 ],
staged_outputs: HashTable<SwTableEntry> [ 1 << 25 ],
sequence_staged_rows: HashTable<RowId> [ 1 << 25 ],
predicted_vals: PredictedVals [ 1 << 20 ],
shard_hist: DenseIdMap<ShardId, usize> [ 1 << 20 ],
instr_indexes: Vec<u32> [ 1 << 20 ],
Expand Down
25 changes: 20 additions & 5 deletions core-relations/src/table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ use crate::{
};

mod rebuild;
mod sequence;
mod sharded_hash_table;
#[cfg(test)]
mod tests;

pub use sequence::SequenceTable;

const PARALLEL_INSERT_BATCH_SIZE: usize = 1 << 12;

/// The complete hash used to choose a physical shard.
Expand Down Expand Up @@ -132,21 +135,28 @@ impl ShardHash {
}
}

/// A pointer to a row in the table.
/// A cached hash paired with a table-specific row location.
///
/// Fixed-arity tables use a [`RowId`] directly. Variable-arity tables use a
/// location that also carries the row's backing-vector range, so hash probes
/// do not need a second metadata lookup before comparing keys.
#[derive(Clone, Debug)]
#[repr(C)]
pub(crate) struct TableEntry {
pub(crate) struct HashedTableEntry<R> {
hash: CompactHash,
row: RowId,
row: R,
}

impl TableEntry {
impl<R> HashedTableEntry<R> {
/// Adapter for hashbrown callbacks, which require the raw `u64`.
fn raw_probe_hash(&self) -> u64 {
self.hash.probe().raw()
}
}

/// A pointer to a fixed-arity row in the table.
pub(crate) type TableEntry = HashedTableEntry<RowId>;

/// Producer-local rows for one physical hash-table shard.
///
/// This preserves producer order and performs no seal/scatter step. A compact
Expand Down Expand Up @@ -1418,8 +1428,13 @@ fn get_entry_mut<'a>(
}

fn shard_hash(shard_data: ShardData, row: &[Value], n_keys: usize) -> ShardHash {
shard_hash_values(shard_data, &row[0..n_keys])
}

/// Hash an arity-independent slice and route it to a physical shard.
fn shard_hash_values(shard_data: ShardData, values: &[Value]) -> ShardHash {
let mut hasher = FxHasher::default();
for val in &row[0..n_keys] {
for val in values {
hasher.write_usize(val.index());
}
ShardHash::from_full(shard_data, FullHash(hasher.finish()))
Expand Down
Loading
Loading