Skip to content

Commit 0d3d5eb

Browse files
author
James Cor
committed
fix and some tests
1 parent 0c4d507 commit 0d3d5eb

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

enginetest/queries/script_queries.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8506,6 +8506,59 @@ where
85068506
},
85078507
},
85088508
},
8509+
{
8510+
Name: "merge join optimization",
8511+
Dialect: "mysql",
8512+
SetUpScript: []string{
8513+
"create table t1 (i int primary key);",
8514+
"create table t2 (j int primary key);",
8515+
"insert into t1 values (1), (2), (3);",
8516+
"insert into t2 values (2), (3), (4);",
8517+
8518+
"create table t3 (i int, j int, primary key (i, j));",
8519+
"create table t4 (x int, y int, primary key (x, y));",
8520+
"insert into t3 values (1, 1), (2, 2), (3, 3);",
8521+
"insert into t4 values (2, 2), (3, 3), (4, 4);",
8522+
},
8523+
Assertions: []ScriptTestAssertion{
8524+
{
8525+
Query: "select /*+ MERGE_JOIN(t1, t2) */ * from t1 join t2 on t1.i = t2.j order by t1.i;",
8526+
Expected: []sql.Row{
8527+
{2, 2},
8528+
{3, 3},
8529+
},
8530+
},
8531+
{
8532+
Query: "select /*+ MERGE_JOIN(t1, t2) */ * from t1 join t2 on t1.i = t2.j order by t2.j;",
8533+
Expected: []sql.Row{
8534+
{2, 2},
8535+
{3, 3},
8536+
},
8537+
},
8538+
{
8539+
Query: "select /*+ MERGE_JOIN(t1, t2) */ * from t1 join t2 on t1.i = t2.j order by t1.i desc;",
8540+
Expected: []sql.Row{
8541+
{3, 3},
8542+
{2, 2},
8543+
},
8544+
},
8545+
{
8546+
Query: "select /*+ MERGE_JOIN(t1, t2) */ * from t1 join t2 on t1.i = t2.j order by t2.j desc;",
8547+
Expected: []sql.Row{
8548+
{3, 3},
8549+
{2, 2},
8550+
},
8551+
},
8552+
8553+
{
8554+
Query: "explain plan select /*+ MERGE_JOIN(t3, t4) */ * from t3 join t3 on t3.i = t4.j order by t3.i;",
8555+
Expected: []sql.Row{
8556+
{2, 2},
8557+
{3, 3},
8558+
},
8559+
},
8560+
},
8561+
},
85098562

85108563
// Char tests
85118564
{

sql/analyzer/replace_sort.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func replaceIdxSortHelper(ctx *sql.Context, scope *plan.Scope, node sql.Node, so
189189
if sameLeft {
190190
newLeft, reversible, err = buildReverseIndexedTable(ctx, newLeft)
191191
} else {
192-
newRight, reversible, err = buildReverseIndexedTable(ctx, newLeft)
192+
newRight, reversible, err = buildReverseIndexedTable(ctx, newRight)
193193
}
194194
if err != nil {
195195
return nil, transform.SameTree, err

0 commit comments

Comments
 (0)