@@ -19,6 +19,7 @@ import (
19
19
"fmt"
20
20
"testing"
21
21
22
+ << << << < HEAD :pkg / planner / funcdep / extract_fd_test.go
22
23
"github.com/pingcap/tidb/pkg/domain"
23
24
"github.com/pingcap/tidb/pkg/infoschema"
24
25
"github.com/pingcap/tidb/pkg/parser"
@@ -27,6 +28,15 @@ import (
27
28
"github.com/pingcap/tidb/pkg/sessiontxn"
28
29
"github.com/pingcap/tidb/pkg/testkit"
29
30
"github.com/pingcap/tidb/pkg/util/hint"
31
+ == == == =
32
+ "github.com/pingcap/tidb/domain"
33
+ "github.com/pingcap/tidb/infoschema"
34
+ "github.com/pingcap/tidb/parser"
35
+ plannercore "github.com/pingcap/tidb/planner/core"
36
+ "github.com/pingcap/tidb/sessionctx"
37
+ "github.com/pingcap/tidb/testkit"
38
+ "github.com/pingcap/tidb/util/hint"
39
+ >> >> >> > 571 d97bb16f (planner : using the funcdep to check the only_full_group_by (#33567 )):planner / funcdep / extract_fd_test .go
30
40
"github.com/stretchr/testify/require"
31
41
)
32
42
@@ -381,3 +391,52 @@ func TestFDSet_MakeOuterJoin(t *testing.T) {
381
391
require .Equal (t , tt .fd , plannercore .FDToString (p .(plannercore.LogicalPlan )), comment )
382
392
}
383
393
}
394
+
395
+ func TestFDSet_MakeOuterJoin (t * testing.T ) {
396
+ store , clean := testkit .CreateMockStore (t )
397
+ defer clean ()
398
+ par := parser .New ()
399
+ par .SetParserConfig (parser.ParserConfig {EnableWindowFunction : true , EnableStrictDoubleTypeCheck : true })
400
+
401
+ tk := testkit .NewTestKit (t , store )
402
+ tk .MustExec ("use test" )
403
+ tk .MustExec ("set @@session.tidb_enable_new_only_full_group_by_check = 'on';" )
404
+ tk .MustExec ("CREATE TABLE X (a INT PRIMARY KEY, b INT, c INT, d INT, e INT)" )
405
+ tk .MustExec ("CREATE UNIQUE INDEX uni ON X (b, c)" )
406
+ tk .MustExec ("CREATE TABLE Y (m INT, n INT, p INT, q INT, PRIMARY KEY (m, n))" )
407
+
408
+ tests := []struct {
409
+ sql string
410
+ best string
411
+ fd string
412
+ }{
413
+ {
414
+ sql : "select * from X left outer join (select *, p+q from Y) Y1 ON true" ,
415
+ best : "Join{DataScan(X)->DataScan(Y)->Projection}->Projection" ,
416
+ 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)}" ,
417
+ },
418
+ }
419
+
420
+ ctx := context .TODO ()
421
+ is := testGetIS (t , tk .Session ())
422
+ for i , tt := range tests {
423
+ comment := fmt .Sprintf ("case:%v sql:%s" , i , tt .sql )
424
+ stmt , err := par .ParseOneStmt (tt .sql , "" , "" )
425
+ require .NoError (t , err , comment )
426
+ tk .Session ().GetSessionVars ().PlanID = 0
427
+ tk .Session ().GetSessionVars ().PlanColumnID = 0
428
+ err = plannercore .Preprocess (tk .Session (), stmt , plannercore .WithPreprocessorReturn (& plannercore.PreprocessorReturn {InfoSchema : is }))
429
+ require .NoError (t , err , comment )
430
+ tk .Session ().PrepareTSFuture (ctx )
431
+ builder , _ := plannercore .NewPlanBuilder ().Init (tk .Session (), is , & hint.BlockHintProcessor {})
432
+ // extract FD to every OP
433
+ p , err := builder .Build (ctx , stmt )
434
+ require .NoError (t , err , comment )
435
+ p , err = plannercore .LogicalOptimizeTest (ctx , builder .GetOptFlag (), p .(plannercore.LogicalPlan ))
436
+ require .NoError (t , err , comment )
437
+ require .Equal (t , tt .best , plannercore .ToString (p ), comment )
438
+ // extract FD to every OP
439
+ p .(plannercore.LogicalPlan ).ExtractFD ()
440
+ require .Equal (t , tt .fd , plannercore .FDToString (p .(plannercore.LogicalPlan )), comment )
441
+ }
442
+ }
0 commit comments