From aed255d2e6423a0f35bccbac46b1bc69c453ad0f Mon Sep 17 00:00:00 2001 From: Pere Diaz Bou Date: Mon, 6 Oct 2025 13:39:16 +0200 Subject: [PATCH] core/mvcc: implement PartialOrd for RowId --- core/mvcc/database/mod.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/core/mvcc/database/mod.rs b/core/mvcc/database/mod.rs index f00690aff..27f7fd76b 100644 --- a/core/mvcc/database/mod.rs +++ b/core/mvcc/database/mod.rs @@ -83,7 +83,7 @@ impl std::fmt::Display for MVTableId { } } -#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub struct RowID { /// The table ID. Analogous to table's root page number. pub table_id: MVTableId, @@ -2178,3 +2178,21 @@ impl Debug for CommitState { } } } + +impl PartialOrd for RowID { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for RowID { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + // Make sure table id is first comparison so that we sort first by table_id and then by + // rowid. Due to order of the struct, table_id is first which is fine but if we were to + // change it we would bring chaos. + match self.table_id.cmp(&other.table_id) { + std::cmp::Ordering::Equal => self.row_id.cmp(&other.row_id), + ord => ord, + } + } +}