Skip to content

Commit 25d94b4

Browse files
committed
Copy children to newChildren to avoid nil child
1 parent d32c9ce commit 25d94b4

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

enginetest/queries/script_queries.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11757,6 +11757,29 @@ select * from t1 except (
1175711757
},
1175811758
},
1175911759
},
11760+
{
11761+
// https://github.com/dolthub/dolt/issues/9789
11762+
Name: "order by on empty set from joins",
11763+
SetUpScript: []string{
11764+
"create table t0(c0 int, primary key(c0))",
11765+
"create table t1(c0 int)",
11766+
"create table t2(c0 int)",
11767+
"create table t3(c0 int)",
11768+
"insert into t0 values (1)",
11769+
"insert into t1 values (1)",
11770+
"insert into t2 values (1)",
11771+
},
11772+
Assertions: []ScriptTestAssertion{
11773+
{
11774+
Query: "select * from t2, t3, t0, t1",
11775+
Expected: []sql.Row{},
11776+
},
11777+
{
11778+
Query: "select * from t2, t3, t0, t1 order by t0.c0",
11779+
Expected: []sql.Row{},
11780+
},
11781+
},
11782+
},
1176011783
}
1176111784

1176211785
var SpatialScriptTests = []ScriptTest{

sql/analyzer/replace_sort.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,10 @@ func replaceIdxSortHelper(ctx *sql.Context, scope *plan.Scope, node sql.Node, so
145145
}
146146

147147
allSame := transform.SameTree
148-
newChildren := make([]sql.Node, len(node.Children()))
149-
for i, child := range node.Children() {
148+
children := node.Children()
149+
newChildren := make([]sql.Node, len(children))
150+
copy(newChildren, children)
151+
for i, child := range children {
150152
var err error
151153
same := transform.SameTree
152154
switch c := child.(type) {
@@ -213,14 +215,11 @@ func replaceIdxSortHelper(ctx *sql.Context, scope *plan.Scope, node sql.Node, so
213215
c.IsReversed = true
214216
}
215217
}
216-
217218
newChildren[i], err = c.WithChildren(newLeft, newRight)
218219
if err != nil {
219220
return nil, transform.SameTree, err
220221
}
221222
allSame = false
222-
default:
223-
newChildren[i] = c
224223
}
225224
if err != nil {
226225
return nil, transform.SameTree, err

0 commit comments

Comments
 (0)