Skip to content

Commit cee8782

Browse files
re-try
1 parent 017ff36 commit cee8782

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

internal/stackql/astanalysis/earlyanalysis/ast_expand.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,19 @@ func (v *indirectExpandAstVisitor) processIndirect(node sqlparser.SQLNode, indir
152152
if err != nil {
153153
return nil //nolint:nilerr //TODO: investigate
154154
}
155+
// Filter parent WHERE params to only pass down unqualified (alias-free) entries.
156+
// Aliased params like "r.org" reference specific outer tables and must not
157+
// leak into child indirection analysis, where the alias would be unresolvable.
158+
filteredWhereParams := parserutil.NewParameterMap()
159+
for k, val := range v.whereParams.GetMap() {
160+
if k.Alias() == "" {
161+
filteredWhereParams.Set(k, val) //nolint:errcheck // best effort
162+
}
163+
}
155164
childAnalyzer, err := NewEarlyScreenerAnalyzer(
156165
v.primitiveGenerator,
157166
v.annotatedAST,
158-
v.whereParams.Clone(),
167+
filteredWhereParams,
159168
v.indirectionDepth+1,
160169
)
161170
if err != nil {

internal/stackql/router/parameter_router.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,7 @@ func (pr *standardParameterRouter) route(
531531
}
532532
t, ok := pr.tablesAliasMap[alias]
533533
if !ok {
534-
// Skip params from parent queries whose alias is not in the current scope.
535-
// This occurs when indirections (views, subqueries) inherit parent WHERE params.
536-
continue
534+
return nil, fmt.Errorf("alias '%s' does not map to any table expression", alias)
537535
}
538536
if t == tb {
539537
ref, ok := pr.colRefs[k]
@@ -551,8 +549,7 @@ func (pr *standardParameterRouter) route(
551549
}
552550
t, ok := pr.tablesAliasMap[alias]
553551
if !ok {
554-
// Skip params from parent queries whose alias is not in the current scope.
555-
continue
552+
return nil, fmt.Errorf("alias '%s' does not map to any table expression", alias)
556553
}
557554
if t == tb {
558555
ref, ok := pr.colRefs[k]

0 commit comments

Comments
 (0)