forked from pingcap/tidb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executor, optimizer: new executor and optimizer implementation
- Loading branch information
Showing
26 changed files
with
1,376 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright 2015 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package executor | ||
|
||
import ( | ||
"github.com/pingcap/tidb/context" | ||
"github.com/pingcap/tidb/field" | ||
"github.com/pingcap/tidb/infoschema" | ||
"github.com/pingcap/tidb/optimizer/plan" | ||
oplan "github.com/pingcap/tidb/plan" | ||
"github.com/pingcap/tidb/rset" | ||
"github.com/pingcap/tidb/util/format" | ||
) | ||
|
||
// adapter wraps a executor, implements rset.Recordset interface | ||
type recordsetAdapter struct { | ||
fields []*field.ResultField | ||
executor Executor | ||
} | ||
|
||
func (a *recordsetAdapter) Do(f func(data []interface{}) (bool, error)) error { | ||
return nil | ||
} | ||
|
||
func (a *recordsetAdapter) Fields() ([]*field.ResultField, error) { | ||
return nil, nil | ||
} | ||
|
||
func (a *recordsetAdapter) FirstRow() ([]interface{}, error) { | ||
return nil, nil | ||
} | ||
|
||
func (a *recordsetAdapter) Rows(limit, offset int) ([][]interface{}, error) { | ||
return nil, nil | ||
} | ||
|
||
func (a *recordsetAdapter) Next() (*oplan.Row, error) { | ||
return nil, nil | ||
} | ||
|
||
func (a *recordsetAdapter) Close() error { | ||
return nil | ||
} | ||
|
||
type statementAdapter struct { | ||
is infoschema.InfoSchema | ||
plan plan.Plan | ||
} | ||
|
||
func (a *statementAdapter) Explain(ctx context.Context, w format.Formatter) { | ||
return | ||
} | ||
|
||
func (a *statementAdapter) OriginText() string { | ||
return "" | ||
} | ||
|
||
func (a *statementAdapter) SetText(text string) { | ||
return | ||
} | ||
|
||
func (a *statementAdapter) IsDDL() bool { | ||
return false | ||
} | ||
|
||
func (a *statementAdapter) Exec(ctx context.Context) (rset.Recordset, error) { | ||
b := newExecutorBuilder(ctx, a.is) | ||
e := b.build(a.plan) | ||
return &recordsetAdapter{ | ||
executor: e, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2015 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package executor | ||
|
||
import ( | ||
"github.com/pingcap/tidb/context" | ||
"github.com/pingcap/tidb/infoschema" | ||
"github.com/pingcap/tidb/optimizer/plan" | ||
) | ||
|
||
// executorBuilder builds an Executor from a Plan. | ||
// the InfoSchema must be the same one used in InfoBinder. | ||
type executorBuilder struct { | ||
ctx context.Context | ||
is infoschema.InfoSchema | ||
} | ||
|
||
func newExecutorBuilder(ctx context.Context, is infoschema.InfoSchema) *executorBuilder { | ||
return &executorBuilder{ | ||
ctx: ctx, | ||
is: is, | ||
} | ||
} | ||
|
||
func (b *executorBuilder) build(p plan.Plan) Executor { | ||
switch v := p.(type) { | ||
case *plan.TableScan: | ||
return b.buildTableScan(v) | ||
case *plan.IndexScan: | ||
return b.buildIndexScan(v) | ||
} | ||
return nil | ||
} | ||
|
||
func (b *executorBuilder) buildTableScan(v *plan.TableScan) Executor { | ||
table, _ := b.is.TableByID(v.Table.ID) | ||
return &TableScanExec{ | ||
t: table, | ||
} | ||
} | ||
|
||
func (b *executorBuilder) buildIndexScan(v *plan.IndexScan) Executor { | ||
table, _ := b.is.TableByID(v.Table.ID) | ||
e := &IndexScanExec{ | ||
Table: table, | ||
} | ||
return e | ||
} |
Oops, something went wrong.