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
1 change: 0 additions & 1 deletion enginetest/memory_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,6 @@ func TestIntegrationQueryPlans(t *testing.T) {
}

func TestImdbQueryPlans(t *testing.T) {
t.Skip("tests are too slow")
harness := enginetest.NewMemoryHarness("nativeIndexes", 1, nil)
enginetest.TestImdbPlans(t, harness)
}
Expand Down
56,156 changes: 29,622 additions & 26,534 deletions enginetest/queries/imdb_plans.go

Large diffs are not rendered by default.

482 changes: 482 additions & 0 deletions enginetest/queries/query_plans.go

Large diffs are not rendered by default.

21 changes: 19 additions & 2 deletions enginetest/scriptgen/setup/scripts/imdb
Original file line number Diff line number Diff line change
Expand Up @@ -306,62 +306,79 @@ create index role_id_cast_info on cast_info(role_id);
exec
analyze table aka_name update histogram on id using data '{"row_count": 900662}';
----

exec
analyze table aka_title update histogram on id using data '{"row_count": 361376}';
----

exec
analyze table cast_info update histogram on id using data '{"row_count": 36124530}';
----

exec
analyze table char_name update histogram on id using data '{"row_count": 3136382}';
----

exec
analyze table company_name update histogram on id using data '{"row_count": 234825}';
----

exec
analyze table company_type update histogram on id using data '{"row_count": 4}';
----

exec
analyze table complete_cast update histogram on id using data '{"row_count": 135086}';
----

exec
analyze table comp_cast_type update histogram on id using data '{"row_count": 4}';
----

exec
analyze table info_type update histogram on id using data '{"row_count": 113}';
----

exec
analyze table keyword update histogram on id using data '{"row_count": 134110}';
----

exec
analyze table kind_type update histogram on id using data '{"row_count": 7}';
----

exec
analyze table link_type update histogram on id using data '{"row_count": 18}';
----

exec
analyze table movie_companies update histogram on id using data '{"row_count": 2604067}';
----

exec
analyze table movie_info update histogram on id using data '{"row_count": 14355706}';
----

exec
analyze table movie_info_idx update histogram on id using data '{"row_count": 1380035}';
----

exec
analyze table movie_keyword update histogram on id using data '{"row_count": 4523930}';
----

exec
analyze table movie_link update histogram on id using data '{"row_count": 29997}';
----

exec
analyze table name update histogram on id using data '{"row_count": 4167453}';
----

exec
analyze table person_info update histogram on id using data '{"row_count": 2024951}';
----

exec
analyze table row_type update histogram on id using data '{"row_count": 12}';
----
analyze table title update histogram on id using data '{"row_count": 2527799}';
----
19 changes: 19 additions & 0 deletions enginetest/scriptgen/setup/setup_data.sg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions sql/memo/expr_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"fmt"
"io"
"iter"
"maps"
"slices"
"sort"
"strings"
Expand Down Expand Up @@ -95,14 +94,18 @@ func (e *ExprGroup) Iter() iter.Seq[RelExpr] {

// children returns a unioned list of child ExprGroup for
// every logical plan in this group.
func (e *ExprGroup) children() iter.Seq[*ExprGroup] {
func (e *ExprGroup) children(yield func(group *ExprGroup) bool) {
children := make(map[GroupId]*ExprGroup)
for n := range e.Iter() {
for _, n := range n.Children() {
children[n.Id] = n
if _, exists := children[n.Id]; !exists {
children[n.Id] = n
if !yield(n) {
return
}
}
}
}
return maps.Values(children)
}

// updateBest updates a group's Best to the given expression if the cost is lower than the current best.
Expand Down
3 changes: 2 additions & 1 deletion sql/memo/join_order_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ func (j *joinOrderBuilder) ReorderJoin(n sql.Node) {
j.m.Tracer.Log("Successfully built single lookup plan")
return
}
j.m.Tracer.Log("Failed to build single lookup plan, falling back to exhaustive enumeration")
j.m.Tracer.Log("Failed to identify an ideal join plan, exhaustive enumeration would be too slow, so preserve the join order in the original query")
return
} else if j.hasCrossJoin {
j.m.Tracer.Log("Join contains cross joins, attempting single lookup plan first")
// Rely on FastReorder to avoid plans that drop filters with cross joins
Expand Down
4 changes: 2 additions & 2 deletions sql/memo/memo.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ func (m *Memo) String() string {
continue
}
exprs[int(TableIdForSource(g.Id))] = g.String()
newGroups = slices.AppendSeq(newGroups, g.children())
newGroups = slices.AppendSeq(newGroups, g.children)
}
groups = newGroups
}
Expand Down Expand Up @@ -678,7 +678,7 @@ func (m *Memo) LogCostDebugString() {
}

exprs[int(TableIdForSource(g.Id))] = g.CostTreeString(prefix)
newGroups = slices.AppendSeq(newGroups, g.children())
newGroups = slices.AppendSeq(newGroups, g.children)
}
groups = newGroups
}
Expand Down
2 changes: 1 addition & 1 deletion sql/memo/rel_props.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func (m *Memo) CardMemoGroups(ctx *sql.Context, g *ExprGroup) {
if g.RelProps.stat != nil {
return
}
for g := range g.children() {
for g := range g.children {
m.CardMemoGroups(ctx, g)
}
s := m.statsForRel(ctx, g.First)
Expand Down
2 changes: 1 addition & 1 deletion sql/memo/select_hints.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (o joinOrderHint) build(grp *ExprGroup) {
}
o.groups[grp.Id] = s

for g := range grp.children() {
for g := range grp.children {
if _, ok := o.groups[g.Id]; !ok {
// avoid duplicate work
o.build(g)
Expand Down
Loading