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: automatically explore enforced plans for DataSource if it has already found an unenforced plan #56289

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion pkg/planner/core/find_best_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@ func isPointGetConvertableSchema(ds *DataSource) bool {
// See #46177 for more information.
func exploreEnforcedPlan(ds *DataSource) bool {
// default value is false to keep it compatible with previous versions.
return fixcontrol.GetBoolWithDefault(ds.SCtx().GetSessionVars().GetOptimizerFixControlMap(), fixcontrol.Fix46177, false)
return fixcontrol.GetBoolWithDefault(ds.SCtx().GetSessionVars().GetOptimizerFixControlMap(), fixcontrol.Fix46177, true)
}

func findBestTask4DS(ds *DataSource, prop *property.PhysicalProperty, planCounter *base.PlanCounterTp, opt *optimizetrace.PhysicalOptimizeOp) (t base.Task, cntPlan int64, err error) {
Expand Down
18 changes: 9 additions & 9 deletions tests/integrationtest/r/cte.result
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,9 @@ c1 c1
// Sort should not exist, because tpk.c1 is pk. Not the best plan for now(#25674).
explain with cte1 as (select c1 from tpk) select /*+ MERGE_JOIN(dt1, dt2) */ * from tpk dt1 inner join cte1 dt2 on dt2.c1 = dt1.c1 order by 1, 2;
id estRows task access object operator info
MergeJoin_27 12500.00 root inner join, left key:cte.tpk.c1, right key:cte.tpk.c1
├─TableReader_24(Build) 10000.00 root data:TableFullScan_23
│ └─TableFullScan_23 10000.00 cop[tikv] table:tpk keep order:true, stats:pseudo
MergeJoin_33 12500.00 root inner join, left key:cte.tpk.c1, right key:cte.tpk.c1
├─TableReader_27(Build) 10000.00 root data:TableFullScan_26
│ └─TableFullScan_26 10000.00 cop[tikv] table:tpk keep order:true, stats:pseudo
└─TableReader_22(Probe) 10000.00 root data:TableFullScan_21
└─TableFullScan_21 10000.00 cop[tikv] table:dt1 keep order:true, stats:pseudo
with cte1 as (select c1 from tpk) select /*+ MERGE_JOIN(dt1, dt2) */ * from tpk dt1 inner join cte1 dt2 on dt2.c1 = dt1.c1 order by 1, 2;
Expand Down Expand Up @@ -507,7 +507,7 @@ c1 c1
// Sort should not exist, because tpk is ordered. Not the best plan for now(#25674).
explain with cte1 as (select c1 from tpk order by c1) select /*+ MERGE_JOIN(dt1, dt2) */ * from t1 dt1 inner join cte1 dt2 on dt2.c1 = dt1.c1 order by 1, 2;
id estRows task access object operator info
MergeJoin_23 12487.50 root inner join, left key:cte.t1.c1, right key:cte.tpk.c1
MergeJoin_26 12487.50 root inner join, left key:cte.t1.c1, right key:cte.tpk.c1
├─TableReader_21(Build) 10000.00 root data:TableFullScan_20
│ └─TableFullScan_20 10000.00 cop[tikv] table:tpk keep order:true, stats:pseudo
└─Sort_19(Probe) 9990.00 root cte.t1.c1
Expand Down Expand Up @@ -564,12 +564,12 @@ insert into tpk1 values(1), (2), (3);
explain with cte1 as (select c1 from tpk) select /*+ merge_join(dt1, dt2) */ * from tpk1 dt1 inner join cte1 dt2 inner join cte1 dt3 on dt1.c1 = dt2.c1 and dt2.c1 = dt3.c1;
id estRows task access object operator info
HashJoin_19 12500.00 root inner join, equal:[eq(cte.tpk.c1, cte.tpk.c1)]
├─Selection_28(Build) 8000.00 root not(isnull(cte.tpk.c1))
│ └─CTEFullScan_29 10000.00 root CTE:cte1 AS dt3 data:CTE_0
├─Selection_31(Build) 8000.00 root not(isnull(cte.tpk.c1))
│ └─CTEFullScan_32 10000.00 root CTE:cte1 AS dt3 data:CTE_0
└─MergeJoin_21(Probe) 10000.00 root inner join, left key:cte.tpk1.c1, right key:cte.tpk.c1
├─Sort_27(Build) 8000.00 root cte.tpk.c1
│ └─Selection_25 8000.00 root not(isnull(cte.tpk.c1))
│ └─CTEFullScan_26 10000.00 root CTE:cte1 AS dt2 data:CTE_0
├─Sort_30(Build) 8000.00 root cte.tpk.c1
│ └─Selection_28 8000.00 root not(isnull(cte.tpk.c1))
│ └─CTEFullScan_29 10000.00 root CTE:cte1 AS dt2 data:CTE_0
└─TableReader_23(Probe) 10000.00 root data:TableFullScan_22
└─TableFullScan_22 10000.00 cop[tikv] table:dt1 keep order:true, stats:pseudo
CTE_0 10000.00 root Non-Recursive CTE
Expand Down