Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions enginetest/queries/trigger_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -3898,6 +3898,26 @@ end;
},
},
},
{
// https://github.com/dolthub/dolt/issues/10175
Name: "trigger with joined view (views are subquery aliases)",
SetUpScript: []string{
"CREATE TABLE t_1 (id BINARY(2), data VARCHAR(10));",
"CREATE TABLE t_2 (id BINARY(2), other BINARY(2), status TINYINT UNSIGNED default 0);",
"CREATE TABLE queue (id BINARY(2), data varchar(10));",
"CREATE VIEW v AS SELECT t_2.id, t_1.data, status FROM t_2 inner join t_1 on other=t_1.id;",
"INSERT INTO t_1 (id, data) VALUES (0xC336, 'Test');",
"INSERT INTO t_2 (id, other) VALUES ROW(0x3E32, 0xC336), ROW(0xEDC1, 0xC336), ROW(0x9B15, 0xC336);",
"CREATE TRIGGER t_change_status after UPDATE ON t_2 FOR EACH ROW INSERT INTO queue(id, data) select id, data from v where v.id = NEW.id;",
"UPDATE t_2 SET status = 1 WHERE id = 0x3E32;",
},
Assertions: []ScriptTestAssertion{
{
Query: `SELECT * FROM queue`,
Expected: []sql.Row{{[]uint8{0x3e, 0x32}, "Test"}},
},
},
},
}

var TriggerCreateInSubroutineTests = []ScriptTest{
Expand Down
11 changes: 6 additions & 5 deletions sql/analyzer/fix_exec_indexes.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,17 +341,18 @@ func (s *idxScope) visitChildren(n sql.Node) error {
}
case *plan.SubqueryAlias:
sqScope := s.copy()
if s.inTrigger() {
// TODO: this might not necessarily be true. But we do need the trigger scope(s) to be passed to the child
// nodes during rowexec, where there's currently no easy way to separate out the trigger scopes from the
// other scopes because it's all one parent row
n.OuterScopeVisibility = true
}
if !n.OuterScopeVisibility && !n.IsLateral {
// TODO: this should not apply to subqueries inside of lateral joins
// Subqueries with no visibility have no parent scopes. Lateral
// join subquery aliases continue to enjoy full visibility.
sqScope.parentScopes = sqScope.parentScopes[:0]
sqScope.lateralScopes = sqScope.lateralScopes[:0]
for _, p := range s.parentScopes {
if p.triggerScope {
sqScope.parentScopes = append(sqScope.parentScopes, p)
}
}
}
newC, cScope, err := assignIndexesHelper(n.Child, sqScope)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion sql/analyzer/resolve_subqueries.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func analyzeSubqueryAlias(ctx *sql.Context, a *Analyzer, sqa *plan.SubqueryAlias
return newn, transform.NewTree, err
}

// cacheSubqueryAlisesInJoins will look for joins against subquery aliases that
// cacheSubqueryAliasesInJoins will look for joins against subquery aliases that
// will repeatedly execute the subquery, and will insert a *plan.CachedResults
// node on top of those nodes. The left-most child of a join root is an exception
// that cannot be cached.
Expand Down
Loading