Skip to content

Commit bbd0659

Browse files
authored
Merge pull request #3263 from dolthub/angela/nested_query
Do not prune tables in semi-joins
2 parents 31b74b2 + 378951e commit bbd0659

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

enginetest/queries/script_queries.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13371,6 +13371,20 @@ select * from t1 except (
1337113371
},
1337213372
},
1337313373
},
13374+
{
13375+
// https://github.com/dolthub/dolt/issues/9951
13376+
Name: "Do not prune tables that are part of a semi-join",
13377+
SetUpScript: []string{
13378+
"create table t0(id int primary key, name longtext, description longtext, comment longtext, created_at timestamp(6), archived bool)",
13379+
"insert into t0 values (1, 'first', 'abc', 'def', '2025-10-14 10:00:00', b'0')",
13380+
},
13381+
Assertions: []ScriptTestAssertion{
13382+
{
13383+
Query: "select * from (select id, name, description, archived from t0 as test0 where (id in (select id from t0))) as dummy_alias order by dummy_alias.name asc;",
13384+
Expected: []sql.Row{{1, "first", "abc", 0}},
13385+
},
13386+
},
13387+
},
1337413388
}
1337513389

1337613390
var SpatialScriptTests = []ScriptTest{

sql/analyzer/symbol_resolution.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func pruneTables(ctx *sql.Context, a *Analyzer, n sql.Node, s *plan.Scope, sel R
8989
case *plan.ResolvedTable:
9090
return pruneTableCols(n, parentCols, parentStars, unqualifiedStar)
9191
case *plan.JoinNode:
92-
if n.JoinType().IsPhysical() || n.JoinType().IsUsing() {
92+
if n.JoinType().IsPhysical() || n.JoinType().IsUsing() || n.JoinType().IsSemi() {
9393
return n, transform.SameTree, nil
9494
}
9595
// we cannot push projections past lateral joins as columns not in the projection,

0 commit comments

Comments
 (0)