Skip to content

Commit

Permalink
small optimisation that makes big difference
Browse files Browse the repository at this point in the history
Before optimisation:
BenchmarkPlanner/large_cases.txt-v4-16  70786    167749 ns/op   74315 B/op    1618 allocs/op
BenchmarkPlanner/large_cases.txt-v4-16  70998    168734 ns/op   74303 B/op    1618 allocs/op

After:
BenchmarkPlanner/large_cases.txt-v4-16  76375    156411 ns/op   67752 B/op    1376 allocs/op
BenchmarkPlanner/large_cases.txt-v4-16  76207    157553 ns/op   67816 B/op    1376 allocs/op

Signed-off-by: Andres Taylor <andres@planetscale.com>
  • Loading branch information
systay committed Jan 25, 2021
1 parent b062f53 commit 7febcf6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 0 additions & 1 deletion go/vt/vtgate/planbuilder/querygraph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ func TestQueryGraph(t *testing.T) {
require.NoError(t, err)
qgraph, err := createQGFromSelect(tree.(*sqlparser.Select), semTable)
require.NoError(t, err)
fmt.Println(qgraph.testString())
assert.Equal(t, tc.output, qgraph.testString())
utils.MustMatch(t, tc.output, qgraph.testString(), "incorrect query graph")
})
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/route_planning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestMergeJoins(t *testing.T) {
}}
for i, tc := range tests {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
result := tryMerge(tc.l, tc.r, tc.predicates, &semantics.SemTable{})
result := tryMerge(tc.l, tc.r, tc.predicates, semantics.NewSemTable())
assert.Equal(t, tc.expected, result)
})
}
Expand Down
12 changes: 11 additions & 1 deletion go/vt/vtgate/semantics/semantic_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ type (
}
)

// NewSemTable creates a new empty SemTable
func NewSemTable() *SemTable {
return &SemTable{exprDependencies: map[sqlparser.Expr]TableSet{}}
}

// TableSetFor returns the bitmask for this particular tableshoe
func (st *SemTable) TableSetFor(t table) TableSet {
for idx, t2 := range st.Tables {
Expand All @@ -54,7 +59,10 @@ func (st *SemTable) TableSetFor(t table) TableSet {

// Dependencies return the table dependencies of the expression.
func (st *SemTable) Dependencies(expr sqlparser.Expr) TableSet {
var deps TableSet
deps, found := st.exprDependencies[expr]
if found {
return deps
}

This comment has been minimized.

Copy link
@harshit-gangal

harshit-gangal Jan 26, 2021

Member

👍


_ = sqlparser.Walk(func(node sqlparser.SQLNode) (kontinue bool, err error) {
colName, ok := node.(*sqlparser.ColName)
Expand All @@ -65,6 +73,8 @@ func (st *SemTable) Dependencies(expr sqlparser.Expr) TableSet {
return true, nil
}, expr)

st.exprDependencies[expr] = deps

return deps
}

Expand Down

0 comments on commit 7febcf6

Please sign in to comment.