Skip to content

Commit 98309db

Browse files
committed
explicitly force evaluation of missing topics fields to BSON null in order to work around a weird MongoDB table join pessimization
1 parent c0d88ec commit 98309db

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div align="center">
22

3-
<strong><em><code>unidoc</code></em></strong><br><small><code>0.1.4</code></small>
3+
<strong><em><code>unidoc</code></em></strong><br><small><code>0.1.5</code></small>
44

55
[![ci build status](https://github.com/kelvin13/swift-unidoc/actions/workflows/build.yml/badge.svg)](https://github.com/kelvin13/swift-unidoc/actions/workflows/build.yml)
66

Sources/UnidocQueries/Queries/WideQuery.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,19 @@ extension WideQuery:VolumeLookupQuery
7171
{
7272
$0[let: id] = Output.Principal[.master] / Volume.Master[.id]
7373

74-
$0[let: topic] = Output.Principal[.master] / Volume.Master[.group]
74+
$0[let: topic] = .expr
75+
{
76+
// For reasons I don’t understand, MongoDB will fail to use any indexes
77+
// whatsoever for this join if the `group` field isn’t present in the
78+
// master document. (Which is true of most of them.) The
79+
// least-intrusive way to fix this is to use an optional-coalescence
80+
// expression to “evaluate” the missing field to `null`.
81+
$0[.coalesce] =
82+
(
83+
Output.Principal[.master] / Volume.Master[.group],
84+
Never??.some(nil)
85+
)
86+
}
7587
$0[let: min] = Output.Principal[.names] / Volume.Names[.planes_autogroup]
7688
$0[let: max] = Output.Principal[.names] / Volume.Names[.planes_max]
7789
}

0 commit comments

Comments
 (0)