From f134b33cbf2c49bb381440c08260e6f20daf4957 Mon Sep 17 00:00:00 2001 From: Tam Nguyen Duc <1218621+tamnd@users.noreply.github.com> Date: Tue, 20 Oct 2026 14:37:15 +0700 Subject: [PATCH 1/2] Add the changelog entry for #445 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 045c7347..9861be09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ All changes that a user can see are in this file. The version is 0.M.patch, wher ### Fixed - A `LATERAL` relation in a nested loop no longer keeps the rows of every run until the query ends. This stopped the server with no memory in the regression tests `join` and `subselect` (#444). +- A correlated subquery finds its rows through an index of a column for `=` with an expression of the outer columns, not only with an outer column (#445). ## 0.1.51 (2026-10-20) From 07e44e8920f73ed55da627eb04b952270f5acb8c Mon Sep 17 00:00:00 2001 From: Tam Nguyen Duc <1218621+tamnd@users.noreply.github.com> Date: Tue, 20 Oct 2026 14:37:15 +0700 Subject: [PATCH 2/2] Run a LATERAL part once when it reads no relation of the left side of its join --- crates/rupg-exec/src/scan.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/rupg-exec/src/scan.rs b/crates/rupg-exec/src/scan.rs index fb4bf5cf..ecc12351 100644 --- a/crates/rupg-exec/src/scan.rs +++ b/crates/rupg-exec/src/scan.rs @@ -240,9 +240,9 @@ impl Tables { index } - /// True when a relation of the part reads a relation outside the part. - fn depends(&self, relations: &[usize]) -> bool { - relations.iter().any(|r| self.needs[*r].iter().any(|n| !relations.contains(n))) + /// True when a relation of the part `relations` reads a relation of `left`. + fn depends_on(&self, relations: &[usize], left: &[usize]) -> bool { + relations.iter().any(|r| self.needs[*r].iter().any(|n| left.contains(n))) } } @@ -644,7 +644,8 @@ impl Scan<'_, '_> { conds: Vec<&'q Expr>, context: &[usize], ) -> Result>> { - if !self.tables.depends(input.right_relations) { + // A part that reads only relations outside the join, which `context` holds, runs once for all the tuples of the left side. + if !self.tables.depends_on(input.right_relations, input.left_relations) { input.right = self.item_tuples(item, conds, context)?; return join(input, self.tables, self.test); }