Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit 2ab5a2f

Browse files
committed
add session variable to activate in-memory inner joins
Signed-off-by: Miguel Molina <[email protected]>
1 parent 2308dd3 commit 2ab5a2f

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

sql/plan/innerjoin.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
)
1111

1212
const experimentalInMemoryJoinKey = "EXPERIMENTAL_IN_MEMORY_JOIN"
13+
const inMemoryJoinSessionVar = "inmemory_joins"
1314

1415
var useInMemoryJoins = os.Getenv(experimentalInMemoryJoinKey) != ""
1516

@@ -66,8 +67,14 @@ func (j *InnerJoin) RowIter(ctx *sql.Context) (sql.RowIter, error) {
6667
return nil, err
6768
}
6869

70+
var inMemorySession bool
71+
_, val := ctx.Get(inMemoryJoinSessionVar)
72+
if val != nil {
73+
inMemorySession = true
74+
}
75+
6976
var iter sql.RowIter
70-
if useInMemoryJoins {
77+
if useInMemoryJoins || inMemorySession {
7178
r, err := j.Right.RowIter(ctx)
7279
if err != nil {
7380
span.Finish()

sql/plan/innerjoin_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ func TestInnerJoin(t *testing.T) {
3939
}
4040

4141
func TestInMemoryInnerJoin(t *testing.T) {
42-
useInMemoryJoins = true
43-
defer func() {
44-
useInMemoryJoins = false
45-
}()
46-
4742
require := require.New(t)
4843
finalSchema := append(lSchema, rSchema...)
4944

@@ -62,7 +57,14 @@ func TestInMemoryInnerJoin(t *testing.T) {
6257

6358
require.Equal(finalSchema, j.Schema())
6459

65-
rows := collectRows(t, j)
60+
ctx := sql.NewEmptyContext()
61+
ctx.Set(inMemoryJoinSessionVar, sql.Text, "true")
62+
63+
iter, err := j.RowIter(ctx)
64+
require.NoError(err)
65+
66+
rows, err := sql.RowIterToRows(iter)
67+
require.NoError(err)
6668
require.Len(rows, 2)
6769

6870
require.Equal([]sql.Row{

0 commit comments

Comments
 (0)