Path: redb/redb.Tests.Integration/Tests/SqlitePro/SqliteProStreamsPageJoinTests.cs Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Tests.Integration/Tests/SqlitePro/SqliteProStreamsPageJoinTests.cs ---- using redb.Tests.Integration.Fixtures; using redb.Tests.Integration.Models; namespace redb.Tests.Integration.Tests.SqlitePro; /// /// The page of the streams form reads the page the CTE cut first and its objects by primary key after it: the CTE is /// joined to _objects by CROSS JOIN, whose order SQLite keeps. With a plain JOIN and no planner statistics SQLite /// put _objects of the scheme on the outer loop and ran the CTE again for each of its rows, so a page of a /// Contains over 122 000 objects did not finish in 900 s while the count of the same filter took 3 ms. /// [Collection("SqlitePro")] public class SqliteProStreamsPageJoinTests { private readonly redb.Core.IRedbService _redb; public SqliteProStreamsPageJoinTests(SqliteProFixture fixture) => _redb = fixture.Redb; [Fact] public async Task StreamsPage_JoinsItsObjects_AfterTheCte() { var restore = _redb.Configuration.EnablePvtPrefilter; try { _redb.UpdateConfiguration(c => c.EnablePvtPrefilter = true); var sql = await _redb.Query() .Where(e => e.Skills!.Contains("Azure")) .OrderByRedb(o => o.Id) .Take(100) .ToSqlStringAsync(); sql.Should().Contain("FROM pvt_cte\nCROSS JOIN _objects o ON pvt_cte._id_object = o._id", "the page cut by the CTE drives and its objects are read by primary key:\n{0}", sql); } finally { _redb.UpdateConfiguration(c => c.EnablePvtPrefilter = restore); } } [Fact] public async Task LeadingForm_KeepsTheWalkOnTheOuterLoop() { var restore = _redb.Configuration.EnablePvtPrefilter; try { _redb.UpdateConfiguration(c => c.EnablePvtPrefilter = true); // Age >= 30 rejects NULL: its LEFT JOIN becomes an inner join SQLite could lead with, ahead of the walk. var sql = await _redb.Query() .Where(e => e.Position != "" && e.Age >= 30 && e.Salary > 70000m) .OrderByDescending(e => e.Salary).ThenByRedb(o => o.Id) .Take(100) .ToSqlStringAsync(); sql.Should().Contain("pvt_walk", "the page sorted by Salary is led by the walk of its index of values:\n{0}", sql) .And.Contain("CROSS JOIN _objects o_src ON o_src._id = d._id_object", "the walked entries stay the outer loop:\n{0}", sql); } finally { _redb.UpdateConfiguration(c => c.EnablePvtPrefilter = restore); } } }