Skip to content

Commit

Permalink
Merge pull request #2002 from actiontech/issue1955-2
Browse files Browse the repository at this point in the history
fix: panic when process join node with using in optimizer
  • Loading branch information
sjjian authored Nov 8, 2023
2 parents 4dad18a + b126a00 commit 027a999
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions sqle/driver/mysql/optimizer/index/optimizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,25 @@ func (o *Optimizer) parseSelectStmt(ss *ast.SelectStmt) {
o.tables[rightCNE.Name.Table.O] = &tableInSelect{joinOnColumn: rightCNE.Name.Name.L}

} else if ss.From.TableRefs.Using != nil {
//FIXME Panic Here by SQL SELECT * FROM table_1 JOIN table_2 on table_1.id = table_2.id JOIN table_3 USING (column_name); USING在最后并且是多表JOIN的最后
leftTableName := left.(*ast.TableSource).Source.(*ast.TableName).Name.O
rightTableName := right.(*ast.TableSource).Source.(*ast.TableName).Name.O
leftSource, ok := left.(*ast.TableSource)
if !ok {
continue
}
leftTable, ok := leftSource.Source.(*ast.TableName)
if !ok {
continue
}
leftTableName := leftTable.Name.O

rightSource, ok := right.(*ast.TableSource)
if !ok {
continue
}
rightTable, ok := rightSource.Source.(*ast.TableName)
if !ok {
continue
}
rightTableName := rightTable.Name.O
for _, col := range ss.From.TableRefs.Using {
o.tables[leftTableName] = &tableInSelect{joinOnColumn: col.Name.L}
o.tables[rightTableName] = &tableInSelect{joinOnColumn: col.Name.L}
Expand Down

0 comments on commit 027a999

Please sign in to comment.