diff options
| author | Alexander_Kabui <alexanderkabui@proton.me> | 2026-10-13 15:11:33 +0300 |
|---|---|---|
| committer | Alexander_Kabui <alexanderkabui@proton.me> | 2026-10-14 07:27:03 +0300 |
| commit | 77924c927ec069042d8da224e49fc8a60455f170 (patch) | |
| tree | 5bfecca19fbfdd7d20a9711a0ab65f9161d2686d /src | |
| parent | 53c3f26ec2fdf209876a8a8eab561acc6fd755d4 (diff) | |
| download | genenetwork4-77924c927ec069042d8da224e49fc8a60455f170.tar.gz | |
* src/indexer/rows.rs (crawl order): match the merge's byte order.
The crawl ordered by dataset with the Name column's utf8mb4_general_ci collation while merge_streams compares labels by Rust byte order, so a label could arrive in two non-contiguous runs and the second begin_dataset would drop the first run's rows. Pin COLLATE utf8mb4_bin on both ORDER BY clauses so the SQL order matches the merge.
Diffstat (limited to 'src')
| -rw-r--r-- | src/indexer/rows.rs | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/src/indexer/rows.rs b/src/indexer/rows.rs index 69b94cc..7c9d5a4 100644 --- a/src/indexer/rows.rs +++ b/src/indexer/rows.rs @@ -16,12 +16,18 @@ //! # Streaming, dataset-grouped crawl //! //! [`stream_dataset_groups`] never materialises the crawl. Each query is -//! executed in its own producer thread with `ORDER BY dataset`; the merge -//! consumes the two sorted streams and hands the caller **one dataset at -//! a time** through a [`DatasetSink`], whose `begin_dataset` / `row` / -//! `end_dataset` callbacks see rows one at a time. The only per-dataset -//! state the caller keeps is bounded by the largest dataset, not by the -//! whole crawl. +//! executed in its own producer thread with `ORDER BY dataset COLLATE +//! utf8mb4_bin`; the merge consumes the two sorted streams and hands the +//! caller **one dataset at a time** through a [`DatasetSink`], whose +//! `begin_dataset` / `row` / `end_dataset` callbacks see rows one at a +//! time. The only per-dataset state the caller keeps is bounded by the +//! largest dataset, not by the whole crawl. +//! +//! The `Name` columns are `utf8mb4_general_ci`, which is *case-insensitive*. +//! Ordering by that collation can interleave the rows of two labels that +//! differ only by case, breaking the "each label's rows are contiguous" +//! assumption the byte-order merge below relies on. Pinning +//! `COLLATE utf8mb4_bin` makes the SQL order match the merge's byte order. use std::sync::mpsc::{Receiver, Sender}; @@ -163,7 +169,7 @@ fn genes_sql() -> String { INNER JOIN ProbeSet ON ProbeSet.Id = ProbeSetXRef.ProbeSetId \ LEFT JOIN Geno ON ProbeSetXRef.Locus = Geno.Name AND Geno.SpeciesId = Species.Id \ WHERE {GENE_PUBLIC_FILTER} \ - ORDER BY dataset" + ORDER BY dataset COLLATE utf8mb4_bin" ) } @@ -197,7 +203,7 @@ fn phenotypes_sql(filtered: bool) -> String { INNER JOIN Publication ON PublishXRef.PublicationId = Publication.Id \ LEFT JOIN Geno ON PublishXRef.Locus = Geno.Name AND Geno.SpeciesId = Species.Id\ {where_clause} \ - ORDER BY dataset" + ORDER BY dataset COLLATE utf8mb4_bin" ) } @@ -387,3 +393,22 @@ fn drain_label( } } } + +#[cfg(test)] +mod tests { + use super::*; + + /// The stream order must match the byte order `merge_streams` compares + /// with. The `Name` columns are `utf8mb4_general_ci`; without the + /// binary collation a case-variant label could interleave and split a + /// dataset group across two `begin_dataset` calls. + #[test] + fn crawl_orders_datasets_bin_collated() { + for sql in [genes_sql(), phenotypes_sql(true), phenotypes_sql(false)] { + assert!( + sql.contains("ORDER BY dataset COLLATE utf8mb4_bin"), + "crawl must order by the binary collation: {sql}" + ); + } + } +} |
