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

plan: move range calculation to package ranger #3208

Merged
merged 15 commits into from
May 9, 2017
Merged

Conversation

winoros
Copy link
Member

@winoros winoros commented May 4, 2017

@@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package plan
package ranger
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to move ranger to util package. Because statistic package still need to use it.

// See the License for the specific language governing permissions and
// limitations under the License.

package util
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't new a util package. If some errors are needed by ranger, just duplicate this error in ranger package.

@@ -0,0 +1,230 @@
package ranger_test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Miss license.

@hanfei1991
Copy link
Member

LGTM @coocood PTAL

@hanfei1991 hanfei1991 added the status/LGT1 Indicates that a PR has LGTM 1. label May 4, 2017
@@ -346,8 +347,8 @@ func (p *DataSource) tryToGetMemTask(prop *requiredProp) (task taskProfile, err
TableAsName: p.TableAsName,
}.init(p.allocator, p.ctx)
memTable.SetSchema(p.schema)
rb := &rangeBuilder{sc: p.ctx.GetSessionVars().StmtCtx}
memTable.Ranges = rb.buildTableRanges(fullRange)
rb := &ranger.Builder{Sc: p.ctx.GetSessionVars().StmtCtx}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you define a helper method to get StmtCtx, I saw redundant "p.ctx.GetSessionVars().StmtCtx"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try to do this in a new pr.

model/model.go Outdated
@@ -119,6 +120,18 @@ func (t *TableInfo) Clone() *TableInfo {
return &nt
}

//GetPkName will return the pk name if pk exitsts.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave a blank.

@@ -83,6 +83,25 @@ func Optimize(ctx context.Context, node ast.Node, is infoschema.InfoSchema) (Pla
return p, nil
}

// BuildLogicalPlan is exported and only used for test.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is only used for test, can we put it in the test?

Copy link
Member Author

@winoros winoros May 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this way will make planBuilder and something exported, more complicated.

model/model.go Outdated
@@ -119,6 +120,18 @@ func (t *TableInfo) Clone() *TableInfo {
return &nt
}

//GetPkName will return the pk name if pk exitsts.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/exitsts/exists

"github.com/pingcap/tidb/expression"
"github.com/pingcap/tidb/model"
"github.com/pingcap/tidb/mysql"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/util/types"
)

var fullRange = []rangePoint{
// FullRange is (-∞,, +∞).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove one ,

@winoros
Copy link
Member Author

winoros commented May 5, 2017

PTAL @coocood @shenli

@coocood coocood self-assigned this May 5, 2017
}

// BuildFromConds is used for test.
func (r *Builder) BuildFromConds(conds []expression.Expression) ([]Point, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just move it to test file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will make more function exported.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@winoros Actually, you can add a foo_internal_test.go in the same package. This way, you do not need to export extra method.

}
}
}
return CIStr{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If pk is not handle, we always return empty string?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and the outside will know whether there is a pk by check this.

@coocood
Copy link
Member

coocood commented May 5, 2017

@winoros
We should implement an AstExprToExpressionForTest function in expression package.
So we can test unexported functions directly, and not expose functions only for test.

@shenli
Copy link
Member

shenli commented May 7, 2017

@winoros Please fix the CI.

@winoros
Copy link
Member Author

winoros commented May 8, 2017

@coocood now i just test the BuildTableRange and BuildIndexRange instead of testing the method of RangeBuilder.

if sf.FuncName.L == ast.EQ && checker.checkScalarFunction(sf) {
return controlTableScan
}
access, _ := ranger.DetachTableScanConditions(corColConds, pkCol.ColName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change this, is this an equivalence transformation?
@winoros

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's the same as the logic inside the DetachTableScanConditions

@XuHuaiyu
Copy link
Contributor

XuHuaiyu commented May 9, 2017

LGTM

@winoros winoros merged commit 9a9db91 into master May 9, 2017
@winoros winoros deleted the yiding/refactor branch May 9, 2017 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/LGT1 Indicates that a PR has LGTM 1.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants