Skip to content

Commit

Permalink
improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
foreyes committed Sep 25, 2019
1 parent ac48ea4 commit 08acb9d
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2049,10 +2049,12 @@ func (b *PlanBuilder) TableHints() *tableHintInfo {

func (b *PlanBuilder) buildSelect(ctx context.Context, sel *ast.SelectStmt) (p LogicalPlan, err error) {
b.pushSelectOffset(sel.QueryBlockOffset)
defer b.popSelectOffset()
b.pushTableHints(sel.TableHints, typeSelect, sel.QueryBlockOffset)
// table hints are only visible in the current SELECT statement.
defer b.popTableHints()
defer func() {
defer b.popSelectOffset()
// table hints are only visible in the current SELECT statement.
defer b.popTableHints()
}()

if sel.SelectStmtOpts != nil {
origin := b.inStraightJoin
Expand Down Expand Up @@ -2700,10 +2702,12 @@ func buildColumns2Handle(

func (b *PlanBuilder) buildUpdate(ctx context.Context, update *ast.UpdateStmt) (Plan, error) {
b.pushSelectOffset(0)
defer b.popSelectOffset()
b.pushTableHints(update.TableHints, typeUpdate, 0)
// table hints are only visible in the current UPDATE statement.
defer b.popTableHints()
defer func() {
defer b.popSelectOffset()
// table hints are only visible in the current UPDATE statement.
defer b.popTableHints()
}()

// update subquery table should be forbidden
var asNameList []string
Expand Down Expand Up @@ -2941,10 +2945,12 @@ func extractTableAsNameForUpdate(p LogicalPlan, asNames map[*model.TableInfo][]*

func (b *PlanBuilder) buildDelete(ctx context.Context, delete *ast.DeleteStmt) (Plan, error) {
b.pushSelectOffset(0)
defer b.popSelectOffset()
b.pushTableHints(delete.TableHints, typeDelete, 0)
// table hints are only visible in the current DELETE statement.
defer b.popTableHints()
defer func() {
defer b.popSelectOffset()
// table hints are only visible in the current DELETE statement.
defer b.popTableHints()
}()

p, err := b.buildResultSetNode(ctx, delete.TableRefs.TableRefs)
if err != nil {
Expand Down

0 comments on commit 08acb9d

Please sign in to comment.