Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parser: implement Restore for TableOptimizerHint #151

Closed
wants to merge 1 commit into from

Conversation

exialin
Copy link
Contributor

@exialin exialin commented Jan 4, 2019

Impletment Restore and unit test for TableOptimizerHint.

Issue: pingcap/tidb#8532


Here is a problem that should be resolved before moving on to SelectStmt. The SelectFields of the following two queries are different:

  1. select /*+ TIDB_SMJ(t1) */ * from t1 join t2
*ast.SelectStmt	&{{{{select /*+ TIDB_SMJ(t1) */ * from t1 join t2}}} {[]} 0xc00000f5c0 false 0xc00000a720 <nil> 0xc00000f5f0 <nil> <nil> [] <nil> <nil> none [0xc0000a6d20] false false}
  *ast.TableOptimizerHint	&{{} TIDB_SMJ [t1] 0}
  *ast.TableRefsClause	&{{} 0xc000146080}
    *ast.Join	&{{} {[]} 0xc000054340 0xc000054380 1 <nil> [] false false}
      *ast.TableSource	&{{} 0xc000144090 }
        *ast.TableName	&{{} {[]}  t1 <nil> <nil> []}
      *ast.TableSource	&{{} 0xc000144120 }
        *ast.TableName	&{{} {[]}  t2 <nil> <nil> []}
  *ast.FieldList	&{{} [0xc000058660]}
    *ast.SelectField	&{{} 27 0xc0000a6d70 <nil>  false}
  1. select /*+ TIDB_SMJ(`t1`) */ * from t1 join t2
*ast.SelectStmt	&{{{{select /*+ TIDB_SMJ(`t1`) */ * from t1 join t2}}} {[]} 0xc00000f5c0 false 0xc00000a760 <nil> 0xc00000f5f0 <nil> <nil> [] <nil> <nil> none [0xc0000a2d20] false false}
  *ast.TableOptimizerHint	&{{} TIDB_SMJ [t1] 0}
  *ast.TableRefsClause	&{{} 0xc000146080}
    *ast.Join	&{{} {[]} 0xc000054340 0xc000054380 1 <nil> [] false false}
      *ast.TableSource	&{{} 0xc000144090 }
        *ast.TableName	&{{} {[]}  t1 <nil> <nil> []}
      *ast.TableSource	&{{} 0xc000144120 }
        *ast.TableName	&{{} {[]}  t2 <nil> <nil> []}
  *ast.FieldList	&{{} [0xc000058660]}
    *ast.SelectField	&{{} 29 0xc0000a2d70 <nil>  false}

The only difference is SelectField.Offset, which will count the backquotes put by Restore. For this PR we can wrap identifiers in the source SQL text with backquotes, but there are hundreds of select test cases of SelectStmt and some shall not be handled this way. So any suggestion?

@AndrewDi
Copy link
Contributor

AndrewDi commented Jan 5, 2019

@exialin I have meet the same problem as you said in the first place: The only difference is SelectField.Offset, which will count the backquotes put by Restore
So I create a new nodeFieldCleaner visitor to reset offset in PR #153 , you can have a look.

@zier-one
Copy link
Contributor

zier-one commented Jan 7, 2019

@exialin I have meet the same problem as you said in the first place: The only difference is SelectField.Offset, which will count the backquotes put by Restore
So I create a new nodeFieldCleaner visitor to reset offset in PR #153 , you can have a look.

I think this is a good solution

@zier-one zier-one closed this Jan 9, 2019
@exialin exialin deleted the restore-select branch January 14, 2019 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants