{
  "id": 18854983,
  "title": "One SQL predicate, eleven implementations: unifying them and what our differential harness caught",
  "url": "https://urgent.news/2026/11/08/one-sql-predicate-eleven-implementations-unifying-them-and-what-our",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-08T04:11:51.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/motedb/one-sql-predicate-eleven-implementations-unifying-them-and-what-our-differential-harness-caught-5b8b"
  },
  "original_language": "en",
  "account": "This story explains how paying down technical debt in a query engine, specifically duplicated semantics, was achieved through building a testing harness. The focus is on MoteDB, a Rust-based embedded multimodal database for robotics workloads, but the pattern applies to any fast-growing engine.\n\nThroughout the development of MoteDB, the same SQL predicate, evaluated by different code paths, returned different answers. This inconsistency stemmed from SQL comparison semantics living in 11 separate implementations. These included the interpreter's eval_binary_op, the fast per-row evaluators, the compiled WHERE path with hand-rolled arms per operator, vectorized scan leaves, JOIN predicate pushdown, aggregate pre-filter, and two inline closures.\n\nTo address this issue, the team took the following steps:\n\n1. Lock the present before changing it: Characteristic tests were written to lock the current behavior of each path before making any changes. This allowed the team to enumerate every behavior and explicitly decide which changes to implement.\n\n2. One semantics layer: An effort was made to have everything route through a single module, reducing the number of implementations from 11 to one. This module defined a single comparison function, Cmp3, and a coercion pair built on Cow to avoid unnecessary allocations. The choice between equality and ordering operations was made once, ensuring consistent behavior for incomparable types.\n\n3. The differential harness: A differential harness was created to generate random predicates with mixed types, NULLs, boundary values, bracketed vector literals, ISO timestamps, and run them through nine execution paths. Any disagreement between paths would fail the run, printing the seed, predicate, and all nine answers. This allowed the team to catch seven pre-existing divergences present in the released version 0.17.\n\nOne notable divergence involved hash-set normalization for IN lists, where pure-numeric text was incorrectly parsed as a microsecond timestamp. The differential harness revealed that the equality route did not parse 7 as a timestamp, while the hash route did, contradicting the same predicate across paths. The verdict was to stop parsing pure-numeric text as timestamps in the equality route, and the characteristic tests were amended accordingly.\n\nIn conclusion, the story demonstrates how a testing harness can identify and unify duplicated semantics in a query engine, leading to more consistent behavior across implementations, and improving overall code quality.",
  "summary": "This is a story about paying down the most expensive kind of technical debt in a query engine — duplicated semantics — and the testing harness that made it safe. It comes from building MoteDB , an embedded multimodal database in Rust for robotics workloads, but the pattern applies to any engine that grew fast. The bug that kept coming back Through four rounds of pre-release bug hunting on v0.17,…",
  "key_points": [
    "Eleven separate implementations of SQL predicate evaluation in MoteDB caused inconsistent results",
    "Team wrote characteristic tests to lock current behavior before making changes",
    "Differential harness caught seven pre-existing divergences in version 0.17"
  ],
  "editors_take": "Consolidating fragmented SQL comparison logic into a single module eliminates the semantic inconsistencies that arise when multiple execution paths independently interpret the same predicate.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}