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

Unity 2 #58617

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open

Unity 2 #58617

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup
  • Loading branch information
qw4990 committed Dec 31, 2024
commit e864e378c83a3a293ff9ce8f37e04f80f0b79b46
36 changes: 35 additions & 1 deletion pkg/planner/core/common_plan_gen.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,47 @@
package core

import (
"context"
"encoding/json"
"fmt"
"github.com/pingcap/tidb/pkg/bindinfo"
"github.com/pingcap/tidb/pkg/domain"
"github.com/pingcap/tidb/pkg/parser"
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pingcap/tidb/pkg/parser/model"

"github.com/pingcap/tidb/pkg/planner/core/base"
"github.com/pingcap/tidb/pkg/util/hint"
)

func (e *Explain) unityPlanAll() {
func (e *Explain) unityPlanAll() (string, error) {
p := parser.New()
stmt, err := p.ParseOneStmt(e.SCtx().GetSessionVars().StmtCtx.OriginalSQL, "", "")
if err != nil {
return "", err
}
tableNames := bindinfo.CollectTableNames(stmt)
for _, t := range tableNames {
fmt.Println("?>>>>>>>>>> ", t.Name)
fmt.Println(">>>>>> ", e.tableIndexNames(t))
}
return "", nil
}

func (e *Explain) tableIndexNames(t *ast.TableName) (idxNames []string) {
is := domain.GetDomain(e.SCtx()).InfoSchema()
schema := t.Schema
if schema.L == "" {
schema = model.NewCIStr(e.SCtx().GetSessionVars().CurrentDB)
}
tt, err := is.TableByName(context.Background(), schema, t.Name)
if err != nil {
panic(err)
}
for _, idx := range tt.Indices() {
idxNames = append(idxNames, idx.Meta().Name.O)
}
return
}

func (e *Explain) unityPlanOne() (string, error) {
Expand Down
6 changes: 5 additions & 1 deletion pkg/planner/core/common_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,11 @@ func (e *Explain) RenderResult() error {
}
e.Rows = append(e.Rows, []string{planJSON})
case types.ExplainFormatUnityPlanAll:
panic("TODO")
planJSON, err := e.unityPlanOne()
if err != nil {
return err
}
e.Rows = append(e.Rows, []string{planJSON})
case types.ExplainFormatUnityJoin:
panic("TODO")
default:
Expand Down