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

planner: support the view hint #39158

Merged
merged 12 commits into from
Nov 17, 2022
2 changes: 1 addition & 1 deletion executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ func (e *hugeMemTableRetriever) dataForColumnsInTable(ctx context.Context, sctx
if err := runWithSystemSession(sctx, func(s sessionctx.Context) error {
planBuilder, _ := plannercore.NewPlanBuilder().Init(s, is, &hint.BlockHintProcessor{})
var err error
viewLogicalPlan, err = planBuilder.BuildDataSourceFromView(ctx, schema.Name, tbl)
viewLogicalPlan, err = planBuilder.BuildDataSourceFromView(ctx, schema.Name, tbl, nil, nil)
return errors.Trace(err)
}); err != nil {
sctx.GetSessionVars().StmtCtx.AppendWarning(err)
Expand Down
2 changes: 1 addition & 1 deletion executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -1904,7 +1904,7 @@ func tryFillViewColumnType(ctx context.Context, sctx sessionctx.Context, is info
return runWithSystemSession(sctx, func(s sessionctx.Context) error {
// Retrieve view columns info.
planBuilder, _ := plannercore.NewPlanBuilder().Init(s, is, &hint.BlockHintProcessor{})
if viewLogicalPlan, err := planBuilder.BuildDataSourceFromView(ctx, dbName, tbl); err == nil {
if viewLogicalPlan, err := planBuilder.BuildDataSourceFromView(ctx, dbName, tbl, nil, nil); err == nil {
viewSchema := viewLogicalPlan.Schema()
viewOutputNames := viewLogicalPlan.OutputNames()
for _, col := range tbl.Columns {
Expand Down
27 changes: 22 additions & 5 deletions parser/ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1808,9 +1808,10 @@ type StatisticsSpec struct {

// CreateStatisticsStmt is a statement to create extended statistics.
// Examples:
// CREATE STATISTICS stats1 (cardinality) ON t(a, b, c);
// CREATE STATISTICS stats2 (dependency) ON t(a, b);
// CREATE STATISTICS stats3 (correlation) ON t(a, b);
//
// CREATE STATISTICS stats1 (cardinality) ON t(a, b, c);
// CREATE STATISTICS stats2 (dependency) ON t(a, b);
// CREATE STATISTICS stats3 (correlation) ON t(a, b);
type CreateStatisticsStmt struct {
stmtNode

Expand Down Expand Up @@ -1878,7 +1879,8 @@ func (n *CreateStatisticsStmt) Accept(v Visitor) (Node, bool) {

// DropStatisticsStmt is a statement to drop extended statistics.
// Examples:
// DROP STATISTICS stats1;
//
// DROP STATISTICS stats1;
type DropStatisticsStmt struct {
stmtNode

Expand Down Expand Up @@ -2009,6 +2011,7 @@ const (
)

// ShowSlow is used for the following command:
//
// admin show slow top [ internal | all] N
// admin show slow recent N
type ShowSlow struct {
Expand Down Expand Up @@ -3464,9 +3467,13 @@ func (n *TableOptimizerHint) Restore(ctx *format.RestoreCtx) error {
}
ctx.WriteName(n.QBName.String())
}
if n.HintName.L == "qb_name" && len(n.Tables) == 0 {
ctx.WritePlain(")")
return nil
}
// Hints without args except query block.
switch n.HintName.L {
case "hash_agg", "stream_agg", "agg_to_cop", "read_consistent_replica", "no_index_merge", "qb_name", "ignore_plan_cache", "limit_to_cop", "straight_join":
case "hash_agg", "stream_agg", "agg_to_cop", "read_consistent_replica", "no_index_merge", "ignore_plan_cache", "limit_to_cop", "straight_join":
ctx.WritePlain(")")
return nil
}
Expand Down Expand Up @@ -3495,6 +3502,16 @@ func (n *TableOptimizerHint) Restore(ctx *format.RestoreCtx) error {
}
ctx.WriteName(index.String())
}
case "qb_name":
if len(n.Tables) > 0 {
ctx.WritePlain(", ")
for i, table := range n.Tables {
if i != 0 {
ctx.WritePlain(". ")
}
table.Restore(ctx)
}
}
case "use_toja", "use_cascades":
if n.HintData.(bool) {
ctx.WritePlain("TRUE")
Expand Down
Loading