Skip to content

Commit

Permalink
This is an automated cherry-pick of #33567
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
  • Loading branch information
winoros authored and ti-chi-bot committed Feb 1, 2024
1 parent e62ed60 commit 75f5360
Show file tree
Hide file tree
Showing 6 changed files with 2,136 additions and 0 deletions.
1,591 changes: 1,591 additions & 0 deletions executor/aggregate_test.go

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions pkg/planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"unicode"

"github.com/pingcap/errors"
<<<<<<< HEAD:pkg/planner/core/logical_plan_builder.go
"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/pkg/domain"
"github.com/pingcap/tidb/pkg/expression"
Expand Down Expand Up @@ -67,6 +68,41 @@ import (
"github.com/pingcap/tidb/pkg/util/set"
"github.com/pingcap/tidb/pkg/util/size"
"github.com/pingcap/tipb/go-tipb"
=======
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/expression"
"github.com/pingcap/tidb/expression/aggregation"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/metrics"
"github.com/pingcap/tidb/parser"
"github.com/pingcap/tidb/parser/ast"
"github.com/pingcap/tidb/parser/format"
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/parser/mysql"
"github.com/pingcap/tidb/parser/opcode"
"github.com/pingcap/tidb/parser/terror"
fd "github.com/pingcap/tidb/planner/funcdep"
"github.com/pingcap/tidb/planner/property"
"github.com/pingcap/tidb/planner/util"
"github.com/pingcap/tidb/privilege"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/statistics"
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/table/tables"
"github.com/pingcap/tidb/table/temptable"
"github.com/pingcap/tidb/types"
driver "github.com/pingcap/tidb/types/parser_driver"
util2 "github.com/pingcap/tidb/util"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/collate"
"github.com/pingcap/tidb/util/dbterror"
"github.com/pingcap/tidb/util/hack"
"github.com/pingcap/tidb/util/logutil"
"github.com/pingcap/tidb/util/plancodec"
"github.com/pingcap/tidb/util/set"
>>>>>>> 571d97bb16f (planner: using the funcdep to check the only_full_group_by (#33567)):planner/core/logical_plan_builder.go
)

const (
Expand Down Expand Up @@ -3827,8 +3863,14 @@ type aggColNameResolver struct {
colNameResolver
}

<<<<<<< HEAD:pkg/planner/core/logical_plan_builder.go
func (*aggColNameResolver) Enter(inNode ast.Node) (ast.Node, bool) {
if _, ok := inNode.(*ast.ColumnNameExpr); ok {
=======
func (c *aggColNameResolver) Enter(inNode ast.Node) (ast.Node, bool) {
switch inNode.(type) {
case *ast.ColumnNameExpr:
>>>>>>> 571d97bb16f (planner: using the funcdep to check the only_full_group_by (#33567)):planner/core/logical_plan_builder.go
return inNode, true
}
return inNode, false
Expand Down
27 changes: 27 additions & 0 deletions pkg/planner/core/logical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"math"
"unsafe"

<<<<<<< HEAD:pkg/planner/core/logical_plans.go
"github.com/pingcap/tidb/pkg/expression"
"github.com/pingcap/tidb/pkg/expression/aggregation"
"github.com/pingcap/tidb/pkg/infoschema"
Expand All @@ -40,6 +41,24 @@ import (
"github.com/pingcap/tidb/pkg/util/ranger"
"github.com/pingcap/tidb/pkg/util/size"
"github.com/pingcap/tipb/go-tipb"
=======
"github.com/pingcap/tidb/expression"
"github.com/pingcap/tidb/expression/aggregation"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/parser/ast"
"github.com/pingcap/tidb/parser/auth"
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/parser/mysql"
fd "github.com/pingcap/tidb/planner/funcdep"
"github.com/pingcap/tidb/planner/property"
"github.com/pingcap/tidb/planner/util"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/statistics"
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/logutil"
"github.com/pingcap/tidb/util/ranger"
>>>>>>> 571d97bb16f (planner: using the funcdep to check the only_full_group_by (#33567)):planner/core/logical_plans.go
"go.uber.org/zap"
)

Expand Down Expand Up @@ -367,12 +386,20 @@ func (p *LogicalJoin) extractFDForOuterJoin(filtersFromApply []expression.Expres
opt.SkipFDRule331 = true
}

<<<<<<< HEAD:pkg/planner/core/logical_plans.go
opt.OnlyInnerFilter = len(eqCondSlice) == 0 && len(outerCondition) == 0 && len(p.OtherConditions) == 0
=======
opt.OnlyInnerFilter = len(eqCondSlice) == 0 && len(outerCondition) == 0
>>>>>>> 571d97bb16f (planner: using the funcdep to check the only_full_group_by (#33567)):planner/core/logical_plans.go
if opt.OnlyInnerFilter {
// if one of the inner condition is constant false, the inner side are all null, left make constant all of that.
for _, one := range innerCondition {
if c, ok := one.(*expression.Constant); ok && c.DeferredExpr == nil && c.ParamMarker == nil {
<<<<<<< HEAD:pkg/planner/core/logical_plans.go
if isTrue, err := c.Value.ToBool(p.SCtx().GetSessionVars().StmtCtx); err == nil {
=======
if isTrue, err := c.Value.ToBool(p.ctx.GetSessionVars().StmtCtx); err == nil {
>>>>>>> 571d97bb16f (planner: using the funcdep to check the only_full_group_by (#33567)):planner/core/logical_plans.go
if isTrue == 0 {
// c is false
opt.InnerIsFalse = true
Expand Down
59 changes: 59 additions & 0 deletions pkg/planner/funcdep/extract_fd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"testing"

<<<<<<< HEAD:pkg/planner/funcdep/extract_fd_test.go
"github.com/pingcap/tidb/pkg/domain"
"github.com/pingcap/tidb/pkg/infoschema"
"github.com/pingcap/tidb/pkg/parser"
Expand All @@ -27,6 +28,15 @@ import (
"github.com/pingcap/tidb/pkg/sessiontxn"
"github.com/pingcap/tidb/pkg/testkit"
"github.com/pingcap/tidb/pkg/util/hint"
=======
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/parser"
plannercore "github.com/pingcap/tidb/planner/core"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/util/hint"
>>>>>>> 571d97bb16f (planner: using the funcdep to check the only_full_group_by (#33567)):planner/funcdep/extract_fd_test.go
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -381,3 +391,52 @@ func TestFDSet_MakeOuterJoin(t *testing.T) {
require.Equal(t, tt.fd, plannercore.FDToString(p.(plannercore.LogicalPlan)), comment)
}
}

func TestFDSet_MakeOuterJoin(t *testing.T) {
store, clean := testkit.CreateMockStore(t)
defer clean()
par := parser.New()
par.SetParserConfig(parser.ParserConfig{EnableWindowFunction: true, EnableStrictDoubleTypeCheck: true})

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("set @@session.tidb_enable_new_only_full_group_by_check = 'on';")
tk.MustExec("CREATE TABLE X (a INT PRIMARY KEY, b INT, c INT, d INT, e INT)")
tk.MustExec("CREATE UNIQUE INDEX uni ON X (b, c)")
tk.MustExec("CREATE TABLE Y (m INT, n INT, p INT, q INT, PRIMARY KEY (m, n))")

tests := []struct {
sql string
best string
fd string
}{
{
sql: "select * from X left outer join (select *, p+q from Y) Y1 ON true",
best: "Join{DataScan(X)->DataScan(Y)->Projection}->Projection",
fd: "{(1)-->(2-5), (2,3)~~>(1,4,5), (6,7)-->(8,9,11), (8,9)-->(11), (1,6,7)-->(2-5,8,9,11)} >>> {(1)-->(2-5), (2,3)~~>(1,4,5), (6,7)-->(8,9,11), (8,9)-->(11), (1,6,7)-->(2-5,8,9,11)}",
},
}

ctx := context.TODO()
is := testGetIS(t, tk.Session())
for i, tt := range tests {
comment := fmt.Sprintf("case:%v sql:%s", i, tt.sql)
stmt, err := par.ParseOneStmt(tt.sql, "", "")
require.NoError(t, err, comment)
tk.Session().GetSessionVars().PlanID = 0
tk.Session().GetSessionVars().PlanColumnID = 0
err = plannercore.Preprocess(tk.Session(), stmt, plannercore.WithPreprocessorReturn(&plannercore.PreprocessorReturn{InfoSchema: is}))
require.NoError(t, err, comment)
tk.Session().PrepareTSFuture(ctx)
builder, _ := plannercore.NewPlanBuilder().Init(tk.Session(), is, &hint.BlockHintProcessor{})
// extract FD to every OP
p, err := builder.Build(ctx, stmt)
require.NoError(t, err, comment)
p, err = plannercore.LogicalOptimizeTest(ctx, builder.GetOptFlag(), p.(plannercore.LogicalPlan))
require.NoError(t, err, comment)
require.Equal(t, tt.best, plannercore.ToString(p), comment)
// extract FD to every OP
p.(plannercore.LogicalPlan).ExtractFD()
require.Equal(t, tt.fd, plannercore.FDToString(p.(plannercore.LogicalPlan)), comment)
}
}
Loading

0 comments on commit 75f5360

Please sign in to comment.