Skip to main content

Column

Struct Column 

Source
pub struct Column {
    pub logical_type: LogicalTypeID,
    pub physical_type: PhysicalTypeID,
    pub table_id: u64,
    pub col_idx: u32,
    pub file_name: String,
    pub file_handle: FileHandle,
    pub buffer_manager: Arc<Mutex<BufferManager>>,
    pub compression_type: CompressionType,
    pub value_size: usize,
    pub num_values: u64,
    pub num_pages: u64,
    pub page_row_offsets: Vec<u64>,
}
Expand description

A column stores values of a single type across multiple pages.

The column owns a dedicated file (named col_{table_id}_{col_idx}) and uses the BufferManager for all page-level I/O with automatic caching.

Fields§

§logical_type: LogicalTypeID

The logical type of values stored in this column.

§physical_type: PhysicalTypeID

Physical type derived from logical_type.

§table_id: u64

The owning table ID (used to construct the file name).

§col_idx: u32

The column index within the table.

§file_name: String

File name used in the BufferManager’s file registry.

§file_handle: FileHandle

File handle for low-level page I/O.

§buffer_manager: Arc<Mutex<BufferManager>>

Shared buffer manager for page caching and eviction.

§compression_type: CompressionType

Compression algorithm applied to serialized values.

§value_size: usize

Byte size of the serialized primitive value (0 for variable-length types).

§num_values: u64

Total number of values stored.

§num_pages: u64

Number of pages allocated.

§page_row_offsets: Vec<u64>

Cumulative value count per page (for binary-search lookup). page_row_offsets[i] = the global row index of the first value in page i.

Implementations§

Source§

impl Column

Source

pub fn new( logical_type: LogicalTypeID, table_id: u64, col_idx: u32, db_path: &Path, buffer_manager: Arc<Mutex<BufferManager>>, page_size: usize, ) -> Self

Create a new column backed by a file in db_path.

The file is named col_{table_id}_{col_idx} and registered with the BufferManager automatically.

compression_type determines the compression algorithm applied to serialized values. Use CompressionType::Uncompressed for no compression.

Source

pub fn with_compression( logical_type: LogicalTypeID, table_id: u64, col_idx: u32, db_path: &Path, buffer_manager: Arc<Mutex<BufferManager>>, page_size: usize, compression_type: CompressionType, ) -> Self

Create a new column with a specific compression algorithm.

Source

pub fn append_value(&mut self, value: &Value) -> Result<()>

Append a single value to the column.

Append a single value to the column.

Automatically allocates a new page when the current one is full or when the current page has reached the maximum values per page (256).

Serialized values are compressed according to self.compression_type.

Source

pub fn get_value(&self, row_idx: u64) -> Result<Value>

Get a single value by row index.

Source

pub fn scan_values(&self, start: u64, count: u64) -> Result<Vec<Value>>

Scan a range of values (inclusive of start, exclusive of start + count).

Source

pub fn read_value_bytes(&self, row_idx: u64) -> Result<Vec<u8>>

Read the raw serialised bytes of a single value (useful for compression).

Source

pub fn flush(&self) -> Result<()>

Flush the column’s dirty pages to disk.

Source

pub fn save_metadata(&self) -> Result<()>

Save column metadata to a .meta sidecar file so it can be reconstructed after a crash or restart without scanning every page.

Layout (all little-endian): magic: 4 bytes b“CMET“ version: u32 logical_type: u32 table_id: u64 col_idx: u32 num_values: u64 num_pages: u64 page_row_offsets: [u64; num_pages]

Source

pub fn load_metadata(&mut self) -> Result<bool>

Load column metadata from a .meta sidecar file.

Returns Ok(true) if metadata was loaded successfully, Ok(false) if no metadata file exists (fresh column).

Trait Implementations§

Source§

impl Debug for Column

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more